浏览代码

feat: 信息价库增加批量修改

vian 2 月之前
父节点
当前提交
d9afc3bd43

+ 11 - 0
modules/price_info_lib/controllers/index.js

@@ -303,6 +303,17 @@ class PriceInfoController extends BaseController {
         }
     }
 
+    async batchUpdate(req, res) {
+        try {
+            const { priceItem, prop, val } = JSON.parse(req.body.data);
+            await facade.batchUpdate(priceItem, prop, val);
+            res.json({ error: 0, message: 'batchUpdate success' });
+        } catch (err) {
+            console.log(err);
+            res.json({ error: 1, message: err.toString() });
+        }
+    }
+
     // 匹配总表
     async matchSummary(req, res) {
         try {

+ 39 - 0
modules/price_info_lib/facade/index.js

@@ -763,6 +763,44 @@ async function exportInfoPriceByCompilation(compilationID) {
 }
 
 
+// 批量修改同省份下所有相同材料(编号、名称、规格、单位)
+async function batchUpdate(priceItem, prop, val) {
+    const areas = await priceInfoAreaModel.find({ compilationID: priceItem.compilationID }, '-_id ID name').lean();
+    const area = areas.find(item => item.ID === priceItem.areaID);
+    if (!area || !area.name) {
+        throw new Error('找不到对应地区');
+    }
+    const province = area.name.split('-')[0];
+    const reg = new RegExp(`^${province}`)
+    const sameProvinceAreas = areas.filter(item => reg.test(item.name));
+    console.log(`sameProvinceAreas`);
+    console.log(sameProvinceAreas);
+    if (!sameProvinceAreas.length) {
+        return;
+    }
+    const areaIDs = sameProvinceAreas.map(item => item.ID);
+    // 根据编号初筛
+    const priceItems = await priceInfoItemModel.find({ libID: priceItem.libID, code: priceItem.code || '' }, '-_id ID areaID code name specs unit').lean();
+    // 批量修改相同材料
+    const bulks = [];
+    const getKey = (item) => {
+        return `${item.code || ''}@${item.name || ''}@${item.specs || ''}@${item.unit || ''}`;
+    }
+    const key = getKey(priceItem);
+    priceItems.forEach(item => {
+        if (areaIDs.includes(item.areaID) && getKey(item) === key) {
+            bulks.push({ updateOne: { filter: { ID: item.ID }, update: { $set: { [prop]: val } } } });
+        }
+    });
+    if (bulks.length) {
+        await priceInfoItemModel.bulkWrite(bulks);
+    }
+
+
+
+}
+
+
 module.exports = {
     getLibs,
     createLib,
@@ -788,4 +826,5 @@ module.exports = {
     exportInfoPriceByLib,
     exportInfoPriceByCompilation,
     getAllLibs,
+    batchUpdate,
 }

+ 1 - 0
modules/price_info_lib/routes/index.js

@@ -31,6 +31,7 @@ module.exports = function (app) {
     router.get("/exportInfoPriceByLib", priceInfoController.auth, priceInfoController.init, priceInfoController.exportInfoPriceByLib);
     router.get("/exportInfoPriceByCompilation", priceInfoController.auth, priceInfoController.init, priceInfoController.exportInfoPriceByCompilation);
     router.post("/getAllLibs", priceInfoController.auth, priceInfoController.init, priceInfoController.getAllLibs);
+    router.post("/batchUpdate", priceInfoController.auth, priceInfoController.init, priceInfoController.batchUpdate);
 
     app.use("/priceInfo", router);
 };

+ 0 - 1
modules/ration_repository/controllers/repository_views_controller.js

@@ -30,7 +30,6 @@ class ViewsController extends BaseController {
         } else {
             compilationList[0].active = 'active'
         }
-        // await rationDao.copyLib(173, 214, 7, 7)
         res.render('maintain/ration_repository/main.html',
             {
                 rationLibs: rationLibs,

+ 1 - 0
package.json

@@ -51,6 +51,7 @@
     "prod_server2": "SET NODE_ENV=prod_s2&& D:/GitHome/ConstructionOperation/node_modules/.bin/babel-node operation.js",
     "prod_sc_server": "SET NODE_ENV=prod_sc&& babel-node operation.js",
     "local2prod_hw_server": "SET NODE_ENV=local2prod_hw&& babel-node operation.js",
+    "local2prod_yh_server": "SET NODE_ENV=prod_s&& babel-node operation.js",
     "qa_hw_server": "SET NODE_ENV=qa_hw&& babel-node operation.js",
     "uat_hw_server": "SET NODE_ENV=uat_hw&& babel-node operation.js",
     "prod_hw_server": "SET NODE_ENV=prod_hw&& babel-node operation.js"

+ 30 - 0
web/maintain/price_info_lib/html/edit.html

@@ -118,6 +118,36 @@
             </div>
         </div>
     </div>
+
+    <div class="modal fade" id="batch-edit" data-backdrop="static" style="display: none;" aria-hidden="true">
+        <div class="modal-dialog" role="document">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h5 class="modal-title">批量修改</h5>
+                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                        <span aria-hidden="true">×</span>
+                    </button>
+                </div>
+                <div class="modal-body">
+                    <div id="edit-item" style="margin-bottom: 1rem;"></div>
+                    <form>
+                        <div class="form-group row" style="margin-left: 0px;">
+                            <label class="col-auto col-form-label" id="edit-label" style="line-height: 26px;">名称</label>
+                            <div class="col">
+                                <input id="edit-text" class="form-control" placeholder="请输入内容" type="text" value="">
+                            </div>
+                        </div>
+                    </form>
+                    <div style="color: red;">*批量修改同一省份下相同材料</div>
+                </div>
+                <div class="modal-footer">
+                    <a id="batch-edit-confirm" href="javascript: void(0);" class="btn btn-primary">确定</a>
+                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                </div>
+            </div>
+        </div>
+    </div>
+    
     <!-- JS. -->
     <script src="/lib/jquery/jquery.min.js"></script>
     <script src="/lib/jquery-contextmenu/jquery.contextMenu.min.js"></script>

+ 2 - 1
web/maintain/price_info_lib/js/priceClass.js

@@ -416,7 +416,7 @@ const CLASS_BOOK = (() => {
   }
 
   // 焦点变更处理
-  const curClass = { ID: null };
+  const curClass = { ID: null, IDList: [] };
   function handleSelectionChanged(row) {
     curRow = row;
     const classNode = tree.items[row] || null;
@@ -429,6 +429,7 @@ const CLASS_BOOK = (() => {
       const children = classNode.getPosterity();
       children.forEach(child => classIDList.push(child.data.ID));
     }
+    curClass.classIDList = [];
     PRICE_BOOK.initData(classIDList);
   }
   const debounceSelectionChanged = _.debounce(function (e, info) {

+ 103 - 2
web/maintain/price_info_lib/js/priceItem.js

@@ -118,11 +118,16 @@ const PRICE_BOOK = (() => {
     const changedCells = [{ row: info.row }];
     handleEdit(changedCells);
   });
-  sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e, info) {
-    const row = info.newSelections && info.newSelections[0] ? info.newSelections[0].row : 0;
+
+  const handleSelectionChange = (row) => {
     // 显示关键字数据
     const keywordList = cache[row] && cache[row].keywordList || [];
     KEYWORD_BOOK.showKeywordData(keywordList);
+  }
+
+  sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e, info) {
+    const row = info.newSelections && info.newSelections[0] ? info.newSelections[0].row : 0;
+    handleSelectionChange(row);
   });
   sheet.bind(GC.Spread.Sheets.Events.RangeChanged, function (e, info) {
     const changedRows = [];
@@ -169,10 +174,97 @@ const PRICE_BOOK = (() => {
     showData(sheet, cache, setting.header);
   }
 
+  const getKey = (item) => {
+    return `${item.code || ''}@${item.name || ''}@${item.specs || ''}@${item.unit || ''}`;
+  }
+
+  // 批量修改
+  const batchEdit = async () => {
+    try {
+      $.bootstrapLoading.start();
+      const row = sheet.getActiveRowIndex();
+      const col = sheet.getActiveColumnIndex();
+      const colHeader = setting.header[col];
+      const priceItem = cache[row];
+      if (!priceItem || !colHeader) {
+        return;
+      }
+      const prop = colHeader.dataCode;
+      const val = $('#edit-text').val();
+      if (['noTaxPrice', 'taxPrice'].includes(prop) && (!val || isNaN(val))) {
+        throw new Error('请输入数值');
+      }
+      await ajaxPost('/priceInfo/batchUpdate', { priceItem, prop, val });
+      const key = getKey(priceItem);
+      cache.forEach(item => {
+        if (key === getKey(item)) {
+          item[prop] = val;
+        }
+      });
+      showData(sheet, cache, setting.header, 5);
+      $('#batch-edit').modal('hide');
+    } catch (error) {
+      alert(error.message);
+    }
+    $.bootstrapLoading.end();
+  }
+
+  // 右键功能
+  function buildContextMenu() {
+    $.contextMenu({
+      selector: '#price-spread',
+      build: function ($triggerElement, e) {
+        // 控制允许右键菜单在哪个位置出现
+        const offset = $('#price-spread').offset();
+        const x = e.pageX - offset.left;
+        const y = e.pageY - offset.top;
+        const target = sheet.hitTest(x, y);
+        if (target.hitTestType === 3) { // 在表格内
+          const sel = sheet.getSelections()[0];
+          if (sel && sel.rowCount === 1 && typeof target.row !== 'undefined') {
+            const orgRow = sheet.getActiveRowIndex();
+            sheet.setActiveCell(target.row, target.col);
+            if (orgRow !== target.row) {
+              handleSelectionChange(target.row);
+            }
+          }
+          return {
+            items: {
+              batchUpdate: {
+                name: '批量修改',
+                icon: "fa-edit",
+                disabled: function () {
+                  return locked || !cache[target.row];
+                },
+                callback: function (key, opt) {
+                  const colHeader = setting.header[target.col];
+                  const item = cache[target.row];
+                  if (item) {
+                    const info = `材料:${item.code || ''} ${item.name || ''} ${item.specs || ''} ${item.unit}`;
+                    $('#edit-item').text(info);
+                    $('#edit-label').text(colHeader.headerName);
+                    $('#edit-text').attr('placeholder', `请输入${colHeader.headerName}`);
+                    $('#edit-text').val(item[colHeader.dataCode] || '');
+                    $('#batch-edit').modal('show');
+                  }
+                }
+              },
+            }
+          };
+        }
+        else {
+          return false;
+        }
+      }
+    });
+  }
+  buildContextMenu();
+
   return {
     clear,
     initData,
     showRepeatData,
+    batchEdit,
   }
 })();
 
@@ -181,4 +273,13 @@ $(document).ready(() => {
   $('#check-repeat').click(() => {
     PRICE_BOOK.showRepeatData();
   });
+
+  // 批量修改
+  $('#batch-edit-confirm').click(() => {
+    PRICE_BOOK.batchEdit();
+  });
+
+  $('#batch-edit').on('shown.bs.modal', function () {
+    $('#edit-text').focus();
+  });
 });