index.vue 10.3 KB
<!-- 银企账号 - 列表 -->
<template>
  <d2-container>
    <div>
      <div class=" header" slot="header">
        <d2-search ref="showSearch" :search-form="searchForm" :form-data="showFormData"></d2-search>
        <div class="up-btns">
          <el-button :id="tableParams.btnId" size="small" type="primary">
            查询
          </el-button>
          <el-button size="small" @click="handleReset">
            重置
          </el-button>
        </div>
      </div>
    </div>
    <div class="d2-container-content">
      <d2-table-header>
        <auth-button category="Button" />
      </d2-table-header>
      <d2-table ref="merchantTable" :get-list-api="getListApi" :search-form="searchFormSearch" :table-params="tableParams" :before-search-fn="beforeSearchFn">
        <auth-button slot="auth-button" slot-scope="scope" :data="scope.scope" />
      </d2-table>
    </div>
    <d2-dialog :is-visible.sync="bankVisible" :title="modeDialogConfig.config.title" :width="modeDialogConfig.config.width" :btnOkLabel="bankOprType == 'detail' ? '关闭' : '保存'" @closeDialog="handleBankClose" @confirmDialog="handleBankConfirm">
      <edit-bank-dialog ref="editBankAccountRef" v-if="bankVisible" @handleBankClose="handleBankClose" :oprType="bankOprType" :merchant-row="merchantRow" />
    </d2-dialog>
  </d2-container>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import { getListApi, getMerchantLevelApi, deleteBankAccount } from '@api/merchantBankAccount'
