mentorConfig.vue 12.6 KB
<template>
  <d2-container class="montor-config" :loading="$store.state.d2admin.loading.value" v-if="showPage">
    <div class="container-content">
      <div class="title">
        <span>导师配置</span>
        <div class="sub-title" v-if="routerQuery.partnerMerchantArr.length">服务商:
          <span v-for="(subV, subIdx) in routerQuery.partnerMerchantArr" :key="subIdx">{{ subV }}</span>
        </div>
      </div>
      <div class="content">
        <glsx-combi-form class="edit-form-container"
                         ref="editFormRef"
                         label-width="154px"
                         default-width="432px"
                         :is-block="true"
                         form-ref="editChildRef"
                         :form-obj="configInfo"
                         :form-data="editFormData">
          <template>
            <div slot="sceneSelect">
              <el-tabs v-model="configInfo.deploymentScene">
                <el-tab-pane v-for="item in openedSceneList" :key="item.scene" :label="item.label" :name="item.scene"></el-tab-pane>
              </el-tabs>
            </div>
          </template>
        </glsx-combi-form>
        <div class="scene_config_box">
          <mentorForm ref="mentor-form-ref1" :mentor-config-info="configInfo.upgradeConfigInfo" :mentor-staff-list="upgradeStaffList" :dialog-merchant-list="upgradeMerchantList" v-show="configInfo.deploymentScene == '1'"></mentorForm>
          <mentorForm ref="mentor-form-ref0" :mentor-config-info="configInfo.equityConfigInfo" :mentor-staff-list="equityStaffList" :dialog-merchant-list="equityMerchantList" v-show="configInfo.deploymentScene == '0'"></mentorForm>
        </div>
      </div>
    </div>
    <div class="footer">
      <el-button @click="submit" type="primary">保存</el-button>
      <el-button @click="navBack">取消</el-button>
    </div>
  </d2-container>
