storeTargetList.vue 10.6 KB
<!-- 门店目标配置 -->
<template>
  <d2-container class="store-target-list m-t-40">
    <div class="header"
         slot="header">
      <d2-search ref="showSearch"
                 class="show-search"
                 :search-form="searchForm"
                 :label-width="'100px'"
                 :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 class="d2-container-content">
      <d2-table-header>
        <auth-button category="Button"
                     style="{display: inline-block}"
                     :show-btn-ids="['9120701']" />
      </d2-table-header>
      <d2-table ref="storeTargetTable"
                :has-num="false"
                :search-form="searchForm"
                :table-params="tableParams"
                :get-list-api="getListApi"
                :before-search-fn="beforeSearchFn"
                @setTableFinishFun="setTableFinishFun">
        <template slot="sceneType"
                  slot-scope="scope">
          <div v-if="scope.scope.sceneType == 1">精品升级</div>
          <div v-if="scope.scope.sceneType == 0">会员权益/升级</div>
        </template>
        <template slot="partnerMerchantName"
                  slot-scope="scope">
          <div v-for="item in scope.scope.serviceList"
               :key="item.merchantId">{{ item.merchantName }}</div>
          <div v-if="!scope.scope.serviceList.length">-</div>
        </template>
        <template slot="partnerMerchantId"
                  slot-scope="scope">
          <div v-for="item in scope.scope.serviceList"
               :key="item.merchantId">{{ item.merchantId }}</div>
          <div v-if="!scope.scope.serviceList.length">-</div>
        </template>
        <div slot="auth-button"
             slot-scope="scope">
          <!-- 查看 -->
          <span style="margin-right: 10px;">
            <auth-button :data="scope.scope"
                         :show-btn-ids="['9120702']" />
          </span>
          <!-- 编辑 -->
          <span style="margin-right: 10px;">
            <auth-button :data="scope.scope"
                         :show-btn-ids="['9120703']" />
          </span>
        </div>
      </d2-table>
    </div>
  </d2-container>
