lxp
2025-03-12 952a20f1c005d80e9bf881287c40e6f4e4266a0b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<template>
  <div>
    <el-dialog :visible.sync="addTrainingPlanDia" :show="currshowlist" @close="$emit('update:currshowlist', false)"
      title="新增培训计划" width="50%">
      <div class="body">
        <el-form ref="trainingPlan" :model="trainingPlan" label-position="right" label-width="90px"
          :rules="trainingPlanRules">
          <el-row>
            <el-col :span="12">
              <!-- <el-form-item label="培训日期:" prop="trainingDate">
                <el-date-picker v-model="trainingPlan.trainingDate" format="yyyy-MM-dd"
                                placeholder="选择日期" size="small" value-format="yyyy-MM-dd"
                                type="date" style="width: 100%"></el-date-picker>
              </el-form-item> -->
              <el-form-item label="培训月份:" prop="trainingDate">
                <el-select v-model="trainingPlan.trainingDate">
                  <el-option v-for="(v, i) in months" :key="i" :label="v.label" :value="v.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="培训日期:" prop="trainingDateTwo">
                <el-date-picker v-model="trainingPlan.trainingDateTwo" type="date" value-format="yyyy-MM-dd"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开始时间:" prop="openingTime">
                <el-time-picker v-model="trainingPlan.openingTime" placeholder="选择时间" size="small" style="width: 100%"
                  value-format="HH:mm:ss"></el-time-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结束时间:" prop="endTime">
                <el-time-picker v-model="trainingPlan.endTime" placeholder="选择时间" size="small" style="width: 100%"
                  value-format="HH:mm:ss"></el-time-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="培训目标:">
                <el-input v-model="trainingPlan.trainingObjectives" placeholder="请输入" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="参加对象:">
                <el-input v-model="trainingPlan.participants" placeholder="请输入" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="培训内容:" prop="trainingContent">
                <el-input v-model="trainingPlan.trainingContent" placeholder="请输入" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="培训讲师:" prop="trainingLecturerId">
                <el-select v-model="trainingPlan.trainingLecturerId" multiple clearable filterable placeholder="请选择"
                  size="small" style="width: 100%">
                  <el-option v-for="item in responsibleOptions" :key="item.id" :label="item.name" :value="item.name">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="课题学分:">
                <el-input type="number" v-model="trainingPlan.projectCredits" label="描述文字" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="培训地点:">
                <el-input v-model="trainingPlan.placeTraining" placeholder="请输入" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="培训方式:">
                <el-input v-model="trainingPlan.trainingMode" placeholder="请输入" size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="举办部门:">
                <el-select v-model="trainingPlan.holdingDepartment" placeholder="请选择">
                  <el-option v-for="(v, i) in departLims" :key="i" :label="v.name" :value="v.id"></el-option>
                </el-select>
                <!--
                <el-input
                  v-model="trainingPlan.holdingDepartment"
                  placeholder="请输入"
                  size="small"
                ></el-input> -->
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="课时:">
                <el-input type="number" v-model="trainingPlan.classHour" label="描述文字" size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeAdd">取 消</el-button>
        <el-button type="primary" @click="submitAdd">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import {
  selectDepartLims,
  addOrUpdatePersonTrainingDetailed,
} from '@/api/cnas/personnel/personnelInfo.js'
import { selectUserCondition } from "@/api/system/user";
export default {
  props: {
    currshowlist: {
      type: Boolean,
      default: false,
    },
    currentChangeRow: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  name: "Add",
  // import 引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    var trainingLecturerIdValidate = (rule, value, callback) => {
      if (typeof value !== "undefined" && value.length == 0) {
        callback(new Error("请选择讲师"));
      } else {
        callback();
      }
    };
    // 这里存放数据
    return {
      departLims: [],
      months: [
        { label: "1月", value: "1月" },
        { label: "2月", value: "2月" },
        { label: "3月", value: "3月" },
        { label: "4月", value: "4月" },
        { label: "5月", value: "5月" },
        { label: "6月", value: "6月" },
        { label: "7月", value: "7月" },
        { label: "8月", value: "8月" },
        { label: "9月", value: "9月" },
        { label: "10月", value: "10月" },
        { label: "11月", value: "11月" },
        { label: "12月", value: "12月" },
      ],
      addTrainingPlanDia: false,
      trainingPlan: {
        id: "",
        planId: "",
        trainingDate: "",
        trainingDateTwo: "",
        classHour: "",
        openingTime: "",
        endTime: "",
        trainingObjectives: "",
        participants: "",
        trainingContent: "",
        trainingLecturerId: undefined,
        projectCredits: "",
        placeTraining: "",
        trainingMode: "",
        holdingDepartment: "",
      },
      trainingPlanRules: {
        trainingDate: [
          { required: true, message: "请选择培训日期", trigger: "change" },
        ],
        trainingDateTwo: [
          { required: true, message: "请选择培训日期", trigger: "change" },
        ],
        openingTime: [
          { required: true, message: "请选择开始时间", trigger: "change" },
        ],
        endTime: [
          { required: true, message: "请选择结束时间", trigger: "change" },
        ],
        trainingContent: [
          { required: true, message: "请输入培训内容", trigger: "blur" },
        ],
        trainingLecturerId: [
          {
            required: true,
            validator: trainingLecturerIdValidate,
            trigger: "change",
          },
        ],
      },
      responsibleOptions: [],
    };
  },
  created() {
    this.departLims = [];
    selectDepartLims().then((res) => {
      this.departLims = res.data;
    });
  },
  // 方法集合
  methods: {
    showDialog(id) {
      this.trainingPlan.planId = id;
      this.getUserList();
      // this.addTrainingPlanDia = true;
    },
    showEditDialog(row) {
      this.getUserList();
      let data = JSON.parse(JSON.stringify(row));
 
      console.log(data.trainingLecturerId);
      let list = data.trainingLecturerId.split(/、|,|,|\\s+/);
      this.$set(this.trainingPlan, "trainingLecturerId", list);
      this.$set(this.trainingPlan, "id", data.id);
      this.$set(this.trainingPlan, "trainingDate", data.trainingDate);
      this.$set(this.trainingPlan, "trainingDateTwo", data.trainingDateTwo);
      this.$set(this.trainingPlan, "classHour", data.classHour);
      this.$set(this.trainingPlan, "openingTime", data.openingTime);
      this.$set(this.trainingPlan, "endTime", data.endTime);
      this.$set(
        this.trainingPlan,
        "trainingObjectives",
        data.trainingObjectives
      );
      this.$set(this.trainingPlan, "participants", data.participants);
      this.$set(this.trainingPlan, "projectCredits", data.projectCredits);
      this.$set(this.trainingPlan, "placeTraining", data.placeTraining);
      this.$set(this.trainingPlan, "trainingContent", data.trainingContent);
      this.$set(this.trainingPlan, "trainingMode", data.trainingMode);
      this.$set(this.trainingPlan, "holdingDepartment", data.holdingDepartment);
      this.$set(this.trainingPlan, "planId", data.planId);
 
      console.log("222", this.trainingPlan);
    },
    // 提交新增
    submitAdd() {
      this.$refs.trainingPlan.validate((valid) => {
        if (valid) {
          // 将培训讲师值封装
          this.trainingPlan.trainingLecturerId =
            this.trainingPlan.trainingLecturerId.join(",");
          console.log(
            "this.trainingPlan.trainingLecturerId",
            this.trainingPlan.trainingLecturerId
          );
          const personTrainingDetailed = this.trainingPlan;
          console.log("personTrainingDetailed", personTrainingDetailed);
          addOrUpdatePersonTrainingDetailed(personTrainingDetailed).then((res) => {
            if (res.code == 200) {
              this.$message.success("提交成功");
              this.closeAdd();
              this.dialogVisible = false;
            }
          });
        }
      });
    },
    // 关闭弹框
    closeAdd() {
      this.$refs.trainingPlan.resetFields();
      this.$emit("search");
      this.$emit("searchPlan");
      this.addTrainingPlanDia = false;
    },
    // 获取负责人信息接口
    getUserList() {
      selectUserCondition().then((res) => {
        if (res.code == 200) {
          this.responsibleOptions = res.data;
        }
      });
    },
  },
  watch: {
    // addTrainingPlanDia(newVal) {
    //   if (newVal) {
    //     this.trainingPlan.planId = null;
    //   }
    // },
    currshowlist(newValue) {
      this.addTrainingPlanDia = this.currshowlist;
      if (!newValue) {
        this.closeAdd();
        this.trainingPlan = {
          id: "",
          planId: "",
          trainingDate: "",
          classHour: "",
          openingTime: "",
          endTime: "",
          trainingObjectives: "",
          participants: "",
          trainingContent: "",
          trainingLecturerId: undefined,
          projectCredits: "",
          placeTraining: "",
          trainingMode: "",
          holdingDepartment: "",
        };
      }
      if (this.currshowlist) {
        this.$nextTick(() => {
          if (this.trainingPlan.trainingLecturerId.length == 0) {
            this.trainingPlan.trainingLecturerId = undefined;
          }
        });
      }
    },
  },
};
</script>
 
<style scoped></style>