index.vue 9.11 KB
<template>
  <div class="warning-contianer">
    <div class="title">预警信息</div>
    <div class="widget">
      <template v-for="(item, index) in list">
        <div :key="index" class="element">
          <label class="label">风险预警{{ index + 1 }}:</label>
          <div class="wrap">
            <div class="cell">
              <label class="cell-label">预警原因:</label>
              <div class="cell-value">{{ matchResultDesc[item.matchResult] }}</div>
            </div>
            <div class="cell">
              <label class="cell-label">具体描述:</label>
              <div class="cell-value">{{ item.matchResultDesc }}</div>
            </div>
            <div class="cell">
              <label class="cell-label">核实情况说明:</label>
              <el-input :disabled="isWatchOrder || item.matchType==1" @input="inputExplain" class="input-value" v-model="item.verifyResultDesc" type="textarea" placeholder="请输入核实后的情况说明" show-word-limit maxlength="100"></el-input>
            </div>
            <div class="cell">
              <label class="cell-label">核实资料补充:</label>
              <div class="inner">
                <div class="image_group">
                  <template v-if="item.accountVerifyImagesList.length">
                    <div v-for="(imgItem, i) in item.accountVerifyImagesList" :key="i" class="imagBox">
                      <img class="imgItem" :src="imgItem.verifyImage" alt="" />
                      <div class="img_mask">
                        <i @click="handlePictureCardPreview(imgItem.verifyImage)" class="el-icon-zoom-in"></i>
                        <i v-if="!isWatchOrder&&item.matchType!=1" @click="toDeleteImg(index, i)" class="el-icon-delete"></i>
                      </div>
                    </div>
                  </template>
                  <div class="upload-value">
                    <el-upload :disabled="isWatchOrder || item.matchType==1" list-type="picture" class="upload_item" action="#" :before-upload="e => beforeAvatarUpload(e)" :on-remove="e => handleRemove(e, index)" :http-request="e => httpRequest(e, index)">
                      <img class="img" slot="default" :src="upload_img" alt="" />
                    </el-upload>
                  </div>
                </div>
                <p class="tips">图片格式为jpg,jpeg,png,大小10M以内</p>
              </div>
            </div>
          </div>
        </div>
      </template>
    </div>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="" />
    </el-dialog>
  </div>
