storeList.vue 7.12 KB
<!-- 发券宝 - 店里列表 -->
<template>
  <div class="coupons">
    <d2-table ref="couponsTable" :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">
      <template slot="auth-button" slot-scope="scope">
        <auth-button :data="scope.scope" />
      </template>
    </d2-table>
    <edit-coupons-dialog :coupons-visible="couponsVisible" :coupon-info="couponInfo" @couponClose="couponClose" />
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import { BaseData } from '@/common/constants.js'
import { deepClone } from '@/common/util'
import editCouponsDialog from './editCouponsDialog'
import { getList, deleteCouponApi, updateCouponApi } from '@api/coupons'
import { commonConfigApi } from '@api/sys.base'
export default {
  name: 'StoreList',
  data() {
    return {
      searchForm: {
        couponTypeList: [],
        regionList: [],
        enabledFlagList: []
      },
      searchFormSearch: {},
      // 编辑
      couponsVisible: false,
      // isAdd: false,
      // 表格参数
      getListApi: getList,
      sortObj: {
        amount: {
          ascending: 1,
          descending: 2
        },
        allowance: {
          ascending: 3,
          descending: 4
        },
        getAmount: {
          ascending: 5,
          descending: 6
        },
        usedAmount: {
          ascending: 7,
          descending: 8
        }
      },
      tableParams: {
        needUnique: true,
        // btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '批次号',
          prop: 'merchantCouponCode'
        }, {
          label: '礼券名称',
          parentProp: 'couponInfo',
          prop: 'couponName'
        }, {
          label: '类型',
          parentProp: 'couponInfo',
          prop: 'couponTypeName'
          // optionConfig: {
          //   searchItemName: 'couponTypeList',
          //   optionId: 'goodsType',
          //   optionLabel: 'goodsTypeName'
          // }
          // optionList: []
        },
        // {
        //   label: '区域',
        //   parentProp: 'yqMerchantInfo',
        //   prop: 'region',
        //   optionConfig: {
        //     searchItemName: 'regionList',
        //     optionId: 'confKey',
        //     optionLabel: 'confValue'
        //   }
        //   // optionList: []
        // },
        {
          label: '门店名称',
          prop: 'merchantName',
          formatter: cellValue => {
            return cellValue.merchantName + ' - ' + cellValue.yqMerchantName
          }
        }, {
          label: '总数',
          prop: 'amount',
          sortable: 'custom'
        }, {
          label: '余量',
          prop: 'allowance',
          sortable: 'custom',
          formatter: cellValue => {
            return cellValue.amount - cellValue.getAmount
          }
        }, {
          label: '发放量',
          prop: 'getAmount',
          sortable: 'custom'
        }, {
          label: '核销量',
          prop: 'usedAmount',
          sortable: 'custom'
        }, {
          label: '状态',
          prop: 'enabledFlag',
          // optionConfig: {
          //   searchItemName: 'enabledFlagList',
          //   optionId: 'confId',
          //   optionLabel: 'confLabel'
          // },
          // optionList: [{ confLabel: '启用', confId: 'Y' }, { confLabel: '停用', confId: 'N' }],
          formatter: cellValue => {
            return {
              Y: '启用',
              N: '停用'
            }[cellValue.enabledFlag]
          }
        }]
      },
      // 基本数据
      baseData: {
        productTypeList: [],
        couponTypeList: [],
        regionList: [],
        enabledFlagList: [{ confLabel: '启用', confId: 'Y' }, { confLabel: '停用', confId: 'N' }]
      },
      couponInfo: {}
    }
  },

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

  components: {
    editCouponsDialog
  },

  mounted() {
    // this.getBaseData()
    // this.getCommonConfig()
  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get'
    }),
    async getBaseData() {
      // this.tableParams.tableColumns[this.findFormIdx('couponTypeName')].optionList = deepClone(await this.get(BaseData.productType))
      this.baseData.couponTypeList = deepClone(await this.get(BaseData.productType))
      this.$nextTick()
    },
    getCommonConfig() {
      commonConfigApi({ confGroup: 'MERCHANT_REGION' }).then(res => {
        // this.tableParams.tableColumns[this.findFormIdx('region')].optionList = res
        // console.log(this.tableParams.tableColumns[this.findFormIdx('region')])
        this.baseData.regionList = res
        this.$nextTick()
      })
    },
    // 找到在formList的位置,通过name来匹配
    findFormIdx(prop) {
      return this.tableParams.tableColumns.findIndex(item => item.prop === prop)
    },
    keyDowmGetList() {
      this.$refs.couponsTable.refreshTable(true, true)
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchFormSearch = {
          ...this.parentSearchForm
          // ...this.searchForm
        }
        resolve()
      })
    },

    // 表格头部搜索-改变
    handleTableHeadChange({ searchItemName, checkedList }) {
      this.searchForm[searchItemName] = deepClone(checkedList)
      this.keyDowmGetList()
    },

    // 编辑
    handleEdit(row) {
      this.couponInfo = row
      this.couponsVisible = !this.couponsVisible
    },

    couponClose(isRefresh) {
      this.couponsVisible = !this.couponsVisible
      isRefresh && this.keyDowmGetList()
      // this.$refs.couponAddForm && this.$refs.couponAddForm.resetFields()
    },

    // 停用
    handleDisabled(row) {
      this.$confirm('是否' + (row.enabledFlag === 'Y' ? '停用' : '启用') + '该礼券?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateCouponApi({
          id: row.id,
          enabledFlag: row.enabledFlag === 'Y' ? 'N' : 'Y'
        }).then(res => {
          this.notice.okTips()
          this.$refs.couponsTable.refreshTable()
        })
      }).catch(err => {
        console.log(err)
      })
    },
    // 删除
    handleDelete(row) {
      this.$confirm('是否确认删除该礼券?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'error'
      }).then(() => {
        deleteCouponApi({ id: row.id }).then(res => {
          this.notice.okTips()
          this.$refs.couponsTable.refreshTable()
        })
      }).catch(err => {
        console.log(err)
      })
    }
  }
}

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