</template>
<script>
import { mapActions } from 'vuex'
import { getStoreTargetListApi } from '@api/inStoreTargetConfig'
import { Util } from '@/common/util'
export default {
  name: "StoreTargetList",
  data() {
    return {
      // 搜索框
      showFormData: [{
        label: '商户名称',
        name: 'allMerchantName',
        type: 'input',
        placeholder: '请输入园区店/导流方/服务商名称',
        isClear: true,
        keyFn: this.keyDownGetList
      }, {
        label: '商户号',
        name: 'allMerchantId',
        type: 'input',
        inputType: 'number',
        placeholder: '请输入园区店/导流方/服务商商户号',
        isClear: true,
        keyFn: this.keyDownGetList
      }, {
        label: '场景名称',
        name: 'sceneType',
        type: 'select',
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'sceneTypeList'
      }, {
        label: '配置状态',
        name: 'configStatus',
        type: 'select',
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'configStatusList'
      }],
      getListApi: getStoreTargetListApi,
      // 表格参数
      tableParams: {
        needUnique: true,
        mutiSelectUniqueKey: 'uniqueVal',
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: {
          width: '100'
        },
        tableColumns: [{
          label: '序号',
          prop: 'ownSerialNum',
          type: 'ownSerialNum',
          width: '60'
        }, {
          label: '流量方',
          prop: 'merchantName',
          width: '120'
        }, {
          label: '流量方商户号',
          prop: 'merchantId',
          width: '120'
        }, {
          label: '业务场景',
          prop: 'sceneType',
          addHtml: 'sceneType'
        }, {
          label: '关联园区店',
          prop: 'yqMerchantName'
        }, {
          label: '关联园区店号',
          prop: 'yqMerchantId'
        }, {
          label: '关联服务商',
          prop: 'partnerMerchantName',
          addHtml: 'partnerMerchantName'
        }, {
          label: '关联服务商商户号',
          prop: 'partnerMerchantId',
          addHtml: 'partnerMerchantId'
        }, {
          label: '配置状态',
          prop: 'status',
          width: '80',
          className: (cellValue) => {
            return {
              Y: 'greenSpot',
              N: 'yellowSpot'
            }[cellValue.configStatus]
          },
          formatter: (cellValue) => {
            return {
              Y: '已配置',
              N: '待配置'
            }[cellValue.configStatus]
          }
        }, {
          label: '创建时间',
          prop: 'created',
          width: '160',
          formatter: (cellValue) => {
            return cellValue.createdDate ? Util.dateFormate(cellValue.createdDate, 'YYYY-MM-DD HH:mm:ss') : ''
          }
        }, {
          label: '更新时间',
          prop: 'update',
          width: '160',
          formatter: (cellValue) => {
            return cellValue.updatedDate ? Util.dateFormate(cellValue.updatedDate, 'YYYY-MM-DD HH:mm:ss') : ''
          }
        }, {
          label: '操作人',
          prop: 'updatedBy',
          width: '80'
        }]
      },
      // 查询条件
      searchForm: {
        allMerchantName: '',
        allMerchantId: '',
        sceneType: '',
        configStatus: ''
      },
      baseData: {
        sceneTypeList: [{
          confId: 1,
          confValue: '精品升级'
        }, {
          confId: 0,
          confValue: '会员权益/升级'
        }],
        configStatusList: [{
          confId: 'N',
          confValue: '待配置'
        }, {
          confId: 'Y',
          confValue: '已配置'
        }]
      },
      spanArr1: [],
      spanIndex1: 0,
      spanArr2: [],
      spanIndex2: 0,
      spanArr3: [],
      spanIndex3: 0
    }
  },
  mounted() {
    this.getBaseData()
  },
  methods: {
    ...mapActions({
      get: 'd2admin/base/get',
      close: 'd2admin/page/close'
    }),
    getBaseData() {
      this.showFormData.forEach((item, index) => {
        if (item.type === 'select') {
          this.baseData[item.name + 'List'].unshift({
            confId: '',
            confValue: '全部'
          })
          this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
        }
      })
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        resolve()
      })
    },
    // 表格数据处理
    setTableFinishFun(data) {
      // this.merge(data)
    },
    // 合并表格
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      const len = this.viewInfo?.tableData?.length
      const t = 14
      if (columnIndex === 0) {
        // 第一列 序号
        const _row_1 = this.spanArr1[rowIndex]
        const _col_1 = _row_1 > 0 ? 1 : 0
        return {
          rowspan: _row_1,
          colspan: _col_1
        }
      } else if (columnIndex === 1) {
        // 第二列 流量方
        const _row_2 = this.spanArr2[rowIndex]
        const _col_2 = _row_2 > 0 ? 1 : 0
        return {
          rowspan: _row_2,
          colspan: _col_2
        }
        // 第三列 流量方商户号
      } else if (columnIndex === 2) {
        const _row_3 = this.spanArr3[rowIndex]
        const _col_3 = _row_3 > 0 ? 1 : 0
        return {
          rowspan: _row_3,
          colspan: _col_3
        }
      } else if (columnIndex === t) {
        const _row_4 = len
        const _col_4 = 1
        return {
          rowspan: _row_4,
          colspan: _col_4
        }
      } else if (rowIndex === len) {
        return {
          rowspan: 1,
          colspan: 1
        }
      }
    },
    // 初始化合并行数组
    mergeInit() {
      this.spanArr1 = [] // 合并序号
      this.spanIndex1 = 0 // 合并序号索引
      this.spanArr2 = [] // 合并流量方
      this.spanIndex2 = 0 // 合并流量方索引
      this.spanArr3 = [] // 合并流量方商户号
      this.spanIndex3 = 0 // 合并流量方商户号索引
    },
    //  合并表格
    merge(data) {
      this.mergeInit()
      if (data.length > 0) {
        for (var i = 0; i < data.length; i++) {
          if (i === 0) {
            // 第一行必须存在,以第一行为基准
            this.spanArr1.push(1) // 合并序号
            this.spanIndex1 = 0
            this.spanArr2.push(1) // 合并流量方
            this.spanIndex2 = 0
            this.spanArr3.push(1) // 合并流量方商户号
            this.spanIndex3 = 0
          } else {
            if (data[i].merchantId == data[i - 1].merchantId) {
              this.spanArr1[this.spanIndex1] += 1
              this.spanArr1.push(0)
              this.spanArr2[this.spanIndex2] += 1
              this.spanArr2.push(0)
              this.spanArr3[this.spanIndex3] += 1
              this.spanArr3.push(0)
            } else {
              this.spanArr1.push(1)
              this.spanIndex1 = i
              this.spanArr2.push(1)
              this.spanIndex2 = i
              this.spanArr3.push(1)
              this.spanIndex3 = i
            }
          }
        }
      }
    },
    // 查看详情
    handleStoreView(row) {
      this.close({ tagName: '/inStoreGoalsConfig' })
      this.$router.push({
        path: '/inStoreConfigView',
        query: row
      })
    },
    // 新增配置
    handleAdd() {
      this.close({ tagName: '/inStoreGoalsConfig' })
      const queryObj = { idEdit: false }
      this.$router.push({
        path: '/addInStoreConfig',
        query: queryObj
      })
    },
    // 编辑配置
    handleStoreEdit(row) {
      this.close({ tagName: '/inStoreGoalsConfig' })
      const queryObj = { idEdit: true, ...row }
      this.$router.push({
        path: '/addInStoreConfig',
        query: queryObj
      })
    },
    // 重置
    handleReset() {
      this.searchForm = {
        allMerchantName: '',
        allMerchantId: '',
        sceneType: '',
        configStatus: ''
      }
      this.$refs.storeTargetTable.refreshTable(true, true)
    }
  }
}
</script>
<style lang="scss" scoped>
.m-t-40 {
  margin-top: 40px;
}
</style>