</template>
<script type="text/ecmascript-6">
import upload_img from '@/assets/images/upload.png'
export default {
  name: 'wraning',
  components: {},
  data() {
    return {
      upload_img,
      dialogVisible: false,
      matchResultDesc: {
        1: '支付账号异常',
        2: '金额过大'
      }
    }
  },
  props: {
    list: Array,
    isWatchOrder: Boolean
  },
  mounted() {},

  methods: {
    inputExplain() {
      this.$emit('getWarningData', this.list)
    },
    toDeleteImg(index, i) {
      this.list[index].accountVerifyImagesList.splice(i, 1)
      this.$emit('getWarningData', this.list)
    },
    handlePictureCardPreview(url) {
      this.dialogImageUrl = url
      this.dialogVisible = true
    },
    beforeAvatarUpload(e) {
      console.log(e)
      return new Promise((resolve, reject) => {
        let AllImgExt = '.png|.jpg|.jpeg'
        let extName = e.name.substring(e.name.lastIndexOf('.')).toLowerCase()
        if (AllImgExt.indexOf(extName) === -1) {
          this.$message.error('上传格式不正确')
          return reject(false)
        }
        const size = e.size / 1024 / 1024
        let maxSize = 10
        let filetype = this.getFileType(e.type)
        if (filetype == 'image') {
          maxSize = 10
        } else {
          maxSize = 30
        }
        if (size > maxSize) {
          this.$message.error(`上传文件不可超过${maxSize}M`)
          return reject(false)
        }
        return resolve(true)
      })
    },
    httpRequest({ file: e }, index) {
      let size = e.size / 1024 / 1024
      let loading = null
      // 大于2给loading
      if (size > 2) {
        loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.3)'
        })
      }
      // // 转码base64
      const reader = new FileReader()
      reader.readAsDataURL(e)
      reader.onload = event => {
        const imgFile = event.target.result
        const arrBase64 = imgFile.split(',')
        const targetNameList = e.name.split('.')
        const fileInfo = targetNameList[targetNameList.length - 1] + '@' + arrBase64[1]
        const fileType = this.getFileType(e.type)
        const paramObj = { file: fileInfo, fileType: fileType }
        let param = {}
        param.fileList = [paramObj]
        this.$apis.common
          .uploadFileApi(param, res => {
            if (loading != null) {
              loading.close()
              loading = null
            }
            // let progress = ((res.loaded / res.total) * 100).toFixed(2)
            // if (progress > 90) {
            //   progress = 90
            // }
          })
          .then(res => {
            if (res.code == 0) {
              const url = res.data[0]
              this.list[index].accountVerifyImagesList.push({ verifyImage: url })
              this.$emit('getWarningData', this.list)
            }
          })
      }
    },
    handleRemove(e, fieldName) {
      if (e.status == 'ready') return
    },
    getFileType(type) {
      if (!type) return 'doc'
      if (type.indexOf('image') > -1) {
        return 'image'
      } else {
        return 'doc'
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.warning-contianer {
  background: white;
  margin: 20px 0 0;
  .title {
    padding: 0 20px;
    font-size: 16px;
    font-weight: bold;
    height: 58px;
    line-height: 58px;
    border-bottom: 1px solid #d8d8d8;
    margin: 0 0;
    color: #333;
  }
  .widget {
    padding: 32px 20px;
    .element {
      display: flex;
      margin-bottom: 20px;
      .label {
        width: 154px;
        text-align: right;
        font-weight: 400;
        font-size: 14px;
        color: #333333;
      }
      .wrap {
        width: 792px;
        background: #f9f9f9;
        box-sizing: border-box;
        padding: 20px;
        .cell {
          display: flex;
          margin-bottom: 20px;
          .cell-label {
            width: 134px;
            font-weight: 400;
            font-size: 14px;
            color: #666666;
            text-align: right;
          }
          .cell-value {
            font-weight: 400;
            font-size: 14px;
            color: #333333;
          }
          .input-value {
            width: 580px;
          }
          .inner {
            .image_group {
              display: flex;
              flex-wrap: wrap;
              .imagBox {
                position: relative;
                .imgItem {
                  width: 104px;
                  height: 104px;
                  border-radius: 4px;
                  margin-right: 10px;
                  margin-bottom: 10px;
                  border: 1px dashed #00000026;
                }
                .img_mask {
                  display: none;
                }
              }
              .imagBox:hover {
                .img_mask {
                  display: block;
                  width: 104px;
                  height: 104px;
                  border-radius: 4px;
                  position: absolute;
                  left: 0;
                  top: 0;
                  right: 0;
                  bottom: 0;
                  background: rgba(0, 0, 0, 0.4);
                  transition: opacity 0.3s;
                  display: flex;
                  align-items: center;
                  justify-content: center;
                  i {
                    color: white;
                    cursor: pointer;
                    font-weight: 400;
                    font-size: 21px;
                  }
                  i:first-child {
                    margin-right: 12px;
                  }
                  i:last-child {
                    margin-right: 0;
                  }
                }
              }
            }
            .upload-value {
              width: 104px;
              height: 104px;
              border: 1px dashed #00000026;
              border-radius: 4px;
              .upload_item {
                width: 104px;
                height: 104px;
                .img {
                  width: 104px;
                  height: 104px;
                  border-radius: 4px;
                }
                /deep/.el-upload-list--picture {
                  display: none;
                }
              }
            }
            .tips {
              font-weight: 400;
              font-size: 14px;
              color: #999999;
              margin-top: 8px;
            }
          }
        }
        .cell:last-child {
          margin-bottom: 0;
        }
      }
    }
    .element:last-child {
      margin-bottom: 0;
    }
  }
}
</style>