index.vue 5.53 KB
<!-- 选择商品弹窗 -->
<template>
  <glsx-dialog class="muti-pro" title="选择商品" :isVisible.sync="isMutiSelectVisible" :btnOkLabel="productList.length ? '确定' : '创建商品'" width="70%" @confirmDialog="handleMutiSelectConfirm" @closeDialog="handleMutiSelectClose" v-loading="loading">
    <div class="noproDiv" v-show="!productList.length && fnCallBack">
      <img src="@/assets/noPro.png" />
      <p class="noproP">系统暂无已创建的商品</p>
    </div>
    <div v-show="productList.length">
      <slot name="search"></slot>
      <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>
    </div>
  </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,
      userInfo: {},
      productList: [],
      fnCallBack: false,
      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
    },
    searchForm: {
      type: Object,
      default: () => {}
    },
    selectedProList: {
      type: Array,
      default: () => []
    }
  },

  components: {
    glsxDialog
  },

  mounted() {
    this.userInfo = this.$globalState.session
    this.getList({}, true)
  },

  methods: {
    getList(page, isReset = false) {
      var params = {
        ...this.searchForm,
        goodsStatus: 1,
        goodsSource: 1,
        pageNum: isReset ? 1 : this.$refs.mutiProRef.page.pageNum,
        pageSize: isReset ? 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.fnCallBack = true
        // 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() {
      if (!this.productList.length) {
        var params = {
          addOrEdit: 1,
          groupOrStore: this.userInfo.accountLevel == 4 ? 2 : 1,
          $title: '新建商品'
        }
        this.$router.push({
          path: '/productGroup/editProduct',
          query: params
        })
        return true
      }
      var selectedData = this.$refs.mutiProRef.mutiSelectArr[this.tableParams.mutiSelectName]
      this.$emit('handleMutiSelectConfirm', selectedData)
    },
    handleMutiSelectClose() {
      this.$emit('handleMutiSelectClose')
    }
  }
}
</script>
<style>
.muti-pro .m-t-10 {
  margin-top: 10px;
}
.muti-pro .noproP {
  width: 100%;
  height: 20px;
  font-family: PingFangSC-Medium;
  font-size: 16px;
  color: #666666;
  line-height: 20px;
  font-weight: 500;
  text-align: center;
}
</style>