EditBankDialog.vue 12.9 KB
<!-- 修改到账模式 -->
<template>
  <div>
    <glsx-combi-form class="edit-form-container" ref="editFormRef" label-width="100px" default-width="370px" :form-ref="editChildRef" :form-obj="editData" :form-data="editFormData" :form-rules="formRules">
      <div slot="merchantId" slot-scope="scope">
        <el-select v-model="editData[scope.scope.name]" :placeholder="scope.scope.placeholder" @change="scope.scope.changeAttr($event, scope.scope)" style="width: 370px;" filterable remote @visible-change="(event) => selectVisibleChange(event, scope.scope)" :remote-method="(event) => remoteMethod(event, scope.scope.searchKey)" v-el-select-loadmore="interestsLoadmoreMerchant" v-loading="merchantLoading">
          <el-option v-for="(subItem,subIdx) in scope.scope.optionList" :key="subIdx" :label="subItem[scope.scope.optionLabel]" :value="subItem[scope.scope.optionId]">
          </el-option>
        </el-select>
      </div>
    </glsx-combi-form>
    <div v-if="oprType != 'add'" class="log-box">
      <div>操作记录</div>
      <div v-for="(item, index) in editData.logList" :key="index" class="log-row">
        <div v-for="(subItem, subIdx) in recordList" :key="subIdx" class="log-item">{{subItem.label}}:{{item[subItem.name]}}</div>
      </div>
    </div>
  </div>
