Browse Source

调差清单导入功能调整

laiguoran 2 năm trước cách đây
mục cha
commit
8d81be05b0

+ 43 - 12
app/public/js/material_checklist.js

@@ -1083,16 +1083,27 @@ $(document).ready(() => {
 
     // 导入功能
     // 上传图片
+    let importFile = null;
     $('#upload-list').click(function () {
         if (materialBillsData.length === 0) {
             toastr.error('请添加工料再导入。');
             return
         }
-        $(this).siblings('input').trigger('click');
+        $("#import").modal('show');
+        // $(this).siblings('input').trigger('click');
     });
     $('#upload-list-file').change(function () {
         const file = this.files[0];
-        const ext = file.name.toLowerCase().split('.').splice(-1)[0];
+        importFile = file;
+    });
+
+    $('#import_btn').click(function() {
+        if (!importFile) {
+            toastr.error('请选择json或excel文件再确定');
+            return;
+        }
+        $('#import').modal('hide');
+        const ext = importFile.name.toLowerCase().split('.').splice(-1)[0];
         const imgStr = /(xls|xlsx|json|XLS|XLSX|JSON)$/;
         if (!imgStr.test(ext)) {
             toastr.error('请导入正确格式的json或excel文件。');
@@ -1103,6 +1114,7 @@ $(document).ready(() => {
             try{
                 const data = ev.target.result;
                 let tree = [];
+                const ignoreUnitPrice = $('#ignore').is(':checked');
                 resetExport();
                 $('#okedit').modal('show');
                 setProgress($('#export-progress'), 30);
@@ -1150,9 +1162,15 @@ $(document).ready(() => {
                 // 分析materialCheckList和tree,找出相同的清单并插入对应不存在的工料
                 for (const t of tree) {
                     if(t.children.length === 0) continue;
-                    const order = _.findIndex(gclGatherData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
-                    const mlOrder = _.findIndex(materialChecklistData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
-                    if (mlOrder === -1 && order !== -1 && _.findIndex(pushChecklist, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null}) === -1) {
+                    const findObject = {
+                        b_code: t.b_code,
+                        name: t.name,
+                        unit: t.unit,
+                    };
+                    if (!ignoreUnitPrice) findObject.unit_price = t.unit_price ? parseFloat(t.unit_price) : null;
+                    const order = _.findIndex(gclGatherData, findObject);
+                    const mlOrder = _.findIndex(materialChecklistData, findObject);
+                    if (mlOrder === -1 && order !== -1 && _.findIndex(pushChecklist, findObject) === -1) {
                         pushChecklist.push({
                             b_code: gclGatherData[order].b_code,
                             name: gclGatherData[order].name,
@@ -1194,7 +1212,9 @@ $(document).ready(() => {
                     }, function () {
                         stop = true;
                         clearInterval(interval);
-                        setTimeout(function () { $('#okedit').modal('hide') }, 1000);
+                        setTimeout(function () {
+                            $('#okedit').modal('hide');
+                        }, 1000);
                     });
                 } else {
                     stopProgress($('#bill-progress'));
@@ -1205,7 +1225,10 @@ $(document).ready(() => {
                 toastr.error(error);
                 stop = true;
                 clearInterval(interval);
-                setTimeout(function () { $('#okedit').modal('hide') }, 1000);
+                setTimeout(function () {
+                    $('#okedit').modal('hide');
+                    $('#import').modal('show');
+                }, 1000);
                 return
             }
 
@@ -1227,8 +1250,9 @@ $(document).ready(() => {
         };
 
         // 以二进制方式打开文件
-        fileReader.readAsBinaryString(file);
+        fileReader.readAsBinaryString(importFile);
         $('#upload-list-file').val('');
+        importFile = null;
     });
 
     function sleep(millisecond) {
@@ -1280,6 +1304,7 @@ $(document).ready(() => {
 
     async function pushListData(tree = []) {
         if (tree.length > 0) {
+            const ignoreUnitPrice = $('#ignore').is(':checked');
             for (const [i,t] of tree.entries()) {
                 $('#list-detail').find('b').text(t.b_code);
                 resetProgress($('#list-progress'));
@@ -1309,8 +1334,12 @@ $(document).ready(() => {
                 if (mbList.length === 0) {
                     continue;
                 }
-
-                const gclIndex = _.findIndex(gclGatherData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
+                const findObject = { b_code: t.b_code,
+                    name: t.name,
+                    unit: t.unit,
+                };
+                if (!ignoreUnitPrice) findObject.unit_price = t.unit_price ? parseFloat(t.unit_price) : null;
+                const gclIndex = _.findIndex(gclGatherData, findObject);
                 const gcl = gclGatherData[gclIndex].leafXmjs;
                 const ms_id = isStageSelf ? materialStageData[0].id : null;
                 // const index = materialChecklistData.indexOf(select);
@@ -1332,7 +1361,9 @@ $(document).ready(() => {
                     const gclData = gclGatherData[gclIndex];
                     for (const [index, ms] of materialStageData.entries()) {
                         if (ms.id !== ms_id) {
-                            const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
+                            const gclFindObject = { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit };
+                            if (!ignoreUnitPrice) gclFindObject.unit_price = gclData.unit_price;
+                            const gclOther = _.find(gclGatherListData[index], gclFindObject);
                             if (gclOther) {
                                 const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
                                 for (const xmj of leafXmjs) {
@@ -1353,7 +1384,7 @@ $(document).ready(() => {
                 }
 
                 // 上传到数据库
-                const select = _.find(materialChecklistData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price ? parseFloat(t.unit_price) : null });
+                const select = _.find(materialChecklistData, findObject);
                 console.log(select, datas, mbList);
                 if (select) {
                     const result = await postDataAsync(window.location.pathname + '/save', {type: 'adds', checklist: { id: select.id, had_bills: 1 }, postData: {xmjs: datas, mbIds: mbList, export: true}});

+ 3 - 3
app/view/material/checklist.ejs

@@ -27,10 +27,10 @@
                 </div>
             </div>
             <div class="ml-auto">
-                <a href="https://jiliang-qa.oss-cn-shenzhen.aliyuncs.com/loginimg/%E6%B8%85%E5%8D%95%E6%9D%90%E6%96%99%E5%8D%95%E4%BD%8D%E6%B6%88%E8%80%97%E9%87%8FExcel%E7%A4%BA%E4%BE%8B.xlsx" class="mx-2"
-                   data-toggle="tooltip" data-placement="top" title="" data-original-title="下载导入示例"><i class="fa fa-cloud-download"></i></a>
+                <!--<a href="https://jiliang-qa.oss-cn-shenzhen.aliyuncs.com/loginimg/%E6%B8%85%E5%8D%95%E6%9D%90%E6%96%99%E5%8D%95%E4%BD%8D%E6%B6%88%E8%80%97%E9%87%8FExcel%E7%A4%BA%E4%BE%8B.xlsx" class="mx-2"-->
+                   <!--data-toggle="tooltip" data-placement="top" title="" data-original-title="下载导入示例"><i class="fa fa-cloud-download"></i></a>-->
                 <button class="btn btn-primary btn-sm" id="upload-list">导入清单工料单位消耗</button>
-                <input type="file" class="form-control-file" id="upload-list-file" style="display: none;" accept=".xls,.xlsx,.json">
+                <!--<input type="file" class="form-control-file" id="upload-list-file" style="display: none;" accept=".xls,.xlsx,.json">-->
             </div>
         </div>
     </div>

+ 51 - 1
app/view/material/checklist_modal.ejs

@@ -81,6 +81,56 @@
         </div>
     </div>
 </div>
+<!--导入清单工料-->
+<div class="modal fade" id="import" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">选择文件</h5>
+            </div>
+            <div class="modal-body">
+                <p>请上传指定格式(.xls或.xlsx或.json) 的文件,<a href="https://jiliang-qa.oss-cn-shenzhen.aliyuncs.com/loginimg/%E6%B8%85%E5%8D%95%E6%9D%90%E6%96%99%E5%8D%95%E4%BD%8D%E6%B6%88%E8%80%97%E9%87%8FExcel%E7%A4%BA%E4%BE%8B.xlsx">下载示例</a>。</p>
+                <div class="form-group">
+                    <label for="exampleFormControlFile1">选择文件</label>
+                    <input type="file" class="form-control-file" id="upload-list-file" accept=".xls,.xlsx,.json">
+                </div>
+                <!--导入后选项-->
+                <!--<div>-->
+                    <!--<hr></hr>-->
+                    <!--<h6>选择导入的工作表</h6>-->
+                    <!--<div class="card p-2 mb-2 border-primary">-->
+                        <!--<div class="form-check">-->
+                            <!--<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1" checked>-->
+                            <!--<label class="form-check-label" for="exampleRadios1">-->
+                                <!--sheet1-->
+                            <!--</label>-->
+                        <!--</div>-->
+                    <!--</div>-->
+                    <!--<div class="card p-2 mb-2">-->
+                        <!--<div class="form-check">-->
+                            <!--<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2" checked>-->
+                            <!--<label class="form-check-label" for="exampleRadios2">-->
+                                <!--sheet2-->
+                            <!--</label>-->
+                        <!--</div>-->
+                    <!--</div>-->
+                <!--</div>-->
+            </div>
+            <div class="modal-footer d-flex justify-content-between">
+                <div class="">
+                    <div class="custom-control custom-checkbox custom-control-inline">
+                        <input type="checkbox" class="custom-control-input" name="customRadioInline1" id="ignore">
+                        <label class="custom-control-label" for="ignore">忽略清单单价</label>
+                    </div>
+                </div>
+                <div>
+                    <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
+                    <button type="button" class="btn btn-sm btn-primary" id="import_btn">确定导入</button>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
 <div class="modal fade" id="okedit" data-backdrop="static">
     <div class="modal-dialog " role="document" >
         <div class="modal-content">
@@ -94,7 +144,7 @@
                         <div id="export-progress" class="progress-bar" role="progressbar" style="width: 100%;" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">100%</div>
                     </div>
                 </div>
-                <div id="bill-detail" style="display: none" class="mt-3">
+                <div id="bill-detail" class="mt-3">
                     <h5>处理清单及工料生成:</h5>
                     <div class="progress">
                         <div id="bill-progress" class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>