licp
2024-12-24 e4bb381c896015c4b87faa002ba6875c06a2fd16
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>
    <div style="text-align: right; margin-bottom: 15px;">
      <el-button type="primary" size="small" @click="dialogVisible = true" v-if="clickNodeVal.userId">添加工作履历</el-button>
      <el-button type="primary" size="small" @click="exportExcel" :loading="outLoading">导出excel</el-button>
    </div>
    <div class="table">
      <el-table :data="tableData" style="width: 100%" height="70vh">
        <el-table-column type="index" label="序号" width="120">
          <template v-slot="scope">
            <span>{{ (search.current - 1) * search.size + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="startTime" label="起始日期" min-width="180">
        </el-table-column>
        <el-table-column prop="endTime" label="结束日期" min-width="180">
        </el-table-column>
        <el-table-column prop="placeWork" label="工作单位" min-width="120">
        </el-table-column>
        <el-table-column prop="department" label="工作部门" min-width="120">
        </el-table-column>
        <el-table-column prop="post" label="职务" min-width="120">
        </el-table-column>
        <el-table-column prop="remarks" label="备注" min-width="180">
        </el-table-column>
        <el-table-column prop="createUser" label="创建人" min-width="180">
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" min-width="180">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="150">
          <template v-slot="scope">
            <el-button type="text" size="small" @click="downloadFile(scope.row.fileName)">下载</el-button>
            <el-button type="text" size="small" @click="checkFun(scope.row)">查看</el-button>
            <el-button type="text" size="small" style="color: red;" @click="deleteFun(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="1"
        :page-sizes="[10, 20, 30, 50, 100]" :page-size="search.size" layout="->,total, sizes, prev, pager, next, jumper"
        :total="search.total">
      </el-pagination>
    </div>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="45%">
      <div style="height: 30vh;">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-row>
            <el-col :span="12">
              <el-form-item label="起始日期" prop="startTime">
                <el-date-picker v-model="ruleForm.startTime" type="date" placeholder="选择日期" size="small"
                  style="width: 99%;" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss" required>
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结束日期">
                <el-date-picker v-model="ruleForm.endTime" type="date" placeholder="选择日期" size="small"
                  style="width: 99%;" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="工作单位" prop="placeWork">
                <el-input v-model="ruleForm.placeWork" size="small" clearable required></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工作部门" prop="department">
                <el-input v-model="ruleForm.department" size="small" clearable required></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="最高职务" prop="post">
                <el-input v-model="ruleForm.post" size="small" clearable required></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="附件资料">
                <el-row>
                  <el-col :span="17"><el-input v-model="ruleForm.fileName" size="small" disabled></el-input></el-col>
                  <el-col :span="7">
                    <el-upload ref="upload" style="float: left; margin: 0 20px;" :action="action"
                      :on-success="onSuccess" :on-change="handleChangePic" :show-file-list="false">
                      <el-button class="uploadFile" slot="trigger" size="mini" type="primary">浏览</el-button>
                    </el-upload>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="备注">
                <el-input v-model="ruleForm.remarks" size="small" clearable></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveOrUpdate">{{ isUpdate ? '更 新' : '保 存' }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
  import fileDownload from '../../../util/file'
export default {
  props: {
    clickNodeVal: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      tableData: [],
      search: {
        size: 20,
        current: 1,
        total: 0
      },
      dialogVisible: false,
      ruleForm: {
        fileName: '',
        sysFileName: ''
      },
      rules: {
        startTime: [
          { required: true, message: '请输入起始日期', trigger: 'blur' },
          { required: true, message: '请输入起始日期', trigger: 'change' }
        ],
        placeWork: [
          { required: true, message: '请输入工作单位', trigger: 'blur' }
        ],
        department: [
          { required: true, message: '请输入工作部门', trigger: 'blur' }
        ],
        post: [
          { required: true, message: '请输入最高职务', trigger: 'blur' }
        ]
      },
      isUpdate: false,
      outLoading: false
    };
  },
  created() {
    this.init();
  },
  computed: {
    action() {
      return this.javaApi + this.$api.personnel.saveCNASFile
    }
  },
  methods: {
    downloadFile(fileName) {
      let url = this.javaApi + '/img/' + fileName;
      fileDownload.downloadIamge(url,fileName)
    },
    handleChangePic(file, fileList) {
      if (fileList.length > 1) {
        fileList.splice(0, 1);
      }
    },
    onSuccess(response, file, fileList) {
      if (response.code === 200) {
        this.$set(this.ruleForm, 'fileName', response.data)
      } else {
        this.$message.warning(response.message)
      }
    },
    exportExcel() {
      this.outLoading = true
      let userId = this.clickNodeVal.userId ? this.clickNodeVal.userId : null
      let departmentId = this.clickNodeVal.id ? this.clickNodeVal.id : null
      this.$axios.get(this.$api.personnel.personTrackRecordExport + "?userId=" + userId + "&departmentId=" + departmentId, { responseType: "blob" }).then(res => {
        this.outLoading = false
        const blob = new Blob([res], { type: 'application/octet-stream' });
        //将Blob 对象转换成字符串
        let reader = new FileReader();
        reader.readAsText(blob, 'utf-8');
        reader.onload = () => {
          try {
            let result = JSON.parse(reader.result);
            if (result.message) {
              this.$message.error(result.message);
            } else {
              const url = URL.createObjectURL(blob);
              const link = document.createElement('a');
              link.href = url;
              link.download = '工作履历.xlsx';
              link.click();
              this.$message.success('导出成功')
            }
          } catch (err) {
            console.log(err);
            const url = URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.href = url;
            link.download = '工作履历.xlsx';
            link.click();
            this.$message.success('导出成功')
          }
        }
      })
    },
    saveOrUpdate() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          if (this.isUpdate) {
            this.$axios.put(this.$api.personnel.personTrackRecordUpdate, this.ruleForm, {
              headers: {
                'Content-Type': 'application/json'
              }
            }).then(res => {
              if (res.code = 200) {
                this.dialogVisible = false
                this.$message.success('更新成功!')
                this.init()
              }
            })
          } else {
            this.ruleForm.userId = this.clickNodeVal.userId
            this.$axios.post(this.$api.personnel.personTrackRecordSave, this.ruleForm, {
              headers: {
                'Content-Type': 'application/json'
              }
            }).then(res => {
              if (res.code = 200) {
                this.dialogVisible = false
                this.$message.success('新增成功!')
                this.init()
              }
            })
          }
        } else {
          return false;
        }
      });
    },
    deleteFun(id) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.delete(this.$api.personnel.personTrackRecordDelete + "?id=" + id).then(res => {
          this.$message.success('删除成功!')
          this.init()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handleSizeChange(val) {
      this.search.size = val
      this.init()
    },
    handleCurrentChange(val) {
      this.search.current = val
      this.init()
    },
    // 初始化调用
    init() {
      if (this.clickNodeVal.userId) {
        this.getPersonnelTraining(this.clickNodeVal.userId ? this.clickNodeVal.userId : null, null);
      } else {
        this.getPersonnelTraining(null, this.clickNodeVal.id ? this.clickNodeVal.id : null);
      }
    },
    getPersonnelTraining(userId, departmentId) {
      this.$axios.get(this.$api.personnel.personTrackRecordSelect + "?userId=" + userId + "&size=" + this.search.size + "&current=" + this.search.current + "&departmentId=" + departmentId).then(res => {
        this.tableData = res.data.records
        this.search.total = res.data.total
      })
    },
    checkFun(row) {
      this.ruleForm = { ...row }
      this.dialogVisible = true
      this.isUpdate = true
    }
  },
  watch: {
    // 监听点击el-tree的数据,进行数据刷新
    clickNodeVal(newVal) {
      if (newVal.userId) {
        // 用户id
        this.getPersonnelTraining(newVal.userId, null);
      } else {
        // 部门id
        this.getPersonnelTraining(null, newVal.id);
      }
    },
    dialogVisible(newVal) {
      if (!newVal) {
        this.isUpdate = false
        this.$refs.ruleForm.resetFields();
        this.ruleForm = {}
      }
    }
  }
};
</script>
<style scoped>
>>>.el-form-item {
  margin-bottom: 13px;
}
</style>