马宇豪
2023-10-07 21e03c21386fb124774df48c8bb1fe3b185dbb48
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
<template>
  <el-dialog title="资格证书" :visible.sync="open" width="50%" append-to-body>
  <div class="app-container home">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="openEdit({},'add')"
          v-hasPermi="['system:experts:add']"
        >新增</el-button>
      </el-col>
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column type="index" label="序号" width="55" align="center" />
      <el-table-column label="证书名称" align="center" prop="name"/>
      <el-table-column label="资格类型" align="center" prop="qualificationType" />
      <el-table-column label="作业类别" align="center" prop="jobCategory" />
      <el-table-column label="操作项目" align="center" prop="operationItems" />
      <el-table-column label="有效期至" align="center" prop="expiredTime"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="openEdit(scope.row,'edit')"
          >编辑</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row,scope.index)"
            v-hasPermi="['system:experts:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="50%" append-to-body>
      <el-form :model="form" :rules="rules" ref="ruleForm" label-width="200px">
        <el-row>
          <el-col :span="20">
            <el-form-item label="证书名称" prop="name">
              <el-input v-model="form.name"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="20">
            <el-form-item label="资格类型" prop="operateTypeId">
              <el-cascader
                v-model="form.operateTypeId"
                :options="typeList"
                style="width: 100%"
                :props="{ expandTrigger: 'hover', value: 'id',label: 'name',emitPath: false}"
                @change="handleChange"></el-cascader>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="20">
            <el-form-item label="过期时间" prop="expiredTime">
              <el-date-picker
                v-model="form.expiredTime"
                value-format="yyyy-MM-dd"
                style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div style="width: 100%;padding-bottom: 30px;display: flex;justify-content: center">
        <el-button type="primary" @click="submit()">提交</el-button>
      </div>
    </el-dialog>
  </div>
  </el-dialog>
</template>
 
<script>
 
// import { verifySimplePhone, verifyIdCard } from "@/utils/validate";
import {addCert, editCert, delCert} from "@/api/coalMine/people";
import {getOperatePage} from "@/api/coalMine/operateType";
 
export default {
  name: "certDialog",
  dicts: [],
  components: { },
  data() {
    return {
      open: false,
      id: null,
      dialogVisible: false,
      title: '新增证书',
      loading: false,
      dataList: [],
      typeList: [],
      form: {
        name: '',
        id: null,
        staffId: null,
        expiredTime: '',
        operateTypeId: null
      },
      rules: {
        name: [{ required: true, message: "请填写证书名称", trigger: "blur" }],
        expiredTime: [{ required: true, message: "请选择过期时间", trigger: "blur" }],
        operateTypeId: [{ required: true, message: "请选择资格类型", trigger: "blur" }]
      }
    };
  },
  created() {
 
  },
  methods: {
    openDialog(data){
      this.dataList = data.cmStaffQas
      this.id = data.id
      this.getList()
      this.open = true
    },
 
    async getList() {
      this.loading = true;
      const res = await getOperatePage({name: ''})
      if(res.code == 200){
        this.typeList = this.handleTree(res.data, "id");
      }else{
        this.$message({
          type: 'warning',
          message: res.msg
        });
      }
      this.loading = false;
    },
 
    openEdit(data,type){
      this.dialogVisible = true
      if(type == 'add'){
        this.title='新增证书'
        this.form = {
          name: '',
          id: null,
          staffId: this.id,
          expiredTime: '',
          operateTypeId: null
        }
      }else {
        this.title='编辑证书'
        for(let i in data){
          if(this.isKey(i,this.form)){
            this.form[i] = data[i]
          }
        }
      }
    },
    isKey(key,obj){
      return key in obj
    },
    handleDelete(row,index){
      this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await delCert(row.id)
        if(res.code == 200){
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.dialogVisible = false
          this.open = false
          this.$emit('closeDialog')
        }else{
          this.$message({
            type: 'warning',
            message: res.msg
          });
        }
      }).catch(() => {
 
      });
    },
    async submit(){
      this.$refs["ruleForm"].validate(async(valid) =>{
        if(valid) {
          const obj = JSON.parse(JSON.stringify(this.form))
          // console.log(obj.qualification[1],'obj',this.findNameById(this.typeList,obj.qualification[1]))
          // if(obj.qualification.length == 2){
          //   obj.qualificationType = this.findNameById(this.typeList,obj.qualification[0])
          //   obj.jobCategory = this.findNameById(this.typeList,obj.qualification[1])
          //   obj.operateTypeId = this.obj.qualification[1]
          // }
          // if(obj.qualification.length == 3){
          //   obj.qualificationType = this.findNameById(this.typeList,obj.qualification[0])
          //   obj.jobCategory = this.findNameById(this.typeList,obj.qualification[1])
          //   obj.operationItems = this.findNameById(this.typeList,obj.qualification[2])
          //   obj.operateTypeId = obj.qualification[2]
          // }
          if(this.title == '新增证书'){
            const {id,...data} = obj
            const res = await addCert(data)
            if(res.code == 200){
              this.$message({
                type:'success',
                message: res.msg
              })
              this.dialogVisible = false
              this.open = false
              this.$emit('closeDialog')
            }else{
              this.$message({
                type:'warning',
                message: res.msg
              })
            }
          }else{
            const res= await editCert(obj)
            if(res.code == 200){
              this.$message({
                type:'success',
                message: res.msg
              })
              this.dialogVisible = false
              this.open = false
              this.$emit('closeDialog')
            }else{
              this.$message({
                type:'warning',
                message: res.msg
              })
            }
          }
        }else{
          this.$message({
            type:'warning',
            message:'请完善必填信息'
          })
        }
      })
    },
 
    findNameById(data,id){
      for(const node of data){
        if(node.id == id){
          return node.name
        }
        if(node.children){
          const foundName = this.findNameById(node.children,id)
          if(foundName){
            return foundName
          }
        }
      }
      return null
    },
 
    handleChange(){
 
    },
    handleQuery(){
 
    },
    resetQuery(){
 
    },
  }
};
</script>
 
<style scoped lang="scss">
.home {}
</style>