index.vue 9.88 KB
<!-- 发券宝 -->
<template>
  <d2-container class="coupons">
    <div class="header"
         slot="header">
      <d2-search ref="showSearch"
                 class="show-search"
                 :search-form="parentSearchForm"
                 :form-data="copyShowFormData" />
      <div class="up-btns">
        <el-button size="small"
                   type="primary"
                   @click="handleSearch">
          查询
        </el-button>
        <el-button size="small"
                   @click="handleReset"> 重置 </el-button>
      </div>
    </div>
    <div class="d2-container-content"
         style="position: positive">
      <span style="position: absolute; right: 41px; top: 42px; z-index: 999">
        <auth-button :show-btn-ids="
                       activeName === 'storeList' ? ['9030601', '9030605'] : ['9030605']
                     "
                     category="Button" />
      </span>
      <el-tabs v-model="activeName"
               type="card"
               @tab-click="handleReset">
        <el-tab-pane label="店面列表"
                     name="storeList">
          <store-list v-if="activeName == 'storeList'"
                      ref="storeList"
                      :parent-search-form="parentSearchForm" />
        </el-tab-pane>
        <el-tab-pane label="领用明细"
                     name="couponsDetail">
          <coupons-detail v-if="activeName == 'couponsDetail'"
                          ref="couponsDetail"
                          :parent-search-form="parentSearchForm" />
        </el-tab-pane>
      </el-tabs>
    </div>
    <edit-coupons-dialog :coupons-visible="couponsVisible"
                         @couponClose="couponClose" />
  </d2-container>
</template>

