123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <template>
- <view
- :class="{actived: fileList.length > 0}"
- class="wk-field-file">
- <view class="wk-field" @click.stop="handleChoose">
- <view v-if="_label" class="wk-field__label">
- <view v-if="field.isNull === 1" class="line" />
- <image :src="$static('images/icon/clip.png')" class="label-icon-file" />
- <text class="label-text">
- {{ _label }}
- </text>
- <view class="add-icon">
- <text class="wk wk-plus" />
- </view>
- </view>
- </view>
- <wk-file-content
- :list="fileList"
- show-delete
- @delete="handleDelete" />
- </view>
- </template>
- <script>
- import { FileDeleteById } from 'API/file'
- import mixins from './mixins'
- import WkFile from '@/utils/file.js'
- import { isArray } from '@/utils/types.js'
- export default {
- name: 'WkFieldFile',
- mixins: [mixins],
- data() {
- return {
- valueStr: '',
- fileList: [],
- batchId: ''
- }
- },
- watch: {
- field: {
- handler() {
- if (this.$isEmpty(this.field.value)) {
- this.fileList = []
- } else {
- this.fileList = isArray(this.field.value) ? this.field.value : []
- }
- if (this.fileList.length > 0) {
- this.batchId = this.fileList[0].batchId
- } else {
- this.batchId = ''
- }
- },
- deep: true,
- immediate: true
- }
- },
- methods: {
- handleChoose() {
- // if (this.config && this.config.batchId) {
- // this.batchId = this.config.batchId
- // }
- const params = { type: 'file' }
- if (this.batchId) {
- params.batchId = this.batchId
- }
- let fileObj = new WkFile(params)
- fileObj.choose().then(response => {
- this.batchId = response[0].batchId
- this.fileList = this.fileList.concat(response)
- fileObj = null
- this.emitEvt()
- })
- },
- handleDelete(index, item) {
- FileDeleteById({
- id: item.fileId
- }).then(() => {
- this.fileList.splice(index, 1)
- if (this.fileList.length === 0) {
- this.batchId = ''
- this.emitEvt()
- }
- }).catch()
- },
- emitEvt() {
- this.$emit('input', this.fileList)
- this.$emit('change', {
- index: this.index,
- field: this.field,
- value: this.fileList
- })
- }
- }
- }
- </script>
- <style scoped lang="scss">
- @import './wkField.scss';
- .wk-field-file {
- .wk-field {
- border-bottom: 0 none;
- .wk-field__label {
- @include left;
- .label-icon-file {
- width: 32rpx;
- height: 32rpx;
- margin-right: 10rpx;
- }
- .label-text {
- flex: 1;
- }
- .add-icon {
- width: 38rpx;
- height: 38rpx;
- background-color: #E1E1E1;
- border-radius: 50%;
- @include center;
- .wk {
- font-size: $wk-font-mini;
- line-height: normal;
- color: white;
- }
- }
- }
- }
- .add-btn {
- font-size: 26rpx;
- color: $theme-color;
- padding-bottom: 20rpx;
- @include right;
- .plus-icon {
- width: 22rpx;
- height: 22rpx;
- margin-right: 20rpx;
- }
- }
- }
- .actived {
- .wk-field {
- padding-bottom: 10rpx;
- }
- }
- </style>
|