index.vue 2.9 KB

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