couponsDetail.vue 7.12 KB
<!-- 领用详情 -->
<template>
  <div class="couponsDetail">
    <d2-table ref="couponsDetailTable"
              :has-num="false"
              :base-data="baseData"
              :sort-obj="sortObj"
              :search-form="searchFormSearch"
              :head-search-form="searchForm"
              :table-params="tableParams"
              :get-list-api="getListApi"
              :before-search-fn="beforeSearchFn"
              @handleTableHeadChange="handleTableHeadChange">
      <span slot="couponName"
            slot-scope="scope">{{ scope.scope.couponName }}{{ scope.scope.customerCouponCode }}</span>
    </d2-table>
  </div>
</template>

<script>
import { getDetailList, getDistinctColum } from '@api/coupons'
import { Util, deepClone } from '@/common/util'
import { BaseData, inviteStatusList } from '@/common/constants.js'
import { mapActions } from 'vuex'
export default {
  name: 'CouponsDetail',
  data() {
    return {
      searchForm: {
        usedFlagList: [],
        employeeNameList: [],
        sellerNameList: [],
        couponTypeList: [],
        inviteStatus: '',
        carSeriesName: ''
      },
      searchFormSearch: {},
      getListApi: getDetailList,
      sortObj: {
        createdDate: {
          descending: 0,
          ascending: 1
        },
        usedTime: {
          ascending: 2,
          descending: 3
        }
      },
      tableParams: {
        listName: 'list',
        tableColumns: [{
          label: '领用时间',
          prop: 'createdDate',
          sortable: 'custom',
          width: '160px',
          formatter: cellValue => {
            return Util.dateFormate(cellValue.createdDate, 'YYYY-MM-DD HH:mm:ss')
          }
        }, {
          label: '车主姓名',
          prop: 'customerName'
        }, {
          label: '客户车型',
          prop: 'carSeriesName',
          width: '200px',
          formatter: cellValue => {
            let cartypeShow = ''
            if (cellValue.customerInfo && cellValue.customerInfo.carBrand) {
              cartypeShow = cellValue.customerInfo.carBrand + ' - ' + cellValue.customerInfo.carChildsBrandName + ' - ' + cellValue.customerInfo.carSeriesName
            } else {
              cartypeShow = '-'
            }
            return cartypeShow
          }
        }, {
          label: '手机号',
          prop: 'customerPhone',
          width: '120px'
        }, {
          label: '预约状态',
          prop: 'inviteStatus',
          width: '100px',
          formatter: (cellValue) => {
            return this.baseData.inviteStatusList.find(item => item.confId === cellValue.inviteStatus)?.confValue
          }
        }, {
          label: '礼券名称',
          prop: 'couponName',
          addHtml: 'couponName'
        }, {
          label: '类型',
          parentProp: 'couponInfo',
          prop: 'couponTypeName'
          // optionConfig: {
          //   searchItemName: 'couponTypeList',
          //   optionId: 'goodsType',
          //   optionLabel: 'goodsTypeName'
          // }
          // optionList: []
        }, {
          label: '门店名称',
          prop: 'merchantName',
          formatter: cellValue => {
            return cellValue.merchantCoupon.merchantName + ' - ' + cellValue.merchantCoupon.yqMerchantName
          }
        }, {
          label: '发券人',
          prop: 'employeeName'
          // optionConfig: {
          //   searchItemName: 'employeeNameList',
          //   optionId: 'confId',
          //   optionLabel: 'confValue'
          // }
          // optionList: []
        }, {
          label: '核销状态',
          prop: 'usedFlag',
          width: '100px',
          formatter: (cellValue) => {
            return {
              N: '待核销',
              Y: '已核销'
            }[cellValue.usedFlag]
          }
          // optionConfig: {
          //   searchItemName: 'usedFlagList',
          //   optionId: 'confId',
          //   optionLabel: 'confValue'
          // }
          // optionList: [{ confValue: '待核销', confId: 'N' }, { confValue: '已核销', confId: 'Y' }]
        }, {
          label: '核销人',
          prop: 'sellerName'
          // optionConfig: {
          //   searchItemName: 'sellerNameList',
          //   optionId: 'confId',
          //   optionLabel: 'confValue'
          // }
          // optionList: []
        }, {
          label: '核销时间',
          prop: 'usedTime',
          sortable: 'custom',
          width: '160px',
          formatter: cellValue => {
            return cellValue.usedTime ? Util.dateFormate(cellValue.usedTime, 'YYYY-MM-DD HH:mm:ss') : ''
          }
        }]
      },
      // 基本数据
      baseData: {
        employeeNameList: [],
        sellerNameList: [],
        couponTypeList: [],
        usedFlagList: [{ confValue: '待核销', confId: 'N' }, { confValue: '已核销', confId: 'Y' }],
        inviteStatusList: inviteStatusList
      }
    }
  },

  props: {
    parentSearchForm: {
      type: Object,
      default: () => { }
    }
  },

  mounted() {
    // this.getDistinctColumList(1, 'employeeNameList')
    // this.getDistinctColumList(2, 'sellerNameList')
    // this.getBaseData()
  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get'
    }),
    async getBaseData() {
      this.baseData.couponTypeList = deepClone(await this.get(BaseData.productType))
      this.$nextTick()
    },
    // columType属性类型(1:发券人;2:转化人)
    getDistinctColumList(columType, listName) {
      getDistinctColum({ columType: columType, currentPage: 1, pageSize: 100 }).then(res => {
        var tempArr = []
        res.forEach(item => {
          tempArr.push({
            confId: item,
            confValue: item
          })
        })
        this.baseData[listName] = tempArr
        // this.tableParams.tableColumns[this.findFormIdx(tableColumnsProp)].optionList = tempArr
      })
    },
    // 找到在formList的位置,通过name来匹配
    findFormIdx(prop) {
      return this.tableParams.tableColumns.findIndex(item => item.prop === prop)
    },
    // 表格头部搜索-改变
    handleTableHeadChange({ searchItemName, checkedList }) {
      this.searchForm[searchItemName] = deepClone(checkedList)
      this.keyDowmGetList()
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchFormSearch = {
          ...this.parentSearchForm,
          startDate: this.parentSearchForm.useTime && this.parentSearchForm.useTime.length ? Util.dateFormate(this.parentSearchForm.useTime[0], 'YYYY-MM-DD HH:mm:ss') : '',
          endDate: this.parentSearchForm.useTime && this.parentSearchForm.useTime.length ? Util.dateFormate(this.parentSearchForm.useTime[1], 'YYYY-MM-DD') + ' 23:59:59' : ''
          // ...this.searchForm
        }
        delete this.searchFormSearch.useTime
        resolve()
      })
    },
    keyDowmGetList() {
      this.$refs.couponsDetailTable.refreshTable(true, true)
    }
  }
}

</script>
<style scoped>
</style>