</template>
<script>
import mentorForm from './mentorForm.vue'
import { setMentorApi, getMentorInfoApi, getNoRelateStaffListApi, getMerchantStoreByServiceApi } from '@api/businessSchool'
import { mapActions } from 'vuex'
import _ from 'lodash'
export default {
  name: 'MentorConfig',
  components: {
    mentorForm
  },
  data() {
    return {
      showPage: false,
      configInfo: {
        staffName: '',
        phoneNumber: '',
        deploymentScene: '',
        equityConfigInfo: {
          titleText: '初级驻店零售',
          merchantArr: [],
          studentStaffs: []
        },
        upgradeConfigInfo: {
          titleText: '初级驻店零售',
          merchantArr: [],
          studentStaffs: []
        }
      },
      editFormData: [{
        label: '员工姓名',
        name: 'staffName',
        type: 'input',
        isHide: false,
        isDisabled: true
      }, {
        label: '手机号',
        name: 'phoneNumber',
        type: 'input',
        isHide: false,
        isDisabled: true
      }, {
        label: '选择业务',
        name: 'sceneSelect',
        isHide: false,
        style: "width: calc(100% - 432px)",
        addHtml: 'sceneSelect'
      }],
      selectedRelateOptions: [], // 关联员工已选的
      upgradeStaffList: [], // 1.1场景所有初级驻店
      equityStaffList: [], // 2.1场景 所有初级驻店
      upgradeMerchantList: [], // 1.1场景所有门店
      equityMerchantList: [], // 2.1场景所有门店
      routerQuery: {
        yqMerchantObj: {},
        partnerMerchantArr: []
      },
      openedSceneList: []
    }
  },
  watch: {
    'configInfo.deploymentScene': {
      handler(val) {
        const customerConfigInfo = val == '1' ? this.configInfo.upgradeConfigInfo : this.configInfo.equityConfigInfo
        const customerMerchantArr = val == '1' ? this.configInfo.upgradeConfigInfo?.merchantArr : this.configInfo.equityConfigInfo?.merchantArr
        if (!customerConfigInfo?.defaultMerchant || customerConfigInfo?.defaultMerchant == '0') {
          customerConfigInfo.defaultMerchant = customerMerchantArr[0]?.shopMerchantId
        }
        this.$nextTick(() => {
          this.$refs['mentor-form-ref' + val]?.updateData(customerConfigInfo.defaultMerchant)
        })
      },
      deep: true
    }
  },
  mounted() {
    this.routerQuery = {
      ...this.$route.query,
      yqMerchantObj: JSON.parse(this.$route.query?.yqMerchantObj),
      partnerMerchantArr: JSON.parse(this.$route.query?.partnerMerchantArr),
      sceneTypeList: JSON.parse(this.$route.query?.sceneTypeList)
    }
    // 获取配置详情
    this.getConfigInfo()
  },
  methods: {
    ...mapActions({
      get: 'd2admin/base/get',
      close: 'd2admin/page/close'
    }),
    getNoRelateStaffList(sceneType) {
      const routerQuery = this.routerQuery
      getNoRelateStaffListApi({ sceneType, merchantId: routerQuery?.yqMerchantObj?.merchantId, currentPage: 1, pageSize: 9999 }).then(res => {
        // 需过滤当前员工
        const index = res?.list.findIndex(val => val.staffUuid == routerQuery?.staffUuid)
        if (index > -1) res.list?.splice(index, 1)
        sceneType == 1 ? this.upgradeStaffList = res?.list || [] : this.equityStaffList = res?.list || []
      })
    },
    // 获取可添加配置的门店数据 (当前园区店关联的服务商下的所有4s店)
    getStoreList(sceneType) {
      const routerQuery = this.routerQuery
      getMerchantStoreByServiceApi({ sceneType, yqMerchantId: routerQuery?.yqMerchantObj?.merchantId }).then(res => {
        sceneType == 1 ? this.upgradeMerchantList = res || [] : this.equityMerchantList = res || []
      })
    },
    initConfigInfo(v) {
      if (v == 0) {
        this.configInfo.equityConfigInfo = {
          merchantArr: [],
          studentStaffs: [],
          titleText: ['初级驻店零售', '中级导师', '高级导师'][0],
          title: 0,
          sceneType: 0,
          merchantName: JSON.parse(this.$route.query?.yqMerchantObj)?.merchantName,
          performanceFlag: this.routerQuery?.performanceFlag == 'Y' // 绩效开关
        }
      } else if (v == 1) {
        this.configInfo.upgradeConfigInfo = {
          merchantArr: [],
          studentStaffs: [],
          titleText: ['初级驻店零售', '中级导师', '高级导师'][0],
          title: 0,
          sceneType: 1,
          merchantName: JSON.parse(this.$route.query?.yqMerchantObj)?.merchantName,
          performanceFlag: this.routerQuery?.performanceFlag == 'Y' // 绩效开关
        }
      }
    },
    // 获取配置详情
    getConfigInfo() {
      const routerQuery = this.routerQuery
      getMentorInfoApi({ staffUuid: routerQuery?.staffUuid }).then(res => {
        routerQuery?.sceneTypeList?.map(v => {
          // 获取未关联导师的初级驻店数据
          this.getNoRelateStaffList(v)
          // 获取场景下园区店关联的4s店
          this.getStoreList(v)
          this.openedSceneList.push({
            scene: `${v}`,
            label: ['2.1', '1.1'][v]
          })
          // 初始化数据
          this.initConfigInfo(v)
        })
        const configInfo = {
          ...this.configInfo,
          staffUuid: routerQuery?.staffUuid,
          staffName: routerQuery?.staffName, // 员工姓名
          phoneNumber: routerQuery?.phoneNumber, // 员工手机号
          deploymentScene: `${routerQuery?.sceneTypeList?.[0]}` // 选择业务
        }
        Array.isArray(res) && res?.forEach(val => {
          val.tutorBonusConfigs?.forEach(v => {
            v.startMonth == '0' ? (v.isStartEdit = true) : ''
            v.endMonth == '99' ? (v.isEndEdit = true) : ''
          })
          if (val.sceneType == 0) { // 会员权益场景
            val.shopMerchantId = `${val.shopMerchantId}`
            if (val.shopMerchantId && val.shopMerchantId != 'null') configInfo.equityConfigInfo.merchantArr.push(val) // 门店配置
            configInfo.equityConfigInfo.performanceFlag = routerQuery?.performanceFlag == 'Y', // 绩效开关
            configInfo.equityConfigInfo.studentStaffs = configInfo.equityConfigInfo.studentStaffs.concat(val.studentStaffs || []) // 学员
            configInfo.equityConfigInfo.titleText = ['初级驻店零售', '中级导师', '高级导师'][val.title || 0], // 当前职级
            configInfo.equityConfigInfo.title = val.title // 当前职级
            configInfo.equityConfigInfo.lastSetTitle = val.title // 最新配置的职级
            configInfo.equityConfigInfo.merchantName = routerQuery?.yqMerchantObj?.merchantName // 园区店
          } else if (val.sceneType == 1) { // 精品升级场景
            val.shopMerchantId = `${val.shopMerchantId}` // 门店
            if (val.shopMerchantId && val.shopMerchantId != 'null') configInfo.upgradeConfigInfo.merchantArr.push(val) // 门店配置
            configInfo.upgradeConfigInfo.performanceFlag = routerQuery?.performanceFlag == 'Y', // 绩效开关
            configInfo.upgradeConfigInfo.studentStaffs = configInfo.upgradeConfigInfo.studentStaffs.concat(val.studentStaffs || []) // 学员
            configInfo.upgradeConfigInfo.titleText = ['初级驻店零售', '中级导师', '高级导师'][val.title || 0], // 当前职级
            configInfo.upgradeConfigInfo.title = val.title // 当前职级
            configInfo.upgradeConfigInfo.lastSetTitle = val.title, // 最新设置的职级
            configInfo.upgradeConfigInfo.merchantName = routerQuery?.yqMerchantObj?.merchantName // 园区店
          }
        })
        // 学员数据去重
        configInfo.equityConfigInfo.studentStaffs = _.uniqBy(configInfo.equityConfigInfo.studentStaffs, 'staffUuid')
        configInfo.upgradeConfigInfo.studentStaffs = _.uniqBy(configInfo.upgradeConfigInfo.studentStaffs, 'staffUuid')
        this.configInfo = configInfo
        this.showPage = true
      }).catch(() => { this.showPage = true })
    },
    // 保存
    async submit() {
      const sceneConfigData = []
      const configInfo = this.configInfo
      for (var i = 1; i > -1; i--) {
        const formValide = await this.$refs[`mentor-form-ref${i}`]?.submitValide(i)
        if (formValide?.merchantValid?.includes('error')) {
          // 有校验不通过的 切换到当前场景
          if (i == 1) this.configInfo.deploymentScene = '1'
          if (i == 0) this.configInfo.deploymentScene = '0'
          return this.$message.error('请检查导师配置是否正确')
        }
        sceneConfigData.push(formValide) // 组件tab数据
      }
      const list = []
      sceneConfigData.map(v => {
        if (v.sceneType >= 0) {
          if (v?.merchantArr?.length) { // 有配置门店
            v?.merchantArr?.map(subV => {
              list.push({
                staffUuid: configInfo?.staffUuid,
                sceneType: v?.sceneType,
                title: v?.setTitle || v?.title,
                studentStaffUuids: v?.studentStaffs?.map(v => { return v.staffUuid }),
                shopMerchantId: subV?.shopMerchantId,
                shopMerchantName: subV?.shopMerchantName,
                tutorBonusConfigs: subV?.tutorBonusConfigs
              })
            })
          } else { // 无门店默认是初级驻店
            list.push({
              staffUuid: configInfo?.staffUuid,
              sceneType: v?.sceneType,
              title: v.setTitle || v.title,
              studentStaffUuids: v?.studentStaffs?.map(v => { return v.staffUuid })
            })
          }
        }
      })
      setMentorApi({ list }).then(res => {
        this.notice.okTips()
        this.navBack()
      })
    },
    // 返回
    navBack() {
      this.close({ tagName: '/staffManage' })
      this.$router.push({ name: 'staffManage' })
      this.close({ tagName: '/mentorConfig' })
    }
  }
}
</script>
<style lang="scss" scoped>
.montor-config{
  .container-content{
    background: #fff;
    .title{
      font-size: 18px;
      color: #333333;
      font-weight: 500;
      border-bottom: 1px solid #E8E8EA;
      padding: 12px 16px 12px 24px;
      &::before{
        position: absolute;
        display: inline-block;
        content: "";
        height: 18px;
        width: 4px;
        top: 16px;
        left: 16px;
        background-color: #0947c6;
      }
      .sub-title{
        display: inline-block;
        margin-left: 8px;
        font-size: 14px;
        color: #666666;
        font-weight: 400;
      }
      .sub-title:last-child{
        max-width: 1300px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        vertical-align: bottom;
        span{
          margin-right: 10px;
        }
      }
    }
    .content{
      padding: 16px 80px;

    }
  }
  .footer{
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 16px;
  }
}
::v-deep .glsx-combi-form-block #sceneSelect .el-form-item__content{
  width: calc(100% - 154px);
}
</style>