index.vue 10.7 KB
<!-- 支付商户管理 -->
<template>
  <div class="marketing">
    <div class="m-b-20">
      <GLButton :size="size" class="default-blue-btn el-icon-plus" type="default" @click="addPayMerchant()" fn="新增支付商户" mode="el-button">新增支付商户</GLButton>
    </div>
    <div class="container">
      <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>

      <!-- 表格区域 开始 -->
      <GLTable ref="activity" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <span slot="testFlag" slot-scope="scope">
          <span :class="{ circleStatusGray: scope.scope.testFlag === 0, circleStatusGreen: scope.scope.testFlag === 1 }"></span>
          <span>{{ scope.scope.testFlag == '1' ? '已生效' : '待生效' }}</span>
        </span>
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
    <collectionTest :isShowTestDialog="isShowTestDialog" :dialogData="dialogData" @handleDialogClose="handleDialogClose"></collectionTest>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
import collectionTest from './components/collectionTestDialog'
export default {
  name: 'activity',
  components: {
    collectionTest
  },
  data() {
    return {
      size: 'small',
      url: url,
      downForm: {
        id: '',
        offReason: '',
        goodsStatus: 0
      },
      shareForm: {},
      searchForm: {
        merchantId: '',
        merchantName: '',
        mchId: '',
        mchName: '',
        appId: '',
        testFlag: ''
      },
      tableSearchForm: {},
      // 搜索
      searchFormData: [
        {
          label: '微信支付商户号',
          name: 'mchId',
          type: 'input',
          width: '215px',
          maxlength: 20
        },
        {
          label: '微信支付商户名',
          name: 'mchName',
          type: 'input',
          width: '215px',
          maxlength: 20
        },
        {
          label: '应用ID',
          name: 'appId',
          type: 'select',
          width: '215px',
          optionList: [],
          optionId: 'appId',
          optionLabel: 'appName',
          optionsName: 'applyTypes'
        },
        {
          label: '所属商户',
          name: 'merchantName',
          type: 'input',
          width: '215px',
          maxlength: 20
        },
        {
          label: '商户号',
          name: 'merchantId',
          type: 'input',
          width: '215px'
        },
        {
          label: '状态',
          name: 'testFlag',
          type: 'select',
          width: '215px',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confName',
          optionsName: 'statusList'
        }
      ],
      // 表格按钮
      tableButtonList: [
        {
          type: 'GLButton',
          name: '收款测试',
          attrs: {
            type: 'text',
            fn: '收款测试'
          },
          listeners: {
            click: this.collectionTest
          },
          condition: row => {
            return row.testFlag == '0' && row.appType
          }
        },
        {
          type: 'GLButton',
          name: '删除',
          attrs: {
            type: 'text',
            fn: '删除'
          },
          condition: row => {
            return row.testFlag == '0'
          },
          listeners: {
            click: this.del
          }
        }
      ],
      // 表格
      getListApi: this.$apis.payMerchantManage.getListApi,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '微信支付商户号',
            prop: 'mchId',
            width: 220
          },
          {
            label: '微信支付商户名',
            prop: 'mchName',
            width: 140
          },
          {
            label: '应用ID',
            prop: 'appPrincipal'
          },
          {
            label: '所属商户',
            prop: 'merchantName'
          },
          {
            label: '商户号',
            prop: 'merchantId'
          },
          {
            label: '所属商户类型',
            prop: 'mchBelong',
            formatter: cellValue => {
              return this.mchBelongList.find(item => item.confId == cellValue.mchBelong)?.confName
            }
          },
          {
            label: '创建人',
            prop: 'createdBy'
          },
          {
            label: '创建日期',
            name: 'createdDate',
            width: 200,
            formatter: cellValue => {
              return dayjs(cellValue.createdDate).format('YYYY-MM-DD HH:mm:ss')
            }
          },
          {
            label: '状态',
            name: 'testFlag',
            addHtml: 'testFlag'
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      baseData: {
        statusList: [
          {
            confId: '0',
            confName: '待生效 '
          },
          {
            confId: '1',
            confName: '已生效'
          }
        ],
        applyTypes: []
      },
      isShowTestDialog: false,
      dialogData: [],
      jumpH5Path: '',
      mchBelongList: [
        {
          confId: '0',
          confName: '广联'
        },
        {
          confId: '1',
          confName: '服务商'
        },
        {
          confId: '2',
          confName: '流量方'
        }
      ]
    }
  },

  mounted() {
    // 获取应用ID列表
    this.$apis.payMerchantManage.getlistAppInfoApi({}).then(res => {
      this.baseData.applyTypes = res
      this.getOptionsList('searchFormData', true)
    })
    if (process.env.NODE_ENV == 'development') {
      // 本地打开修改dj-scrm-wx-work-main-xxx
      this.jumpH5Path = `${this.$request.baseURL}/dj-scrm-wx-work-main-zxw/#/testPayMerchant/index`
    } else {
      this.jumpH5Path = `${window.location.origin}/scrm-wx-merchant-activity/#/testPayMerchant/index`
    }
  },

  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        resolve()
      })
    },

    secondConfirm(title, txt, apiModule, apiName, apiParams, fn) {
      this.$confirm(txt, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: action => {
          if (action == 'confirm') {
            this.$apis[apiModule][apiName](apiParams).then(res => {
              this.$message({
                message: res.code == '0' ? '操作成功' : res.message,
                type: res.code == '0' ? 'success' : 'error'
              })
              if (res.code == '0') {
                fn && fn()
                this.handleSearch()
              }
            })
          }
        }
      })
    },

    // 收款测试
    collectionTest(row) {
      let fetchArr = []
      row.appType?.split(',').forEach(val => {
        if (val == 'MINIAPP') {
          fetchArr.push(this.getWeappQrcode(row))
        }
        if (val == 'BIZ') {
          fetchArr.push(this.getBizQrcode(row))
        }
      })
      return new Promise(resolve => {
        Promise.all(fetchArr).then(() => {
          this.isShowTestDialog = !this.isShowTestDialog
          resolve()
        })
      })
    },
    // 获取微信小程序收款测试码
    getWeappQrcode(row) {
      return new Promise((resolve, reject) => {
        this.$apis.payMerchantManage
          .createWeappQrcodeApi({
            appId: 'wxe10067a63c1856ac',
            qrcodeType: 'QR_WXA_UNLIMIT',
            path: 'pages/crowdfunding/testPayMerchant/testPayMerchant',
            scene: `${row.payMannerId},1`,
            channelName: 'DJ'
          })
          .then(res => {
            if (res.code == '0') {
              this.dialogData.push({
                title: row.appPrincipal,
                url: res.data
              })
              resolve()
            } else {
              this.$message.error(res.message)
              reject()
            }
          })
      })
    },
    // 获取公众号收款测试码
    getBizQrcode(row) {
      return new Promise(resolve => {
        this.$apis.payMerchantManage
          .creatBizQrcodeApi({
            payMannerId: row.payMannerId,
            path: this.jumpH5Path
          })
          .then(res => {
            if (res.code == '0') {
              this.dialogData.push({
                title: row.appPrincipal,
                url: res.data
              })
              resolve()
            } else {
              this.$message.error(res.message)
            }
          })
      })
    },

    handleDialogClose() {
      this.dialogData = []
      this.isShowTestDialog = !this.isShowTestDialog
    },

    //删除
    del(row) {
      var params = {}
      params.payMannerId = row.payMannerId
      this.secondConfirm('删除', '确定删除此支付商户?', 'payMerchantManage', 'delPayMerchantApi', params)
    },

    //新增支付商户
    addPayMerchant() {
      this.$router.push('/payMerchantsManage/addPayMerchant')
    },

    getOptionsList(formName, hasAll = false) {
      this[formName].forEach((item, index) => {
        if (item.type === 'select' && this.baseData[item.optionsName].length) {
          this.$set(this[formName][index], 'optionList', this.$common.utils.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)
          }
        }
      })
    },

    handleSearch() {
      this.$refs.activity.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        merchantId: '',
        merchantName: '',
        mchId: '',
        mchName: '',
        appId: '',
        testFlag: ''
      }
      this.handleSearch()
    },

    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.activity.data.length ? (this.$refs.activity.tableHeightValues = '') : this.$refs.activity.setTableHeightFun()
    }
  }
}
</script>

<style scoped></style>