import { mapActions, mapState } from 'vuex'
import EditBankDialog from './components/EditBankDialog.vue'
import { BaseData, merchantStoreServiceList } from '@/common/constants.js'
import baseDialog from '@/components/baseDialog'
import reportTrackFunMixin from '@/mixins/reportTrackFunMixin'
export default {
  name: 'AccountList',
  mixins: [reportTrackFunMixin], // 导入混入
  data() {
    return {
      bankVisible: false,
      merchantRow: {},
      bankOprType: 'add',
      nameToOption: {
        1: 'dj',
        2: 'gh',
        8: 'zy'
      },
      merchantLevelOptions: {
        dj: [],
        gh: [],
        zy: []
      },
      // 搜索
      merchantLevelVal: [],
      searchForm: {
        merchantType: '',
        channelType: '',
        merchantName: '',
        merchantId: '',
        openAccBankName: '',
        enterDate: [],
        bankAccountNo: '',
        bankAccountName: ''
      },
      searchFormSearch: {},
      showFormData: [{
        label: '商户分类',
        name: 'merchantType',
        type: 'select',
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confLabel',
        optionsName: 'merchantStoreServiceList'
      }, {
        label: '渠道',
        name: 'channelType',
        type: 'select',
        optionList: [],
        optionId: 'value',
        optionLabel: 'name',
        optionsName: 'channelTypeList'
      }, {
        label: '商户名称',
        name: 'merchantName',
        type: 'input',
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '商户号',
        name: 'merchantId',
        type: 'input',
        inputType: 'number',
        maxlength: '50',
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '开户行',
        name: 'openAccBankName',
        type: 'input',
        maxlength: '50',
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '录入时间',
        name: 'enterDate',
        type: 'datePicker',
        isClear: true,
        pickerOptions: 'rangePickerOptions'
      }, {
        label: '银行账号',
        name: 'bankAccountNo',
        type: 'input',
        maxlength: '50',
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '账户名称',
        name: 'bankAccountName',
        type: 'input',
        maxlength: '50',
        isClear: true,
        keyFn: this.keyDowmGetList
      }],
      // 表格
      getListApi: getListApi,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        mutiSelectUniqueKey: "merchantId",
        mutiSelectName: "merchantId",
        tableColumns: [{
          label: '商户名称',
          prop: 'merchantName'
        }, {
          label: '商户号',
          prop: 'merchantId'
        }, {
          label: '渠道',
          prop: '',
          formatter: cellValue => {
            return this.baseData.channelTypeShow[cellValue.channelType]
          }
        },
        {
          label: '开户行',
          prop: 'openAccBankName'
        },
        {
          label: '银行账号',
          prop: 'bankAccountNo'
        },
        {
          label: '账户名称',
          prop: 'bankAccountName'
        },
        {
          label: '录入时间',
          prop: 'createdDate',
          formatter: (cellValue) => {
            return Util.dateFormate(cellValue.createdDate, 'YYYY-MM-DD HH:mm:ss')
          }
        }]
      },
      baseData: {
        channelTypeList: [],
        channelTypeShow: {
          1: '嘀加',
          2: '广汇',
          8: '直营'
        },
        merchantStoreServiceList: deepClone(merchantStoreServiceList),
      },
      modeDialogConfig: {
        config: {
          title: '新增银企账号',
          width: '1080px'
        }
      }
    }
  },
  components: {
    baseDialog,
    EditBankDialog
  },

  watch: {
    'searchForm.bankAccountNo'(value) {
      // 只允许:数字 0-9、英文字母 A-Za-z、常见特殊字符(如 !@#$%^&*()_+-=[]{}|;:'",.<>/?`~)
      // 排除:中文、空格、换行符、制表符等
      const allowedPattern = /[^a-zA-Z0-9!@#$%^&*()_+\-=\[\]{}|;:'",.<>?\/`~]/g;
      const cleanedInput = value.replace(allowedPattern, "");

      // 更新银行账号数据
      this.searchForm.bankAccountNo = cleanedInput
    }
  },

  mounted() {
    this.getBaseData()
    this.onPageShow()
  },
  beforeDestroy() {
    this.onPageHide()
  },

  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    }),
  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get'
    }),
    ...mapActions('d2admin/user', ['actionSetDownloadList']),
    async getBaseData() {
      this.baseData.channelTypeList = await this.get(BaseData.channelType)
      this.getOptionsList()
    },

    getOptionsList() {
      this.showFormData.forEach((item, index) => {
        if (item.type === 'select') {
          if (this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this.showFormData[index].optionLabel] !== '全部') {
            const temp = {}
            temp[this.showFormData[index].optionId] = ''
            temp[this.showFormData[index].optionLabel] = '全部'
            this.baseData[item.optionsName].unshift(temp)
          }
          this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
        }
      })
      console.log(this.showFormData, 'showFormData')
    },

    getMerchantLevel(channelType) {
      // channelType:1-嘀加;2-广汇;8-直营
      getMerchantLevelApi({ channelType: channelType }).then(res => {
        // this.merchantLevelOptions[this.nameToOption[channelType]] = JSON.parse(res)
        this.merchantLevelOptions[this.nameToOption[channelType]] = res
      })
    },

    handleAdd() {
      this.modeDialogConfig.config.title = '新增银企账号'
      this.bankOprType = 'add'
      this.handleBankClose()
    },

    handleDetail(row) {
      this.modeDialogConfig.config.title = '查看银企账号'
      this.bankOprType = 'detail'
      this.merchantRow = row
      this.handleBankClose()
    },

    // 修改银企账号
    handleEdit(row) {
      this.modeDialogConfig.config.title = '编辑银企账号'
      this.bankOprType = 'edit'
      this.merchantRow = row
      this.handleBankClose()
    },

    // 修改到账模式确认
    handleBankConfirm() {
      this.$refs.editBankAccountRef.submitForm()
    },
    handleBankClose(isRefreshTable = false) {
      this.bankVisible = !this.bankVisible
      if (isRefreshTable) {
        this.$refs.merchantTable.resetRefreshTable()
      }
    },
    handleReset() {
      this.searchForm = {
        merchantType: '',
        channelType: '',
        merchantName: '',
        merchantId: '',
        openAccBankName: '',
        enterDate: [],
        bankAccountNo: '',
        bankAccountName: ''
      }
      this.merchantLevelVal = []
      this.$refs.merchantTable.resetRefreshTable()
    },

    getParams() {
      var params = deepClone(this.searchForm)
      const dateFormatList = [{
        attr: 'enterDate',
        startAttr: 'startCreatedTime',
        endAttr: 'endCreatedTime',
      }]
      dateFormatList.forEach(item => {
        if (params[item.attr] && params[item.attr].length) {
          params[item.startAttr] = Util.dateFormate(params[item.attr][0], 'YYYY-MM-DD 00:00:00')
          params[item.endAttr] = Util.dateFormate(params[item.attr][1], 'YYYY-MM-DD 23:59:59')
          delete params[item.attr]
        }
      })
      return params
    },

    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchFormSearch = this.getParams()
        resolve()
      })
    },

    keyDowmGetList() {
      this.$refs.merchantTable.refreshTable()
    },

    handleDelete(row) {
      this.$confirm('删除后不可恢复,确认是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const params = { merchantId: row.merchantId }
        deleteBankAccount(params).then(res => {
          this.$message.success("删除成功")
          this.handleReset()
        })
      }).catch(() => { })
    },

    handleExport() {
      const params = {}
      params.method = 'dj.api.smartcarlife.merchantBankEnterpriseAccount.export.async'
      const list = [
        ...this.dowloadList,
        {
          name: '银企账号',
          exportParam: JSON.stringify(params),
          status: 'waiting',
          timeid: new Date().getTime()
        }
      ]
      this.actionSetDownloadList({ list, type: 'dowloadList' })
    }
  }
}

</script>
<style>
.header {
  background-color: #fff;
}

.el-cascader-panel .el-cascader-menu {
  width: 260px;
}
.btnClass span {
  margin-right: 5px;
}
</style>