<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item :label="$t('年份')" prop="year">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.year"
                        type="year"
                        value-format="yyyy"
                        :placeholder="$t('请选择') + $t('年份')"
                        @input="handleQuery">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="$t('课程名称')" prop="item">
        <el-input
          v-model="queryParams.item"
          :placeholder="$t('请输入') + $t('课程名称')"
          clearable
          size="small"
          @input="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['training:regular:add']"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['training:regular:edit']"
        >{{ $t('修改') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['training:regular:remove']"
        >{{ $t('删除') }}</el-button>
      </el-col>
      <!--<el-col :span="1.5">
        <el-button
          type="info"
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['training:regular:edit']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['training:regular:export']"
        >{{ $t('导出') }}</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-row class="colorMark">
      <svg-icon icon-class="rectangleLightgreen" class="rectangleLightgreen"></svg-icon>{{ $t('需要培训') }}
      <svg-icon icon-class="rectangleFlesh" class="rectangleFlesh"></svg-icon>{{ $t('指定人员') }}
      <svg-icon icon-class="rectangleYellow" class="rectangleYellow"></svg-icon>{{ $t('当被此项目涉及到时，如MOC、事件调查，需要培训') }}
    </el-row>

    <el-table ref="regularTable" v-loading="loading" :data="regularList" @selection-change="handleSelectionChange" :cell-class-name="tableCellClassName" :height="clientHeight" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column :label="$t('年份')" align="center" prop="year" width="50" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('课程代码')" align="center" prop="courseCode" width="150" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('课程名称')" align="center" prop="item" width="350" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('计划培训时间')" align="center" prop="planTrainingdate" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.notPlan === 'false'">{{ scope.row.notTrainingdate }}</span>
          <span v-else>{{ scope.row.planTrainingdate }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('授课人')" align="center" prop="lecturerName" width="230" :show-overflow-tooltip="true" />
      <el-table-column :label="$t('课时')" align="center" prop="hour" :show-overflow-tooltip="true"/>
      <el-table-column v-for="(item, index) in actualpostIdOptions" width="150" :label="item.dictLabel" :key="index" align="center">
        <template slot-scope="scope">
          {{scope.row.actualpost[index]}}
        </template>
      </el-table-column>
      <el-table-column :label="$t('备注')" align="center" prop="remarks" width="300" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('操作')" align="center" fixed="right" width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['training:regular:edit']"
          >{{ $t('修改') }}</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['training:regular:remove']"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改装置培训计划对话框 -->
    <el-dialog v-dialogDrag :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-form-item :label="$t('年份')" prop="year">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.year"
                          type="year"
                          value-format="yyyy"
                          @change="getLecturer"
                          :placeholder="$t('请选择') + $t('年份')">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('课程代码')" prop="courseCode">
          <el-input v-model="form.courseCode" :placeholder="$t('请输入') + $t('课程代码')" />
        </el-form-item>
        <el-form-item :label="$t('课程名称')" prop="item">
          <el-input v-model="form.item" :placeholder="$t('请输入') + $t('课程名称')" />
        </el-form-item>
        <el-form-item :label="$t('需参培岗位')" prop="actualpostId">
          <el-select v-model="actualpostIds" multiple :placeholder="$t('请选择') + $t('需参培岗位')" @change="changeActualpost">
            <el-option
              v-for="dict in actualpostOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('是否存在')+$t('空格') +$t('指定人员')" prop="haveDesignated">
          <el-checkbox v-model="haveDesignated"></el-checkbox>
        </el-form-item>
        <el-form-item :label="$t('指定人员')+$t('空格') + $t('岗位')" prop="designatedPosition" v-if="haveDesignated === true">
          <el-select v-model="designatedPositions" multiple :placeholder="$t('请选择') + $t('指定岗位')" @change="changeDesignated">
            <el-option
              v-for="dict in designatedPositionOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('指定人员')" prop="designatedStaff" v-if="haveDesignated === true && designatedPositions.length > 0">
          <el-select v-model="designatedStaffs" filterable multiple :placeholder="$t('请选择') + $t('指定人员')">
            <el-option
              v-for="dict in stffmgrOptions"
              :key="dict.staffid"
              :label="dict.name"
              :value="dict.staffid">
              <span style="float: left">{{ dict.name }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.staffid }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('是否涉及') + $t('其他部门')" prop="involvedMoc">
          <el-checkbox v-model="form.involvedMoc" @change="changeInvolved"></el-checkbox>
        </el-form-item>
        <el-form-item :label="$t('指定其他部门')" prop="designatedOther" v-if="form.involvedMoc === true">
          <el-select v-model="otherPositions" multiple :placeholder="$t('请选择') + $t('其他部门')">
            <el-option
              v-for="dict in otherPositionOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('备注')" prop="remarks">
          <el-input v-model="form.remarks" :placeholder="$t('请输入') + $t('备注')" />
        </el-form-item>
        <el-form-item :label="$t('是否') + $t('计划培训时间')" prop="notPlan">
          <el-checkbox v-model="form.notPlan"></el-checkbox>
        </el-form-item>
        <el-form-item :label="$t('计划培训时间')" >
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.planTrainingdate"
                          type="month"
                          value-format="yyyy-MM"
                          v-if="form.notPlan === true"
                          :placeholder="$t('请选择') + $t('计划培训时间')">
          </el-date-picker>
          <el-input v-model="form.notTrainingdate" :placeholder="$t('请输入') + $t('计划培训时间')" v-if="form.notPlan === false" />
        </el-form-item>
        <el-form-item :label="$t('授课人')" prop="lecturer">
          <el-select v-model="lecturers" filterable multiple :placeholder="$t('请选择') +$t('授课人')">
            <el-option
              v-for="dict in lecturerOptions"
              :key="dict.staffid"
              :label="dict.name"
              :value="dict.staffid">
              <span style="float: left">{{ dict.name }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.staffid }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('课时')" prop="hour">
          <el-input v-model="form.hour" :placeholder="$t('请输入') + $t('课时')" />
        </el-form-item>
        <el-form-item :label="$t('归属部门')" prop="deptId">
          <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" :placeholder="$t('请选择') + $t('归属部门')" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="submitDisabled">{{ $t('确 定') }}</el-button>
        <el-button @click="cancel">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>
    <!-- 用户导入对话框 -->
    <el-dialog v-dialogDrag :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          {{ $t('将文件拖到此处，或') }}
          <em>{{ $t('点击上传') }}</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />{{ $t('是否更新已经存在的用户数据') }}
          <el-link type="info" style="font-size:12px" @click="importTemplate">{{ $t('下载模板') }}</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">{{ $t('提示：仅允许导入“xls”或“xlsx”格式文件！') }}</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">{{ $t('确 定') }}</el-button>
        <el-button @click="upload.open = false">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listRegular, getRegular, delRegular, addRegular, updateRegular, exportRegular, importTemplate} from "@/api/training/regular";
  import { listStaffmgr, listAllStaffmgr } from "@/api/plant/staffmgr";
  import { treeselect } from "@/api/system/dept";
  import { getToken } from "@/utils/auth";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";

  export default {
    name: "Regular",
    components: { Treeselect },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: false,
        // 总条数
        total: 0,
        // 装置培训计划表格数据
        regularList: [],
        // 弹出层标题
        title: "",
        // 部门树选项
        deptOptions: undefined,
        clientHeight:300,
        // 是否显示弹出层
        open: false,
        // 台账显示岗位字典
        actualpostIdOptions: [],
        // 需参培岗位字典
        actualpostOptions: [],
        // 授课人字典
        lecturerOptions: [],
        // 指定岗位字典
        designatedPositionOptions: [],
        // 指定部门字典
        otherPositionOptions: [],
        //培训岗位多选
        actualpostIds: [],
        //指定人员岗位多选
        designatedPositions: [],
        //其他部门多选
        otherPositions: [],
        //指定人员id多选
        designatedStaffs: [],
        //授课人多选
        lecturers: [],
        //是否存在岗位多选
        haveDesignated: false,
        //人员表联查
        stffmgrOptions: undefined,
        //人员表查询参数
        staffmgrQueryParams: {
          actualposts: null
        },
        //确认按钮是否可点
        submitDisabled: false,
        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/training/regular/importData"
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          year: this.getNowTime()
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          year: [
            { required: true, message: this.$t('年份') + this.$t('不能为空'), trigger: "blur" }
          ],
          courseCode: [
            { required: true, message: this.$t('课程代码') + this.$t('不能为空'), trigger: "blur" }
          ],
          item: [
            { required: true, message: this.$t('课程名称') + this.$t('不能为空'), trigger: "blur" }
          ],
          deptId: [
            { required: true, message: this.$t('部门编号')+ this.$t('不能为空'), trigger: "blur" }
          ],
        }
      };
    },
    watch: {
      // 根据名称筛选部门树
      deptName(val) {
        this.$refs.tree.filter(val);
      }
    },
    created() {
      //设置表格高度对应屏幕高度
      this.$nextTick(() => {
        this.clientHeight = document.body.clientHeight -250
      })

      this.getDicts("ACTUALPOST").then(response => {
        this.actualpostIdOptions = response.data;
      });
      this.getDicts("ACTUALPOST").then(response => {
        this.actualpostOptions = response.data;
      });
      this.getDicts("ACTUALPOST").then(response => {
        this.designatedPositionOptions = response.data;
      });
      let _this = this
      this.getDicts("ACTUALPOST").then(response => {
        response.data.forEach(function (positionValue, positionkey, arr) {
          if (positionValue.dictValue === "28" || positionValue.dictValue === "30" || positionValue.dictValue === "32") {
            _this.otherPositionOptions.push(positionValue)
          }
        })
        this.getStaffmar();
        this.getLecturer();
        this.getTreeselect();
      });
    },
    methods: {
      /** 查询装置培训计划列表 */
      getList() {
        this.loading = true;
        let _this = this
        listRegular(this.queryParams).then(response => {
          this.regularList = response.rows;
          this.regularList.forEach(function (value,key,arr) {
            let stffmgrName = "";
            if (value.lecturer != null) {
              let staffId = value.lecturer.split(",");
              staffId.forEach(function (id, index) {
                _this.stffmgrOptions.forEach(function (item) {
                  if (item.staffid === id) {
                    if (index === 0) {
                      stffmgrName = item.name
                    }else {
                      stffmgrName = stffmgrName + "," + item.name
                    }
                  }
                });
              });
            }
            _this.regularList[key].lecturerName = stffmgrName
          });
          this.total = response.total;
          this.loading = false;
          this.$nextTick(() => {
            this.$refs.regularTable.doLayout(); // 解决表格错位
          });
        });
      },
      /** 获取当前年份 */
      getNowTime() {
        var now = new Date();
        var year = now.getFullYear(); //得到年份
        var defaultDate = `${year}`;
        defaultDate = `${year}`
        return defaultDate;
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      //获取人员表
      getStaffmar() {
        listStaffmgr(this.staffmgrQueryParams).then(response => {
          this.stffmgrOptions = response.rows;
          this.$nextTick(() => {
            this.getList();
          })
        });
      },
      getLecturer(year) {
        this.staffmgrQueryParams.leftYear = year
        listAllStaffmgr(this.staffmgrQueryParams).then(response => {
          this.lecturerOptions = response.rows;
        });
      },
      //根据分数显示颜色提示
      tableCellClassName({ row, column, rowIndex, columnIndex }) {
        var postNum = this.actualpostIdOptions.length;
        for (var i = 0; i < postNum; i++) {
          if (columnIndex == 7 + i){
            return this.changeColor(row.actualpost[i])
          }
        }
      },
      changeColor (value) {
        if (value === "M") {
          return 'cellChoose'
        }else if (value === "|") {
          return 'cellDesignated'
        }else if (value === "(M)") {
          return 'cellInvolvedMoc'
        }
      },
      //需培训岗位变动
      changeActualpost() {
        let _this = this
        this.getDicts("ACTUALPOST").then(response => {
          this.designatedPositionOptions = response.data;
          this.actualpostIds.forEach(function (value, key, arr) {
            _this.designatedPositionOptions.forEach(function (positionValue, positionkey, arr) {
              if (positionValue.dictValue === value) {
                _this.designatedPositionOptions.splice(positionkey ,1)
              }
            })
          })
        });
      },
      //指定人员训岗位变动
      changeDesignated() {
        if (this.designatedPositions.length > 0) {
          var designatedId = null;
          this.designatedPositions.forEach(function (value,key,arr) {
            if (key != 0) {
              designatedId = designatedId + "," + value;
            }else if (key == 0) {
              designatedId = value;
            }
          })
          this.staffmgrQueryParams.actualposts = designatedId;
          this.staffmgrQueryParams.leftYear = this.form.year
          listAllStaffmgr(this.staffmgrQueryParams).then(response => {
            this.stffmgrOptions = response.rows;
          });

          let _this = this
          this.getDicts("ACTUALPOST").then(response => {
            this.actualpostOptions = response.data;
            this.designatedPositions.forEach(function (value, key, arr) {
              _this.actualpostOptions.forEach(function (positionValue, positionkey, arr) {
                if (positionValue.dictValue === value) {
                  _this.actualpostOptions.splice(positionkey ,1)
                }
              })
            })
          });
        }else {
          this.designatedStaffs = [];
        }
      },
      //是否涉及其他部门变动
      changeInvolved() {
        if (this.form.involvedMoc === true) {
          this.otherPositions = ['28','30','32']
        }else {
          this.otherPositions = []
        }
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          courseCode: null,
          item: null,
          actualpostId: null,
          remarks: null,
          delFlag: null,
          createrCode: null,
          createdate: null,
          updaterCode: null,
          updatedate: null,
          deptId: null,
          planTrainingdate: null,
          actualCompletedate: null,
          lecturer: null,
          hour: null,
          year: null,
          designatedPosition: null,
          designatedStaff: null,
          involvedMoc: null,
          designatedOther: null,
          notPlan: null,
          notTrainingdate: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.submitDisabled = false;
        this.form.involvedMoc = false
        this.form.notPlan = true
        this.actualpostIds = [];
        this.lecturers = [];
        this.haveDesignated = false;
        this.designatedPositions = [];
        this.otherPositions = [];
        this.getDicts("ACTUALPOST").then(response => {
          this.actualpostOptions = response.data;
        });
        this.getDicts("ACTUALPOST").then(response => {
          this.designatedPositionOptions = response.data;
        });
        this.title = this.$t('添加') + this.$t('装置') +this.$t('空格') + this.$t('培训计划');
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        let _this = this
        this.submitDisabled = false;
        const id = row.id || this.ids
        getRegular(id).then(response => {
          this.form = response.data;
          if (this.form.actualpostId != null) {
            this.actualpostIds = this.form.actualpostId.split(',');
            this.getDicts("ACTUALPOST").then(response => {
              this.designatedPositionOptions = response.data;
              this.actualpostIds.forEach(function (value, key, arr) {
                _this.designatedPositionOptions.forEach(function (positionValue, positionkey, arr) {
                  if (positionValue.dictValue === value) {
                    _this.designatedPositionOptions.splice(positionkey ,1)
                  }
                })
              })
            });
          }else {
            this.getDicts("ACTUALPOST").then(response => {
              this.designatedPositionOptions = response.data;
            })
            this.actualpostIds = [];
          }
          if (this.form.designatedPosition != null) {
            this.designatedPositions = this.form.designatedPosition.split(',');
            this.getDicts("ACTUALPOST").then(response => {
              this.actualpostOptions = response.data;
              this.designatedPositions.forEach(function (value, key, arr) {
                _this.actualpostOptions.forEach(function (positionValue, positionkey, arr) {
                  if (positionValue.dictValue === value) {
                    _this.actualpostOptions.splice(positionkey ,1)
                  }
                })
              })
            });
            this.haveDesignated = true;
            var designatedId = null;
            this.designatedPositions.forEach(function (value,key,arr) {
              if (key != 0) {
                designatedId = designatedId + "," + value;
              }else if (key == 0) {
                designatedId = value;
              }
            })
            this.staffmgrQueryParams.actualposts = designatedId;
            this.staffmgrQueryParams.leftYear = this.form.year
            this.$nextTick(() => {
              listStaffmgr(this.staffmgrQueryParams).then(response => {
                this.stffmgrOptions = response.rows;
              });
            })
          }else {
            this.haveDesignated = false;
            this.designatedPositions = [];
            this.getDicts("ACTUALPOST").then(response => {
              this.actualpostOptions = response.data;
            })
          }
          if (this.form.designatedStaff != null) {
            this.designatedStaffs = this.form.designatedStaff.split(',');
          }else {
            this.designatedStaffs = [];
          }
          if (this.form.lecturer != null) {
            this.lecturers = this.form.lecturer.split(',');
          }else {
            this.lecturers =[];
          }
          if (response.data.involvedMoc === 'true') {
            this.form.involvedMoc = true
          }else {
            this.form.involvedMoc = false
          }

          //指定其他部门下拉框内容
          if (this.form.designatedOther != null) {
            this.otherPositions = this.form.designatedOther.split(',');
          }else {
            this.otherPositions = [];
          }

          if (response.data.notPlan === 'true') {
            this.form.notPlan = true
          }else {
            this.form.notPlan = false
          }
          this.open = true;
          this.title = this.$t('修改') + this.$t('装置') +this.$t('空格') + this.$t('培训计划');
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          this.submitDisabled = true;
          if (valid) {
            var id = null;
            this.actualpostIds.forEach(function (value,key,arr) {
              if (key != 0) {
                id = id + "," + value;
              }else if (key == 0) {
                id = value;
              }
            })
            this.form.actualpostId = id;

            var designatedId = null;
            this.designatedPositions.forEach(function (value,key,arr) {
              if (key != 0) {
                designatedId = designatedId + "," + value;
              }else if (key == 0) {
                designatedId = value;
              }
            })
            // 王子文 2022年4月18日 13点31分 修改
            // 如果 复选框被选中 将指定人信息存入数据传输对象
            if (this.haveDesignated === true) {
              this.form.designatedPosition = designatedId;
            } else {
              this.form.designatedPosition = null;
            }
            // this.form.designatedPosition = designatedId;

            var designatedOther = null;
            this.otherPositions.forEach(function (value,key,arr) {
              if (key != 0) {
                designatedOther = designatedOther + "," + value;
              }else if (key == 0) {
                designatedOther = value;
              }
            })
            this.form.designatedOther = designatedOther;

            var staffId = null;
            this.designatedStaffs.forEach(function (value,key,arr) {
              if (key != 0) {
                staffId = staffId + "," + value;
              }else if (key == 0) {
                staffId = value;
              }
            })
            this.form.designatedStaff = staffId;

            var lecturerId = null;
            this.lecturers.forEach(function (value,key,arr) {
              if (key != 0) {
                lecturerId = lecturerId + "," + value;
              }else if (key == 0) {
                lecturerId = value;
              }
            })
            this.form.lecturer = lecturerId;
            if (this.form.id != null) {
              updateRegular(this.form).then(response => {
                this.msgSuccess(this.$t('修改成功'));
                this.open = false;
                this.submitDisabled = false;
                this.getList();
              });
            } else {
              addRegular(this.form).then(response => {
                this.msgSuccess(this.$t('新增成功'));
                this.open = false;
                this.submitDisabled = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: "warning"
        }).then(function() {
          return delRegular(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess(this.$t('删除成功'));
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm(this.$t('是否确认导出所有装置培训计划数据项?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: "warning"
        }).then(function() {
          return exportRegular(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = this.$t('用户导入');
        this.upload.open = true;
      },
      /** 下载模板操作 */
      importTemplate() {
        importTemplate().then(response => {
          this.download(response.msg);
        });
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert(response.msg, this.$t('导入结果'), { dangerouslyUseHTMLString: true });
        this.getList();
      },
      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit();
      }
    }
  };
</script>

<style scoped>
  .colorMark {
    color: #6f6f6f;
    text-align: right;
    font-weight:bold;
    font-size: 13px;
    padding-bottom: 5px;
  }

  .rectangleLightgreen {
    width: 40px !important;
    height: 20px !important;
  }
  .rectangleFlesh {
    width: 40px !important;
    height: 20px !important;
  }
  .rectangleYellow {
    width: 40px !important;
    height: 20px !important;
  }
</style>
