selectGoodsDialog.vue 13.6 KB
<template>
  <baseDialog :dialog-config="dialogConfig" :is-show.sync="visible" class="accountDailog" @handleClick="handleAddConfirm">
    <div class="tableBox">
      <!-- <span>
        <p class="edit-title" style="textAlign:center">
          {{ showData[sourcePage].title }}
          <el-button type="text" style="paddingLeft:20px" v-if="sourcePage == 'serviceStore'"
            @click="resetCheck">重新选择</el-button>
        </p>
      </span> -->
      <!-- <div class="checkSpan">
        <p v-for="item in selectedDataShow">已选:<span style="paddingRight:20px">{{ item.merchantName }}</span><span>{{
          item.merchantId }}</span>
        </p>
      </div> -->
      <div style="padding: 10px 50px;">
        <el-input v-model="upgradeGoodsName" placeholder="搜索商品名称" maxlength="20" style="width:300px;paddingRight:20px" />
        <el-button size="small" type="primary" @click="search">
          查询
        </el-button>
      </div>
      <!-- @select="selectFn"-->
      <el-table ref="selectingTable" height="464px" :row-key="rowKey" :data="selectedTableData" class="table" border
                @select-all="handleAll" @select="selectFn" :header-cell-class-name="cellClass">
        <!-- :selectable="selectable" -->
        <el-table-column type="selection" :reserve-selection="true" width="55" align="center" />
        <el-table-column prop="goodsName" align="center" label="商品名称"></el-table-column>
        <el-table-column prop="categoryName" align="center" label="商品图">
          <template slot-scope="scope">
            <img :src="scope.row.thumbUrl" style="width: 50px; height: 50px" />
          </template>
        </el-table-column>
        <el-table-column prop="categoryName" align="center" label="价格">
          <template slot-scope="scope">
            <span>{{ scope.row.sellPrice }}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination small background :page-sizes="[10, 20, 30, 40]" @size-change="handleSizeChange"
                     @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="pageSize"
                     layout="total,sizes, prev, pager, next,jumper" :total="total" />
    </div>
  </baseDialog>
</template>

