<template>
  <div>
    <el-form :model="auditionForm" ref="auditionForm" >
      <el-form-item
        label="分部"
        prop="organId"
        :label-width="formLabelWidth"
        :rules="[{ required: true, message: '请选择分部', trigger: 'blur' }]"
      >
        <el-select
          style="width: 100% !important"
          class="multiple"
          v-model.trim="auditionForm.organId"
          filterable
          clearable
          placeholder="请选择分部"
        >
          <el-option
            v-for="(item, index) in organList"
            :key="index"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="课程时长"
        prop="courseType"
        :label-width="formLabelWidth"
        :rules="[
          { required: true, message: '请选择课程时长', trigger: 'blur' },
        ]"
      >
        <el-select
          style="width: 100% !important"
          class="multiple"
          v-model.trim="auditionForm.courseType"
          filterable
          clearable
          placeholder="课程时长"
        >
          <el-option
            v-for="(item, index) in courseType"
            :key="index"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="课程单价"
        prop="courseType"
        :label-width="formLabelWidth"
        :rules="[
          { required: true, message: '请选择课程单价', trigger: 'blur' },
        ]"
      >
        <el-input clearable placeholder="课程单价" type="number" v-model="courseType" maxlength="9" />
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { resetOrganizationCourseDurationSettings,addOrganizationCourseDurationSettings } from "@/api/specialSetting";
export default {
  props: ["activeRow", "organList", "courseType"],
  data() {
    return {
      auditionForm: {
        organId: "",
        courseType: "",
        timer: [],
        id: "",
      },
      inputVisible: false,
      formLabelWidth: "80px",
      dynamicTags: [],
      inputValue: "",
    };
  },
  mounted() {
    if (this.activeRow) {
      this.auditionForm.organId = this.activeRow.organId;
      this.auditionForm.timer = this.activeRow.duration.split(",");
      this.dynamicTags = this.activeRow.duration.split(",");
      this.auditionForm.courseType = this.activeRow.courseType;
      this.auditionForm.id = this.activeRow.id;
    }
  },
  methods: {
    async submitInfo(str) {
      console.log(str);
      this.$refs.auditionForm.validate(async (_) => {
        if (_) {
          if (str == "update") {
            try {
              const res = await resetOrganizationCourseDurationSettings({
                organId: this.auditionForm.organId,
                duration: this.dynamicTags.join(","),
                courseType: this.auditionForm.courseType,
                id: this.auditionForm.id,
              });
                this.$message.success("修改成功");
                this.$emit('close')
            } catch {}
          }else if(str == "create"){
                   try {
              const res = await addOrganizationCourseDurationSettings({
                organId: this.auditionForm.organId,
                duration: this.dynamicTags.join(","),
                courseType: this.auditionForm.courseType,
              });
                this.$message.success("新建成功");
                this.$emit('close')
            } catch {}
          }
        }
      });

    },
  },
  watch: {
    dynamicTags(val) {
      this.auditionForm.timer = val;
    },
  },
};
</script>
<style lang="scss" scoped>
.courseMask {
  .el-tag.el-tag--info {
    margin-right: 4px;
  }
}
</style>