'use strict';
/**
*
*
* @author Mai
* @date
* @version
*/
(function($){
$.cs_gclGather = function (setting) {
if (!setting.selector) return;
if (!setting.spreadSetting) {
setting.spreadSetting = {
cols: [
{title: '清单编号', field: 'b_code', width: 80, formatter: '@'},
{title: '名称', field: 'name', width: 150, formatter: '@'},
{title: '单位', field: 'unit', width: 50, formatter: '@'},
{title: '单价', field: 'unit_price', width: 60, formatter: '@'},
{title: '数量', field: 'quantity', width: 60, },
{title: '数量', field: 'total_price', width: 60, },
],
emptyRows: 0,
headRows: 1,
headRowHeight: [32],
defaultRowHeight: 21,
headerFont: '12px 微软雅黑',
font: '12px 微软雅黑',
selectedBackColor: '#fffacd',
readOnly: true,
};
}
if (!setting.gatherFields) setting.gatherFields = ['quantity', 'total_price'];
const resultId = setting.id + '-spread';
const obj = $(setting.selector);
obj.html(
'
\n' +
`
\n` +
' \n' +
'
\n' +
'
' +
'\n' +
'
'
);
autoFlashHeight();
const spread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
const sheet = spread.getActiveSheet();
const result = [];
SpreadJsObj.initSheet(sheet, setting.spreadSetting);
SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, result);
const recursiveGather = function(nodes) {
for (const node of nodes) {
if (node.children && node.children.length > 0) {
recursiveGather(node.children);
} else {
if (!node.b_code) continue;
let gcl = result.find(x => {
return x.b_code === node.b_code && x.name === node.name && x.unit === node.unit && x.unit_price === node.unit_price;
});
if (!gcl) {
gcl = { b_code: node.b_code, name: node.name, unit: node.unit, unit_price: node.unit_price };
result.push(gcl);
}
for (const f of setting.gatherFields) {
gcl[f] = ZhCalc.add(gcl[f], node[f]);
}
}
}
};
const gather = function (node) {
$(`#${setting.id}-info`).html(`${node.code || ''}${node.b_code || ''} ${node.name || ''} - ${moment(new Date()).format('YYYY-MM-DD HH:mm:ss')}`);
recursiveGather([node]);
result.sort((a, b) => {
return checkUtils.compareCode(a.b_code, b.b_code);
});
SpreadJsObj.reLoadSheetData(sheet);
};
$('#gcl-gather-refresh').click(() => {
gather(SpreadJsObj.getSelectObject(setting.relaSheet));
});
return { spread, sheet, gather}
};
})(jQuery);