From 21e03c21386fb124774df48c8bb1fe3b185dbb48 Mon Sep 17 00:00:00 2001
From: 马宇豪 <978517621@qq.com>
Date: 星期六, 07 十月 2023 14:56:23 +0800
Subject: [PATCH] 新增接口页面

---
 src/views/notCoalMine/nTeacherManage/nTeacher/components/teacherDialog.vue |  472 +++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 312 insertions(+), 160 deletions(-)

diff --git a/src/views/notCoalMine/nTeacherManage/nTeacher/components/teacherDialog.vue b/src/views/notCoalMine/nTeacherManage/nTeacher/components/teacherDialog.vue
index a17417d..f18dc0d 100644
--- a/src/views/notCoalMine/nTeacherManage/nTeacher/components/teacherDialog.vue
+++ b/src/views/notCoalMine/nTeacherManage/nTeacher/components/teacherDialog.vue
@@ -5,14 +5,14 @@
         <el-row>
           <el-col :span="20">
             <el-form-item label="姓名" prop="name">
-              <el-input v-model="form.name"></el-input>
+              <el-input v-model="form.name" :readonly="disable"></el-input>
             </el-form-item>
           </el-col>
         </el-row>
         <el-row>
           <el-col :span="20">
             <el-form-item label="性别" prop="sex">
-              <el-radio-group v-model="form.sex">
+              <el-radio-group v-model="form.sex" :disabled="disable">
                 <el-radio :label="0">男</el-radio>
                 <el-radio :label="1">女</el-radio>
               </el-radio-group>
@@ -21,40 +21,48 @@
         </el-row>
         <el-row>
           <el-col :span="20">
-            <el-form-item label="身份证号" prop="idCard">
-              <el-input v-model="form.idCard"></el-input>
+            <el-form-item label="身份证号" prop="code">
+              <el-input v-model="form.code" :readonly="disable"></el-input>
             </el-form-item>
           </el-col>
         </el-row>
         <el-row>
           <el-col :span="20">
-            <el-form-item label="联系电话" prop="phone">
-              <el-input v-model="form.phone"></el-input>
+            <el-form-item label="联系电话" prop="mobilePhone">
+              <el-input v-model="form.mobilePhone" :readonly="disable"></el-input>
             </el-form-item>
           </el-col>
         </el-row>
         <el-row>
           <el-col :span="20">
-            <el-form-item label="职称" prop="title">
-              <el-input v-model="form.title"></el-input>
+            <el-form-item label="职称" prop="jobTitle">
+              <el-input v-model="form.jobTitle" :readonly="disable"></el-input>
             </el-form-item>
           </el-col>
         </el-row>
         <el-row>
           <el-col :span="20">
-            <el-form-item label="最高学历" prop="degree">
-              <el-input v-model="form.degree"></el-input>
+            <el-form-item label="最高学历" prop="eduLevel">
+              <el-select v-model="form.eduLevel" placeholder="请选择" style="width: 100%" :disabled="disable">
+                <el-option
+                  v-for="dict in dict.type.sys_highest_education_code"
+                  :key="dict.value"
+                  :label="dict.label"
+                  :value="dict.value"
+                />
+              </el-select>
             </el-form-item>
           </el-col>
         </el-row>
         <el-row>
           <el-col :span="20">
-            <el-form-item label="资质到期" prop="birthday">
+            <el-form-item label="资质到期" prop="expiredTime">
               <el-date-picker
                 style="width: 100%"
-                v-model="form.birthday"
+                v-model="form.expiredTime"
                 value-format="yyyy-MM-dd"
                 type="date"
+                :disabled="disable"
                 placeholder="选择日期">
               </el-date-picker>
             </el-form-item>
@@ -62,10 +70,10 @@
         </el-row>
         <el-row>
           <el-col :span="20">
-            <el-form-item label="在职情况" prop="dutyStatus">
-              <el-radio-group v-model="form.dutyStatus">
-                <el-radio :label="0">在岗</el-radio>
-                <el-radio :label="1">退休</el-radio>
+            <el-form-item label="在职情况" prop="status">
+              <el-radio-group v-model="form.status" :disabled="disable">
+                <el-radio label="0">正常</el-radio>
+                <el-radio label="1">停用</el-radio>
               </el-radio-group>
             </el-form-item>
           </el-col>
@@ -73,17 +81,18 @@
         <el-row>
           <el-col :span="20">
             <el-form-item label="描述">
