addTeachingTask.vue 12.4 KB
<template>
  <d2-container class="editTeachingTask">
    <div class="storeConfig con">
      <p class="titleClass">选择要指派的督导</p>
      <div class="itemCon">
        <el-form ref="supervisorFormRef"
                 :model="infoForm"
                 :rules="formRules"
                 :label-width="formDefaultObj.labelWidth">
          <el-form-item label="督导:"
                        prop="flightSupervisorId">
            <el-button icon="el-icon-plus"
                       @click="handleSelectSupervisor">选择督导</el-button>
          </el-form-item>
          <el-form-item v-if="supervisorTableData.length > 0">
            <el-table :data="supervisorTableData"
                      border
                      style="width: 100%">
              <el-table-column type="index"
                               label="序号"
                               align="center"
                               width="60">
              </el-table-column>
              <el-table-column prop="staffName"
                               label="督导名称"
                               align="center">
              </el-table-column>
              <el-table-column prop="staffPhone"
                               label="手机号"
                               align="center">
              </el-table-column>
              <el-table-column label="操作"
                               align="center"
                               width="80">
                <template slot-scope="scope">
                  <el-button type="text"
                             @click="handleDeleteSupervisor(scope.$index)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
        </el-form>
      </div>
      <p class="titleClass">选择要带教的门店</p>
      <div class="itemCon">
        <el-form ref="merchantFormRef"
                 :model="infoForm"
                 :rules="formRules"
                 :label-width="formDefaultObj.labelWidth">
          <el-form-item label="门店:"
                        prop="merchantId">
            <el-button icon="el-icon-plus"
                       @click="handleStoreMerchant">选择门店</el-button>
          </el-form-item>
          <el-form-item v-if="storeTableData.length > 0">
            <el-table :data="storeTableData"
                      border
                      style="width: 100%">
              <el-table-column type="index"
                               label="序号"
                               align="center"
                               width="60">
              </el-table-column>
              <el-table-column prop="merchantName"
                               label="门店名称"
                               align="center">
              </el-table-column>
              <el-table-column label="区域运营"
                               align="center">
                <div slot-scope="scope">
                  <template v-if="
                    scope.row.areaOperatorList && scope.row.areaOperatorList.length > 1
                  ">
                    <span>{{ scope.row.areaOperatorList[0].areaOperatorName + ' ' + scope.row.areaOperatorList[0].areaOperatorPhone }}</span>
                    <el-popover placement="top"
                                width="fit-content"
                                trigger="hover">
                      <div :class="{ scrollHeight: scope.row.areaOperatorList.length >= 10 }">
                        <div v-for="(item, index) in scope.row.areaOperatorList"
                             :key="index">
                          {{ item.areaOperatorName + ' ' + item.areaOperatorPhone }}
                        </div>
                      </div>
                      <span class="more-info"
                            slot="reference">...({{ scope.row.areaOperatorList.length }})</span>
                    </el-popover>
                  </template>
                  <template v-else>
                    <span>--</span>
                  </template>
                </div>
              </el-table-column>
              <el-table-column label="操作"
                               align="center"
                               width="80">
                <template slot-scope="scope">
                  <el-button type="text"
                             @click="handleDeleteStore(scope.$index)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
        </el-form>
      </div>
      <p class="titleClass">其他信息</p>
      <div class="itemCon">
        <el-form ref="otherFormRef"
                 :model="infoForm"
                 :rules="formRules"
                 :label-width="formDefaultObj.labelWidth">
          <el-form-item label="支援类型:"
                        prop="supportType">
            <el-select v-model="infoForm.supportType"
                       style="width: 310px"
                       placeholder="请选择">
              <el-option v-for="(item, index) in supportTypeOpt"
                         :key="index"
                         :label="item.confValue"
                         :value="item.confId" />
            </el-select>
          </el-form-item>
          <el-form-item label="情况描述:"
                        prop="situationDescription">
            <el-input v-model="infoForm.situationDescription"
                      type="textarea"
                      :rows="4"
                      placeholder="请输入情况描述"
                      maxlength="200"
                      style="width: 500px"
                      clearable
                      show-word-limit />
          </el-form-item>
        </el-form>
      </div>
      <div class="footer">
        <el-button @click="submitForm"
                   type="primary"
                   :loading="$store.state.d2admin.loading.value">提交</el-button>
        <el-button @click="routerBack">取消</el-button>
      </div>
    </div>
    <!-- 选择督导弹窗 -->
    <select-supervisor-dialog v-if="selectSupervisorVisible"
                              :select-supervisor-visible="selectSupervisorVisible"
                              @handleSelectSupervisorConfirm="handleSelectSupervisorConfirm"
                              @handleSelectSupervisorClose="handleSelectSupervisorClose"></select-supervisor-dialog>
    <!-- 选择门店弹窗 -->
    <select-store-dialog v-if="selectStoreVisible"
                         :select-store-visible="selectStoreVisible"
                         :supervisor-uuid="supervisorTableData[0].uuid"
                         @handleSelectStoreConfirm="handleSelectStoreConfirm"
                         @handleSelectStoreClose="handleSelectStoreClose"></select-store-dialog>
  </d2-container>
</template>

