瀏覽代碼

删除指标库功能完善 up

laiguoran 7 年之前
父節點
當前提交
d6f12e8151
共有 5 個文件被更改,包括 31 次插入9 次删除
  1. 14 0
      app/base/base_service.js
  2. 3 2
      app/controller/lib_controller.js
  3. 9 4
      app/public/js/lib_detail.js
  4. 5 2
      app/service/quota_lib.js
  5. 0 1
      app/view/lib/detail.ejs

+ 14 - 0
app/base/base_service.js

@@ -141,5 +141,19 @@ class BaseService extends Service {
             throw '写入错误';
         }
     }
+
+    /**
+     * 在事务中删除数据
+     *
+     * @param {Array|Object} datas
+     * @param transaction - 事务
+     * @returns {Promise<void>}
+     */
+    async deleteData(data, transaction) {
+        const deleteResult = await transaction.delete(this.tableName, data);
+        if (!deleteResult.affectedRows > 0) {
+            throw '删除错误';
+        }
+    }
 }
 module.exports = BaseService;

+ 3 - 2
app/controller/lib_controller.js

@@ -229,8 +229,9 @@ module.exports = app => {
                     throw '删除标段失败';
                 }
 
-                fs.unlinkSync(libInfo.filepath);
-
+                if(fs.existsSync(libInfo.filepath)) {
+                    fs.unlinkSync(libInfo.filepath);
+                }
                 ctx.redirect('/lib');
             } catch (error) {
                 console.log(error);

+ 9 - 4
app/public/js/lib_detail.js

@@ -68,9 +68,11 @@ $(document).ready(function() {
                 let index_html = '';
                 const index_list = result.indexList;
                 for(let i in index_list) {
-                    index_list[i].unit1 = index_list[i].unit1 !== null ? index_list[i].unit1 : '';
-                    index_list[i].unit2 = index_list[i].unit2 !== null ? index_list[i].unit2 : '';
-                    index_html += '<tr> <td>'+ index_list[i].code +'</td> <td>'+ index_list[i].name +'</td> <td>'+ index_list[i].unit1 +'</td> <td>'+ index_list[i].unit2 +'</td> <td></td> <td>'+ index_list[i].rule +'</td> <td></td> <td></td> </tr>';
+                    index_html += '<tr> <td>'+ index_list[i].code +'</td> <td>'+ index_list[i].name +'</td>' +
+                        '<td>'+ (index_list[i].unit1 !== null ? index_list[i].unit1 : '') +'</td>' +
+                        '<td>'+ (index_list[i].unit2 !== null ? index_list[i].unit2 : '') +'</td>' +
+                        '<td>'+ index_list[i].rule +'</td> <td>'+ (index_list[i].eval_rule !== null ? index_list[i].eval_rule : '') +'</td>' +
+                        '<td>'+ (index_list[i].value !== null ? index_list[i].value : '') +'</td> </tr>';
                 }
                 $('#indexList').html(index_html);
 
@@ -79,7 +81,10 @@ $(document).ready(function() {
                 for(let i in param_list) {
                     param_list[i].calc_value = param_list[i].calc_value !== null ? param_list[i].calc_value : '';
                     let subNode = param_list[i].match_type === 3 ? '(自动绑定)' : (param_list[i].match_type === 4 ? param_list[i].match_key : '');
-                    param_html += '<tr> <td>'+ param_list[i].name +'</th><td>'+ subNode +'</td><td><input type="number" class="form-control form-control-sm" value="'+ param_list[i].calc_value +'" data-old-value="'+ param_list[i].calc_value +'" data-lib-id="'+ param_list[i].lib_id +'" data-node-id="'+ param_list[i].node_id +'" data-code="'+ param_list[i].code +'"></td> </tr>';
+                    param_html += '<tr> <td>'+ param_list[i].name +'</td><td>'+ subNode +'</td>' +
+                        '<td><input type="number" class="form-control form-control-sm" value="'+ param_list[i].calc_value +'" ' +
+                        'data-old-value="'+ param_list[i].calc_value +'" data-lib-id="'+ param_list[i].lib_id +'" ' +
+                        'data-node-id="'+ param_list[i].node_id +'" data-code="'+ param_list[i].code +'"></td> </tr>';
                 }
                 $('#paramList').html(param_html);
             });

+ 5 - 2
app/service/quota_lib.js

@@ -96,8 +96,11 @@ module.exports = app => {
         async deleteLibById(id) {
             const conn = await this.db.beginTransaction(); // 初始化事务
             try{
-                const libResult = await conn.deleteById(id);
-                const billsResult = await conn.delete('is_quota_bills',{lib_id: id});
+                const libResult = await this.ctx.service.quotaLib.deleteData({id: id}, conn);
+                const billsResult = await this.ctx.service.bills.deleteData({lib_id: id}, conn);
+                const indexResult = await this.ctx.service.tenderIndex.deleteData({lib_id: id}, conn);
+                const nodeResult = await this.ctx.service.tenderNode.deleteData({lib_id: id}, conn);
+                const paramResult = await this.ctx.service.tenderParam.deleteData({lib_id: id}, conn);
                 await conn.commit(); // 提交事务
                 return true;
             } catch(err) {

+ 0 - 1
app/view/lib/detail.ejs

@@ -33,7 +33,6 @@
                                 <th>指标编号</th>
                                 <th>项目或费用名称</th>
                                 <th colspan="2">指标单位</th>
-                                <th>合价(元)</th>
                                 <th>计算规则</th>
                                 <th>指标计算</th>
                                 <th>经济指标</th>