Ver código fonte

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

MaiXinRong 1 ano atrás
pai
commit
e4d46927f4

+ 10 - 15
app/const/profile.js

@@ -7,6 +7,11 @@
  * @date 2024/03/26
  * @version
  */
+const cert_type = [
+    { name: '执业注册', value: 1, source: 'cert_reg', sort: 1 },
+    { name: '执业资格', value: 2, source: 'cert_qual', sort: 2 },
+];
+// 执业注册和执业资格的value值需要不同,这样取名称时可以合起来获取
 // 执业注册
 const cert_reg = [
     { name: '一级注册建筑师', value: 1, sort: 1 },
@@ -25,22 +30,12 @@ const cert_reg = [
 ];
 // 执业资格
 const cert_qual = [
-    { name: '监理工程师', value: 1, sort: 1 },
-    { name: '造价工程师', value: 2, sort: 2 },
-    { name: '建造师', value: 3, sort: 3 },
+    { name: '监理工程师', value: 14, sort: 1 },
+    { name: '造价工程师', value: 15, sort: 2 },
+    { name: '建造师', value: 16, sort: 3 },
 ];
 
-const post_cert_const = ['reg', 'qual', 'code', 'reg_unit', 'job_title', 'file_name', 'file_path', 'edu_json'];
-const cert_const = {
-    reg: 'registration',
-    qual: 'qualification',
-    code: 'code',
-    reg_unit: 'reg_unit',
-    job_title: 'job_title',
-    file_name: 'file_name',
-    file_path: 'file_path',
-    edu_json: 'edu_json',
-};
+const post_cert_const = ['type', 'name', 'code', 'reg_unit', 'job_title', 'file_name', 'file_path', 'edu_json'];
 const edu_json = {
     id: null,
     date: null,
@@ -50,10 +45,10 @@ const edu_json = {
 };
 
 const cert = {
+    certType: cert_type,
     certReg: cert_reg,
     certQual: cert_qual,
     postCertConst: post_cert_const,
-    certConst: cert_const,
     eduJsonConst: edu_json,
 };
 

+ 5 - 2
app/controller/profile_controller.js

@@ -105,8 +105,11 @@ module.exports = app => {
                 accountData,
                 certList,
                 fujianOssPath: ctx.app.config.fujianOssPath,
-                certRegConst: profileConst.cert.certReg,
-                certQualConst: profileConst.cert.certQual,
+                certTypeConst: profileConst.cert.certType,
+                certSourceConst: {
+                    cert_reg: ctx.helper._.orderBy(profileConst.cert.certReg, ['sort'], ['asc']),
+                    cert_qual: ctx.helper._.orderBy(profileConst.cert.certQual, ['sort'], ['asc']),
+                },
                 jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.profile.cert),
             };
             await this.layout('profile/cert.ejs', renderData, 'profile/cert_modal.ejs');

+ 3 - 2
app/controller/tender_controller.js

@@ -1085,12 +1085,13 @@ module.exports = app => {
 
         async certSet(ctx) {
             try {
-                const allCertList = await ctx.service.accountCert.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id }, orders: [['create_time', 'desc']] });
+                const allCertList = await ctx.service.accountCert.getAllCertByPid(ctx.session.sessionProject.id);
                 const tenderCertList = await ctx.service.tenderCert.getListByTid(ctx.tender.id, allCertList);
                 const renderData = {
                     allCertList,
                     tenderCertList,
-                    certRegConst: profileConst.cert.certReg,
+                    certTypeConst: profileConst.cert.certType,
+                    certSourceConst: [...profileConst.cert.certReg, ...profileConst.cert.certQual],
                     fujianOssPath: ctx.app.config.fujianOssPath,
                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.tender.cert),
                 };

+ 1 - 0
app/extend/helper.js

@@ -1730,6 +1730,7 @@ module.exports = {
         return endDateTime;
     },
     showCol4ObjArray(objArray, colName, key = 'value', showKey = 'name') {
+        if (!colName) return '';
         const info = _.find(objArray, { [key]: colName });
         return info ? info[showKey] : '';
     },

+ 38 - 11
app/public/js/profile_cert.js

@@ -65,11 +65,37 @@ $(document).ready(function() {
             key,
             value,
         };
+        if (key === 'type') {
+            let html = '';
+            if (value === 0) {
+                update_data.other = {
+                    key: 'name',
+                    value: null,
+                };
+                html = '<option value="0">请选择</option>';
+            } else {
+                update_data.other = {
+                    key: 'name',
+                    value: certSourceConst[showCol4ObjArray(certTypeConst, value, 'value', 'source')][0].value,
+                };
+                html = changeSourceHtml(certSourceConst[showCol4ObjArray(certTypeConst, value, 'value', 'source')]);
+            }
+            $(this).parents('.one-cert-msg').find('.select-cert-name').html(html);
+        }
+        console.log(update_data);
         postData('/profile/cert/save', { type: 'update_cert', update_data }, function(result) {
             console.log(result);
         });
     });
 
