فهرست منبع

变更清单模式全选功能

ellisran 11 ماه پیش
والد
کامیت
cad17c0704
2فایلهای تغییر یافته به همراه175 افزوده شده و 33 حذف شده
  1. 167 33
      app/public/js/change_information_add_list.js
  2. 8 0
      app/view/change/addlist.ejs

+ 167 - 33
app/public/js/change_information_add_list.js

@@ -145,7 +145,7 @@ $(document).ready(() => {
                 }
             }
             SpreadJsObj.loadSheetData(xmjSpreadSheet, SpreadJsObj.DataType.Data, xmjs);
-            checkSelectAll();
+            checkSelectAll(data);
         },
         selectionChanged: function (e, info) {
             const data = SpreadJsObj.getSelectObject(info.sheet);
@@ -202,6 +202,8 @@ $(document).ready(() => {
             if (info.sheet.zh_setting) {
                 const select = SpreadJsObj.getSelectObject(info.sheet);
                 const col = info.sheet.zh_setting.cols[info.col];
+                const gclInfo = SpreadJsObj.getSelectObject(gclSpreadSheet);
+                const gclIndex = changeListData.indexOf(gclInfo);
                 if (col.field === 'is_change') {
                     if (xmjCol.readOnly.isChangeList(select)) {
                         info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
@@ -211,24 +213,6 @@ $(document).ready(() => {
                         info.sheet.endEdit(true);
                     }
                     const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
-                    let gclIndex = -1;
-                    let gclInfo = null;
-                    if (select.deal_id) {
-                        gclInfo = _.find(changeListData, function (item) {
-                            return item.id && item.id === select.deal_id; });
-                        gclIndex =_.findIndex(changeListData, function (item) {
-                            return item.id && item.id === select.deal_id; });
-                    } else {
-                        gclInfo = _.find(changeListData, function (item) {
-                            return item.leafXmjs && _.find(item.leafXmjs, function (item2) {
-                                return item2.gcl_id === select.gcl_id && (item2.mx_id === undefined || item2.mx_id === select.mx_id) });
-                        });
-                        gclIndex = _.findIndex(changeListData, function (item) {
-                            return item.leafXmjs && _.find(item.leafXmjs, function (item2) {
-                                return item2.gcl_id === select.gcl_id && (item2.mx_id === undefined || item2.mx_id === select.mx_id) });
-                        });
-                    }
-                    console.log(gclIndex);
                     if (!gclInfo) {
                         info.sheet.setValue(info.row, info.col, 0);
                         return;
@@ -262,7 +246,7 @@ $(document).ready(() => {
                                 mx_id: '',
                             }
                             _.assign(data, newData);
-                        } else {
+                        } else if (gclInfo.leafXmjs) {
                             const xmjInfo = _.find(gclInfo.leafXmjs, function (item) {
                                 return item.gcl_id === select.gcl_id && (item.mx_id === undefined || item.mx_id === select.mx_id);
                             });
@@ -295,6 +279,7 @@ $(document).ready(() => {
                             select.is_change = 1;
                             changeListData[gclIndex].is_change = 1;
                             SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
+                            checkSelectAll(gclInfo);
                         }, function () {
                             info.sheet.setValue(info.row, info.col, 0);
                         });
@@ -316,6 +301,7 @@ $(document).ready(() => {
                             }, function (result) {
                                 changeList = result.changeList;
                                 select.is_change = 0;
+                                checkSelectAll(gclInfo);
                                 if (select.deal_id) {
                                     changeListData[gclIndex].is_change = 0;
                                     SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
@@ -519,22 +505,170 @@ $(document).ready(() => {
         gclSpread.refresh();
         xmjSpread.refresh();
     });
-});
-function checkSelectAll() {
-    let check = $('#code-list tr').length > 0 ? true : false;
-    const codeNum = $('#code-list tr').length;
-    let i = 0;
-    $('#code-list tr').each(function () {
-        if ($(this).css('display') !== 'none' && !$(this).find('input').is(':checked')) {
-            check = false;
-            return;
+
+    // 全选及取消
+    $('#code-select-all').click(function () {
+        // 全选checkbox
+        const data = SpreadJsObj.getSelectObject(gclSpreadSheet);
+        if ($(this).is(':checked')){
+            const addDatas = [];
+            if (data && data.id) {
+                if (_.findIndex(changeList, function (item) {
+                    return item.id && item.id === data.id;
+                }) === -1) {
+                    addDatas.push({
+                        lid: data.id,
+                        code: data.code,
+                        name: data.name || '',
+                        unit: data.unit || '',
+                        unit_price: data.unit_price,
+                        oamount: data.quantity ? parseFloat(data.quantity) : 0,
+                        oamount2: data.quantity ? parseFloat(data.quantity) : 0,
+                        bwmx: '',
+                        xmj_code: '',
+                        xmj_jldy: '',
+                        xmj_dwgc: '',
+                        xmj_fbgc: '',
+                        xmj_fxgc: '',
+                        gcl_id: '',
+                        mx_id: '',
+                    });
+                }
+            } else if (data && data.leafXmjs) {
+                for (const leaf of data.leafXmjs) {
+                    if (_.findIndex(changeList, function (item) {
+                        return item.gcl_id === leaf.gcl_id && item.mx_id === (leaf.mx_id || '');
+                    }) === -1) {
+                        addDatas.push({
+                            lid: leaf.gcl_id,
+                            code: data.code,
+                            name: data.name || '',
+                            unit: data.unit || '',
+                            unit_price: data.unit_price,
+                            oamount: leaf.quantity,
+                            oamount2: leaf.quantity,
+                            bwmx: leaf.bwmx || leaf.jldy || '',
+                            xmj_code: leaf.code || '',
+                            xmj_jldy: leaf.jldy || '',
+                            xmj_dwgc: leaf.dwgc || '',
+                            xmj_fbgc: leaf.fbgc || '',
+                            xmj_fxgc: leaf.fxgc || '',
+                            gcl_id: leaf.gcl_id,
+                            mx_id: leaf.mx_id,
+                        });
+                    }
+                }
+            }
+            console.log(addDatas);
+            if (addDatas.length > 0) {
+                // 更新至服务器
+                postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
+                    type: 'add-change-list',
+                    postData: addDatas,
+                }, function (result) {
+                    changeList = result.changeList;
+                    const gclIndex = changeListData.indexOf(data);
+                    data.is_change = 1;
+                    changeListData[gclIndex].is_change = 1;
+                    SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
+                    gclSpreadObj.resetXmjSpread(data);
+                }, function () {
+                    $('#code-select-all').prop('checked', false);
+                });
+            }
+        } else {
+            const cList = xmjSpreadSheet.zh_data;
+            const removeDatas = [];
+            let hadContinue = false;
+            for (const c of cList) {
+                const cInfo = c.deal_id ? _.find(changeList, { lid: c.deal_id }) : _.find(changeList, function (item) {
+                   return item.gcl_id === c.gcl_id && item.mx_id === c.mx_id;
+                });
+                if (_.find(changeUsedData, {cbid: cInfo.id})) {
+                    hadContinue = true;
+                    continue;
+                } else if (checkIsSettle(cInfo)) {
+                    hadContinue = true;
+                    continue;
+                }
+                removeDatas.push(cInfo);
+            }
+            console.log(removeDatas);
+            if (removeDatas.length > 0) {
+                postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
+                    type: 'del-change-list',
+                    ids: _.map(removeDatas, 'id'),
+                    postData: null
+                }, function (result) {
+                    changeList = result.changeList;
+                    if (!hadContinue) {
+                        const gclIndex = changeListData.indexOf(data);
+                        data.is_change = 0;
+                        changeListData[gclIndex].is_change = 0;
+                        SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
+                    }
+                    gclSpreadObj.resetXmjSpread(data);
+                }, function () {
+                    $('#code-select-all').prop('checked', true);
+                });
+            }
+        }
+    });
+    // 选中所有新增部位/清单
+    $('#select-all-revise').click(function() {
+        const qtySpr = '*;*', infoSpr = '!_!', recSpr = '$#$';
+        const gclTr = $('#table-list-select tr');
+        for (const tr of gclTr) {
+            const lid = $(tr).data('lid');
+            let gcl = _.find(gclGatherData, function (item) {
+                return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
+            });
+            if (!gcl) gcl = gclGatherData[$(this).data('gcl')];
+            if (!gcl || !gcl.cid) continue;
+
+            let data_bwmx = [];
+            if ($(tr).attr('data-bwmx') !== '') {
+                data_bwmx = $(tr).attr('data-bwmx').split(recSpr);
+                data_bwmx = data_bwmx.filter(x => {
+                    const rec = x.split(qtySpr);
+                    const info = rec[0].split(infoSpr);
+                    if (info.length < 8) return true;
+
+                    const leaf = gcl.leafXmjs.find(lx => { return lx.mx_id === info[6]});
+                    return !leaf || !leaf.cid || leaf.ccid !== window.location.pathname.split('/')[4];
+                });
+            }
+            let hasNew = false;
+            for (const [index, leaf] of gcl.leafXmjs.entries()) {
+                if (!leaf.cid || leaf.ccid !== window.location.pathname.split('/')[4]) continue;
+                const bwmx = [leaf.code, leaf.jldy || '', leaf.dwgc || '', leaf.fbgc || '', leaf.fxgc || '', leaf.gcl_id, leaf.mx_id, leaf.bwmx || leaf.jldy || ''];
+                const de_qu = bwmx.join(infoSpr) + qtySpr + (leaf.quantity || 0);
+                if (data_bwmx.indexOf(de_qu) < 0) data_bwmx.push(de_qu);
+                hasNew = true;
+            }
+            if (hasNew) $(tr).attr('data-bwmx', data_bwmx.join(recSpr)).addClass('table-success');
         }
-        else if ($(this).css('display') === 'none') {
-            i++;
+
+        // 触发点击当前清单,重载当前全部部位
+        const dataIndex = $('#code-list').attr('data-index');
+        if (dataIndex) {
+            $(`tr[data-index=${dataIndex}]`).trigger('click');
         }
     });
-    if (check && i === codeNum) {
-        check = false;
+});
+function checkSelectAll(data) {
+    let check = false;
+    if (data && data.id && data.is_change) {
+        check = true;
+    } else if(data && data.leafXmjs) {
+        check = data.leafXmjs.length > 0 ? true : false;
+        data.leafXmjs.forEach(function (item) {
+            const is_change = _.findIndex(changeList, { gcl_id: item.gcl_id, mx_id: item.mx_id || '' }) !== -1
+            if (!is_change) {
+                check = false;
+                return;
+            }
+        });
     }
     $('#code-select-all').prop('checked', check);
 }

+ 8 - 0
app/view/change/addlist.ejs

@@ -24,6 +24,14 @@
                             <li class="nav-item">
                                 <a class="nav-link active" href="javascript:void(0)">所属项目节</a>
                             </li>
+                            <li class="nav-item">
+                                <div class="d-inline-block mt-1 ml-3 mr-1">
+                                    <div class="custom-control custom-checkbox">
+                                        <input type="checkbox" class="custom-control-input" id="code-select-all">
+                                        <label class="custom-control-label" for="code-select-all">全选</label>
+                                    </div>
+                                </div>
+                            </li>
                             <li class="nav-item" style="width: 350px;" id="xmj-search">
                             </li>
                         </ul>