</template>
<script>
import { Util, deepClone } from '@/common/util'
import { sendSms } from '@api/merchant'
import { listWithPageAccountStatuses } from '@/api/publicAccount'
import { updateBankAccount, getBankById } from '@/api/merchantBankAccount'
export default {
  name: 'EditBankDialog',
  props: {
    merchantRow: {
      type: Object,
      default: () => { }
    },
    oprType: {
      type: String,
      default: 'add'
    }
  },
  data() {
    return {
      editChildRef: "editChildRef",
      merchantLoading: false,
      currentPage: 1,
      pageSize: 10,
      merchantTotalPage: 0,
      merchantNameKeyword: '',
      formRules: {
        merchantId: [{ required: true, message: "请选择商户", trigger: "change" }],
        openAccBankName: [{ required: true, message: "请填写开户行", trigger: "blur" }],
        bankAccountNo: [{ required: true, message: "请填写银行账号", trigger: "blur" }],
        bankAccountName: [{ required: true, message: "请填写账户名称", trigger: "blur" }],
      },
      editData: {
        merchantId: '',
        merchantType: '',
        merchantTypeTxt: '',
        channelType: '',
        channelTypeTxt: ''
      },
      editFormData: [{
        label: "商户名称",
        name: 'merchantId',
        addHtml: "merchantId",
        style: { width: "46%" },
        type: 'select',
        placeholder: '请选择商户',
        optionList: [],
        optionId: 'merchantId',
        optionLabel: 'merchantName',
        optionsName: 'merchantOpt',
        searchKey: 'merchantNameKeyword',
        changeAttr: (value, targetItem) => {
          if (value) {
            const findItem = targetItem.optionList.find(item => {
              return value == item.merchantId
            })
            if (findItem) {
              this.editData.merchantName = findItem.merchantName
              this.editData.merchantType = findItem.merchantType
              this.editData.channelType = findItem.channelType
              this.formatterTxt('merchantTypeTxt')
              this.formatterTxt('channelTypeTxt')
            }
          }
        }
      }, {
        label: '商户分类',
        name: 'merchantTypeTxt',
        type: 'showTxt',
        style: { width: "46%" },
        formatter: (cellValue) => {
          if (cellValue.merchantType) {
            if (cellValue.merchantType == '6' || cellValue.merchantType == '9') {
              this.editData.merchantTypeTxt = '园区店'
            } else if (cellValue.merchantType == '7') {
              this.editData.merchantTypeTxt = '服务商'
            } else {
              this.editData.merchantTypeTxt = '4S店'
            }
          }
        }
      }, {
        label: '渠道',
        name: 'channelTypeTxt',
        type: 'showTxt',
        style: { width: "46%" },
        formatter: cellValue => {
          this.editData.channelTypeTxt = this.baseData.channelTypeShow[cellValue.channelType]
        }
      }, {
        label: "开户行",
        name: "openAccBankName",
        type: "input",
        style: { width: "46%" },
        maxlength: 50
      }, {
        label: "银行账号",
        name: "bankAccountNo",
        type: "input",
        style: { width: "46%" },
        maxlength: 50,
        inputFn: (event) => {
          // 只允许:数字 0-9、英文字母 A-Za-z、常见特殊字符(如 !@#$%^&*()_+-=[]{}|;:'",.<>/?`~)
          // 排除:中文、空格、换行符、制表符等
          const allowedPattern = /[^a-zA-Z0-9!@#$%^&*()_+\-=\[\]{}|;:'",.<>?\/`~]/g;
          const cleanedInput = event.replace(allowedPattern, "");

          // 更新银行账号数据
          this.editData.bankAccountNo = cleanedInput;
          this.editData.bankAccountNo = this.editData.bankAccountNo
            .replace(/\s/g, "")
            .replace(/(.{4})/g, "$1 ")
          let arr = this.editData.bankAccountNo.split("")
          if (arr[arr.length - 1] == " ") {
            arr.splice(arr.length - 1, 1)
            this.editData.bankAccountNo = arr.join("")
          }
        }
      }, {
        label: "账户名称",
        name: "bankAccountName",
        type: "input",
        style: { width: "46%" },
        maxlength: 50
      }, {
        label: '录入时间',
        name: 'createdDate',
        type: 'showTxt',
        isHide: true,
        style: { width: "46%" }
      }],
      recordList: [{
        label: '操作项',
        name: 'operTxt'
      }, {
        label: '操作时间',
        name: 'createdDateTxt'
      }, {
        label: '操作人',
        name: 'createdBy'
      }],
      baseData: {
        merchantOpt: [],
        channelTypeShow: {
          1: '嘀加',
          2: '广汇',
          8: '直营'
        },
        oprTypeObj: {
          1: '新增银企账号',
          2: '修改银企账号',
          3: '删除银企账号',
        }
      }
    }
  },
  mounted() {
    this.getMerchantList()
    this.getInfo()
  },
  directives: {
    "el-select-loadmore": {
      bind(el, binding) {
        const SELECTWRAP_DOM = el.querySelector(
          ".el-select-dropdown .el-select-dropdown__wrap"
        )
        SELECTWRAP_DOM.addEventListener("scroll", function () {
          const condition =
            this.scrollHeight - this.scrollTop <= this.clientHeight
          if (condition) {
            binding.value()
          }
        })
      }
    }
  },
  methods: {
    formatterTxt(attr) {
      let idx = this.editFormData.findIndex(item => item.name == attr)
      if (idx == -1) {
        return true
      }
      this.editFormData[idx].formatter && this.editFormData[idx].formatter(this.editData)
    },

    getInfo() {
      const idx = this.editFormData.findIndex(item => item.name == 'createdDate')
      this.editFormData[idx].isHide = this.oprType == 'add'
      if (this.oprType == 'add') {
        return true
      }
      if (this.oprType == 'detail') {
        this.editFormData.forEach((item, idx) => {
          this.editFormData[idx].type = 'showTxt'
          if (item.name == 'merchantId') {
            delete this.editFormData[idx].addHtml
            this.editFormData[idx].name = 'merchantName'
          }
          this.formRules = {}
        })
      }
      if (this.oprType == 'edit') {
        const idx = this.editFormData.findIndex(item => item.name == 'merchantId')
        this.editFormData[idx].type = 'showTxt'
        delete this.editFormData[idx].addHtml
        this.editFormData[idx].name = 'merchantName'
      }
      this.loading = true
      getBankById({ merchantId: this.merchantRow.merchantId }).then(res => {
        this.editData = deepClone(res)
        this.editData.channelTypeTxt = this.baseData.channelTypeShow[this.editData.channelType]
        this.editData.createdDate = Util.dateFormate(this.editData.createdDate, 'YYYY-MM-DD HH:mm:ss')
        if (this.editData.merchantType) {
          if (this.editData.merchantType == '6' || this.editData.merchantType == '9') {
            this.editData.merchantTypeTxt = '园区店'
          } else if (this.editData.merchantType == '7') {
            this.editData.merchantTypeTxt = '服务商'
          } else {
            this.editData.merchantTypeTxt = '4S店'
          }
        }
        if (this.editData.bankAccountNo) {
          this.editData.bankAccountNo = this.editData.bankAccountNo
            .replace(/\s/g, "")
            .replace(/(.{4})/g, "$1 ")
        }
        this.editData.logList.forEach((item, idx) => {
          this.editData.logList[idx].operTxt = this.baseData.oprTypeObj[item.operType]
          this.editData.logList[idx].createdDateTxt = Util.dateFormate(item.createdDate, 'YYYY-MM-DD HH:mm:ss')
        })
      }).finally(() => {
        this.loading = false
      })

    },

    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find(k => k.name == refreshSigle)
        var index = this[formName].findIndex(k => k.name == refreshSigle)
        this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
        if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
          const temp = {}
          temp[this[formName][index].optionId] = ''
          temp[this[formName][index].optionLabel] = '全部'
          this[formName][index].optionList.unshift(temp)
        }
      } else {
        this[formName].forEach((item, index) => {
          if (item.type === 'select' && this.baseData[item.optionsName].length) {
            this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
            if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
              const temp = {}
              temp[this[formName][index].optionId] = ''
              temp[this[formName][index].optionLabel] = '全部'
              this[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },
    getMerchantList() {
      this.merchantLoading = true
      var params = { currentPage: this.currentPage, pageSize: this.pageSize, merchantName: this.merchantNameKeyword, merchantTypeList: [2, 7, -1] }
      listWithPageAccountStatuses(params).then(res => {
        if (res.list) {
          res.list = res.list.map(item => {
            return {
              merchantId: item.merchantId,
              merchantName: item.merchantName,
              merchantType: item.merchantType,
              channelType: item.channelType
            }
          })
        }
        this.merchantTotalPage = res.total
        this.baseData.merchantOpt = this.baseData.merchantOpt ? this.baseData.merchantOpt.concat(res.list || []) : res.list
        this.getOptionsList('editFormData', false, 'merchantId')
      }).finally(() => {
        this.merchantLoading = false
      })
    },


    // 获取更多4s店数据
    interestsLoadmoreMerchant() {
      setTimeout(() => {
        if (this.merchantLoading) {
          return true
        }
        this.currentPage = this.currentPage + 1
        if (this.merchantTotalPage < this.currentPage) {
          this.currentPage = this.merchantTotalPage
          return
        }
        this.getMerchantList()
      }, 10)
    },

    selectVisibleChange(event, item) {
      if (event && item.name == 'merchantId') {
        if (this.merchantNameKeyword) {
          this.remoteMethod('', 'merchantNameKeyword')
        }
      }
    },
    remoteMethod(query, searchKey) {
      this[searchKey] = query
      this.currentPage = 1
      this.baseData.merchantOpt = []
      this.getOptionsList('editFormData', false, 'merchantId')
      this.getMerchantList()
    },
    // 保存提交
    submitForm() {
      if (this.oprType == 'detail') {
        this.$emit('handleBankClose')
      } else {
        this.$refs.editFormRef.$refs[this.editChildRef].validate((valid) => {
          if (valid) {
            this.loading = true
            let params = deepClone(this.editData)
            params.bankAccountNo = params.bankAccountNo.replace(/\s*/g, "")
            updateBankAccount(params).then(res => {
              this.notice.okTips(this.oprType == 'add' ? '新增成功' : '修改成功')
              // 刷新列表页
              this.$emit('handleBankClose', true)
            }).finally(() => {
              this.loading = false
            })
          }
        })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.title-tips {
  margin: 30px 0 0 45px;
  color: #999;
}
.log-box {
  padding: 16px 20px;
  background: #fafafa;
  color: #333333;
  font-size: 16px;
  .log-row {
    display: flex;
    color: #333333;
    font-size: 14px;
    margin-top: 20px;
    .log-item {
      width: 30%;
    }
  }
}
</style>