refundUpdateDialog.vue 16.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
<!-- 审核 -->
<template>
  <baseDialog :dialog-config="dialogConfig" :is-show.sync="visible" class="accountDailog-1" @handleClick="handleAddConfirm">
    <div class="refund-update-dialog">
      <glsx-combi-form class="edit-form-container" ref="editFormRef" label-width="150px" default-width="370px" :form-ref="editChildRef" :form-obj="infoForm" :form-data="editFormData" :form-rules="formRules">
        <template slot="attachmentListHtml" slot-scope="scope">
          <el-upload action="" accept=".png,.jpg" class="upload-file" :show-file-list="false" :file-list="uploadFileList" :limit="5" :auto-upload="false" :on-remove="importFileChange" :on-change="
              (file, fileList) => handleFileChange(file, fileList, scope.scope)
            " :on-exceed="hanldeOnExceed" multiple>
            <!-- <i class="el-icon-upload"></i>
            <div class="el-upload__text">点击或将文件拖拽到此区域上传</div>
            <div class="item-tips text-tips">
              支持格式:.png .jpg
            </div> -->
            <div class="upload-txt">+ 上传文件</div>
          </el-upload>
          <!-- 文件列表区域 -->
          <div class="file-box">
            <div v-for="(subItem, subIndex) in infoForm.attachmentList" :key="subIndex">
              <div class="file-item" v-if="!filterEmpty(subItem.uploadProgress) || subItem.fileUrl">
                <div class="file-content" @click="handleFileView(subItem)">
                  <el-progress define-back-color="#F5F7FA" :text-inside="true" text-color="#333333" :show-text="false" :stroke-width="26" stroke-linecap="butt" :percentage="subItem.uploadProgress"></el-progress>
                  <div class="file-name">{{ subItem.fileName }}</div>
                </div>
                <i v-if="!subItem.fileUrl" class="el-icon-close del-icon" @click="doCancel(scope.scope, subIndex)"></i>
                <i v-if="subItem.fileUrl" class="el-icon-delete" @click="handleFileDelete(scope.scope, subIndex)"></i>
              </div>
            </div>
          </div>
          <div class="upload-tips">支持文件格式: .png .jpg ,单个文件不能超过10M,最多上传5个文件。</div>
        </template>
      </glsx-combi-form>
    </div>
    <el-image-viewer v-if="imgViewerVisible" :on-close="closeImgViewer" :url-list="imageFileArr" :initial-index="initialIndex" />
  </baseDialog>
</template>

