giftList.vue 8.8 KB
<!-- 定向礼包-->
<template>
  <div class="marketing">
    <div class="m-b-10">
      <!-- <el-button :size="size" type="primary" fn="新增礼包" class="el-icon-plus" @click="handleEdit('add')">新增礼包</el-button> -->
      <GLButton :size="size" type="primary" fn="新增礼包" class="el-icon-plus" @click="handleEdit('add')">新增礼包</GLButton>
    </div>
    <div class="list-tips m-b-10">
      <img class="tips-img" src="@/assets/icon-info.png" />
      <span>集团礼包:将多种券组合成礼包,由集团指定的门店进行发放,客户领取后可在指定的门店间进行使用。</span>
    </div>
    <div class="container">
      <div>
        <GLCombiForm @handleOk="handleSearch" :rowNumber="1" @handleRest="handleReset" ref="showSearch" :formObj="searchForm" :formData="searchFormData"></GLCombiForm>
        <GLButton style="float:right;margin-bottom:10px;" :size="size" class="default-blue-btn" type="default" fn="导出" @click="handleExport">导出</GLButton>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="giftListRef" :getListApi="getListApi" :hasNum="false" :noDataImg="url" :searchForm="searchForm" :tableParams="tableParams" :pageConf="pageConf" @setTableFinishFun="setTableFinishFun">
        <div slot="giftInfo" slot-scope="scope">
          <div class="p-b-12">礼包明细</div>
          <div class="gift-detail flex-wrap">
            <div class="gift-item" v-for="(item, index) in scope.scope.couponDTOList" :key="index">
              <img :src="require(`@/assets/coupon/icon-${attrToIcon[item.discountType]}.png`)" />
              <p :class="['gift-coupon-name', item.status == '3' ? ' txt-grey' : '']">{{ item.couponName }} × {{ item.couponAmount }}</p>
              <p v-show="item.status == '3'" class="gift-tips">已失效</p>
            </div>
          </div>
        </div>
        <div slot="name" slot-scope="scope">
          <p class="cursor-pointer" @click="handleDetail(scope.scope)">{{ scope.scope.name }}</p>
        </div>
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
        </div>
      </GLTable>
    </div>
  </div>
</template>

