1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- '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(
- '<div class="sjs-bar">\n' +
- ` <div class="pb-1 d-flex"><button class="btn btn-primary btn-sm" id="gcl-gather-refresh">汇总</button>\n` +
- ' <span class="pl-2" id="' + setting.id + '-info"></span>\n' +
- ' </div>\n' +
- '</div>' +
- '<div id="' + resultId + '" class="sjs-sh">\n' +
- '</div>'
- );
- 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);
|