|
@@ -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}});
|