<script>
import storeList from './storeList'
import couponsDetail from './couponsDetail'
import editCouponsDialog from './editCouponsDialog'
// import { exportListApi, exportDetailListApi } from '@api/coupons'
// import { asyncExportExcel } from '@api/sys.base'
import { getDistinctColum } from '@api/coupons'
import { Util, deepClone } from '@/common/util'
import { BaseData, inviteStatusList } from '@/common/constants.js'
import { mapActions, mapState } from 'vuex'
export default {
  name: 'Coupons',
  data() {
    return {
      activeName: 'storeList',
      parentSearchForm: {
        couponName: '',
        merchantNameKeyWord: ''
      },
      copyShowFormData: [],
      showFormData: [{
        label: '礼券名称',
        name: 'couponName',
        type: 'input',
        isClear: true,
        keyFn: this.handleSearch
      }, {
        label: '门店名称',
        name: 'merchantNameKeyWord',
        type: 'input',
        isClear: true,
        keyFn: this.handleSearch
      }],
      // 新增
      couponsVisible: false,
      baseData: {
        couponTypeList: [],
        enabledFlagList: [{ confLabel: '启用', confId: 'Y' }, { confLabel: '停用', confId: 'N' }],
        employeeNameList: [],
        sellerNameList: [],
        couponTypeList: [],
        usedFlagList: [{ confValue: '待核销', confId: 'N' }, { confValue: '已核销', confId: 'Y' }],
        inviteStatusList: inviteStatusList
      }
    }
  },

  components: {
    storeList,
    couponsDetail,
    editCouponsDialog
  },

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

  watch: {
    activeName: {
      handler(newVal) {
        this.parentSearchForm = {
          couponName: '',
          merchantNameKeyWord: ''
        }
        this.changeShowFormData()
      }
    }
  },

  mounted() {
    this.getBaseData()
  },

  methods: {
    ...mapActions('d2admin/user', ['actionSetDownloadList']),
    ...mapActions({ get: 'd2admin/base/get' }),
    handleSearch() {
      // console.log(this.activeName)
      this.$nextTick(() => {
        this.$refs[this.activeName].keyDowmGetList()
      })
    },
    async getBaseData() {
      this.baseData.couponTypeList = deepClone(await this.get(BaseData.productType))
      this.getDistinctColumList(2, 'sellerNameList')
      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.changeShowFormData()
      })
    },
    changeShowFormData() {
      const copyShowFormData = deepClone(this.showFormData)
      switch (this.activeName) {
        case 'storeList':
          copyShowFormData.push({
            label: '类型',
            name: 'couponTypeList',
            type: 'select',
            multiple: true,
            isClear: true,
            optionList: this.baseData.couponTypeList,
            optionId: 'goodsType',
            optionLabel: 'goodsTypeName',
            collapseTags: true,
            keyFn: this.handleSearch
          }, {
            label: '状态',
            name: 'enabledFlagList',
            type: 'select',
            multiple: true,
            isClear: true,
            optionList: this.baseData.enabledFlagList,
            optionId: 'confId',
            optionLabel: 'confLabel',
            keyFn: this.handleSearch
          })
          this.copyShowFormData = copyShowFormData
          break
        case 'couponsDetail':
          copyShowFormData.push({
            label: '类型',
            name: 'couponTypes',
            type: 'select',
            multiple: true,
            isClear: true,
            optionList: this.baseData.couponTypeList,
            optionId: 'goodsType',
            optionLabel: 'goodsTypeName',
            collapseTags: true,
            keyFn: this.handleSearch
          }, {
            label: '发券人',
            name: 'employeeNameKeyword',
            type: 'input',
            isClear: true,
            keyFn: this.handleSearch
          }, {
            label: '核销状态',
            name: 'usedFlagList',
            type: 'select',
            multiple: true,
            isClear: true,
            optionList: this.baseData.usedFlagList,
            optionId: 'confId',
            optionLabel: 'confValue',
            keyFn: this.handleSearch
          }, {
            label: '核销人',
            name: 'sellerNameList',
            type: 'select',
            multiple: true,
            isClear: true,
            optionList: this.baseData.sellerNameList,
            optionId: 'confId',
            optionLabel: 'confValue',
            collapseTags: true,
            keyFn: this.handleSearch
          }, {
            label: '领用时间',
            name: 'useTime',
            type: 'datePicker',
            isClear: true,
            pickerOptions: 'rangePickerOptions',
            keyFn: this.handleSearch
          }, {
            label: '预约状态',
            name: 'inviteStatus',
            type: 'select',
            // multiple: true,
            isClear: true,
            optionList: this.baseData.inviteStatusList,
            optionId: 'confId',
            optionLabel: 'confValue',
            keyFn: this.handleSearch
          }, {
            label: '客户车型',
            name: 'carSeriesName',
            type: 'input',
            isClear: true,
            keyFn: this.handleSearch
          })
          this.copyShowFormData = copyShowFormData
          break
      }
    },
    handleReset() {
      this.parentSearchForm = {
        couponName: '',
        merchantNameKeyWord: ''
      }
      this.handleSearch()
    },
    handleExport() {
      // this.activeName === 'storeList'
      //   ? exportListApi({
      //     ...this.parentSearchForm,
      //     currentPage: 1
      //   }).then(res => {
      //     this.$open(res)
      //   })
      //   : exportDetailListApi({
      //     ...this.parentSearchForm,
      //     currentPage: 1
      //   }).then(res => {
      //     this.$open(res)
      //   })
      var method = this.activeName === 'storeList'
        ? 'dj.api.life.merchant.coupon.exportExcel.async'
        // ? 'dj.api.life.merchant.coupon.exportExcel'
        // : 'dj.api.life.customer.coupon.exportExcel'
        : 'dj.api.life.customer.coupon.exportExcel.async'

      var params = {
        ...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' : '',
        currentPage: 1,
        method: method
      }

      for (const key in params) {
        if (params[key] instanceof Array && params[key]?.length < 1) {
          delete params[key]
        } else if (params[key] instanceof Array) {
          params[key]?.forEach((val, index) => {
            const keyName = `${key}[${index}]`
            params[keyName] = val
            delete params[key]
          })
        }
      }

      // asyncExportExcel({ exportParam: JSON.stringify(params) }).then(res => {
      const list = [
        ...this.dowloadList,
        {
          name: this.activeName === 'storeList'
            ? '店面列表'
            : '领用明细',
          exportParam: JSON.stringify(params),
          status: 'waiting',
          timeid: new Date().getTime()
        }
      ]
      this.actionSetDownloadList({ list, type: 'dowloadList' })
      // })
    },
    handleAdd() {
      this.couponsVisible = !this.couponsVisible
      // this.$refs.couponAddForm && this.$refs.couponAddForm.resetFields()
    },
    couponClose(isRefresh) {
      this.couponsVisible = !this.couponsVisible
      isRefresh && this.handleSearch()
      // this.$refs.couponAddForm && this.$refs.couponAddForm.resetFields()
    }
  }
}

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