index.vue 4.51 KB
<!-- 选择商品弹窗 -->
<template>
  <glsx-dialog class="muti-pro" title="选择商品" :isVisible.sync="isMutiSelectVisible" width="70%" @confirmDialog="handleMutiSelectConfirm" @closeDialog="handleMutiSelectClose">
      <GLTable v-loading="loading" ref="mutiProRef" :tableData="productList" :hasPage="false" :noDataImg="url" :tableParams="tableParams" @refreshTable="getList">
        <span slot="goodsImage" slot-scope="scope">
          <img class="m-t-10 img-60" :src="scope.scope.goodsImage" />
        </span>
      </GLTable>
  </glsx-dialog>
</template>

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

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

  components: {
    glsxDialog
  },

  created() {
    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
      }
      var that = this
      this.loading = true
      this.$apis.common.getGoodsListApi(params).then(res => {
        this.productList = res
        this.loading = false
        // 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
          }
        })
        this.recoverySelected()
        this.$refs.mutiProRef.tableHeightValues = '50vh'
      })
    },
    recoverySelected() {
      if (this.selectedProList && 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)
      this.$emit('handleMutiSelectConfirm', selectedData)
    },
    handleMutiSelectClose() {
      this.$emit('handleMutiSelectClose')
    }
  }
}
</script>
<style>
.muti-pro .m-t-10 {
  margin-top: 10px;
}
</style>