service.vue 7.18 KB
<template>
  <div class="service-box">
    <div class="service-flex">
      <div class="service-tab">
        <template v-for="(item) in serviceTabList">
          <template>
            <div
              :class="['tab-item',{ active: discountType == item.type }]"
              :key="item.type"
              @click="discountType = item.type"
            >
              {{ item.label }}
            </div>
          </template>
        </template>
        <div
          class="tab-border"
          :style="setLeft"
        ></div>
      </div>
      <!-- <div class="service-tip">(仅支持引用无限库存券)</div> -->
      <div class="tab-right">
        <div
          class="refresh-btn"
          @click="getServiceList"
        >
          <i class="el-icon-refresh-right"></i>
          刷新列表
        </div>
        <div
          class="add-btn"
          @click="addCoupon"
        >
          <i class="el-icon-plus"></i>
          新建
        </div>
      </div>
    </div>
    <template v-for="(item, index) in serviceTabList">
      <template>
        <div :key="index">
          <GLTable
            v-loading="loading"
            v-show="discountType == item.type"
            :ref="'serviceRef' + item.type"
            :tableData="serviceList"
            :tableParams="tableParams"
            @refreshTable="getServiceList"
            @select="handleSelectionServiceTable(...arguments, 'couponId')"
            @select-all="handleSelectionServiceTableAll(...arguments, 'couponId')"
          >
            <template
              slot="effectiveType"
              slot-scope="scope"
            >
              <span>{{ toLabelText(scope.scope) }}</span>
            </template>
            <template
              slot="stock"
              slot-scope="scope"
            >
              <span>{{ scope.scope.limitStockFlag == 1 ? scope.scope.stock : '无限制' }}</span>
            </template>
            <template
              slot="useType"
              slot-scope="scope"
            >
              <span>{{ toRestrictLabelText(scope.scope) }}</span>
            </template>
            <template
              slot="amount"
              slot-scope="scope"
            >
              <el-input-number
                size="small"
                :min="1"
                :max="scope.scope.maxStock"
                :step="1"
                v-model="scope.scope.amount"
                @change="changeAmount(...arguments,scope.scope,'couponId')"
              ></el-input-number>
            </template>
          </GLTable>
        </div>
      </template>
    </template>
  </div>
</template>

<script type='text/ecmascript-6'>
import util from '@/utils/index'
import selectedMixin from '../mixins/selectedMixin'
export default {
  name: 'service',
  mixins: [selectedMixin],
  props: {
    merchantId: [Number, String],
    selectedServiceList: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
      serviceTabList: [
        { label: '门店服务', type: 7 },
        { label: '折扣券', type: 2 },
        { label: '代金券', type: 3 },
        { label: '兑换券', type: 4 }
      ],
      discountType: 7,
      loading: false,
      serviceList: [],
      tableParams: {
        listName: 'list',
        // 行数据的key
        mutiSelectUniqueKey: 'packageCode',
        checkSelectKey: 'id',
        checkSelectVal: '',
        checkSelectable: null,
        // 多选ref的名称
        mutiSelectName: 'list',
        tableColumns: [
          {
            label: '名称',
            prop: 'couponName',
            width: 180
          },
          {
            label: '车主展示价/元',
            prop: 'anticipatedCost',
            formatter: cellValue => {
              return (cellValue.anticipatedCost / 100).toFixed(2)
            }
          },
          {
            label: '有效期',
            prop: 'effectiveType',
            addHtml: 'effectiveType'
          },
          {
            label: '使用限制',
            prop: 'useType',
            addHtml: 'useType'
          },
          {
            label: '选择数量',
            prop: 'amount',
            addHtml: 'amount'
          }
        ]
      },
      selectedList: []
    }
  },
  watch: {
    discountType () {
      this.serviceList = []
      this.getServiceList()
    }
  },
  computed: {
    setLeft () {
      const { discountType } = this
      return { left: (discountType == 7 ? 0 : discountType - 1) * 88 + 2 + 'px' }
    }
  },
  mounted () {
    this.selectedList = this.selectedServiceList
    this.getServiceList()
  },
  methods: {
    getServiceList () {
      const { discountType, merchantId } = this,
        { page: { pageNum, pageSize } } = this.$refs[`serviceRef${discountType}`][0],
        params = {
          status: 2,
          discountType,
          merchantId,
          limitStockFlag: 2,
          pageNum,
          pageSize
        }
      this.loading = true
      this.$apis.points.getghDirectionalGiftListApi(params).then(res => {
        this.loading = false
        res.list.map(e => {
          let maxStock = e.residueAmount
          e.amount = 1
          e.couponId = e.id
          e.maxStock = maxStock > 10 ? 10 : maxStock
        })
        // 重置分页组件
        this.serviceList = res.list

        this.$refs['serviceRef' + discountType][0].tableTotal = res.total
        this.selectedPreExisting(this.selectedList, this.serviceList, 'couponId', this.$refs['serviceRef' + this.discountType][0])
        this.setAmount(this.selectedList, this.serviceList, 'couponId')
      }).finally(() => {
        this.loading = false
      })
    },
    //格式化数据
    toLabelText (row) {
      return {
        3: '永久有效',
        2: row.effectiveStartTime ? row.effectiveStartTime.split(' ')[0] + '-' + row.effectiveEndTime.split(' ')[0] : '',
        1: row.effectiveDays + '天'
      }[row.effectiveType]
    },
    toRestrictLabelText (row) {
      return {
        0: '无限制',
        1: '有效期内可使用' + row.useAmount + '次',
        2: '每' + row.useLimitDays + '天可以使用' + row.useAmount + '次'
      }[row.useType]
    },
    addCoupon () {
      window.open('/login?redirect=tools%2FcouponManage%2Findex')
    },
  }
}
</script>

<style scoped lang='scss'>
.service-flex {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  .service-tip {
    color: #999;
    margin-left: 8px;
  }
  .tab-right {
    display: flex;
    margin-left: auto;
    .refresh-btn {
      cursor: pointer;
      color: #666666;
    }
    .add-btn {
      cursor: pointer;
      margin-left: 10px;
      color: #5850ff;
    }
  }

  .service-tab {
    height: 36px;
    background: #f8f8f8;
    border-radius: 4px;
    display: flex;
    // max-width: 352px;
    position: relative;
    .tab-border {
      position: absolute;
      left: 2px;
      top: 2px;
      z-index: 1;
      width: 84px;
      height: 32px;
      background: #ffffff;
      transition: all 0.25s;
      border-radius: 4px;
    }

    .tab-item {
      width: 88px;
      z-index: 2;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      &.active {
        border-radius: 3px;
        color: #5850ff;
      }
    }
  }
}
</style>