<script>
import { getGroundingManageList } from '@api/grounding'
// import { queryMerchantGoodsCategoryList } from '@api/inStoreTargetConfig'
import { deepClone } from '@/common/util'
export default {
  name: 'SelectGoodsDialog',

  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    storeConfigConObjSearchObj: {
      type: Object,
      default: () => ({})
    },
    periodItemForm: {
      type: Object,
      default: () => ({})
    },
    // 页面来源
    // sourcePage: {
    //   type: String,
    //   default: ''
    // },
    // storeApi: {
    //   type: Function,
    //   default: () => { }
    // },
    // selectedRecord: {
    //   type: Array,
    //   default: () => []
    // },
    goodsTypeList: {
      type: Array,
      default: () => []
    },
    packageList: {
      type: Array,
      default: () => []
    }
    // storeSearchForm: {
    //   type: Object,
    //   default: () => { }
    // }
  },
  data() {
    return {
      upgradeGoodsName: '',
      selectedTableData: [],
      selectedTableList: [],
      // selectedDataShow: [],
      // selectingData: [],
      // needTip: ['editProduct'],
      // 分页
      total: 0,
      currentPage: 1,
      pageSize: 10,
      // baseData: {
      //   RefStoreList: []
      // },
      searchFormSearch: {},
      dialogConfig: {
        title: '商品选择',
        width: '800px'
      }

    }
  },
  computed: {
    visible: {
      get() {
        return this.dialogVisible
      },
      set(val) {
        this.$emit('update:dialogVisible', val)
      }
    }
  },
  watch: {
  },
  mounted() {
    this.dialogConfig.title = this.periodItemForm.selectPackageType == 1 ? '单商品或多商品' : '商品组合'
    this.queryMerchantGoodsCategoryList()
    this.selectedTableList = deepClone(this.packageList)
    // console.log('this.queryMerchantGoodsCategoryList')
  },
  methods: {
    rowKey(row) {
      return row.id
    },
    search() {
      this.currentPage = 1
      this.pageSize = 10
      this.queryMerchantGoodsCategoryList()
    },
    queryMerchantGoodsCategoryList() {
      const goodsTypeList = this.goodsTypeList.map(item => item.categoryType)
      const params = {
        goodsSource: 0,
        status: 1,
        // upgradeProductFlag: 'Y',
        upradeFlag: 'Y',
        ...this.storeConfigConObjSearchObj,
        merchantId: this.storeConfigConObjSearchObj.merchantIds[0],
        upgradeGoodsName: this.upgradeGoodsName,
        goodsTypeList,
        currentPage: this.currentPage,
        pageSize: this.pageSize
      }
      getGroundingManageList(params).then(res => {
        this.selectedTableData = res.list.map(item => {
          item.merchantGoodsId = item.id
          return {
            merchantGoodsId: item.id,
            id: item.id,
            goodsName: item.upgradeGoodsName,
            thumbUrl: item.goodsInfo?.thumbUrl,
            sellPrice: item.sellPrice,
            upgradeGoodsName: item.upgradeGoodsName
            // goodsInfo: item.goodsInfo
          }
          // let goods ={
          //   merchantGoodsId: item.id,
          //   goodsInfo: {
          //     thumbUrl: item.thumbUrl,
          //     shopPrice: item.shopPrice
          //   }
          // }
          // delete item.createdDate
          // delete item.updatedDate
          // return item
        })
        this.total = res.total
        console.log(res, 'getGroundingManageList')
        this.$nextTick(() => {
          this.selectedTableData.forEach(item => {
            this.packageList.forEach(d => {
              if (d.id == item.id) {
                this.$refs.selectingTable.toggleRowSelection(item, true)
              }
            })
          })
        })
        console.log(res, this.selectedTableData)
        // this.goodsTypeList =
        // console.log
      }).catch((err) => {
        console.log(err)
      })
    },
    handleAddConfirm() {
      const selectItemList = this.$refs.selectingTable.selection
      if (selectItemList.length || this.selectedTableList.length) {
        this.visible = false
        this.$emit("handleAddConfirm", selectItemList)
      } else {
        this.$message.warning('请勾选商品')
      }
      // console.log(selectItemList)
      // this.$emit('handleAddConfirm')
    },
    // cellClass(row) {
    //   // if (this.showData[this.sourcePage].selectMethod == 'Single') { // 单选时隐藏全选按钮
    //   if (row.columnIndex === 0) {
    //     return 'disabledCheck'
    //   }
    //   // }
    // },

    selectFn(selection, row) {
      console.log(JSON.stringify(selection).indexOf(JSON.stringify(row)) == -1, 'selectFn')
      if (JSON.stringify(selection).indexOf(JSON.stringify(row)) == -1) {
        this.selectedTableList = this.packageList.filter(item => item.id !== row.id)
      } else {
        console.log(selection, row, 'selectFn')
        this.selectedTableList.push(row)
      }

      // if (this.showData[this.sourcePage].selectMethod == 'Single') {
      //   this.dialogCheck(selection, row)
      // } else {
      //   this.handleChange(selection, row)
      // }
    },

    // dialogCheck: function (selection, row) {
    //   this.$refs[this.seletingTable].clearSelection()
    //   this.selectedData = []
    //   this.selectedDataShow = []
    //   if (row) {
    //     this.$refs[this.seletingTable].toggleRowSelection(row, true)
    //     this.selectedDataShow.push({ merchantName: row.merchantName, merchantId: row.merchantNo })
    //     this.selectedData.push(row)
    //   }
    //   this.$emit('chooseData', this.selectedData)
    // },

    // selectable(row, index) {
    //   if (row.isDisable) {
    //     return false
    //   }
    //   return true
    // },
    // getSelectingList() {
    //   // console.log('this.selectedRecord_2', this.selectedRecord);
    //   // console.log('this.selectedData_2', this.selectedData);

    //   const params = {
    //     currentPage: this.currentPage,
    //     pageSize: this.pageSize,
    //     categoryName: this.categoryName
    //   }
    //   if (this.sourcePage != '4sStore') { // 只有4s点列表需要分页
    //     params.currentPage = 1
    //     params.pageSize = 100000
    //   }

    //   this.storeApi(params).then(res => {
    //     this.selectingData = res.list
    //     this.total = res.total
    //   })
    // },

    // searchList() {
    //   this.getSelectingList()
    // },

    // handleChange(selection, row) {
    //   // console.log('handleChange');
    //   // console.log('selection', selection);
    //   // console.log('row', row);
    //   // console.log('JSON.stringify(selection).indexOf(JSON.stringify(row)) == -1', JSON.stringify(selection).indexOf(JSON.stringify(row)) == -1);

    //   if (this.sourcePage == 'serviceStore') { // 服务商
    //     if (JSON.stringify(selection).indexOf(JSON.stringify(row)) == -1) { // 判断是否取消选中
    //       // 如果是取消,则判断是否存在财务规则
    //       const showIndex = this.selectedDataShow.findIndex(item => (item.merchantId == row.merchantNo))
    //       const dataIndex = this.selectedData.findIndex(item => (item.merchantNo == row.merchantNo))

    //       let showHtml = ''
    //       switch (row.ruleFlag) {
    //         case 1:
    //           showHtml = '该商户配置有财务规则,取消关联会重置财务配置;被修改的关联关系保存后,系统自动重置对应4s在对应场景的财务规则'
    //           break
    //         case 2:
    //           showHtml = '该商户配置有对账规则,取消关联会重置对账配置;被修改的关联关系保存后,系统自动重置对应4s在对应场景的对账规则'
    //           break
    //         case 3:
    //           showHtml = '该商户配置有财务规则和对账规则,取消关联会重置财务配置和对账配置;被修改的关联关系保存后,系统自动重置对应4s在对应场景的财务规则和对账规则'
    //           break
    //         default:
    //           showHtml = ''
    //       }
    //       if (row.ruleFlag == 1 || row.ruleFlag == 2 || row.ruleFlag == 3) {
    //         this.$confirm(showHtml, '提示', {
    //           confirmButtonText: '确定',
    //           showCancelButton: true,
    //           type: 'warning'
    //         }).then(() => {
    //           this.selectedDataShow.splice(showIndex, 1)
    //           this.selectedData.splice(dataIndex, 1)
    //         }).catch(err => {
    //           this.$refs[this.seletingTable].toggleRowSelection(row, true)
    //         })
    //       } else {
    //         this.selectedDataShow.splice(showIndex, 1)
    //         this.selectedData.splice(dataIndex, 1)
    //       }
    //     } else {
    //       // 新增则添加
    //       this.selectedDataShow.push({ merchantName: row.merchantName, merchantId: row.merchantNo })
    //       this.selectedData.push(row)
    //     }
    //   }
    //   if (this.selectedRecord.length == 0) {
    //     this.$emit('chooseData', this.selectedData)
    //   }
    // },
    handleAll(selection) {
      this.selectedData = selection
      this.selectedDataShow = selection
      this.$emit('chooseData', selection)
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.queryMerchantGoodsCategoryList()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.queryMerchantGoodsCategoryList()
    },
    cellClass(row) {
      if (row.columnIndex === 0) {
        return 'disableheadselection'
      }
    }
    // handleRelateStoreConfirm() {
    //   this.$emit('handleRelateStoreConfirm', this.selectedData)
    // },
    // handleRelateStoreClose() {
    //   this.$emit('handleRelateStoreClose')
    // },

    // resetCheck() {
    //   const allCheck = this.$refs[this.seletingTable].selection
    //   const flag = allCheck.some((item) => {
    //     return item.ruleFlag == 1 || item.ruleFlag == 2 || item.ruleFlag == 3
    //   })
    //   if (flag) {
    //     this.$confirm('选择的商户中配置有财务规则或对账规则,取消关联会重置财务配置或对账配置', '提示', {
    //       confirmButtonText: '确定',
    //       showCancelButton: true,
    //       type: 'warning'
    //     }).then(() => {
    //       this.$refs[this.seletingTable].clearSelection()
    //       this.selectedData = []
    //       this.selectedDataShow = []
    //       this.$emit('chooseData', this.selectedData)
    //     }).catch(err => {
    //       console.log(err)
    //     })
    //   } else {
    //     this.$refs[this.seletingTable].clearSelection()
    //     this.selectedData = []
    //     this.selectedDataShow = []
    //     this.$emit('chooseData', this.selectedData)
    //   }
    // },

    // clearSelect() {
    //   const checkItem = this.$refs[this.seletingTable].selection
    //   if (checkItem && checkItem.length > 0) {
    //     this.$refs[this.seletingTable].clearSelection()
    //   }
    //   this.selectedData = []
    //   this.selectedDataShow = []
    // }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .disableheadselection>.cell .el-checkbox__inner {
  display: none;
}
</style>