wk-field-file.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view
  3. :class="{actived: fileList.length > 0}"
  4. class="wk-field-file">
  5. <view class="wk-field" @click.stop="handleChoose">
  6. <view v-if="_label" class="wk-field__label">
  7. <view v-if="field.isNull === 1" class="line" />
  8. <image :src="$static('images/icon/clip.png')" class="label-icon-file" />
  9. <text class="label-text">
  10. {{ _label }}
  11. </text>
  12. <view class="add-icon">
  13. <text class="wk wk-plus" />
  14. </view>
  15. </view>
  16. </view>
  17. <wk-file-content
  18. :list="fileList"
  19. show-delete
  20. @delete="handleDelete" />
  21. </view>
  22. </template>
  23. <script>
  24. import { FileDeleteById } from 'API/file'
  25. import mixins from './mixins'
  26. import WkFile from '@/utils/file.js'
  27. import { isArray } from '@/utils/types.js'
  28. export default {
  29. name: 'WkFieldFile',
  30. mixins: [mixins],
  31. data() {
  32. return {
  33. valueStr: '',
  34. fileList: [],
  35. batchId: ''
  36. }
  37. },
  38. watch: {
  39. field: {
  40. handler() {
  41. if (this.$isEmpty(this.field.value)) {
  42. this.fileList = []
  43. } else {
  44. this.fileList = isArray(this.field.value) ? this.field.value : []
  45. }
  46. if (this.fileList.length > 0) {
  47. this.batchId = this.fileList[0].batchId
  48. } else {
  49. this.batchId = ''
  50. }
  51. },
  52. deep: true,
  53. immediate: true
  54. }
  55. },
  56. methods: {
  57. handleChoose() {
  58. // if (this.config && this.config.batchId) {
  59. // this.batchId = this.config.batchId
  60. // }
  61. const params = { type: 'file' }
  62. if (this.batchId) {
  63. params.batchId = this.batchId
  64. }
  65. let fileObj = new WkFile(params)
  66. fileObj.choose().then(response => {
  67. this.batchId = response[0].batchId
  68. this.fileList = this.fileList.concat(response)
  69. fileObj = null
  70. this.emitEvt()
  71. })
  72. },
  73. handleDelete(index, item) {
  74. FileDeleteById({
  75. id: item.fileId
  76. }).then(() => {
  77. this.fileList.splice(index, 1)
  78. if (this.fileList.length === 0) {
  79. this.batchId = ''
  80. this.emitEvt()
  81. }
  82. }).catch()
  83. },
  84. emitEvt() {
  85. this.$emit('input', this.fileList)
  86. this.$emit('change', {
  87. index: this.index,
  88. field: this.field,
  89. value: this.fileList
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style scoped lang="scss">
  96. @import './wkField.scss';
  97. .wk-field-file {
  98. .wk-field {
  99. border-bottom: 0 none;
  100. .wk-field__label {
  101. @include left;
  102. .label-icon-file {
  103. width: 32rpx;
  104. height: 32rpx;
  105. margin-right: 10rpx;
  106. }
  107. .label-text {
  108. flex: 1;
  109. }
  110. .add-icon {
  111. width: 38rpx;
  112. height: 38rpx;
  113. background-color: #E1E1E1;
  114. border-radius: 50%;
  115. @include center;
  116. .wk {
  117. font-size: $wk-font-mini;
  118. line-height: normal;
  119. color: white;
  120. }
  121. }
  122. }
  123. }
  124. .add-btn {
  125. font-size: 26rpx;
  126. color: $theme-color;
  127. padding-bottom: 20rpx;
  128. @include right;
  129. .plus-icon {
  130. width: 22rpx;
  131. height: 22rpx;
  132. margin-right: 20rpx;
  133. }
  134. }
  135. }
  136. .actived {
  137. .wk-field {
  138. padding-bottom: 10rpx;
  139. }
  140. }
  141. </style>