+    function changeSourceHtml(source = []) {
+        let html = '';
+        for (const s of source) {
+            html += `<option value="${s.value}">${s.name}</option>`;
+        }
+        return html;
+    }
+
     $('body').on('change', '#certs .one-cert-msg input[type="text"]', function() {
         const value = $(this).val();
         const key = $(this).data('type');
@@ -301,13 +327,9 @@ $(document).ready(function() {
     }
 
     function insertCertHtml(i, data) {
-        let regHtml = ``;
-        for (const r of certRegConst) {
-            regHtml += `<option value="${r.value}">${r.name}</option>`;
-        }
-        let qualHtml = ``;
-        for (const q of certQualConst) {
-            qualHtml += `<option value="${q.value}">${q.name}</option>`;
+        let typeHtml = ``;
+        for (const r of certTypeConst) {
+            typeHtml += `<option value="${r.value}">${r.name}</option>`;
         }
         const html = `<div class="col-6 mt-3 one-cert" data-cid="${data.id}">
                                         <div class="card">
@@ -324,15 +346,14 @@ $(document).ready(function() {
                                                         <label for="uname" class="ml-3 col-form-label">证件名称:</label>
                                                         <div class="row col-sm-10 pr-0">
                                                             <div class="col-6 pr-0">
-                                                                <select class="form-control form-control-sm select—cert-reg" data-type="reg">
+                                                                <select class="form-control form-control-sm select—cert-type" data-type="type">
                                                                     <option value="0">请选择</option>
-                                                                    ${regHtml}
+                                                                    ${typeHtml}
                                                                 </select>
                                                             </div>
                                                             <div class="col-6 pr-0">
-                                                                <select class="form-control form-control-sm select—cert-qual" data-type="qual">
+                                                                <select class="form-control form-control-sm select—cert-name" data-type="name">
                                                                     <option value="0">请选择</option>
-                                                                    ${qualHtml}
                                                                 </select>
                                                             </div>
                                                         </div>
@@ -375,4 +396,10 @@ $(document).ready(function() {
                 </div>`;
         return html;
     }
+
+    function showCol4ObjArray(arr, col, key, showKey) {
+        if (!col) return '';
+        const obj = _.find(arr, { [key]: col });
+        return obj ? obj[showKey] : '';
+    }
 });

+ 6 - 7
app/public/js/tender_cert.js

@@ -23,7 +23,7 @@ $(function () {
         for (const tc of tenderCertList) {
             let certHtml = '';
             for (const c of tc.account_info.certs) {
-                certHtml += `<option value="${c.id}" ${c.id === tc.cert_id ? 'selected': ''}>${showCol4ObjArray(certRegConst, c.registration, 'value', 'name')}</option>`;
+                certHtml += `<option value="${c.id}" ${c.id === tc.cert_id ? 'selected': ''}>${showCol4ObjArray(certSourceConst, c.name, 'value', 'name')}</option>`;
             }
             html += `<tr class="text-center" data-insert="0" data-id="${tc.id}" data-certid="${tc.cert_id}" data-remove="0">
                         <td>${tc.account_info.name}</td>
@@ -103,13 +103,11 @@ $(function () {
     $('dl').on('click', 'dd', function () {
         const auditorId = parseInt($(this).data('id'))
         if (auditorId) {
-            console.log(auditorId);
             const userInfo = _.find(accountList, { id: auditorId });
             const certList = _.filter(allCertList, { uid: parseInt(auditorId) });
-            console.log(certList);
             let certHtml = '';
             for (const c of certList) {
-                certHtml += `<option value="${c.id}">${showCol4ObjArray(certRegConst, c.registration, 'value', 'name')}</option>`;
+                certHtml += `<option value="${c.id}">${showCol4ObjArray(certSourceConst, c.name, 'value', 'name')}</option>`;
             }
             const html = `<tr class="text-center" data-insert="1" data-remove="0" data-uid="${userInfo.id}" data-certid="${certList.length > 0 ? certList[0].id : 0}">
                         <td>${userInfo.name}</td>
@@ -190,7 +188,7 @@ $(function () {
         {title: '所在部门', colSpan: '1', rowSpan: '2', field: 'department', hAlign: 0, width: 100, formatter: '@'},
         {title: '职务', colSpan: '1', rowSpan: '2', field: 'role', hAlign: 0, width: 80, formatter: '@', readOnly: true, getValue: 'getValue.role'},
         {title: '在岗时间', colSpan: '1', rowSpan: '2', field: 'job_time', hAlign: 0, width: 150, formatter: '@'},
-        {title: '持证情况|证件名称', colSpan: '4|1', rowSpan: '1|1', field: 'cert_reg', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.cert_reg'},
+        {title: '持证情况|证件名称', colSpan: '4|1', rowSpan: '1|1', field: 'cert_name', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.cert_name'},
         {title: '|证书编号', colSpan: '|1', rowSpan: '|1', field: 'cert_code', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.cert_code'},
         {title: '|注册单位', colSpan: '|1', rowSpan: '|1', field: 'reg_unit', hAlign: 0, width: 150, readOnly: true, getValue: 'getValue.reg_unit'},
         {title: '|证书附件', colSpan: '|1', rowSpan: '|1', field: 'file_path', hAlign: 1, width: 55, readOnly: true, cellType: 'imageBtn',
@@ -223,8 +221,8 @@ $(function () {
             role: function (data) {
                 return data.account_info ? data.account_info.role : '';
             },
-            cert_reg: function (data) {
-                return data.cert_info ? showCol4ObjArray(certRegConst, data.cert_info.registration, 'value', 'name') : '';
+            cert_name: function (data) {
+                return data.cert_info ? showCol4ObjArray(certSourceConst, data.cert_info.name, 'value', 'name') : '';
             },
             cert_code: function (data) {
                 return data.cert_info ? data.cert_info.code : '';
@@ -369,6 +367,7 @@ $(function () {
     certSpread.bind(spreadNS.Events.EditEnded, certSpreadObj.editEnded);
 
     function showCol4ObjArray(arr, col, key, showKey) {
+        if (!col) return '';
         const obj = _.find(arr, { [key]: col });
         return obj ? obj[showKey] : '';
     }

+ 12 - 1
app/service/account_cert.js

@@ -23,6 +23,14 @@ module.exports = app => {
             this.tableName = 'account_cert';
         }
 
+        async getAllCertByPid(pid, WithoutNullName = 0) {
+            const list = await this.getAllDataByCondition({ where: { pid }, orders: [['create_time', 'desc']] });
+            if (WithoutNullName) {
+                return this._.filter(list, l => l.name !== null && l.name !== '');
+            }
+            return list;
+        }
+
         async addCert(uid) {
             const result = await this.db.insert(this.tableName, {
                 pid: this.ctx.session.sessionProject.id,
@@ -38,7 +46,10 @@ module.exports = app => {
             };
             // 判断key是否在常量里,并转换为对应的值
             if (!this._.includes(profileConst.cert.postCertConst, data.key)) throw '参数有误';
-            updateData[profileConst.cert.certConst[data.key]] = data.value ? data.value : null;
+            updateData[data.key] = data.value ? data.value : null;
+            if (data.other && this._.includes(profileConst.cert.postCertConst, data.other.key)) {
+                updateData[data.other.key] = data.other.value ? data.other.value : null;
+            }
             return await this.db.update(this.tableName, updateData);
         }
 

+ 2 - 2
app/service/tender_cert.js

@@ -67,7 +67,7 @@ module.exports = app => {
                     await transaction.updateRows(this.tableName, list.updateList);
                 }
                 await transaction.commit();
-                const allCertList = await this.ctx.service.accountCert.getAllDataByCondition({ where: { pid: this.ctx.session.sessionProject.id }, orders: [['create_time', 'desc']] });
+                const allCertList = await this.ctx.service.accountCert.getAllCertByPid(this.ctx.session.sessionProject.id);
                 return await this.getListByTid(tid, allCertList);
             } catch (err) {
                 await transaction.rollback();
@@ -99,7 +99,7 @@ module.exports = app => {
                 }
                 if (updateData.length > 0) await transaction.updateRows(this.tableName, updateData);
                 await transaction.commit();
-                const allCertList = await this.ctx.service.accountCert.getAllDataByCondition({ where: { pid: this.ctx.session.sessionProject.id }, orders: [['create_time', 'desc']] });
+                const allCertList = await this.ctx.service.accountCert.getAllCertByPid(this.ctx.session.sessionProject.id);
                 return await this.getListByTid(tid, allCertList);
             } catch (err) {
                 await transaction.rollback();

+ 12 - 9
app/view/profile/cert.ejs

@@ -38,18 +38,21 @@
                                                         <label for="uname" class="ml-3 col-form-label">证件名称:</label>
                                                         <div class="row col-sm-10 pr-0">
                                                             <div class="col-6 pr-0">
-                                                                <select class="form-control form-control-sm select—cert-reg" data-type="reg">
+                                                                <select class="form-control form-control-sm select-cert-type" data-type="type">
                                                                     <option value="0">请选择</option>
-                                                                    <% for (const r of certRegConst) { %>
-                                                                    <option value="<%- r.value %>" <% if (c.registration === r.value) { %>selected<% } %>><%- r.name %></option>
+                                                                    <% for (const t of certTypeConst) { %>
+                                                                    <option value="<%- t.value %>" <% if (c.type === t.value) { %>selected<% } %>><%- t.name %></option>
                                                                     <% } %>
                                                                 </select>
                                                             </div>
                                                             <div class="col-6 pr-0">
-                                                                <select class="form-control form-control-sm select—cert-qual" data-type="qual">
-                                                                    <option value="0">请选择</option>
-                                                                    <% for (const q of certQualConst) { %>
-                                                                        <option value="<%- q.value %>" <% if (c.qualification === q.value) { %>selected<% } %>><%- q.name %></option>
+                                                                <select class="form-control form-control-sm select-cert-name" data-type="name">
+                                                                    <% if (c.type) { %>
+                                                                        <% for (const q of certSourceConst[ctx.helper.showCol4ObjArray(certTypeConst, c.type, 'value', 'source')]) { %>
+                                                                            <option value="<%- q.value %>" <% if (c.name === q.value) { %>selected<% } %>><%- q.name %></option>
+                                                                        <% } %>
+                                                                    <% } else { %>
+                                                                        <option value="0">请选择</option>
                                                                     <% } %>
                                                                 </select>
                                                             </div>
@@ -147,7 +150,7 @@
     </div>
 </div>
 <script>
-    const certRegConst = JSON.parse(unescape('<%- escape(JSON.stringify(certRegConst)) %>'));
-    const certQualConst = JSON.parse(unescape('<%- escape(JSON.stringify(certQualConst)) %>'));
+    const certTypeConst = JSON.parse(unescape('<%- escape(JSON.stringify(certTypeConst)) %>'));
+    const certSourceConst = JSON.parse(unescape('<%- escape(JSON.stringify(certSourceConst)) %>'));
     const fujianOssPath = JSON.parse(unescape('<%- escape(JSON.stringify(fujianOssPath)) %>'));
 </script>

+ 2 - 1
app/view/tender/cert.ejs

@@ -32,5 +32,6 @@
     const fujianOssPath = JSON.parse(unescape('<%- escape(JSON.stringify(fujianOssPath)) %>'));
     let tenderCertList = JSON.parse(unescape('<%- escape(JSON.stringify(tenderCertList)) %>'));
     const allCertList = JSON.parse(unescape('<%- escape(JSON.stringify(allCertList)) %>'));
-    const certRegConst = JSON.parse(unescape('<%- escape(JSON.stringify(certRegConst)) %>'));
+    const certTypeConst = JSON.parse(unescape('<%- escape(JSON.stringify(certTypeConst)) %>'));
+    const certSourceConst = JSON.parse(unescape('<%- escape(JSON.stringify(certSourceConst)) %>'));
 </script>

+ 1 - 1
app/view/tender/cert_modal.ejs

@@ -47,7 +47,7 @@
                         <td>
                             <select class="form-control form-control-sm">
                                 <% for (const c of tc.account_info.certs) { %>
-                                <option value="<%- c.id %>" <% if (tc.cert_id === c.id) { %>selected<% } %>><%- ctx.helper.showCol4ObjArray(certRegConst, c.registration, 'value', 'name') %></option>
+                                <option value="<%- c.id %>" <% if (tc.cert_id === c.id) { %>selected<% } %>><%- ctx.helper.showCol4ObjArray(certSourceConst, c.name, 'value', 'name') %></option>
                                 <% } %>
                             </select>
                         </td>

+ 2 - 2
sql/update.sql

@@ -52,8 +52,8 @@ CREATE TABLE `zh_account_cert`  (
   `id` int NOT NULL AUTO_INCREMENT,
   `pid` int NULL COMMENT '项目id',
   `uid` int NULL COMMENT '用户id',
-  `registration` tinyint(5) NULL DEFAULT NULL COMMENT '执业注册',
-  `qualification` tinyint(5) NULL DEFAULT NULL COMMENT '执业资格',
+  `type` tinyint(5) NULL DEFAULT NULL COMMENT '证书名称分类',
+  `name` tinyint(5) NULL DEFAULT NULL COMMENT '证书名称',
   `code` varchar(255) NULL DEFAULT NULL COMMENT '证件编号',
   `reg_unit` varchar(255) NULL DEFAULT NULL COMMENT '注册单位',
   `job_title` varchar(255) NULL DEFAULT NULL COMMENT '技术职称',