index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="jnpf-sign" :class="align=='right'?'flex-end':'flex-start'" v-if="signType === 'currency'">
  3. <view class="jnpf-sign-box">
  4. <template v-if="showBtn">
  5. <image class="jnpf-sign-img" :src="innerValue" mode="scaleToFill" v-show="innerValue"
  6. @tap.stop="handlePreviewImage(innerValue)" />
  7. <view class="jnpf-sign-btn" :class="{'jnpf-sign-disabled':disabled}" v-if="!detailed && !isInvoke"
  8. @click="addSign()">
  9. <i class="icon-ym icon-ym-signature" />
  10. <view class="title" v-if="!innerValue">{{ signTip }}</view>
  11. </view>
  12. <view class="jnpf-sign-btn" :class="{'jnpf-sign-disabled':disabled}" v-if="!detailed && isInvoke"
  13. @click="showSignMode()">
  14. <i class="icon-ym icon-ym-signature" />
  15. <view class="title" v-if="!innerValue">{{ signTip }}</view>
  16. </view>
  17. </template>
  18. </view>
  19. </view>
  20. <view class="u-flex signature-box" v-else>
  21. <view class="jnpf-sign-btn" :class="{'jnpf-sign-disabled':disabled}" @click="showSignMode()">
  22. <i class="icon-ym icon-ym-signature" />
  23. <view class="title">添加签名</view>
  24. </view>
  25. <image class="jnpf-sign-img" :src="modelValue" mode="scaleToFill" v-show="modelValue "
  26. @tap.stop="handlePreviewImage(modelValue )" />
  27. </view>
  28. <u-action-sheet :list="signOptions" v-model="signMode" @click="handleCommand"></u-action-sheet>
  29. <Sign ref="sign" @input="setValue" />
  30. </template>
  31. <script>
  32. import Sign from './Sign.vue'
  33. export default {
  34. name: 'jnpf-sign',
  35. emits: ['change', 'update:modelValue'],
  36. components: {
  37. Sign
  38. },
  39. props: {
  40. modelValue: {
  41. type: [String, Number, Boolean],
  42. },
  43. fieldKey: {
  44. type: String,
  45. default: ''
  46. },
  47. signTip: {
  48. type: String,
  49. default: '添加签名'
  50. },
  51. disabled: {
  52. type: Boolean,
  53. default: false
  54. },
  55. detailed: {
  56. type: Boolean,
  57. default: false
  58. },
  59. align: {
  60. type: String,
  61. default: 'right'
  62. },
  63. showBtn: {
  64. type: Boolean,
  65. default: true
  66. },
  67. defaultCurrent: {
  68. type: Boolean,
  69. default: false
  70. }, // 默认签名
  71. isInvoke: {
  72. type: Boolean,
  73. default: false
  74. }, // 调用签名
  75. signType: {
  76. type: String,
  77. default: 'currency'
  78. },
  79. },
  80. data() {
  81. return {
  82. innerValue: '',
  83. signMode: false,
  84. signList: [],
  85. signOptions: [{
  86. value: '1',
  87. text: '手写签名'
  88. }, {
  89. value: '2',
  90. text: '调用签名'
  91. }],
  92. }
  93. },
  94. created() {
  95. uni.$on('setSignValue', (res) => {
  96. let fieldKey = uni.getStorageSync('sign-fieldKey')
  97. if (this.fieldKey == fieldKey) this.setValue(res)
  98. })
  99. },
  100. onLoad(e) {
  101. this.$nextTick(async () => {
  102. await this.getSignData()
  103. })
  104. },
  105. onUnload() {
  106. uni.$off('setSignValue')
  107. },
  108. watch: {
  109. modelValue: {
  110. handler(val) {
  111. this.innerValue = val || ''
  112. },
  113. deep: true,
  114. immediate: true
  115. },
  116. },
  117. methods: {
  118. showSignMode() {
  119. if (this.disabled) return
  120. this.signMode = true
  121. },
  122. handleCommand(index) {
  123. if (index !== 1) return this.addSign()
  124. uni.navigateTo({
  125. url: '/pages/apply/interPage/signInvokeList' + '?fieldKey=' + this.fieldKey + '&signVal=' +
  126. encodeURIComponent(this.modelValue)
  127. })
  128. },
  129. addSign() {
  130. if (this.disabled) return
  131. this.$nextTick(() => {
  132. this.$refs.sign.showSignature();
  133. })
  134. },
  135. setValue(val) {
  136. if (!val) return
  137. this.innerValue = val
  138. this.$emit('update:modelValue', val)
  139. this.$emit('change', val)
  140. },
  141. handlePreviewImage(url) {
  142. // #ifndef MP
  143. uni.previewImage({
  144. urls: [url],
  145. current: url,
  146. success: () => {},
  147. fail: () => {
  148. uni.showToast({
  149. title: '预览图片失败',
  150. icon: 'none'
  151. });
  152. }
  153. });
  154. // #endif
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss">
  160. .signature-box {
  161. width: 100%;
  162. border-top: 1rpx solid #fbfbfc;
  163. justify-content: space-between;
  164. .jnpf-sign-btn {
  165. color: #2188ff;
  166. display: flex;
  167. flex-shrink: 0;
  168. height: 56rpx;
  169. .icon-ym-signature {
  170. font-size: 52rpx;
  171. }
  172. .title {
  173. line-height: 56rpx;
  174. font-size: 28rpx;
  175. }
  176. }
  177. .jnpf-sign-img {
  178. width: 160rpx;
  179. height: 56rpx;
  180. flex-shrink: 0;
  181. background-color: #fff !important;
  182. }
  183. }
  184. .jnpf-sign {
  185. width: 100%;
  186. display: flex;
  187. align-items: center;
  188. &.flex-end {
  189. justify-content: flex-end;
  190. }
  191. &.flex-start {
  192. justify-content: flex-start;
  193. }
  194. .jnpf-sign-box {
  195. display: flex;
  196. }
  197. .jnpf-sign-img {
  198. width: 160rpx;
  199. height: 80rpx;
  200. flex-shrink: 0;
  201. }
  202. .jnpf-sign-btn {
  203. color: #2188ff;
  204. width: 100%;
  205. display: flex;
  206. flex-shrink: 0;
  207. height: 56rpx;
  208. &.jnpf-sign-disabled {
  209. color: #9B9B9B !important;
  210. }
  211. .icon-ym-signature {
  212. font-size: 52rpx;
  213. }
  214. .title {
  215. line-height: 56rpx;
  216. font-size: 28rpx;
  217. }
  218. }
  219. }
  220. </style>