relateMerDialog.vue 6.62 KB
<!-- 管理商户关联关系 -->
<template>
  <d2-dialog title="管理商户关联关系"
             :is-visible.sync="relateStoreVisible"
             width="80%"
             btn-ok-label="关联"
             @confirmDialog="handleRelateConfirm"
             @closeDialog="handleRelateClose"
             class="relateStore">
    <el-form ref="relateForm"
             :model="infoForm"
             :rules="formRules"
             label-width="120px">
      <el-form-item label="选择场景:"
                    prop="scene">
        <el-select v-model="infoForm.scene"
                   style="width:400px"
                   @change="changeScene">
          <el-option v-for="(item,index) in baseData.sceneTypeList"
                     :key="item.confId"
                     :label="item.confLabel"
                     :value="item.confId"
                     :disabled="item.disabled" />
        </el-select>
      </el-form-item>
    </el-form>
    <div style="display: flex;">
      <div style="width:33%">
        <merchant-choose v-if="store4sVisible"
                         ref="store4sTb"
                         source-page="4sStore"
                         :store-api="storeApi1"
                         @chooseData="get4sChooseData" />
      </div>
      <div style="width:33%"
           v-if="yqStoreVisible">
        <merchant-choose v-if="yqStoreVisible"
                         ref="yqStoreTb"
                         source-page="yqStore"
                         :store-api="storeApi2"
                         :selected-record="selectedyqData"
                         @chooseData="getyqChooseData" />
      </div>
      <div style="width:33%">
        <merchant-choose v-if="serviceStoreVisible"
                         ref="serviceStoreTb"
                         source-page="serviceStore"
                         :store-api="storeApi3"
                         :selected-record="selectedServiceData"
                         @chooseData="getServiceChooseData" />
      </div>
    </div>
  </d2-dialog>
</template>

<script>
import { serviceGetMerchantList, getyqMerchantList, getServiceList, querySceneRefByShop, addOrUpdateSceneMerchantRef } from '@api/merchant'
import merchantChoose from "./merchantChoose"
import { deepClone } from '@/common/util'
export default {
  name: 'RelateMerDialog',
  components: {
    merchantChoose
  },
  data() {
    return {
      infoForm: {
        scene: 1
      },
      formRules: {},
      baseData: {
        sceneTypeList:
          [
            {
              confId: 1,
              confLabel: '精品升级'
            }, {
              confId: 2,
              confLabel: '次新车转化'
              // disabled: true
            }, {
              confId: 3,
              confLabel: '售后众筹'
            },
            {
              confId: 0,
              confLabel: '会员权益/升级'
              // disabled: true
            },
            {
              confId: 4,
              confLabel: '积分商城'
            }
          ]
      },
      store4sVisible: true,
      yqStoreVisible: true,
      serviceStoreVisible: true,
      storeApi1: serviceGetMerchantList,
      storeApi2: getyqMerchantList,
      storeApi3: getServiceList,
      choose4sData: [], // 选择的4s店选项
      chooseyqData: [], // 选择的园区店店选项
      chooseServiceData: [], // 选择的服务商选项
      selectedyqData: [], // 选中4s店以后回显历史已选园区店
      selectedServiceData: [] // 选中4s店以后回显历史已选服务商
    }
  },

  props: {
    relateStoreVisible: {
      type: Boolean,
      default: false
    }

  },

  mounted() {

  },

  methods: {
    changeScene(value) {
      this.$refs.store4sTb.clearSelect()
      // this.$refs.yqStoreTb.clearSelect()
      this.$refs.serviceStoreTb.clearSelect()
    },

    getParams() {
      var params = deepClone(this.infoForm)
      if (this.choose4sData && this.choose4sData.length > 0) {
        params.shopInfo = this.choose4sData[0]
      }
      if (this.chooseyqData && this.chooseyqData.length > 0) {
        var yqMerchantName = this.chooseyqData[0].merchantName
        var yqMerchantId = this.chooseyqData[0].merchantNo
        params.yqMerchant = {
          ...this.chooseyqData[0],
          yqMerchantName,
          yqMerchantId
        }
      }
      if (this.chooseServiceData && this.chooseServiceData.length > 0) {
        params.serviceList = this.chooseServiceData
      }
      return params
    },

    handleRelateConfirm() {
      const params = this.getParams()

      if (this.choose4sData.length == 0) {
        this.notice.warningTips('请选择4s店')
        return
      }
      if (this.chooseyqData.length == 0) {
        this.notice.warningTips('请选择园区店')
        return
      }
      if (this.chooseServiceData.length == 0) {
        this.notice.warningTips('请选择服务商')
        return
      }

      addOrUpdateSceneMerchantRef(params).then(res => {
        this.notice.okTips()
        this.handleRelateClose(true)
      })
    },
    handleRelateClose(flag) {
      this.$emit('handleRelateClose', flag)
    },

    get4sChooseData(data) {
      console.log('get4sChooseData', data)
      this.choose4sData = data
      if (data && data.length > 0) {
        const params = {}
        params.scene = this.infoForm.scene
        params.merchantId = data[0].merchantNo
        querySceneRefByShop(params).then(res => {
          this.selectedyqData = []
          this.selectedServiceData = []
          if (res.yqMerchant) {
            this.selectedyqData.push(res.yqMerchant)
          }
          if (res.serviceList) {
            this.selectedServiceData = res.serviceList
          }
        })
      }
    },

    getyqChooseData(data) {
      console.log('getyqChooseData', data)
      this.chooseyqData = data
    },

    getServiceChooseData(data) {
      console.log('getServiceChooseData', data)
      this.chooseServiceData = data
    }
  }
}

</script>
<style lang="scss">
.relateStore .table {
  margin: 0 auto 20px !important;
  width: 98%;
}
.relateStore .tableCon {
  display: flex;
  .tableBox {
    flex: 1;
  }
}
.service-store .relateStore .el-table .cell,
.d2-form .relateStore .el-table .cell {
  line-height: 26px !important;
}
.service-store .relateStore .el-table--medium td,
.d2-form .relateStore .el-table--medium td {
  padding: 6px 8px !important;
}
.relateStore .red {
  color: red;
}
.relateStore .tip-icon {
  position: absolute;
  display: inline-block;
  height: 10px;
  width: 10px;
  line-height: 10px;
  color: #ffffff;
  background-color: red;
  border: 1px solid red;
  border-radius: 50%;
  cursor: pointer;
  font-size: 6px;
  margin-left: 2px;
}
</style>