gas.vue 3.4 KB
<template>
  <GLTable
    v-loading="loading"
    ref="serviceRef"
    :tableData="serviceList"
    :tableParams="tableParams"
    @refreshTable="getServiceList"
    @select="handleSelectionServiceTable(...arguments, 'oilCouponId')"
    @select-all="handleSelectionServiceTableAll(...arguments, 'oilCouponId')"
  >
    <template
      slot="gasImageSlot"
      slot-scope="scope"
    >
      <el-popover
        placement="top"
        trigger="hover"
      >
        <img
          class="img-plus"
          :src="scope.scope.aliasUrl"
        />
        <template slot="reference">
          <img
            :src="scope.scope.aliasUrl"
            class="img"
          >
        </template>
      </el-popover>
    </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,'oilCouponId')"
      ></el-input-number>
    </template>
  </GLTable>
</template>

<script type='text/ecmascript-6'>
import selectedMixin from '../mixins/selectedMixin'
export default {
  name: 'gas',
  mixins: [selectedMixin],
  props: {
    selectedGasList: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
      loading: false,
      serviceList: [],
      tableParams: {
        listName: 'list',
        // 行数据的key
        mutiSelectUniqueKey: 'packageCode',
        checkSelectKey: 'id',
        checkSelectVal: '',
        checkSelectable: null,
        // 多选ref的名称
        mutiSelectName: 'list',
        tableColumns: [
          {
            label: '商品图片',
            addHtml: 'gasImageSlot',
            width: 100
          },
          {
            label: '名称',
            prop: 'aliasName',
          },
          {
            label: '油卡面额/元',
            prop: 'faceValue',
          },
          {
            label: '售价/元',
            formatter: cellValue => {
              return cellValue.salesPrice ? Number(cellValue.salesPrice / 100).toFixed(2) : '--'
            }
          },
          {
            label: '选择数量',
            addHtml: 'amount'
          }
        ]
      },
      selectedList: [],
    }
  },
  mounted () {
    this.selectedList = this.selectedGasList
    this.getServiceList()
  },
  methods: {
    getServiceList () {
      const { page: { pageNum, pageSize } } = this.$refs.serviceRef,
        params = {
          pageNum,
          pageSize
        }
      this.loading = true
      this.$apis.points.getOilCouponList(params).then(res => {
        this.loading = false
        res.list.map(e => {
          let maxStock = e.stock - e.usedStock
          e.amount = 1
          e.oilCouponId = e.id
          e.maxStock = maxStock > 10 ? 10 : maxStock
        })
        // 重置分页组件
        this.serviceList = res.list
        this.$refs.serviceRef.tableTotal = res.total
        this.selectedPreExisting(this.selectedList, this.serviceList, 'oilCouponId', this.$refs.serviceRef)
        this.setAmount(this.selectedList, this.serviceList, 'oilCouponId')
      }).finally(() => {
        this.loading = false
      })
    },

  }
}
</script>

<style scoped lang='scss'>
.img {
  width: 36px;
  height: 36px;
  // img{
  //   width: 100%;
  //   height: 100%;
  // }
}
.img-plus {
  width: 200px;
  height: 200px;
}
</style>