labelCourseDialog.vue 7.88 KB
<template>
  <d2-dialog :is-visible="dialogVisible" class="accountDailog" :title="recordInfo ? '编辑课程标签' : '新建课程标签'" width="720px"
    @confirmDialog="handleAddConfirm" @closeDialog="handleClose">
    <div class="publish-info">
      <el-form :model="formData" :rules="rules" ref="channelForm">
        <el-form-item label-width="120px" label="员工标签:" prop="tagIds">
          <el-button class="radio-box" size="small" @click="selectTagDialog('findAllLabel')">选择标签</el-button>
          <div class="customer-box m-t-10">
            <div class="el-input-tag input-tag-wrapper">
              <div v-for="(subItem, subIdx) in formData.tagIds" :key="subIdx">
                <el-tag v-for="(k, n) in subItem.labelList" :key="n" class="customer-tag" size="small" type="info"
                  :closable="true" :disable-transitions="false" @close="handleDelete(n, subIdx, 'tagIds')">
                  <span>{{ k.groupAttName }}:{{ k.groupName }}:{{ k.tagName }}</span>
                </el-tag>
              </div>
            </div>
          </div>
        </el-form-item>
        <el-form-item label-width="120px" label="课程标签:" prop="courseIds">
          <el-button class="radio-box" size="small" @click="selectTagCourseDialog">选择课程</el-button>
          <div class="customer-box m-t-10">
            <div class="el-input-tag input-tag-wrapper">
              <!-- <div v-for="(subItem, subIdx) in formData.courseIds" :key="subIdx"> -->
              <el-tag v-for="(k, n) in formData.courseIds" :key="n" class="customer-tag" size="small" type="info"
                :closable="true" :disable-transitions="false" @close="handleDeleteCustomer(n, 'courseIds')">
                <span>{{ k.catalogName + ":" + k.courseTitle }}</span>
              </el-tag>
            </div>
            <!-- </div> -->
          </div>
        </el-form-item>
      </el-form>
    </div>
    <selectTag ref="selectTagForm" :relateStoreVisible="selectTagVisible" @tagSelected="handleRelateStoreConfirm">
    </selectTag>
    <findStaffTagCourseDialog :storeSelected="formData.courseIds" v-if="findStaffTagCourseVisible"
      :relateStoreVisible="findStaffTagCourseVisible" @handleRelateStoreConfirm="handleRelateConfirm"
      @handleRelateStoreClose="findStaffTagCourseVisible = false">
    </findStaffTagCourseDialog>
  </d2-dialog>
</template>

