index.vue 13 KB
<!-- 商品管理-门店 -->
<template>
  <div class="marketing pro-group p-t-20">
    <div class="m-b-20">
      <GLButton :size="size" type="primary" class="el-icon-plus" @click="addCashCoupon()" fn="新建代金券" display="disabled" mode="el-button">新建代金券</GLButton>
      <GLButton :size="size" type="primary" class="el-icon-plus" style="margin-left: 30px" @click="addDiscountCoupon()" fn="新建折扣劵" display="disabled" mode="el-button">新建折扣劵</GLButton>
      <GLButton :size="size" type="primary" class="el-icon-plus" style="margin-left: 30px" @click="addExchangeCoupon()" fn="新建兑换券" display="disabled" mode="el-button">新建兑换券</GLButton>
      <!-- <el-button :size="size" type="primary" class="el-icon-plus" @click="addCashCoupon()">新建代金券</el-button> -->
      <!-- <el-button :size="size" type="primary" class="el-icon-plus" style="margin-left:30px;" @click="addService()">新建会员服务</el-button> -->
      <!-- <el-button :size="size" type="primary" class="el-icon-plus" style="margin-left: 30px" @click="addDiscountCoupon()">新建折扣劵</el-button>
      <el-button :size="size" type="primary" class="el-icon-plus" style="margin-left: 30px" @click="addExchangeCoupon()">新建兑换券</el-button> -->
    </div>
    <div class="container">
      <div>
        <glsx-combi-form ref="showSearch" :formObj="searchForm" :formData="searchFormData">
          <span slot="footer" class="footer-btns">
            <el-button :size="size" @click="handleReset">重置</el-button>
            <el-button :size="size" type="primary" @click="handleSearch">查询</el-button>
            <el-button :size="size" type="primary" @click="handleExport">导出</el-button>
          </span>
        </glsx-combi-form>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="coupon" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <GLButton v-if="scope.scope.status == '1'" type="text" @click="start(scope.scope)" fn="生效" display="disabled" mode="el-button">生效</GLButton>
          <!-- <el-button v-if="scope.scope.status == '1'" type="text" @click="start(scope.scope)">生效</el-button> -->
          <el-button v-if="scope.scope.status == '2'" type="text" @click="end(scope.scope)">失效</el-button>
          <!-- <el-button v-if="scope.scope.status == '1'" type="text" @click="handleEdit(2, scope.scope)">编辑</el-button> -->
          <GLButton v-if="scope.scope.status == '2' || scope.scope.status == '3'" type="text" @click="handleEdit(3, scope.scope)" :fn="scope.scope.discountType == 3 ? '查看代金券' : scope.scope.discountType == 7 ? '查看会员服务' : scope.scope.discountType == 2 ? '查看折扣券' : '查看兑换券'" mode="el-button">查看</GLButton>
          <!-- <el-button v-if="scope.scope.status == '2' || scope.scope.status == '3'" type="text" @click="handleEdit(3, scope.scope)">查看</el-button> -->
          <GLButton v-if="scope.scope.status == '1' || scope.scope.status == '3'" type="text" @click="del(scope.scope)" fn="删除" mode="el-button" display="disabled">删除</GLButton>
          <!-- <el-button v-if="scope.scope.status == '1' || scope.scope.status == '3'" type="text" @click="del(scope.scope)">删除</el-button> -->
          <GLButton type="text" @click="writeOffDetail(scope.scope)" fn="核销详情" mode="el-button">核销详情</GLButton>
          <GLButton type="text" @click="receiveDetail(scope.scope)" fn="领取详情" mode="el-button">领取详情</GLButton>
          <!-- <el-button type="text" @click="writeOffDetail(scope.scope)">核销详情</el-button>
          <el-button type="text" @click="receiveDetail(scope.scope)">领取详情</el-button> -->
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>