<script>
import { mapActions, mapState } from "vuex"
import { deepClone } from "@/common/util"
import selectSupervisorDialog from "./components/selectSupervisorDialog"
import selectStoreDialog from "./components/selectStoreDialog"
import { teaching_supportTypeOpt } from '@/common/constants.js'
import { teachTaskCreate } from '@api/teachingManage'
export default {
  name: "EditTeachingTask",
  components: {
    selectSupervisorDialog,
    selectStoreDialog
  },
  data() {
    return {
      formDefaultObj: {
        labelWidth: "150px",
        defaultWidth: "530px"
      },
      infoForm: {
        flightSupervisorId: "", // 督导
        merchantId: "", // 门店
        supportType: "", // 支援类型
        situationDescription: "" // 情况描述
      },
      formRules: {
        flightSupervisorId: [
          { required: true, message: "请选择督导", trigger: "change" }
        ],
        merchantId: [
          { required: true, message: "请选择门店", trigger: "change" }
        ],
        supportType: [
          { required: true, message: "请选择支援类型", trigger: "change" }
        ],
        situationDescription: [
          { required: true, message: "请输入情况描述", trigger: "blur" }
        ]
      },
      baseData: {},
      selectSupervisorVisible: false,
      supervisorTableData: [],
      selectStoreVisible: false,
      storeTableData: [],
      supportTypeOpt: deepClone(teaching_supportTypeOpt)
    }
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList,
      updateList: (state) => state.d2admin.user.updateList
    })
  },
  mounted() {
    // this.loading = true
    // this.loadItem()
  },
  methods: {
    ...mapActions({ close: "d2admin/page/close" }),
    routerBack() {
      this.$router.go(-1)
    },

    // 选择督导
    handleSelectSupervisor() {
      this.selectSupervisorVisible = true
    },

    // 选择门店
    handleStoreMerchant() {
      if (this.infoForm.flightSupervisorId) {
        this.selectStoreVisible = true
      } else {
        this.$message.warning('请先选择督导')
      }
    },

    handleSelectSupervisorConfirm(selectedData) {
      const _valueObj = deepClone(selectedData)
      console.log("_valueObj", _valueObj)
      this.infoForm.flightSupervisorId = _valueObj.id
      this.supervisorTableData = []
      this.storeTableData = [] // 选择督导后,门店清空
      this.supervisorTableData.push(_valueObj)
      this.$refs.supervisorFormRef.clearValidate()
      this.handleSelectSupervisorClose()
    },
    handleSelectSupervisorClose() {
      this.selectSupervisorVisible = false
    },

    handleSelectStoreConfirm(selectedData) {
      const _valueObj = deepClone(selectedData)
      console.log("_valueObj", _valueObj)
      this.infoForm.merchantId = _valueObj.merchantId
      this.storeTableData = []
      this.storeTableData.push(_valueObj)
      this.$refs.merchantFormRef.clearValidate()
      this.handleSelectStoreClose()
    },
    handleSelectStoreClose() {
      this.selectStoreVisible = false
    },

    // 删除督导
    handleDeleteSupervisor(subIndex) {
      this.infoForm.flightSupervisorId = null
      this.supervisorTableData.splice(subIndex, 1)
      // 删除督导后,门店清空
      this.handleDeleteStore(0)
    },

    // 删除门店
    handleDeleteStore(subIndex) {
      this.infoForm.merchantId = null
      this.storeTableData.splice(subIndex, 1)
    },

    validateForm() {
      let supervisorForm_flag = false
      let merchantForm_flag = false
      let otherForm_flag = false
      this.$refs.supervisorFormRef.validate((valid) => {
        supervisorForm_flag = valid
      })
      this.$refs.merchantFormRef.validate((valid) => {
        merchantForm_flag = valid
      })
      this.$refs.otherFormRef.validate((valid) => {
        otherForm_flag = valid
      })
      return supervisorForm_flag && merchantForm_flag && otherForm_flag
    },

    submitForm() {
      const flag = this.validateForm()
      if (flag) {
        const params = deepClone(this.infoForm)
        const supervisor = this.supervisorTableData[0]
        params.flightSupervisorName = supervisor.staffName
        params.flightSupervisorPhone = supervisor.staffPhone
        params.flightSupervisorUuid = supervisor.uuid
        const store = this.storeTableData[0]
        params.merchantName = store.merchantName
        if (store.areaOperatorList && store.areaOperatorList.length > 0) {
          params.areaOperatorList = store.areaOperatorList.map(item => {
            return {
              areaOperatorPhone: item.areaOperatorPhone,
              areaOperatorName: item.areaOperatorName
            }
          })
        }
        delete params.flightSupervisorId
        // return console.log('params', params)
        teachTaskCreate(params)
          .then((res) => {
            console.log(res)
            this.$notify({
              type: "success",
              title: "保存成功"
            })
            this.close({ tagName: "/addTeachingTask" })
            this.$router.push({ name: "teachingManage" })
          })
          .catch((err) => {
            console.log(err)
          })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.titleClass {
  height: 50px;
  line-height: 50px;
  padding: 0 20px;
  border-bottom: 1px solid #e5e5e5;
  font-size: 16px;
  font-weight: 600;
  color: #333333;
  margin: 0 !important;
}

.storeConfig {
  margin-bottom: 20px;
}

.itemCon {
  width: 800px;
  box-sizing: border-box;
  padding: 20px 0 1px;
}

.con {
  // border-radius: ;
  background-color: #fff;
}

.footer {
  text-align: center;
  padding-bottom: 30px;
}

.more-info {
  white-space: nowrap;
  color: #5850ff;
  cursor: pointer;
}
</style>