-              <el-input v-model="form.remark" type="textarea" :autosize="{ minRows: 2}"></el-input>
+              <el-input v-model="form.description" type="textarea" :autosize="{ minRows: 2}" :readonly="disable"></el-input>
             </el-form-item>
           </el-col>
         </el-row>
         <el-row>
           <el-col :span="20">
-            <el-form-item label="证件照">
+            <el-form-item label="证件照" prop="photoAttachment">
               <el-upload
+                :disabled="disable"
                 action="#"
                 multiple
-                :limit="20"
+                :limit="1"
                 :on-exceed="overLimit"
                 :auto-upload="false"
                 accept="image/*,.pdf"
@@ -92,7 +101,7 @@
                 :before-upload="beforeAvatarUpload"
                 :on-change="resumeChange"
                 :on-preview="handlePreview"
-                :on-remove="handleRemove">
+                :on-remove="(file,fileList)=>handleRemove(file,fileList,'证件照')">
                 <i class="el-icon-plus"></i>
               </el-upload>
             </el-form-item>
@@ -100,11 +109,12 @@
         </el-row>
         <el-row>
           <el-col :span="20">
-            <el-form-item label="资质">
+            <el-form-item label="资质" prop="qaAttachment">
               <el-upload
+                :disabled="disable"
                 action=""
                 multiple
-                :limit="20"
+                :limit="1"
                 :on-exceed="overLimit"
                 :auto-upload="false"
                 accept="image/*,.pdf"
@@ -113,32 +123,85 @@
                 :before-upload="beforeAvatarUpload"
                 :on-change="inventChange"
                 :on-preview="handlePreview"
-                :on-remove="handleRemove">
+                :on-remove="(file,fileList)=>handleRemove(file,fileList,'资质')">
                 <i class="el-icon-plus"></i>
               </el-upload>
             </el-form-item>
           </el-col>
         </el-row>
+        <el-row>
+          <el-col :span="20">
+            <el-form-item label="工种详情" prop="operateTypes">
+                <el-table :data="form.operateTypes" border>
+                  <el-table-column label="序号" type="index" align="center"/>
+                  <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" class-name="small-padding fixed-width" v-if="disable == false">
+                    <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="deleteItem(scope.index)" v-hasPermi="['system:experts:remove']">删除</el-button>
+                    </template>
+                  </el-table-column>
+                </el-table>
+                <el-button v-if="disable == false" @click="openEdit({},'add')" style="margin-top: 15px">新增</el-button>
+            </el-form-item>
+          </el-col>
+        </el-row>
       </el-form>
-      <div style="width: 100%;padding-bottom: 30px;display: flex;justify-content: center">
+      <div style="width: 100%;padding-bottom: 30px;display: flex;justify-content: center" v-if="disable == false">
         <el-button type="primary" @click="submit()">提交</el-button>
       </div>
-      <el-dialog :visible.sync="dialogVisible">
+      <el-dialog :visible.sync="dialogVisible" append-to-body>
         <img width="100%" :src="dialogImageUrl" alt="">
+      </el-dialog>
+      <el-dialog :title="dialogTitle" :visible.sync="addVisible" width="50%" append-to-body>
+        <el-form :model="addForm" :rules="addRules" ref="addRuleForm" label-width="200px">
+          <el-row>
+            <el-col :span="20">
+              <el-form-item label="资格类型" prop="operate">
+                <el-cascader
+                  v-model="addForm.operate"
+                  :options="typeList"
+                  style="width: 100%"
+                  :props="{ expandTrigger: 'hover', value: 'id',label: 'name'}"></el-cascader>
+              </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="submitAdd()">提交</el-button>
+        </div>
       </el-dialog>
     </div>
   </el-dialog>
 </template>
 
 <script>
-// import {getExpertTypes,addExpertInfo,uploadFile} from '@/api/system/form'
 import { verifySimplePhone, verifyIdCard } from "@/utils/validate";