<script>
import url from '@/assets/empty.png'
import { exportFn } from '@/common/constant'
export default {
  name: 'coupon',
  data() {
    return {
      size: 'small',
      url: url,
      // 下架
      isDownVisible: false,
      downForm: {
        id: '',
        offReason: '',
        goodsStatus: 0
      },
      downRules: {
        offReason: [{ required: true, message: '请输入下架备注', trigger: 'change' }]
      },
      // 分享
      isShareVisible: false,
      shareForm: {},
      // 表格
      searchForm: {
        couponName: '',
        discountType: '',
        status: '',
        discountTypes: [2, 3, 4]
      },
      tableSearchForm: {},
      // 搜索
      searchFormData: [
        {
          label: '名称',
          name: 'couponName',
          type: 'input',
          maxlength: 20
        },
        // {
        //   label: '创建日期',
        //   name: 'createDate',
        //   type: 'datePicker',
        //   isClear: true,
        //   pickerOptions: 'beforeRangePickerOptions'
        // },
        {
          label: '优惠券类型',
          name: 'discountType',
          type: 'select',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confName',
          optionsName: 'discountTypeList'
        },
        {
          label: '优惠券状态',
          name: 'status',
          type: 'select',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confName',
          optionsName: 'statusList'
        }
      ],
      // 表格
      getListApi: this.$apis.couponManage.getMerchantListApi,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '名称',
            prop: 'couponName',
            line: 2
          },
          {
            label: '优惠券类型',
            name: 'discountType',
            formatter: cellValue => {
              return this.baseData.discountTypeList.find(item => item.confId == cellValue.discountType).confName
            }
          },
          {
            label: '已领取',
            prop: 'getAmount'
          },
          {
            label: '剩余',
            prop: 'residueAmount'
          },
          {
            label: '使用途径',
            name: 'useChannel',
            formatter: cellValue => {
              var useChannel = ''
              if (cellValue.useChannel) {
                useChannel = this.baseData.useChannelList.find(item => item.confId == cellValue.useChannel).confName
              }
              return useChannel
            }
          },
          {
            label: '优惠券状态',
            name: 'status',
            formatter: cellValue => {
              return this.baseData.statusList.find(item => item.confId == cellValue.status).confName
            }
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      baseData: {
        discountTypeList: [
          {
            confId: '2',
            confName: '折扣券'
          },
          {
            confId: '3',
            confName: '代金券'
          },
          {
            confId: '4',
            confName: '兑换券'
          }
          // {
          //   confId: '7',
          //   confName: '会员服务'
          // }
        ],
        statusList: [
          {
            confId: '1',
            confName: '未生效'
          },
          {
            confId: '2',
            confName: '生效中'
          },
          {
            confId: '3',
            confName: '已失效'
          }
        ],
        useChannelList: [
          {
            confId: '1',
            confName: '线上商品'
          },
          {
            confId: '2',
            confName: '到店核销'
          }
        ]
      }
    }
  },

  components: {},

  mounted() {
    this.getOptionsList('searchFormData')
  },

  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        // delete this.tableSearchForm.createDate
        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()
              }
            })
          }
        }
      })
    },

    //生效
    start(item) {
      this.startOrEndConfirm('生效', item)
    },

    //失效
    end(item) {
      this.startOrEndConfirm('失效', item)
    },

    startOrEndConfirm(txt, row) {
      var title = txt
      var params = {}
      params.couponId = row.id
      if (txt == '生效') {
        params.status = '2' //优惠券状态(2:生效,3:失效)
      } else if (txt == '失效') {
        params.status = '3' //优惠券状态(2:生效,3:失效)
      }
      this.secondConfirm(title, '确定要' + txt + '该优惠券?', 'couponManage', 'effectiveCouponApi', params)
    },

    //核销记录
    writeOffDetail(row) {
      this.$router.push('/couponManage/writeOffDetail/' + row.id)
    },

    //领取记录
    receiveDetail(row) {
      this.$router.push('/couponManage/receiveDetail/' + row.id)
    },

    //删除
    del(row) {
      var params = {}
      params.couponId = row.id
      this.secondConfirm('删除', '确定删除此优惠券?', 'couponManage', 'deleteCouponApi', params)
    },

    //新增代金券
    addCashCoupon() {
      this.$router.push('/couponManage/editCashCoupon/1')
    },

    //新增会员服务
    addService() {
      this.$router.push('/couponManage/editMemberService/1')
    },

    //新增折扣劵
    addDiscountCoupon() {
      this.$router.push('/couponManage/editDiscountCoupon/1')
    },

    //新增兑换劵
    addExchangeCoupon() {
      this.$router.push('/couponManage/editExchangeCoupon/1')
    },

    // addOrEdit:1-新增;2-编辑;3-查看
    handleEdit(addOrEdit, row) {
      var goto = ''
      //优惠券类型 1:满减券,2:折扣券,3:代金券,4:实物券 5:购车代金券 6:商品折扣券,7:会员服务
      if (row.discountType == '3') {
        //代金券
        goto = '/couponManage/editCashCoupon/'
      } else if (row.discountType == '7') {
        //会员服务
        goto = '/couponManage/editMemberService/'
      } else if (row.discountType == '2') {
        //折扣劵
        goto = '/couponManage/editDiscountCoupon/'
      } else if (row.discountType == '4') {
        //兑换券
        goto = '/couponManage/editExchangeCoupon/'
      }
      this.$router.push(goto + addOrEdit + '/' + row.id)
    },

    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find(k => k.name == refreshSigle)
        var index = this[formName].findIndex(k => k.name == refreshSigle)
        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)
        }
      } else {
        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)
            }
          }
        })
      }
    },

    handleExport(row) {
      var params = this.getParams()
      this.$apis.couponManage.couponExportApi(params).then(res => {
        exportFn(res)
      })
    },

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

    handleReset() {
      this.searchForm = {
        couponName: '',
        discountType: '',
        status: '',
        discountTypes: [2, 3, 4]
      }
      this.handleSearch()
    },

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

<style scoped></style>