<script>
import { getPlatformMerchant } from "@api/refundExamine"
import { update } from '@api/refundExamine'
import { uploadFile } from "@/api/sys.base"
import { deepClone } from "@/common/util"
export default {
  name: 'refundUpdateDialog',
  components: {
    'el-image-viewer': () => import('element-ui/packages/image/src/image-viewer')
  },
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      dialogConfig: {
        title: '修改信息',
        width: '720px'
      },
      editChildRef: "editChildRef",
      infoForm: {
        platformMerchantId: '',
        payee: '',
        openAccBankName: '',
        bankAccountNo: '',
        attachmentList: [],
        remark: ''
      },
      formRules: {
        platformMerchantId: [
          { required: true, message: "请选择支付主体", trigger: "change" }
        ],
        payee: [
          {
            required: true,
            message: "请输入收款人,最大不超过20个字",
            trigger: "blur"
          }
        ],
        openAccBankName: [
          {
            required: true,
            message: "请输入开户行,最大不超过50个字",
            trigger: "blur"
          }
        ],
        bankAccountNo: [
          {
            required: true,
            message: "请输入银行账号,只支持纯数字,最大不超过30个字",
            trigger: "blur"
          }
        ],
        payReason: [
          {
            required: true,
            message: "请输入付款事由,最大不超过500个字",
            trigger: "blur"
          }
        ],
        attachmentList: [
          {
            required: false,
            message: "请上传结算凭证",
            trigger: "blur"
          }
        ],
        remark: [
          {
            required: true,
            message: "请输入备注",
            trigger: "blur"
          }
        ],
      },
      editFormData: [{
        label: "支付主体",
        name: "platformMerchantId",
        type: "select",
        isClear: true,
        optionList: [],
        optionId: "merchantId",
        optionLabel: "merchantShowName",
        optionsName: "platformMerchantIdList"
      }, {
        label: "收款人",
        name: "payee",
        type: "input",
        isClear: true,
        maxlength: 20
      }, {
        label: "开户行",
        name: "openAccBankName",
        type: "input",
        isClear: true,
        maxlength: 50
      },
      {
        label: "银行账号",
        name: "bankAccountNo",
        type: "input",
        // inputType: "number",
        isClear: true,
        maxlength: 30,
        inputFn: (event) => {
          if (!(/^\d|\s+$/.test(event.slice(event.length)))) {
            this.infoForm.bankAccountNo = event.replace(/\D/g, '')
          }
          this.infoForm.bankAccountNo = this.infoForm.bankAccountNo.replace(/\s/g, '').replace(/(.{4})/g, "$1 ")
          let arr = this.infoForm.bankAccountNo.split('')
          if (arr[arr.length - 1] == ' ') {
            arr.splice(arr.length - 1, 1)
            this.infoForm.bankAccountNo = arr.join('')
          }
        }
      }, {
        label: "付款事由",
        name: "payReason",
        type: "input",
        maxlength: 500,
        inputType: "textarea",
        showLimit: true,
        rows: 4,
        width: "370px"
      }, {
        label: "结算凭证",
        name: "attachmentList",
        isHide: true,
        addHtml: "attachmentListHtml"
      }, {
        label: "备注",
        name: "remark",
        type: "input",
        maxlength: 200,
        inputType: "textarea",
        showLimit: true,
        rows: 4,
        width: "370px"
      }],
      baseData: {
        platformMerchantIdList: []
      },
      uploadFileList: [],
      imgViewerVisible: false,
      imageFileArr: [],
      initialIndex: 0,
    }
  },

  props: {
    // examineType: {
    //   type: String,
    //   default: ''
    // },
    refundVisible: {
      type: Boolean,
      default: false
    },
    detailInfo: {
      type: Object,
      default: () => { }
    }
  },
  watch: {
    'infoForm.attachmentList': {
      handler(newVal) {
        if (newVal) {
          this.uploadFileList = newVal.filter(v => !this.filterEmpty(v.uploadProgress) || v.fileUrl) // 文件列表
          const imageFileArr = newVal.filter(v => v.fileUrl && (v.fileUrl.includes('.png') || v.fileUrl.includes('jpg')))
          this.imageFileArr = imageFileArr.map(item => { return item.fileUrl })
        }
      },
      deep: true
    }
  },
  computed: {
    visible: {
      get() {
        return this.refundVisible
      },
      set(newVal) {
        this.$emit('dialogClose', { flag: newVal, attrName: 'refundVisible' })
      }
    }
  },

  mounted() {
    // this.dialogConfig.title = this.examineType
    this.infoForm = deepClone(this.detailInfo)
    this.getPlatformMerchant()
    this.dealAttachment()
    if (this.infoForm.bankAccountNo) {
      this.infoForm.bankAccountNo = this.infoForm.bankAccountNo.replace(/\s/g, '').replace(/(.{4})/g, "$1 ")
    }
    console.log(this.infoForm, 'infoForm--------')
  },

  methods: {
    getOptionsList(formName = 'editFormData') {
      this[formName].forEach((item, index) => {
        if (item.type === "select" || item.type === "radio") {
          this.$set(
            this[formName][index],
            "optionList",
            this.baseData[item.optionsName]
          )
        }
      })
    },

    dealAttachment() {
      // fileType  文件类型(1.申请附件,2.结算凭证)';只保留结算凭证
      /* status状态(已完成才有结算凭证)
      { confId: 0, confValue: "运营审核" },
      { confId: 1, confValue: "商务审核" },
      { confId: 2, confValue: "财务复核" },
      { confId: 3, confValue: "财务结算" },
      { confId: 4, confValue: "已完成" },
      { confId: 5, confValue: "驳回" }
      */
      console.log(this.infoForm.status)
      this.infoForm.attachmentList = this.infoForm.status != 4 ? [] : (this.infoForm.attachmentList.filter(item => item.fileType == 2) || [])
      if (this.infoForm.status == 4) {
        let idx = this.editFormData.findIndex(item => item.label == '结算凭证')
        this.editFormData[idx].isHide = false
        // this.formRules.attachmentList[0].required = true
      }
    },

    getPlatformMerchant() {
      this.baseData.platformMerchantIdList = []
      var params = {}
      getPlatformMerchant(params).then((res) => {
        this.baseData.platformMerchantIdList = res
        this.getOptionsList()
      })
    },

    // 获取文件
    importFileChange(file, fileList) {
      this.uploadFileList = fileList
      this.infoForm.attachmentList = deepClone(fileList)
    },

    hanldeOnExceed(files, fileList) {
      this.$message({
        message: "最多可上传5个文件",
        type: "error"
      })
    },

    filterEmpty(data) {
      return (data ?? "") === ""
    },
    // 删除文件
    handleFileDelete(targetItem, subIndex) {
      this.clearItem(targetItem, subIndex)
    },
    // 预览文件
    handleFileView(item) {
      if (!item.fileUrl) return
      if (item?.fileUrl.includes('.pdf')) { // pdf文件直接打开新窗口预览
        window.open(item.fileUrl)
      } else {
        this.imgViewerVisible = true
        this.imageFileArr.forEach((val, index) => {
          if (val == item.fileUrl) this.initialIndex = index
        })
        console.log(this.imageFileArr)
      }
    },
    closeImgViewer() {
      this.imgViewerVisible = false
    },
    // 清空上传文件数组项内容
    clearItem(targetItem, subIndex) {
      this.$set(this.infoForm[targetItem.name][subIndex], "fileUrl", "")
      this.$set(this.infoForm[targetItem.name][subIndex], "uploadProgress", "")
    },
    // 取消上传
    doCancel(targetItem, subIndex) {
      const _formData = this.infoForm
      const cancelUploadObj = _formData[targetItem.name][subIndex].cancelAxios
      cancelUploadObj && cancelUploadObj.cancel && cancelUploadObj.cancel()
      this.clearItem(targetItem, subIndex)
    },

    handleFileChange(file, fileList, targetItem) {
      console.log("file", file)
      console.log("fileList", fileList)
      // return false
      // setTimeout(() => {
      var reader = new FileReader()
      var fileInfo = file.raw
      if (
        !fileInfo.name.includes(".png") &&
        !fileInfo.name.includes(".jpg")
      ) {
        this.$message({
          message: "文件格式不支持上传",
          type: "error"
        })
        return false
      }
      // 默认10MB
      const limitSize = 10
      const isLt = fileInfo.size / 1024 / 1024 < limitSize
      if (!isLt) {
        this.$message({
          message: "上传文件大小不能超过" + limitSize + "MB!",
          type: "error"
        })
        this.uploadFileList = this.uploadFileList.filter((item) => {
          return item.size / 1024 / 1024 < 10
        })
        return false
      }
      reader.readAsDataURL(fileInfo)
      reader.onload = (e) => {
        // const _attachmentList = this.infoForm.attachmentList
        const _formData = this.infoForm
        _formData[targetItem.name].push({
          fileUrl: "",
          uploadProgress: 0,
          fileName: fileInfo.name?.substring(0, 128),
          fileSize: fileInfo.size,
          fileType: 2, // 文件类型(1.申请附件,2.结算凭证)
          cancelAxios: {}
        })
        const index = _formData[targetItem.name].length - 1
        const fileData = e.target.result
        const base64 =
          fileInfo.name.split(".")[fileInfo.name.split(".").length - 1] +
          "@" +
          fileData.split(",")[1]
        // const requestEvent = fileInfo.type == 'application/pdf' ? uploadPDF : uploadExcel
        const fileTypeKey = {
          "image/png": "png",
          "image/jpeg": "jpg"
        }
        // this.btnLoding = true
        uploadFile({
          file: base64,
          fileType: 'image',
          onProcess: (e) => {
            // 上传进度
            const { loaded, total } = e
            const uploadPrecent = ((loaded / total) * 100) | 0
            _formData[targetItem.name][index].uploadProgress = uploadPrecent
          },
          cancelFun: _formData[targetItem.name][index].cancelAxios // 取消上传
        })
          .then((res) => {
            // let allSuc = true
            _formData[targetItem.name][index].fileUrl = res // 文件地址
            // _formData[targetItem.name].forEach(item => {
            //   if (item.fileUrl == '') {
            //     allSuc = false
            //   }
            // })
            // if (allSuc) { // 所有文件上传成功
            //   this.btnLoding = false
            // }
          })
          .catch(() => {
            // this.btnLoding = false
            this.clearItem(targetItem, index) // 上传失败将内容清空 不删除数组 防止其它上传进度 找不到对应下标
          })
        console.log("_formData[targetItem.name]", _formData[targetItem.name])
      }
      // }, 50)
    },

    handleAddConfirm() {
      this.$refs.editFormRef.$refs[this.editChildRef].validate((valid) => {
        if (valid) {
          var params = deepClone(this.infoForm)
          const attachmentList = params.attachmentList
          for (var i = 0; i < attachmentList.length; i++) {
            if (attachmentList[i].fileUrl == "") {
              attachmentList.splice(i, 1)
              i-- // 需要将i减1,因为数组长度已经减少了1
            }
          }
          params.attachmentList.forEach((k, idx) => {
            params.attachmentList[idx] = {
              fileUrl: k.fileUrl,
              fileName: k.fileName
            }
          })
          params.bankAccountNo = params.bankAccountNo.replace(/\s*/g, '')
          // console.log(params, 'params-----------')
          update(params).then((res) => {
            this.notice.okTips("操作成功")
            this.$emit('refundConfirm')
            this.visible = true
          })
        }
      })
    }
  }
}
</script>
<style lang="scss">
.accountDailog-1 {
  .el-icon-circle-close {
    color: #ffffff;
  }
  .refund-update-dialog {
    .reject-input {
      ::v-deep .el-textarea__inner {
        height: 70px;
      }
    }

    .el-textarea .el-input__count {
      right: 10px;
      bottom: -6px;
      font-size: 12px;
      color: #999999;
      background-color: transparent;
    }

    .tips {
      color: #999999;
    }
    .upload-file {
      width: 110px;
      height: 32px;
      border-radius: 4px;
      opacity: 1;
      border: 1px solid #00000026;
      background: #ffffff;
      text-align: center;
      .upload-txt {
        height: 22px;
        color: #666666;
        font-size: 14px;
        text-align: left;
        line-height: 22px;
      }
    }
    .upload-tips {
      height: 20px;
      color: #999999;
      font-size: 14px;
      text-align: left;
    }

    .file-box {
      width: 350px;

      .file-item {
        margin-top: 6px;
        position: relative;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;

        ::v-deep .el-progress-bar {
          width: 320px;
          background: #ffffff;
          border: 1px solid #f4f6fc;
          border-radius: 4px;

          .el-progress-bar__outer {
            background: transparent;
            border-radius: 4px;

            .el-progress-bar__inner {
              background: #f5f7fa;
              border-radius: 4px;
            }
          }
        }

        ::v-deep .el-image-viewer__wrapper {
          width: 100vw;
          height: 100vh;
        }

        .file-name {
          box-sizing: border-box;
          width: 318px;
          height: 26px;
          line-height: 26px;
          background: #f5f7fa;
          color: #333333;
          font-size: 14px;
          transform: translateY(-50%);
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          border-radius: 4px;
          padding: 0 8px;
        }

        .image-file {
          z-index: -1;
        }
      }

      .file-item:first-child {
        margin-top: 8px;

        .file-name {
          position: absolute;
          left: 0px;
          top: 15px;
          transform: translateY(-50%);
          color: #333333;
          font-size: 14px;
        }
      }
    }
  }
}
</style>