selectMerchantDialog.vue 6.62 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">
      <template v-if="isOil">
        <glsx-combi-form
          ref="showSearch"
          labelWidth="105px"
          :formObj="dialogSearchForm"
          :formData="dialogFormData"
        >
          <span slot="footer">
            <el-button
              :size="size"
              type="primary"
              @click="handleOk"
            >查询</el-button>
            <el-button
              :size="size"
              @click="handleRest"
            >重置</el-button>
          </span>
        </glsx-combi-form>
      </template>
      <!-- <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="isOil"
          :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: [10, 20, 30, 40],
      dialogSearchForm: {
        merchantName: '',
        merchantId: ''
      },
      dialogFormData: [
        {
          label: '商户名称',
          name: 'merchantName',
          type: 'input',
          placeholder: '请输入商户名称',
          width: '300px',
          labelWidth: '10px'
        },
        {
          label: '商户ID',
          name: 'merchantId',
          type: 'input',
          inputType: 'number',
          placeholder: '请输入商户ID',
          width: '300px',
          labelWidth: '10px'
        }
      ],
      getListApi: null,
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      tableParams: {
        listName: 'merchantList',
        mutiSelectName: 'goodsIndex',
        mutiSelectUniqueKey: 'id',
        tableOption: false,
        tableColumns: [
          {
            label: '商户名称',
            prop: 'merchantName'
          },
          {
            label: '商户id',
            prop: 'merchantId'
          },
        ]
      },
      isOil: this.$parent.formObj.goodsSource == 3 || this.$parent.formObj.goodsSource == 4
    }
  },
  created () {
    const { isOil } = this
    this.copyList = JSON.parse(JSON.stringify(this.selectedList))
    this.getListApi = this.$apis.goods[isOil ? 'getAllMerchantListApi' : 'getMerchantListApi']
    this.tableParams.listName = isOil ? 'list' : 'merchantList'
    this.tableParams.tableColumns[1].prop = isOil ? 'merchantNo' : 'merchantId'
  },
  methods: {
    handleOk () {
      console.log(this.dialogSearchForm)
      this.$refs.tableRef.refreshTable()
    },
    handleRest () {
      this.dialogSearchForm = {
        merchantName: '',
        merchantId: ''
      }
      this.handleOk()
    },
    beforeSearchFn () {
      return new Promise(resolve => {
        if (!this.isOil) 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', ''))
      list.map(item => this.$set(item, 'originalPrice', ''))
      if(this.$parent.formObj.goodsSource == 4){
        list.map(item => this.$set(item, 'marketPrice', this.$parent.formObj.marketPrice))
        list.map(item => this.$set(item, 'sellPrice', this.$parent.formObj.sellPrice))
      }
      this.$emit('confirmDialog', [...list, ...this.copyList])
    },
    handleClose () {
      this.$emit('closeDialog')
    },
    setTableFinishFun () {
      const KEY = this.isOil ? 'merchantNo' : 'merchantId'
      this.copyList.forEach(row => {
        this.$nextTick(() => {
          let idx = this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].data.findIndex(item => item[KEY] == row[KEY])
          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[KEY] == row[KEY])
              if (id > -1) this.copyList.splice(id, 1)
            } 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>