index.vue 3.74 KB
<!-- 选择商品弹窗 -->
<template>
  <GLDialog class="muti-pro" bigTitle="选择商品" mode="big" :visible.sync="isMutiSelectVisible" :before-close="handleMutiSelectClose" @onOk="handleMutiSelectConfirm" @onCancel="handleMutiSelectClose">
    <div class="flex">
      <el-form :inline="true" :model="searchForm">
        <el-form-item label="商品名称:">
          <el-input :size="size" v-model="searchForm.name" placeholder="请输入商品名称" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button :size="size" type="primary" @click="getList(true)">查询</el-button>
          <el-button :size="size" @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <GLTable ref="mutiProRef" :tableData="productList" :searchForm="searchForm" :tableParams="tableParams" @refreshTable="getList">
      <span slot="coverImgUrl" slot-scope="scope">
        <img class="m-t-10 img-60" :src="scope.scope.coverImgUrl" />
      </span>
    </GLTable>
  </GLDialog>
</template>

<script>
// import { getGoodsList } from '@/api/modules/common'
export default {
  name: 'selectMutiProDialog',
  data() {
    return {
      size: 'small',
      // 表格组件
      // getListApi: getGoodsList,
      productList: [],
      // pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      // 表格参数
      tableParams: {
        listName: 'list',
        // 行数据的key
        mutiSelectUniqueKey: 'id',
        // 多选ref的名称
        mutiSelectName: 'list',
        tableColumns: [
          {
            label: '商品名称',
            prop: 'name'
          },
          {
            label: '缩略图',
            prop: 'coverImgUrl',
            addHtml: 'coverImgUrl'
          },
          {
            label: '价格(元)',
            prop: 'price1',
            formatter: cellValue => {
              return cellValue.price2 && cellValue.price1 != cellValue.price2 ? (cellValue.price1 / 100).toFixed(2) + '-' + (cellValue.price2 / 100).toFixed(2) : (cellValue.price1 / 100).toFixed(2)
            }
          },
          {
            label: '来源门店',
            prop: 'merchantName'
          }
        ]
      }
    }
  },

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

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

  methods: {
    getList(page, isMounted = false) {
      var params = {
        // goodsStatus: 1,
        // goodsSource: 1,
        ...this.searchForm,
        pageNum: isMounted ? 1 : this.$refs.mutiProRef.page.pageNum,
        pageSize: isMounted ? 10 : this.$refs.mutiProRef.page.pageSize
      }
      var that = this
      this.getListApi(params).then(res => {
        this.productList = res.list
        this.$refs.mutiProRef.tableTotal = res.total
        this.recoverySelected()
      })
    },
    handleReset() {
      this.searchForm.name = ''
      this.getList()
    },
    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)
      this.$emit('handleMutiSelectConfirm', selectedData)
    },
    handleMutiSelectClose() {
      this.$emit('handleMutiSelectClose')
    }
  }
}
</script>
<style>
.muti-pro .m-t-10 {
  margin-top: 10px;
}
</style>