|
|
@@ -12,12 +12,12 @@
|
|
|
* 清单导入模块,前端导入excel,进行数据提取,用lz-string进行压缩上传处理
|
|
|
* */
|
|
|
|
|
|
-const importBills = (function(){
|
|
|
+const importBills = (function () {
|
|
|
//单元格数据是否存在
|
|
|
- function _isDef(data){
|
|
|
+ function _isDef(data) {
|
|
|
return typeof data !== 'undefined' && data !== null && data !== '';
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//去除转义字符
|
|
|
function _deESC(data) {
|
|
|
return _isDef(data) ? data.toString().replace(/[\r,\n,\s,\t]/g, '') : data;
|
|
|
@@ -39,11 +39,11 @@ const importBills = (function(){
|
|
|
qdsl: 1 //清单示例
|
|
|
};
|
|
|
//获取列字段对应
|
|
|
- function getColMapping(type){
|
|
|
+ function getColMapping(type) {
|
|
|
if (type === 0) { //工程量清单
|
|
|
- return {code: 0, name: 1, unit: 2, quantity: 4};
|
|
|
+ return { code: 0, name: 1, unit: 2, quantity: 4 };
|
|
|
} else { //清单示例表
|
|
|
- return {code: 0, name: 1, unit: 2, quantity: 3};
|
|
|
+ return { code: 0, name: 1, unit: 2, quantity: 3 };
|
|
|
}
|
|
|
}
|
|
|
function isGCLHead(dataRow) {
|
|
|
@@ -76,11 +76,11 @@ const importBills = (function(){
|
|
|
let existsRoot = findLast(rst, x => x.name === name && x.depth === 0);
|
|
|
if (!existsRoot) {
|
|
|
let root = {
|
|
|
- ID: uuid.v1(),
|
|
|
- NextSiblingID: -1,
|
|
|
- ParentID: -1,
|
|
|
- name: name,
|
|
|
- depth: 0,
|
|
|
+ ID: uuid.v1(),
|
|
|
+ NextSiblingID: -1,
|
|
|
+ ParentID: -1,
|
|
|
+ name: name,
|
|
|
+ depth: 0,
|
|
|
parent: null,
|
|
|
unitPriceAnalysis: 1
|
|
|
};
|
|
|
@@ -104,13 +104,13 @@ const importBills = (function(){
|
|
|
code = String(code);
|
|
|
let depth = getDepth(code);
|
|
|
let data = {
|
|
|
- ID: uuid.v1(),
|
|
|
- NextSiblingID: -1,
|
|
|
- ParentID: -1,
|
|
|
- code: code,
|
|
|
- name: name,
|
|
|
- unit: unit,
|
|
|
- quantity: quantity,
|
|
|
+ ID: uuid.v1(),
|
|
|
+ NextSiblingID: -1,
|
|
|
+ ParentID: -1,
|
|
|
+ code: code,
|
|
|
+ name: name,
|
|
|
+ unit: unit,
|
|
|
+ quantity: quantity,
|
|
|
depth: depth,
|
|
|
unitPriceAnalysis: 1,
|
|
|
};
|
|
|
@@ -163,7 +163,7 @@ const importBills = (function(){
|
|
|
|
|
|
//提取清单示例数据
|
|
|
function extractSLDatas(sheetData) {
|
|
|
- let colMapping = {code: 0, name: 1, unit: 2, quantity: 3};
|
|
|
+ let colMapping = { code: 0, name: 1, unit: 2, quantity: 3 };
|
|
|
let dataTable = sheetData.data.dataTable,
|
|
|
rowCount = sheetData.rowCount;
|
|
|
let rst = [];
|
|
|
@@ -174,13 +174,15 @@ const importBills = (function(){
|
|
|
unit = dataTable[row][colMapping.unit] ? dataTable[row][colMapping.unit].value : null,
|
|
|
quantity = dataTable[row][colMapping.quantity] ? dataTable[row][colMapping.quantity].value : null;
|
|
|
if (!code) { //没有编号的数据,名称必须为:清单 第xx章,认为新的表根节点
|
|
|
- if (name && /清单 第\d+章/.test(name)) {
|
|
|
+ const reg = /清单\s+第[^章]+章/;
|
|
|
+ //if (name && /清单 第\d+章/.test(name)) {
|
|
|
+ if (name && reg.test(name)) {
|
|
|
curRoot = {
|
|
|
- code: null,
|
|
|
- name: name,
|
|
|
- ID: uuid.v1(),
|
|
|
- ParentID: -1,
|
|
|
- NextSiblingID: -1,
|
|
|
+ code: null,
|
|
|
+ name: name,
|
|
|
+ ID: uuid.v1(),
|
|
|
+ ParentID: -1,
|
|
|
+ NextSiblingID: -1,
|
|
|
parent: null,
|
|
|
unitPriceAnalysis: 1
|
|
|
};
|
|
|
@@ -224,7 +226,7 @@ const importBills = (function(){
|
|
|
console.log(rst);
|
|
|
return rst;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function extactDatas(sheets) {
|
|
|
let rst = [];
|
|
|
let curSheetType = null;
|
|
|
@@ -264,10 +266,10 @@ const importBills = (function(){
|
|
|
//清单 第100章 总则清单需要加上固定ID
|
|
|
let oneHundredBills = rootDatas.find(data => data.name && /第100章/.test(data.name));
|
|
|
if (oneHundredBills) {
|
|
|
- oneHundredBills.flags = [{flag: fixedFlag.ONE_HUNDRED_BILLS, fieldName: 'fixed'}];
|
|
|
+ oneHundredBills.flags = [{ flag: fixedFlag.ONE_HUNDRED_BILLS, fieldName: 'fixed' }];
|
|
|
}
|
|
|
return rst;
|
|
|
}
|
|
|
|
|
|
- return {extactDatas}
|
|
|
+ return { extactDatas }
|
|
|
})();
|