ソースを参照

关联标段功能补齐

ellisran 3 ヶ月 前
コミット
c0607d00e3

+ 1 - 1
app/controller/sub_proj_setting_controller.js

@@ -545,7 +545,7 @@ module.exports = app => {
                         if (data.tidList.split(',').length === 0) {
                             throw '参数有误';
                         }
-                        responseData.data = await ctx.service.tender.bindSp(data.spid, data.tidList.split(','));
+                        responseData.data = await ctx.service.tender.bindSp(projectId, data.spid, data.tidList.split(','));
                         break;
                     default:
                         throw '参数有误';

+ 0 - 1
app/public/js/setting_manage.js

@@ -608,7 +608,6 @@ $(document).ready(() => {
             }
         }
         data.tidList = tenderList.join(',');
-        console.log(data);
         // 请求获取右侧列表信息
         const _self = $(this);
         postData(`/sp/${spid}/setting/manage/tender/save`, data, function (result) {

+ 22 - 0
app/service/category.js

@@ -156,6 +156,28 @@ module.exports = app => {
         }
 
         /**
+         * 获取项目下全部分类数据
+         *
+         * @param {Number} subProject - 子项目
+         * @returns {Promise<*>}
+         */
+        async getOrgAllCategory(pid) {
+            const data = await this.getAllDataByCondition({ where: { pid, spid: '' } });
+            const values = await this.ctx.service.categoryValue.getAllDataByCondition({
+                where: { pid, spid: '' },
+                orders: [['sort', 'asc'], ['id', 'asc']],
+            });
+            // values 按名称排序
+            // values.sort((a, b) => a.value.localeCompare(b.value, 'zh-Hans-CN', { sensitivity: 'accent' }));
+            for (const d of data) {
+                d.value = values.filter(function (v) {
+                    return v.cid === d.id;
+                });
+            }
+            return data;
+        }
+
+        /**
          * 重置分类已用排序
          *
          * @param {Array} data - 分类已用排序数据(TODO未做验证)

+ 53 - 2
app/service/tender.js

@@ -662,8 +662,59 @@ module.exports = app => {
             return list;
         }
 
-        async bindSp(spid, tids) {
-            return await this.db.update(this.tableName, { spid }, { where: { id: tids } });
+        async bindSp(pid, spid, tids) {
+            const subProject = await this.ctx.service.subProject.getDataById(spid);
+            const orgRelaTenderId = subProject.rela_tender !== '' ? subProject.rela_tender.split(',') : [];
+            orgRelaTenderId.push(...tids);
+            // 更新category
+            const orgCategoryData = await this.ctx.service.category.getOrgAllCategory(pid);
+            const newCategoryData = await this.ctx.service.category.getAllCategory(subProject);
+            const updateTenders = [];
+            for (const tid of tids) {
+                const tender = await this.getDataById(tid);
+                const oneUpdate = {
+                    id: tid,
+                    spid,
+                };
+                if (tender.category) {
+                    const newCategory = [];
+                    const orgCategory = JSON.parse(tender.category);
+                    for (const c of orgCategory) {
+                        const orgC = orgCategoryData.find(item => item.id === c.cid);
+                        if (orgC) {
+                            const newC = newCategoryData.find(item => item.name === orgC.name);
+                            if (newC) {
+                                const orgV = orgC.value.find(item => item.id === c.value);
+                                if (orgV) {
+                                    const newV = newC.value.find(item => item.value === orgV.value);
+                                    if (newV) {
+                                        newCategory.push({
+                                            cid: newC.id,
+                                            value: newV.id,
+                                        });
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    if (newCategory.length > 0) {
+                        oneUpdate.category = JSON.stringify(newCategory);
+                    }
+                }
+                updateTenders.push(oneUpdate);
+            }
+            const conn = await this.db.beginTransaction();
+            try {
+                await conn.updateRows(this.tableName, updateTenders);
+                await conn.update(this.ctx.service.subProject.tableName, { id: subProject.id, rela_tender: this._.uniq(orgRelaTenderId).join(',') });
+                await conn.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender: this._.uniq(orgRelaTenderId).join(',') });
+                await conn.commit();
+                return true;
+            } catch (error) {
+                await conn.rollback();
+                throw error;
+            }
+            // return await this.ctx.subProject.setRelaTender({ id: spid, rela_tender: newTids });
         }
     }
 

+ 1 - 1
app/view/sp_setting/manage.ejs

@@ -4,7 +4,7 @@
         <div class="title-main d-flex justify-content-between">
             <div>
                 <div class="d-inline-block mr-2" style="font-weight: 500">
-                    标段管理
+                    标段设置
                 </div>
                 <div class="d-inline-block" id="show-level"></div>
                 <div class="d-inline-block"><button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#select-tender">关联标段</button></div>

+ 2 - 2
config/menu.js

@@ -428,10 +428,10 @@ const projectSettingMenu = {
         caption: '决策大屏',
     },
     manage: {
-        name: '标段管理',
+        name: '标段设置',
         display: true,
         url: '/setting/manage',
-        caption: '标段管理',
+        caption: '标段设置',
     },
 };