indexForCoupon.vue 5.85 KB
<!-- 选择商品弹窗 -->
<template>
  <glsx-dialog class="muti-pro" title="选择商品" :isVisible.sync="isMutiSelectVisible" width="70%" @confirmDialog="handleMutiSelectConfirm" @closeDialog="handleMutiSelectClose" :noClose="false" :noCancel="true" :showClose="true">
    <div style="max-height:60vh">
      <div class="noproDiv" v-if="!productList.length && fnCallBack">
        <img src="@/assets/noPro.png" />
        <p class="noproP">系统暂无已创建的商品</p>
      </div>
      <div v-if="productList.length">
        <el-form :inline="true" :model="searchProForm">
          <el-form-item label="商品名称:">
            <el-input :size="size" v-model="searchProForm.name" placeholder="请输入商品名称" maxlength="20" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button :size="size" type="primary" @click="handleConfigSearch">查询</el-button>
            <el-button :size="size" @click="handleConfigReset">重置</el-button>
          </el-form-item>
        </el-form>
        <GLTable ref="mutiProRef" :tableData="productList" :hasPage="false" :tableParams="tableParams" @refreshTable="getList">
          <span slot="goodsImage" slot-scope="scope">
            <img class="m-t-10 img-60" :src="scope.scope.goodsImage" />
          </span>
        </GLTable>
      </div>
    </div>
  </glsx-dialog>
</template>

<script>
// import { getGoodsList } from '@/api/modules/common'
import glsxDialog from '@/components/glsx-dialog'
export default {
  name: 'selectMutiProForcouponDialog',
  data() {
    return {
      // 表格组件
      // getListApi: this.$apis.common.getGoodsListApi,
      productList: [],
      // pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      searchProForm: {
        name: ''
      },
      // 表格参数
      tableParams: {
        listName: 'list',
        // 行数据的key
        mutiSelectUniqueKey: 'id',
        // 多选ref的名称
        mutiSelectName: 'list',
        tableColumns: [
          {
            label: '商品名称',
            prop: 'goodsName'
          },
          {
            label: '缩略图',
            prop: 'goodsImage',
            addHtml: 'goodsImage'
          },
          {
            label: '零售价(元)',
            prop: 'retailPrice'
          },
          {
            label: '来源门店',
            prop: 'merchantName'
          }
        ]
      },
      fnCallBack: false
    }
  },

  props: {
    isMutiSelectVisible: {
      type: Boolean,
      default: false
    },
    selectedProList: {
      type: Array,
      default: () => []
    }
  },

  components: {
    glsxDialog
  },

  mounted() {
    this.getList(true)
  },

  methods: {
    getList(isMounted = false) {
      var params = {
        goodsStatus: 1,
        goodsSource: 1,
        // pageNum: isMounted ? 1 : this.$refs.mutiProRef.page.pageNum,
        // pageSize: isMounted ? 10 : this.$refs.mutiProRef.page.pageSize
        currentPage: 1,
        pageNum: 1,
        pageSize: 100000,
        pageStart: 0,
        goodsName: this.searchProForm.name
      }
      var that = this
      this.$apis.couponManage.getAllGoodsApi(params).then(res => {
        this.fnCallBack = true
        // console.log(res)
        // this.productList = res
        this.productList = res.list
        // this.$refs.mutiProRef.tableTotal = res.total
        this.productList.forEach(function(item) {
          // item.saleAmount = item.goodsStatistics.saleAmount
          // if (item.specificationDetailList.length > 1) {
          //   let retailPriceList = item.specificationDetailList.sort(function(a, b) {
          //     return a.retailPrice - b.retailPrice
          //   })
          //   let stockeList = item.specificationDetailList.sort(function(a, b) {
          //     return a.stock - b.stock
          //   })
          //   let minRatilPrice = retailPriceList[0].retailPrice / 100
          //   let maxRatilPrice = retailPriceList[retailPriceList.length - 1].retailPrice / 100
          //   let minStock = stockeList[0].stock
          //   let maxStock = stockeList[stockeList.length - 1].stock
          //   item.retailPrice = minRatilPrice == maxRatilPrice ? minRatilPrice.toFixed(2) : minRatilPrice.toFixed(2) + '-' + maxRatilPrice.toFixed(2)
          //   item.minRatilPrice = minRatilPrice.toFixed(2)
          //   item.goodsStock = minStock == maxStock ? minStock : minStock + '-' + maxStock
          // } else if (item.specificationDetailList.length == 1) {
          //   item.retailPrice = (item.specificationDetailList[0].retailPrice / 100).toFixed(2)
          //   item.minRatilPrice = item.retailPrice
          //   item.goodsStock = item.specificationDetailList[0].stock
          // } else {
          //   item.retailPrice = (item.retailPrice / 100).toFixed(2)
          //   item.minRatilPrice = item.retailPrice
          // }
          item.retailPrice = (item.retailPrice / 100).toFixed(2)
        })
        this.recoverySelected()
      })
    },
    recoverySelected() {
      if (this.selectedProList.length) {
        this.selectedProList.forEach(row => {
          this.$refs.mutiProRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].toggleRowSelection(row)
        })
      }
    },
    handleMutiSelectConfirm() {
      var selectedData = this.$refs.mutiProRef.mutiSelectArr[this.tableParams.mutiSelectName]
      console.log(selectedData)
      if (!selectedData) {
        this.$message({
          message: '未选择商品',
          type: 'error'
        })
        return
      }
      this.$emit('handleMutiSelectConfirm', selectedData)
    },
    handleMutiSelectClose() {
      this.$emit('handleMutiSelectClose')
    },
    handleConfigSearch() {
      this.getList(true)
    },
    handleConfigReset() {
      this.searchProForm.name = ''
      this.getList(true)
    }
  }
}
</script>
<style>
.muti-pro .m-t-10 {
  margin-top: 10px;
}
</style>