<script>
import { savecourserelation, updatecourserelation, stafftagcourseFind } from "@api/contentManager"
import findStaffTagCourseDialog from "./findStaffTagCourseDialog"
import selectTag from "./selectTag"
import { deepClone } from "@/common/util"
export default {
  name: "listOfPenaltiesDialog",
  components: {
    selectTag,
    findStaffTagCourseDialog
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    recordInfo: {
      type: Object,
      default: null
    }
  },
  computed: {
    show: {
      get() {
        return this.dialogVisible
      },
      set(val) {
        this.$emit("update:dialogVisible", val)
      }
    }
  },
  data() {
    // var validatorTagIds = (rule, value, callback) => {
    //   if (this.storeSearchForm?.configList && this.storeSearchForm.configList.length > 0) {
    //     callback()
    //   } else {
    //     callback(new Error("请选择员工"))
    //   }
    // }
    // var validatorForm = (rule, value, callback) => {
    //   if (this.storeSearchForm?.configList && this.storeSearchForm.configList.length > 0) {
    //     callback()
    //   } else {
    //     callback(new Error("请选择员工"))
    //   }
    // }
    return {
      savecourserelation,
      updatecourserelation,
      tagId: "",
      findStaffTagCourseVisible: false,
      selectTagVisible: true,
      customerLoading: false,
      formData: {
        // customerDataList: [],
        tagIds: [],
        courseIds: []
      },
      rules: {
        tagIds: [
          { required: true, message: "请选择员工标签对象", trigger: "change" },
        ],
        courseIds: [
          { required: true, message: "请选择课程列表对象", trigger: "change" }
        ]
      }
    }
  },
  mounted() {
    console.log(this.recordInfo)
    if (this.recordInfo) {
      this.tagId = this.recordInfo.id
      this.getStafftagcourseFind()
    }
  },
  methods: {
    getStafftagcourseFind() {
      stafftagcourseFind({
        id: this.tagId,
      }).then(res => {
        console.log(res)
        this.formData.tagIds = res.staffTagGroups.map((item) => {
          return {
            labelGroup: { id: item.groupAtt, name: item.groupAttName },
            labelList: item.staffTagDefinitions.map((el) => {
              return {
                id: el.id,
                name: el.labelName,
                ...el
              }
            }),
            labelType: item.groupType,
            checked: false,
            tagChecked: [],
            isIndeterminate: false,
            checkAll: false
          }
        })
        this.formData.courseIds = res.staffTagCourseRelationDetails
      })
    },
    selectTagDialog(type) {
      this.$refs.selectTagForm.init(
        {
          type: true,
          item: JSON.parse(JSON.stringify(this.formData.tagIds))
        }
      )
    },
    selectTagCourseDialog(type) {
      this.findStaffTagCourseVisible = true
    },
    handleRelateConfirm(obj) {
      // console.log(obj, 'obj')
      this.formData.courseIds = obj
      this.$refs.channelForm.validateField('courseIds')
    },
    handleRelateStoreConfirm(obj) {
      this.formData.tagIds = obj
      this.$refs.channelForm.validateField('tagIds')
    },
    handleDeleteCustomer(idx, name) {
      this.formData[name].splice(idx, 1)
    },
    handleDelete(idx, pIdx) {
      this.formData.tagIds[pIdx].labelList.splice(idx, 1)
      if (this.formData.tagIds[pIdx].labelList.length == 0) {
        this.formData.tagIds.splice(pIdx, 1)
      }
    },
    handleAddConfirm() {
      this.$refs.channelForm.validate(valid => {
        console.log(valid, 'valid')
        if (valid) {
          const params = {}
          console.log(this.formData)
          params.tagIds = []
          this.formData.tagIds.forEach(item => {
            item.ids = item.labelList.forEach(el => {
              params.tagIds.push(el.id)
            })
          })
          params.courseIds = this.formData.courseIds.map(item => item.courseId)
          params.id = this.tagId
          const apiName = this.tagId ? 'updatecourserelation' : 'savecourserelation';
          this[apiName](params).then(res => {
            console.log(res)
            this.handleClose()
            this.$message.success('保存成功')
            this.$emit('confirmDialogFn')
          }).catch((err) => {
            console.log(err)
          })
        }
      })
    },
    handleClose() {
      this.show = false
    }
  }
}
</script>

<style scoped lang="scss">
.publish-info {
  // padding: 16px 20px;

  ::v-deep {
    .cell {
      padding-left: 0;
      padding-right: 0;
    }
  }
}

.emp-table-box {
  // width: 567px;
}

.customer-box {
  width: 540px;
  height: 150px;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #e5e5e5;

  .customer-title {
    box-sizing: border-box;
    height: 39px;
    line-height: 39px;
    padding: 0 10px;
    // border-bottom: 1px solid #dcdfe6;
  }

  .input-tag-wrapper {
    max-height: 150px;
    overflow: auto;
    position: relative;
    font-size: 14px;
    padding: 0 10px 10px;
    box-sizing: border-box;
    color: #666;
    display: inline-block;
    outline: none;
    flex-wrap: wrap;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    display: flex;
    align-items: center;
    font-size: 14px;

    .el-tag.el-tag--info .el-tag__close {
      color: #909399 !important;
      background: transparent !important;
    }

    .customer-tag {
      margin: 4px;
    }

    i {
      color: #75acff;
      margin-right: 3px;
      font-size: 14px;
    }
  }
}
</style>