|
@@ -10,7 +10,8 @@ let gljSheet = null;
|
|
|
let sourceData = [];
|
|
|
let spread = null;
|
|
|
let isChanging = false;
|
|
|
-let gljActiveRowIndex = 0;
|
|
|
+let firstMixRatioRow = -1;
|
|
|
+let firstMachineRow = -1;
|
|
|
$(document).ready(function () {
|
|
|
|
|
|
// 初始化表格
|
|
@@ -21,13 +22,12 @@ $(document).ready(function () {
|
|
|
$("#notify").slideUp('fast');
|
|
|
if (changeInfo.length > 0) {
|
|
|
for (let index in changeInfo) {
|
|
|
- let cell = sheet.getCell(changeInfo[index].row, changeInfo[index].col, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
+ let cell = gljSheet.getCell(changeInfo[index].row, changeInfo[index].col, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
cell.value(changeInfo[index].newValue);
|
|
|
}
|
|
|
}
|
|
|
changeInfo = [];
|
|
|
});
|
|
|
-
|
|
|
});
|
|
|
|
|
|
/**
|
|
@@ -53,6 +53,10 @@ function initGLJExcel() {
|
|
|
{name: '送达地点', field: 'delivery_address', visible: true},
|
|
|
{name: '不调价', field: 'is_adjust_price', visible: true, cellType: new GC.Spread.Sheets.CellTypes.CheckBox(), validator: 'boolean'},
|
|
|
{name: 'UID', field: 'unit_price.id', visible: false},
|
|
|
+ {name: '工料机ID', field: 'glj_id', visible: false},
|
|
|
+ {name: '组成物消耗量', field: 'consumption', visible: false},
|
|
|
+ {name: '父级关联编码', field: 'connect_code', visible: false},
|
|
|
+ {name: '消耗量', field: 'ratio_data', visible: false},
|
|
|
];
|
|
|
// 数据转换格式
|
|
|
sourceData = JSON.parse(jsonData);
|
|
@@ -115,7 +119,7 @@ function initGLJExcel() {
|
|
|
let type = gljSheet.getValue(row, typeColumn);
|
|
|
|
|
|
// 如果类型为混凝土、砂浆、配合比、机械,则提示
|
|
|
- if (field === 'unit_price.market_price' && canNotChangeTypeId.indexOf(type) >= 0) {
|
|
|
+ if (field === 'unit_price.market_price' && canNotChangeTypeId.indexOf(type + '') >= 0) {
|
|
|
alert('当前工料机的市场单价由组成物计算得出,不可直接修改');
|
|
|
}
|
|
|
});
|
|
@@ -129,6 +133,7 @@ function initGLJExcel() {
|
|
|
}
|
|
|
|
|
|
});
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -171,6 +176,8 @@ function specialColumn(sourceData) {
|
|
|
let isEvaluateColumn = getFieldColumn(header, 'is_evaluate');
|
|
|
// 获取市场单价列号
|
|
|
let marketPriceColumn = getFieldColumn(header, 'unit_price.market_price');
|
|
|
+ let connectCodeColumn = getFieldColumn(header, 'connect_code');
|
|
|
+ let consumptionColumn = getFieldColumn(header, 'consumption');
|
|
|
for(let data of sourceData) {
|
|
|
// 只有材料才显示是否暂估
|
|
|
if (materialIdList.indexOf(data.unit_price.type + '') < 0) {
|
|
@@ -180,15 +187,126 @@ function specialColumn(sourceData) {
|
|
|
gljSheet.getRange(rowCounter, isEvaluateColumn, 1, 1).locked(true);
|
|
|
gljSheet.setValue(rowCounter, isEvaluateColumn, '');
|
|
|
}
|
|
|
+
|
|
|
// 如果类型为混凝土、砂浆、配合比、机械,则市场单价不能修改
|
|
|
- if (canNotChangeTypeId.indexOf(data.unit_price.type) >= 0) {
|
|
|
+ if (canNotChangeTypeId.indexOf(data.unit_price.type + '') >= 0) {
|
|
|
+ firstMixRatioRow = firstMixRatioRow === -1 && data.unit_price.type !== GLJTypeConst.GENERAL_MACHINE ?
|
|
|
+ rowCounter : firstMixRatioRow;
|
|
|
+ firstMachineRow = firstMachineRow === -1 && data.unit_price.type === GLJTypeConst.GENERAL_MACHINE ?
|
|
|
+ rowCounter : firstMachineRow;
|
|
|
// 锁定该单元格
|
|
|
gljSheet.getRange(rowCounter, marketPriceColumn, 1, 1).locked(true);
|
|
|
}
|
|
|
+ // 处理数据
|
|
|
+ if (data.ratio_data.length > 0) {
|
|
|
+ let connectCode = [];
|
|
|
+ let consumption = [];
|
|
|
+ for (let tmp of data.ratio_data) {
|
|
|
+ connectCode.push(tmp.connect_code);
|
|
|
+ consumption.push(tmp.consumption);
|
|
|
+ }
|
|
|
+ let connectCodeString = connectCode.join(',');
|
|
|
+ let consumptionString = consumption.join(',');
|
|
|
+ gljSheet.setValue(rowCounter, connectCodeColumn, connectCodeString);
|
|
|
+ gljSheet.setValue(rowCounter, consumptionColumn, consumptionString);
|
|
|
+ }
|
|
|
rowCounter++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 组成物父级价格计算
|
|
|
+ *
|
|
|
+ * @param {Number} row
|
|
|
+ * @return {Object}
|
|
|
+ */
|
|
|
+function compositionParentCalculate(row) {
|
|
|
+ // 获取关联编码
|
|
|
+ let connectCodeColumn = getFieldColumn(header, 'connect_code');
|
|
|
+ let activeConnectCode = gljSheet.getValue(row, connectCodeColumn);
|
|
|
+
|
|
|
+ // 不属于组成物则忽略
|
|
|
+ if (activeConnectCode === '' || activeConnectCode === undefined) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ activeConnectCode = activeConnectCode.split(',');
|
|
|
+
|
|
|
+ // 计算同级组成物的价格
|
|
|
+ // 遍历所有记录
|
|
|
+ let maxRow = gljSheet.getRowCount();
|
|
|
+ let consumptionColumn = getFieldColumn(header, 'consumption');
|
|
|
+ let marketPriceColumn = getFieldColumn(header, 'unit_price.market_price');
|
|
|
+ let parentMarketPrice = {};
|
|
|
+ for (let i = 0; i < maxRow; i++) {
|
|
|
+ let connectCode = gljSheet.getValue(i, connectCodeColumn);
|
|
|
+ if (connectCode === null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ connectCode = connectCode.split(',');
|
|
|
+ // 消耗量
|
|
|
+ let consumption = gljSheet.getValue(i, consumptionColumn);
|
|
|
+ consumption = consumption.split(',');
|
|
|
+
|
|
|
+ // 获取市场价
|
|
|
+ let marketPrice = gljSheet.getValue(i, marketPriceColumn);
|
|
|
+
|
|
|
+ for (let active of activeConnectCode) {
|
|
|
+ let index = connectCode.indexOf(active);
|
|
|
+ if (index < 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ let rowConsumption = consumption[index] === undefined ? 0 : consumption[index];
|
|
|
+ // 计算价格
|
|
|
+ let rowMarketPrice = (marketPrice * rowConsumption).toDecimal(2);
|
|
|
+ parentMarketPrice[active] = parentMarketPrice[active] === undefined ?
|
|
|
+ rowMarketPrice : (parentMarketPrice[active] + rowMarketPrice).toDecimal(2);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return parentMarketPrice;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 组成物父类数据更新
|
|
|
+ *
|
|
|
+ * @param {Object} parentMarketPrice
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+function compositionParentUpdate(parentMarketPrice) {
|
|
|
+ let marketPriceColumn = getFieldColumn(header, 'unit_price.market_price');
|
|
|
+ // 定位到父节点,然后更新
|
|
|
+ for (let code in parentMarketPrice) {
|
|
|
+ let changeRow = searchKeyword(code);
|
|
|
+ gljSheet.setValue(changeRow, marketPriceColumn, parentMarketPrice[code]);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 查找指定数据并返回行号
|
|
|
+ *
|
|
|
+ * @param {String} keyword
|
|
|
+ * @param {Number} rowStart
|
|
|
+ * @param {Number} columnStart
|
|
|
+ * @return {Number}
|
|
|
+ */
|
|
|
+function searchKeyword(keyword, rowStart = 0, columnStart = 0) {
|
|
|
+ let condition = new GC.Spread.Sheets.Search.SearchCondition();
|
|
|
+ condition.searchString = keyword;
|
|
|
+ condition.startSheetIndex = 0;
|
|
|
+ condition.endSheetIndex = 0;
|
|
|
+ condition.searchFlags = GC.Spread.Sheets.Search.SearchFlags.ignoreCase | GC.Spread.Sheets.Search.SearchFlags.blockRange;
|
|
|
+ condition.searchOrder = GC.Spread.Sheets.Search.SearchOrder.nOrder;
|
|
|
+ condition.searchTarget = GC.Spread.Sheets.Search.SearchFoundFlags.cellText;
|
|
|
+ condition.sheetArea = GC.Spread.Sheets.SheetArea.viewport;
|
|
|
+ condition.rowStart = rowStart;
|
|
|
+ condition.columnStart = columnStart;
|
|
|
+
|
|
|
+ let result = spread.search(condition);
|
|
|
+ return result.foundRowIndex;
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
* 基价单价计算
|
|
@@ -222,7 +340,7 @@ function adjustPriceCalculate(type, info) {
|
|
|
// 材料、主材、设备 调整基价=基价单价
|
|
|
case GLJTypeConst.MAIN_MATERIAL:
|
|
|
case GLJTypeConst.EQUIPMENT:
|
|
|
- let basePrice = sheet.getValue(info.row, basePriceColumn);
|
|
|
+ let basePrice = gljSheet.getValue(info.row, basePriceColumn);
|
|
|
gljSheet.setValue(info.row, adjustPriceColumn, basePrice);
|
|
|
break;
|
|
|
|
|
@@ -238,11 +356,11 @@ function adjustPriceCalculate(type, info) {
|
|
|
*/
|
|
|
function marketPriceCalculate(type, info) {
|
|
|
switch (type) {
|
|
|
- // 人工、材料(普通材料)触发 需计算混凝土、砂浆、配合比、机械的市场单价 @todo 后续添加
|
|
|
+ // 人工、材料(普通材料)触发 需计算混凝土、砂浆、配合比、机械的市场单价
|
|
|
case GLJTypeConst.LABOUR:
|
|
|
case GLJTypeConst.GENERAL_MATERIAL:
|
|
|
// 计算
|
|
|
- console.log('触发计算');
|
|
|
+ compositionParentUpdate(info.parentMarketPrice);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -253,15 +371,28 @@ function marketPriceCalculate(type, info) {
|
|
|
* @param {Array} typeList
|
|
|
* @return {void}
|
|
|
*/
|
|
|
-function filterDataByType(type) {
|
|
|
- sourceData = [];
|
|
|
- let testData = JSON.parse(jsonData);
|
|
|
- for(let tmp of testData) {
|
|
|
- if (type.indexOf(tmp.unit_price.type) >= 0) {
|
|
|
- sourceData.push(tmp);
|
|
|
- }
|
|
|
+function filterDataByType(typeList) {
|
|
|
+ let typeColumn = getFieldColumn(header, 'unit_price.type');
|
|
|
+ typeColumn = parseInt(typeColumn);
|
|
|
+ let filter = new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, typeColumn, -1, 1));
|
|
|
+ gljSheet.rowFilter(filter);
|
|
|
+ filter.filterButtonVisible(false);
|
|
|
+
|
|
|
+ for (let type of typeList) {
|
|
|
+ let condition = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.numberCondition, {
|
|
|
+ compareType: GC.Spread.Sheets.ConditionalFormatting.GeneralComparisonOperators.equalsTo,
|
|
|
+ expected: type
|
|
|
+ });
|
|
|
+
|
|
|
+ filter.addFilterItem(typeColumn, condition);
|
|
|
}
|
|
|
- gljSheet.setDataSource(sourceData);
|
|
|
+
|
|
|
+ filter.filter(typeColumn);
|
|
|
+ gljSheet.invalidateLayout();
|
|
|
+ gljSheet.repaint();
|
|
|
+ let filterRow = typeList.indexOf(GLJTypeConst.GENERAL_MACHINE) >= 0 ? firstMachineRow : firstMixRatioRow;
|
|
|
+ // 筛选后选中第一个符合类型的单元格
|
|
|
+ gljSheet.setSelection(filterRow, 0, 1, 1);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -306,10 +437,22 @@ function updateBindEvent(element, info) {
|
|
|
}
|
|
|
let id = gljSheet.getValue(row, idColumn);
|
|
|
|
|
|
+ // 直接在前端计算后传值后台改
|
|
|
+ let extend = {};
|
|
|
+ let parentMarketPrice = compositionParentCalculate(row);
|
|
|
+ if (Object.keys(parentMarketPrice).length > 0) {
|
|
|
+ for (let activeCode in parentMarketPrice) {
|
|
|
+ let tmpObject = {
|
|
|
+ market_price: parentMarketPrice[activeCode],
|
|
|
+ };
|
|
|
+ extend[activeCode] = tmpObject;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ extend = Object.keys(extend).length > 0 ? JSON.stringify(extend) : '';
|
|
|
$.ajax({
|
|
|
url: '/glj/update',
|
|
|
type: 'post',
|
|
|
- data: {id: id, field: field, value: value},
|
|
|
+ data: {id: id, field: field, value: value, extend: extend},
|
|
|
dataType: 'json',
|
|
|
error: function() {
|
|
|
alert('数据传输有误!');
|
|
@@ -326,6 +469,9 @@ function updateBindEvent(element, info) {
|
|
|
alert('更改数据失败!');
|
|
|
} else {
|
|
|
// 成功则触发相应事件
|
|
|
+ if (parentMarketPrice !== null) {
|
|
|
+ info.parentMarketPrice = parentMarketPrice;
|
|
|
+ }
|
|
|
successTrigger(field, info);
|
|
|
}
|
|
|
}
|
|
@@ -340,6 +486,7 @@ function updateBindEvent(element, info) {
|
|
|
*/
|
|
|
function getActiveProjectGLJId() {
|
|
|
let activeGLJRow = gljSheet.getActiveRowIndex();
|
|
|
+
|
|
|
// 获取当前行的工料机id
|
|
|
let gljIdColumn = getFieldColumn(header, 'id');
|
|
|
let gljId = gljSheet.getValue(activeGLJRow, gljIdColumn);
|
|
@@ -357,7 +504,7 @@ function setGLJQuantity(row, change) {
|
|
|
let quantityColumn = getFieldColumn(header, 'quantity');
|
|
|
let oldValue = gljSheet.getValue(row, quantityColumn);
|
|
|
|
|
|
- change = Number((oldValue + change).toFixed(2));
|
|
|
+ change = (oldValue + change).toDecimal(2);
|
|
|
gljSheet.setValue(row, quantityColumn, change);
|
|
|
}
|
|
|
|
|
@@ -374,7 +521,7 @@ function setGLJCellByField(row, field, value, appendMode) {
|
|
|
let columnIndex = getFieldColumn(header, field);
|
|
|
if (appendMode) {
|
|
|
let oldValue = gljSheet.getValue(row, columnIndex);
|
|
|
- value = Number((oldValue + value).toFixed(2));
|
|
|
+ value = (oldValue + value).toDecimal(2);
|
|
|
}
|
|
|
gljSheet.setValue(row, columnIndex, value);
|
|
|
}
|