<script>
import url from '@/assets/empty.png'
import { aToExport } from '@/common/constant'
export default {
  name: 'giftList',
  data() {
    return {
      attrToIcon: {
        2: 'discount',
        3: 'cash',
        4: 'exchange',
        7: 'service'
      },
      buttonList: [
        {
          type: 'GLButton',
          name: row => {
            return '编辑'
          },
          attrs: {
            type: 'text',
            fn: '编辑'
          },
          listeners: {
            click: row => this.handleEdit('edit', row.scope)
          }
        },
        {
          type: 'GLButton',
          name: row => {
            return '删除'
          },
          attrs: {
            type: 'text',
            fn: '删除'
          },
          listeners: {
            click: row => this.handleDelete(row.scope)
          }
        }
      ],
      size: 'small',
      url: url,
      searchForm: {
        name: '',
        merchantName: ''
      },
      // 搜索
      searchFormData: [
        {
          label: '礼包名称',
          name: 'name',
          type: 'input',
          maxlength: 30,
          placeholder: '请输入礼包/备注名称',
          isClear: true
        },
        {
          label: '下发门店',
          name: 'merchantName',
          type: 'input',
          maxlength: 30,
          placeholder: '请输入门店名称',
          isClear: true
        },
      ],
      // 表格
      getListApi: this.$apis.groupGiftBag.getListApi,
      tableParams: {
        listName: 'list',
        tableOption: {
          width: 200,
          align: 'center'
        },
        tableColumns: [
          {
            label: '',
            prop: '',
            columnattrs: {
              type: 'expand'
            },
            addHtml: 'giftInfo'
          },
          {
            label: '序号',
            prop: 'idx',
            width: 60
          },
          {
            label: '礼包名称',
            prop: 'name',
            addHtml: 'name'
          },
          {
            label: '预估成本/元',
            prop: 'anticipatedCost',
            formatter: cellValue => {
              let total = cellValue.couponDTOList.reduce(function(prev, cur) {
                return prev + +(cur.couponAnticipatedCost * cur.couponAmount).toFixed(0)
              }, 0)
              return total / 100
            }
          },
          {
            label: '下发门店',
            prop: 'staffList',
            line: 1,
            formatter: cellValue => {
              return cellValue.storeList.map(item => item.merchantName).join('、')
            }
          },
          {
            label: '已领取',
            prop: 'stock',
            formatter: cellValue => {
              return cellValue.receivedAmount || '0'
            }
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
    }
  },

  mounted() {
  },

  methods: {
    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()
              }
            })
          }
        }
      })
    },

    handleDelete(row) {
      this.secondConfirm('删除', '是否确认删除该礼包?', 'groupGiftBag', 'deleteGiftApi', { id: row.id })
    },
    // 导出
    handleExport() {
      var params = {...this.searchForm}
      this.$apis.groupGiftBag.giftExportApi(params).then(res => {
        aToExport(res)
      })
    },
    // 查看
    handleDetail(row) {
      this.$router.push({
        path: '/groupGiftBag/giftDetail',
        query: {
          id: row.id
        }
      })
    },

    // add-新增;edit-编辑
    handleEdit(addOrEdit, row) {
      var params = {
        addOrEdit: addOrEdit,
        $title: encodeURI(addOrEdit == 'add' ? '新增礼包' : '编辑礼包')
      }
      addOrEdit != 'add' && (params.id = row.id)
      this.$router.push({
        path: '/groupGiftBag/editGift',
        query: params
      })
    },
    setTableFinishFun() {
      var page = this.$refs.giftListRef.page
      // 添加序号
      this.$refs.giftListRef.data.forEach((item, index) => {
        item.idx = index + (page[this.pageConf.pageNum] - 1) * page[this.pageConf.pageSize] + 1
      })
      //接收到的数据为空
      this.$refs.giftListRef.data.length ? (this.$refs.giftListRef.tableHeightValues = '') : this.$refs.giftListRef.setTableHeightFun()
    },

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

    handleReset() {
      this.searchForm = {
        name: '',
        merchantName: ''
      },
      this.handleSearch()
    }
  }
}
</script>

<style lang="scss" scoped>
.p-b-12 {
  margin-bottom: 14px;
  font-weight: 500;
  padding-left: 10px;
  color: #333333;
}
.approve-status {
  width: 6px;
  height: 6px;
  border-radius: 4px;
  margin-right: 8px;
  display: inline-block;
}

.qr-dialog {
  /deep/.el-dialog__body {
    // padding: 20px;
    .el-scrollbar__wrap {
      overflow: hidden;
    }
    .qrcode-body {
      display: flex;
      flex-direction: column;
      align-items: center;
      p {
        line-height: 28px;
        margin-bottom: 16px;
      }
      .el-select {
        .el-input__inner {
          width: 360px;
          height: 36px;
        }
        .el-input__icon {
          line-height: 36px;
        }
      }
      .img {
        margin-top: 16px;
        background: #eee;
        display: flex;
        align-items: center;
        justify-content: center;
        &,
        img {
          width: 160px;
          height: 160px;
        }
      }
    }
  }
}

.gift-detail {
  padding:0 200px 0 10px;
  .gift-item {
    margin-right: 80px;
    display: flex;
    align-items: center;
    color: #333333;
    width: 400px;
    img {
      height: 23px;
      width: 58px;
      margin-right: 10px;
    }
    .gift-coupon-name {
      display: inline-block;
    }
    .gift-tips {
      display: inline-block;
      font-size: 12px;
      height: 18px;
      line-height: 18px;
      color: #999999;
      background-color: #eeeded;
      margin-right: 7px;
    }
  }
}
.gift-detail .gift-item:last-child {
  margin-right: 0;
}
</style>