uploadInfo.vue 4.32 KB
<template>
  <div class="upload-contianer">
    <div class="title">上传资料</div>
    <div class="widget">
      <uploadHandler :isRequire="true" :disabled="disabled" @getImages="getImages($event, 'YB0001')" title="购车发票" limitNum="1" :imagesList="uploadMessage.buyCar"></uploadHandler>
      <uploadHandler :isRequire="true" :disabled="disabled" @getImages="getImages($event, 'YB0002')" title="合同购买时里程数" limitNum="1" :imagesList="uploadMessage.mileage"></uploadHandler>
      <uploadHandler :isRequire="true" :disabled="disabled" @getCardImg="getCardImg" uploadType="1" title="行驶证或车辆合格证" :cardImg="cardImg"></uploadHandler>
      <uploadHandler :disabled="disabled" @getImages="getImages($event, 'YB0005')" title="其他" limitNum="9" :imagesList="uploadMessage.others"></uploadHandler>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
import upload_img from '@/assets/beforeSale/upload.png'
import uploadHandler from './components/UploadHandler.vue'
export default {
  name: 'uploadInfo',
  components: {
    uploadHandler
  },
  data() {
    return {
      upload_img,
      dialogVisible: false,
      attachmentList: [],
      license: [{}, {}]
    }
  },
  props: {
    uploadMessage: Object,
    cardImg: Object,
    disabled: Boolean,
    imgsQuery: Array
  },
  mounted() {},
  methods: {
    getImages(e, code) {
      this.handlerData()
      if (code === 'YB0005') {
        this.others = []
      } else if (code === 'YB0001' && !e.length) {
        this.buyCar = []
      } else if (code === 'YB0002' && !e.length) {
        this.mileage = []
      }
      e.forEach(url => {
        let obj = {
          attachmentCode: code,
          attachmentFile: url,
          attachmentType: 'IMG'
        }
        if (code === 'YB0001') {
          this.buyCar = [obj]
        } else if (code === 'YB0002') {
          this.mileage = [obj]
        } else if (code === 'YB0005') {
          this.others.push(obj)
        }
      })
      this.getAllImages()
    },
    getCardImg(e) {
      this.handlerData()
      const _value = e.detail,
        type = e.type
      const _attachmentCode = type == 1 ? 'YB0003' : 'YB0004'
      const _attachmentFile = type == 1 ? _value.font : _value.reverse
      const _obj = {
        attachmentCode: _attachmentCode,
        attachmentFile: _attachmentFile,
        attachmentType: 'IMG'
      }
      if (!_attachmentFile && type == 1) {
        this.license[0] = {}
      } else if (!_attachmentFile && type == 2) {
        this.license[1] = {}
      } else {
        this.license[type - 1] = _obj
      }
      this.getAllImages()
    },
    getAllImages() {
      let attachmentList = [],
        _tempArr1 = [],
        _tempArr2 = [],
        _tempArr3 = [],
        _tempArr4 = []
      if (this.buyCar) {
        this.buyCar.forEach(e => {
          _tempArr1.push(e)
        })
      }
      if (this.mileage) {
        this.mileage.forEach(e => {
          _tempArr2.push(e)
        })
      }
      if (this.others) {
        this.others.forEach(e => {
          _tempArr3.push(e)
        })
      }
      if (this.license) {
        this.license.forEach(e => {
          if (e.attachmentFile) {
            _tempArr4.push(e)
          }
        })
      }
      attachmentList = [..._tempArr1, ..._tempArr2, ..._tempArr3, ..._tempArr4]
      this.$emit('getAttachmentList', attachmentList)
    },
    handlerData() {
      if (this.imgsQuery.length && !this.active) {
        this.buyCar = []
        this.mileage = []
        this.license = [{}, {}]
        this.others = []
        this.imgsQuery.forEach(el => {
          if (el.attachmentCode === 'YB0001') {
            this.buyCar = [el]
          } else if (el.attachmentCode === 'YB0002') {
            this.mileage = [el]
          } else if (el.attachmentCode === 'YB0003') {
            this.license[0] = el
          } else if (el.attachmentCode === 'YB0004') {
            this.license[1] = el
          } else if (el.attachmentCode === 'YB0005') {
            this.others.push(el)
          }
        })
        this.active = true
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.upload-contianer {
  background: white;
  margin: 10px 0 0;
  .title {
    font-size: 16px;
    font-weight: 600;
    padding: 15px 20px;
    border-bottom: 1px solid #e7eaec;
    margin: 0 0;
  }
  .widget {
    padding: 32px 0px;
  }
}
</style>