index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="jnpf-signature" :class="align=='right'?'flex-end':'flex-start'">
  3. <view class="jnpf-signature-box">
  4. <template v-if="showBtn">
  5. <image class="jnpf-signature-img" :src="jnpf.getAuthImgUrl(innerValue)" mode="scaleToFill"
  6. v-show="innerValue" @tap.stop="handlePreviewImage(innerValue)" />
  7. <view class="jnpf-signature-btn" :class="{'jnpf-signature-disabled':disabled}" v-if="!detailed"
  8. @click="open()">
  9. <i class="icon-ym icon-ym-signature1" />
  10. <view class="title" v-if="!innerValue">电子签章</view>
  11. </view>
  12. </template>
  13. </view>
  14. <MultSelect :show="show" :list="options" @confirm="confirm" @close="show = false" :default-value="defaultValue"
  15. filterable />
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. getListByIds
  21. } from '@/api/signature.js'
  22. import MultSelect from '@/components/MultSelect'
  23. import jnpf from '@/utils/jnpf'
  24. export default {
  25. name: 'jnpf-sign',
  26. components: {
  27. MultSelect
  28. },
  29. props: {
  30. modelValue: {
  31. type: [String, Number, Boolean],
  32. },
  33. disabled: {
  34. type: Boolean,
  35. default: false
  36. },
  37. detailed: {
  38. type: Boolean,
  39. default: false
  40. },
  41. showBtn: {
  42. type: Boolean,
  43. default: true
  44. },
  45. align: {
  46. type: String,
  47. default: 'right'
  48. },
  49. ableIds: {
  50. type: Array,
  51. default: () => []
  52. }
  53. },
  54. data() {
  55. return {
  56. innerValue: '',
  57. show: false,
  58. options: [],
  59. defaultValue: []
  60. }
  61. },
  62. watch: {
  63. modelValue: {
  64. handler(val) {
  65. this.innerValue = val || ''
  66. },
  67. immediate: true,
  68. }
  69. },
  70. methods: {
  71. getListByIds() {
  72. getListByIds({
  73. 'ids': this.ableIds
  74. }).then(res => {
  75. this.options = res.data.list || []
  76. const index = this.options.findIndex(o => this.innerValue === o.icon)
  77. if (index > -1) this.defaultValue = [this.options[index].id]
  78. this.show = true
  79. })
  80. },
  81. open() {
  82. if (this.disabled) return
  83. if (!this.ableIds.length) return this.show = true
  84. if (this.ableIds.length) this.getListByIds()
  85. },
  86. confirm(val) {
  87. if (!val.length) return
  88. this.innerValue = val[0].icon || ''
  89. this.$emit('update:modelValue', this.innerValue)
  90. this.$emit('change', val[0])
  91. },
  92. handlePreviewImage(url) {
  93. // #ifdef H5
  94. uni.previewImage({
  95. urls: [jnpf.getAuthImgUrl(url)],
  96. current: url,
  97. success: () => {},
  98. fail: () => {
  99. uni.showToast({
  100. title: '预览图片失败',
  101. icon: 'none'
  102. });
  103. }
  104. });
  105. // #endif
  106. }
  107. }
  108. }
  109. </script>
  110. <style scoped lang="scss">
  111. .jnpf-signature {
  112. width: 100%;
  113. display: flex;
  114. align-items: center;
  115. &.flex-end {
  116. justify-content: flex-end;
  117. }
  118. &.flex-start {
  119. justify-content: flex-start;
  120. }
  121. .jnpf-signature-box {
  122. display: flex;
  123. }
  124. .jnpf-signature-img {
  125. width: 160rpx;
  126. height: 80rpx;
  127. flex-shrink: 0;
  128. }
  129. .jnpf-signature-btn {
  130. color: #2188ff;
  131. width: 100%;
  132. display: flex;
  133. flex-shrink: 0;
  134. &.jnpf-signature-disabled {
  135. color: #9B9B9B !important;
  136. }
  137. .icon-ym-signature1 {
  138. font-size: 52rpx;
  139. }
  140. .title {
  141. font-size: 28rpx;
  142. }
  143. }
  144. }
  145. </style>