+import {getOperatePage} from "@/api/coalMine/operateType";
+import {addTeacher, editTeacher, uploadFile} from "@/api/coalMine/teacher";
 export default {
   name: "teacherDialog",
+  dicts: ['sys_highest_education_code'],
   data() {
-    var validatePass = (rule, value, callback) => {
-      if (this.fileList.length == 0) {
+    // let validateTypes = (rule, value, callback) => {
+    //   if (this.form.operateTypes.length == 0) {
+    //     callback(new Error('请添加工种详情'));
+    //   } else {
+    //     callback();
+    //   }
+    // }
+    let validateResume = (rule, value, callback) => {
+      if (this.resumeList.length == 0) {
         callback(new Error('请上传证件照'));
+      } else {
+        callback();
+      }
+    }
+    let validateCert = (rule, value, callback) => {
+      if (this.inventionList.length == 0) {
+        callback(new Error('请上传资质证书'));
       } else {
         callback();
       }
@@ -168,94 +231,91 @@
     return {
       title: '新增教师',
       open: false,
+      disable: false,
       labelPosition: 'right',
       form:{
+        id: null,
+        isCm: '0',
         name:'',
         sex:'',
-        profession: [],
-        bigClassify:null,
-        smallClassify: null,
-        birthday: '',
-        phone:'',
-        title: '',
-        idCard: '',
-        dutyStatus: null,
-        companyName: '',
-        companyAddress: '',
-        deptName: '',
-        job: '',
-        companyTelephone: '',
-        faxNum: '',
-        email: '',
-        graduationSchool: '',
-        degree: '',
-        speciality: '',
-        currentProfession: '',
-        supportDirectionSafety: [],
-        supportDirectionPrevention: [],
-        supportDirectionEmergency: [],
-        resumeKey: '',
-        paperSituationKey: '',
-        remark: '',
+        code: '',
+        mobilePhone: '',
+        jobTitle: '',
+        eduLevel: '',
+        expiredTime: '',
+        status: '',
+        operateTypes: [],
+        photoAttachment: null,
+        qaAttachment: null,
+        description: '',
       },
-      expertsType: [],
-      directionList: [
-        {
-          value: 1,
-          label: '现场检查'
-        },
-        {
-          value: 2,
-          label: '调查评估'
-        },
-        {
-          value: 3,
-          label: '咨询服务'
-        },
-        {
-          value: 4,
-          label: '教育培训'
-        },
-        {
-          value: 5,
-          label: '其他'
-        }
-      ],
       resumeList: [],
       inventionList: [],
       dialogImageUrl: '',
       dialogVisible: false,
-      rules:{
-        name:[{ required: true, message: '请填写姓名', trigger: 'blur' }],
-        sex:[{ required: true, message: '请选择性别', trigger: 'blur' }],
-        profession: [{ required: true, message: '请选择专业类别', trigger: 'blur' }],
-        birthday: [{ required: true, message: '请选择出生日期', trigger: 'blur' }],
-        phone:[{ required: true, validator: validatePhone, trigger: 'blur' }],
-        title: [{ required: true, message: '请填写职称', trigger: 'blur' }],
-        electronicPhoto: [{ required: true,validator: validatePass, trigger: 'blur' }],
-        idCard: [{ required: true, validator: verifyId, trigger: 'blur' }],
-        dutyStatus: [{ required: true, message: '请选择在岗情况', trigger: 'blur' }],
-        companyName: [{ required: true, message: '请填写单位全称', trigger: 'blur' }],
-        degree: [{ required: true, message: '请填写最高学历', trigger: 'blur' }]
+      dialogTitle: '新增',
+      addVisible: false,
+      addForm: {
+        operate: [],
+        qualificationType: '',
+        jobCategory: '',
+        operationItems: '',
+        operateTypeId: null
       },
+      typeList: [],
+      rules:{
+        name:[{ required: true, message: '请填写姓名', trigger: 'blur'}],
+        sex:[{ required: true, message: '请选择性别', trigger: 'blur'}],
+        code:[{ required: true, validator: verifyId, trigger: 'blur' }],
+        mobilePhone:[{ required: true, validator: validatePhone, trigger: 'blur' }],
+        // code:[{ required: true, message: '请填写身份证号', trigger: 'blur'}],
+        // mobilePhone:[{ required: true, message: '请填写联系方式', trigger: 'blur'}],
+        jobTitle: [{ required: true, message: '请填写职称', trigger: 'blur'}],
+        eduLevel: [{ required: true, message: '请选择最高学历', trigger: 'blur'}],
+        expiredTime: [{ required: true, message: '请选择到期时间', trigger: 'blur'}],
+        status: [{ required: true, message: '请选择在岗情况', trigger: 'blur'}],
+        // operateTypes: [{ required: true,validator: validateTypes, trigger: 'blur' }],
+        photoAttachment: [{ required: true,validator: validateResume, trigger: 'blur'}],
+        qaAttachment: [{ required: true,validator: validateCert, trigger: 'blur'}]
+      },
+      addRules:{
+        operate:[{ required: true, message: '请选择', trigger: 'blur' }]
+      }
     };
   },
   created() {
     const t = this
-    const width = document.documentElement.clientWidth
-    if(width < 750){t.labelPosition = 'top'}
   },
   methods: {
     openDialog(val,type){
-      const width = document.documentElement.clientWidth
-      if(width < 750){this.labelPosition = 'top'}
+      this.resumeList = []
+      this.inventionList = []
       if(type == 'add'){
         this.title = '新增教师'
+        this.disable = false
+        this.form = {
+          id: null,
+          isCm: '0',
+          name:'',
+          sex:'',
+          code: '',
+          mobilePhone: '',
+          jobTitle: '',
+          eduLevel: '',
+          expiredTime: '',
+          status: '',
+          operateTypes: [],
+          photoAttachment: null,
+          qaAttachment: null,
+          description: '',
+        }
       }else{
         if(type == 'edit'){
           this.title = '编辑教师'
+          this.disable = false
         }else{
           this.title = '查看教师'
+          this.disable = true
         }
         if(val){
           for(let i in val){
@@ -264,29 +324,150 @@
             }
           }
         }
+        this.form.sex = Number(this.form.sex)
+        // 仅限单张图片处理
+        this.form.photoAttachment = val.photoAttachment.id
+        this.form.qaAttachment = val.qaAttachment.id
+        this.resumeList.push({
+          name: val.photoAttachment.fileName,
+          url: process.env.VUE_APP_BASE_API + val.photoAttachment.fileUrl
+        })
+        this.inventionList.push({
+          name: val.qaAttachment.fileName,
+          url: process.env.VUE_APP_BASE_API + val.qaAttachment.fileUrl
+        })
+        if(!this.form.operateTypes){
+          this.form.operateTypes = []
+        }
+        console.log(this.form,'form')
       }
       this.open = true
     },
+
     isValidKey(key,obj){
       return key in obj
     },
 
+    openEdit(data,type){
+      this.getList()
+      if(type == 'add'){
+        this.dialogTitle = '新增'
+        this.addVisible = true
+        this.addForm = {
+          operate: [],
+          qualificationType: '',
+          jobCategory: '',
+          operationItems: '',
+          operateTypeId: null
+        }
+      }else{
 
-    async getExpertsType(){
-      const res = await getExpertTypes()
+      }
+    },
+    async submitUpload() {
+      const { resumeList, inventionList, form } = this;
+      const uploadAndCollect = async (fileList, type) => {
+        if (fileList.length > 0 && fileList.find((file)=>file.raw)) {
+          for (const file of fileList) {
+            const formData = new FormData();
+            formData.append("file", file.raw);
+            formData.append("module", 'accountPath');
+            try {
+              const res = await uploadFile(formData);
+              if (res.code === 200) {
+                if (type === '证件照') {
+                  form.photoAttachment = res.data.id;
+                }
+                if (type === '资质') {
+                  form.qaAttachment = res.data.id;
+                }
+              } else {
+                this.$message.error('图片上传出错!');
+              }
+            } catch (error) {
+              this.$message.error('图片上传出错!');
+            }
+          }
+        }else{
+          return
+        }
+      };
+      const uploadPromises = [
+        uploadAndCollect(resumeList, '证件照'),
+        uploadAndCollect(inventionList, '资质')
+      ];
+      try {
+        await Promise.all(uploadPromises);
+        console.log(form, 'form1');
+      } catch (error) {
+        console.error('上传出错:', error);
+      }
+    },
+
+    async submit(){
+      this.$refs["ruleForm"].validate(async(valid) =>{
+        if(valid) {
+          await this.submitUpload()
+          if(this.title == '新增教师'){
+            const {id,...data} = this.form
+            const res= await addTeacher(data)
+            if(res.code == 200){
+              this.$message({
+                type:'success',
+                message: res.msg
+              })
+              this.resumeList = []
+              this.inventionList = []
+              this.open = false
+              this.$emit('closeDialog')
+            }else{
+              this.$message({
+                type:'warning',
+                message: res.msg
+              })
+            }
+          }else{
+            const res= await editTeacher(this.form)
+            if(res.code == 200){
+              this.$message({
+                type:'success',
+                message: res.msg
+              })
+              this.fileList = []
+              this.open = false
+              this.$emit('closeDialog')
+            }else{
+              this.$message({
+                type:'warning',
+                message: res.msg
+              })
+            }
+          }
+        }else{
+          this.$message({
+            type:'warning',
+            message:'请完善必填信息'
+          })
+        }
+      })
+    },
+    deleteItem(index){
+      this.form.operateTypes.splice(index,1);
+    },
+    async getList() {
+      this.loading = true;
+      const res = await getOperatePage({name: ''})
       if(res.code == 200){
-        this.expertsType = res.data
+        this.typeList = this.handleTree(res.data, "id");
       }else{
         this.$message({
           type: 'warning',
           message: res.msg
         });
       }
+      this.loading = false;
     },
 
-    avatorChange(file, fileList) {
-      this.fileList = fileList;
-    },
     resumeChange(file, fileList) {
       this.resumeList = fileList;
     },
@@ -310,71 +491,31 @@
       }
       return isLt5M;
     },
-    async submitUpload() {
-      const t = this;
-      // 创建一个数组来存储所有上传操作的 Promise
-      const uploadPromises = [];
-      // 定义一个函数来上传文件并将结果存入 resumeLink 数组
-      async function uploadAndCollect(fileList, type) {
-        if (fileList.length > 0) {
-          const resumeLink = [];
-          for (const file of fileList) {
-            const formData = new FormData();
-            formData.append("file", file.raw);
-            formData.append("module", 'expertPath');
 
-            const res = await uploadFile(formData);
-            if (res.code === 200) {
-              resumeLink.push(res.data[0].fileKey);
-            } else {
-              this.$message.error('图片上传出错!');
-            }
-          }
-          // 将收集到的文件链接设置到 this.form 中
-          if (type == '工作简历') { t.form.resumeKey = resumeLink.join(',')}
-          if (type == '发明著作') { t.form.paperSituationKey = resumeLink.join(',')}
-          return resumeLink;
-        }
-        return [];
+    handleRemove(file,fileList,type) {
+      if(type == '证件照'){
+        this.resumeList = fileList
+      }else{
+        this.inventionList = fileList
       }
-      // 依次执行上传操作并等待完成
-      uploadPromises.push(uploadAndCollect(t.resumeList, '工作简历'));
-      uploadPromises.push(uploadAndCollect(t.inventionList,'发明著作'));
-      // 等待所有上传操作完成
-      await Promise.all(uploadPromises);
-      // 打印已更新的 this.form
-      console.log(t.form, 'form1');
     },
-    handleRemove(file, fileList) {
-      console.log(file, fileList);
-    },
-    async submit(){
-      this.$refs["ruleForm"].validate(async(valid) =>{
+    async submitAdd(){
+      this.$refs["addRuleForm"].validate(async(valid) =>{
         if(valid) {
-          await this.submitUpload()
-          let data = this.form
-          data.supportDirectionSafety = data.supportDirectionSafety.join(',')
-          data.supportDirectionPrevention = data.supportDirectionPrevention.join(',')
-          data.supportDirectionEmergency = data.supportDirectionEmergency.join(',')
-          data.bigClassify = data.profession[0]
-          data.smallClassify = data.profession[1]
-          delete data.profession
-          const res= await addExpertInfo(data)
-          if(res.code == 200){
-            this.$message({
-              type:'success',
-              message: res.msg
-            })
-            this.$emit('closeDialog')
-            this.$refs.ruleForm.resetFields()
-            this.resumeList = []
-            this.inventionList = []
-          }else{
-            this.$message({
-              type:'warning',
-              message: res.msg
-            })
+          if(this.addForm.operate.length == 2){
+            this.addForm.qualificationType = this.findNameById(this.typeList,this.addForm.operate[0])
+            this.addForm.jobCategory = this.findNameById(this.typeList,this.addForm.operate[1])
+            this.addForm.operateTypeId = this.addForm.operate[1]
           }
+          if(this.addForm.operate.length == 3){
+            this.addForm.qualificationType = this.findNameById(this.typeList,this.addForm.operate[0])
+            this.addForm.jobCategory = this.findNameById(this.typeList,this.addForm.operate[1])
+            this.addForm.operationItems = this.findNameById(this.typeList,this.addForm.operate[2])
+            this.addForm.operateTypeId = this.addForm.operate[2]
+          }
+          const {operate,...obj} = this.addForm
+          this.form.operateTypes.push(obj)
+          this.addVisible = false
         }else{
           this.$message({
             type:'warning',
@@ -383,8 +524,19 @@
         }
       })
     },
-    changeSource(num){
-      this.form.source = num
+    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
     }
   }
 };

--
Gitblit v1.9.2