selectMerchantDialog.vue 5.06 KB
<template>
  <GLDialog bigTitle="选择门店" mode="big" :visible.sync="isVisible" :show-close="true" :before-close="handleClose" :close-on-click-modal="false" @onOk="onOk" @onCancel="handleClose">
    <div class="dialog_body">
      <!-- <GLCombiForm :rowNumber="1" class="dialog_search" ref="searchRef" :formObj="dialogSearchForm" :formData="dialogFormData" @handleOk="handleOk" @handleRest="handleRest"></GLCombiForm> -->
      <div class="dialog_table">
        <GLTable v-if="showTable" :hasPage="false" :pageSizes="pageSizes" ref="tableRef" :beforeSearchFn="beforeSearchFn" :pageConf="pageConf" @setTableFinishFun="setTableFinishFun" :searchForm="dialogSearchForm" :tableParams="tableParams" :getListApi="getListApi">
          <div slot="spreadPrice" slot-scope="scope">
            <span :style="{ color: Number(scope.scope.lineationPrice - scope.scope.costPrice) <= 0 ? '#eb4e4e' : '#666666' }">{{ Number(Number(scope.scope.lineationPrice - scope.scope.costPrice).toFixed(1)) }}</span>
          </div>
        </GLTable>
      </div>
    </div>
  </GLDialog>
</template>

<script>
export default {
  name: 'index',
  props: {
    isVisible: {
      type: Boolean,
      default: false
    },
    selectedList: {
      type: Array,
      default: ()=> []
    },
    goodsId:{
      type: String,
      default: ''
    }
  },
  data() {
    return {
      showTable: true,
      copyList: [],
      couponList: [],
      directChargeList: [],
      pageSizes: [5, 10, 20, 30, 40],
      dialogSearchForm: {
        merchantName: '',
        merchantId: ''
      },
      dialogFormData: [
        {
          label: '商户名称',
          name: 'merchantName',
          type: 'input',
          isClear: true
        },
        {
          label: '商户ID',
          name: 'merchantId',
          type: 'input',
          isClear: true
        }
      ],
      getListApi: this.$apis.goods.getMerchantListApi,
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      tableParams: {
        listName: 'merchantList',
        mutiSelectName: 'goodsIndex',
        mutiSelectUniqueKey: 'id',
        tableOption: false,
        tableColumns: [
          {
            label: '商户名称',
            prop: 'merchantName'
          },
          {
            label: '商户id',
            prop: 'merchantId'
          },
        ]
      }
    }
  },
  created() {
    this.copyList = JSON.parse(JSON.stringify(this.selectedList))
    console.log(this.copyList)
  },
  methods: {
    handleOk() {
      this.$refs.tableRef.refreshTable()
    },
    handleRest() {
      this.dialogSearchForm = {
        merchantName: '',
        merchantId: ''
      }
      this.handleOk()
    },
    beforeSearchFn(){
      return new Promise(resolve => {
        this.dialogSearchForm = {
          id: this.goodsId
        }
        resolve()
      })
    },
    onOk() {
      let list = this.$refs.tableRef.mutiSelectArr[this.tableParams.mutiSelectName] || []
      // for (let i = 0; i < this.selectedList.length; i++) {
      //   let idx = list.findIndex(item => item.id == this.selectedList[i].id)
      //   if (idx > -1) {
      //     list.splice(idx, 1)
      //   }
      // }
      list.map(item => this.$set(item, 'activityPrice', ''))
      this.$emit('confirmDialog', [...list,  ...this.copyList])
    },
    handleClose() {
      this.$emit('closeDialog')
    },
    setTableFinishFun() {
      this.copyList.forEach(row => {
        this.$nextTick(() => {
          let idx = this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].data.findIndex(item => item.id == row.id)
          if (idx > -1) {
            try {
              this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].toggleRowSelection(this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].data[idx], true)
              let id = this.copyList.findIndex(item => item.id == row.id)
              if (id > -1) this.copyList.splice(id, 1)
              console.log(this.copyList)
            } catch (err) {
              console.log(err)
            }
          }
        })
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.container {
  /deep/ .table-header {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    .el-button {
      min-width: 0;
    }
  }
  .good_name {
    img {
      width: 40px;
      height: 20px;
      vertical-align: text-bottom;
    }
  }
  .dialog_body {
    border: 1px solid #e5e5e5;
    .dialog_search {
      padding: 20px 20px 0;
      /deep/ .el-form-item {
        width: 312px;
      }
    }
    .coupon_type {
      width: 100%;
      display: inline-block;
      border-bottom: 1px solid #eee;
      .type {
        display: inline-block;
        height: 40px;
        width: 70px;
        line-height: 40px;
        font-weight: 500;
        text-align: center;
        font-size: 16px;
        cursor: pointer;
      }
      .active_type {
        color: #5850ff;
        border-bottom: 2px solid #5850ff;
      }
    }
    .dialog_table {
      padding: 20px;
    }
  }
}
</style>