|
|
@@ -0,0 +1,85 @@
|
|
|
+const rptContract = (function(){
|
|
|
+
|
|
|
+ let contractSpread, contractSheet, contractTree;
|
|
|
+ const initSpread = function() {
|
|
|
+ if (!contractSpread) {
|
|
|
+ contractSpread = SpreadJsObj.createNewSpread($('#rpt-contract-spread')[0]);
|
|
|
+ contractSheet = contractSpread.getActiveSheet();
|
|
|
+ SpreadJsObj.initSheet(contractSheet, {
|
|
|
+ cols: [
|
|
|
+ {title: '选择', colSpan: '1', rowSpan: '1', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox'},
|
|
|
+ {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 120, formatter: '@', cellType: 'tree'},
|
|
|
+ {title: '合同编号', colSpan: '1', rowSpan: '1', field: 'c_code', hAlign: 0, width: 120, formatter: '@'},
|
|
|
+ {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 200, formatter: '@'},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ readOnly: true,
|
|
|
+ });
|
|
|
+ contractSpread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
|
|
|
+ if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
|
|
|
+
|
|
|
+ const col = info.sheet.zh_setting.cols[info.col];
|
|
|
+ if (col.field !== 'selected') return;
|
|
|
+
|
|
|
+ const node = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
+ node.selected = !node.selected;
|
|
|
+ if (node.children && node.children.length > 0) {
|
|
|
+ const posterity = info.sheet.zh_tree.getPosterity(node);
|
|
|
+ for (const p of posterity) {
|
|
|
+ p.selected = node.selected;
|
|
|
+ }
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
|
|
|
+ } else {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
|
|
|
+ }
|
|
|
+ if (node.selected) {
|
|
|
+ const rows = [];
|
|
|
+ const parents = info.sheet.zh_tree.getAllParents(node);
|
|
|
+ for (const p of parents) {
|
|
|
+ p.selected = true;
|
|
|
+ rows.push(info.sheet.zh_tree.getNodeIndex(p));
|
|
|
+ }
|
|
|
+ SpreadJsObj.reLoadRowsData(info.sheet, rows);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#select-contract').on('shown.bs.modal', function() {
|
|
|
+ contractSpread.refresh();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const loadContractTree = function(type, contractType, tid) {
|
|
|
+ postData(`/sp/${spid}/load`, { filter: 'contract', type, contractType, tid }, function(result) {
|
|
|
+ contractTree = createNewPathTree('base', { id: 'contract_id', pid: 'contract_pid', order: 'order', level: 'level', fullPath: 'full_path', rootId: -1 });
|
|
|
+ contractTree.loadDatas(result.contract);
|
|
|
+ SpreadJsObj.loadSheetData(contractSheet, SpreadJsObj.DataType.Tree, contractTree);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ const update = function() {
|
|
|
+ const updateData = {
|
|
|
+ contractTree: contractTree.nodes.filter(x => {
|
|
|
+ return x.c_code === undefined;
|
|
|
+ }).map(x => {
|
|
|
+ return {id: x.id, selected: x.selected};
|
|
|
+ }),
|
|
|
+ contract: contractTree.nodes.filter(x => {
|
|
|
+ return x.c_code !== undefined;
|
|
|
+ }).map(x => {
|
|
|
+ return {id: x.id, selected: x.selected};
|
|
|
+ })
|
|
|
+ };
|
|
|
+ postData(`/sp/${spid}/save`, { updateType: 'contract', updateData }, function(result) {
|
|
|
+ $('#select-contract').modal('hide');
|
|
|
+ });
|
|
|
+ };
|
|
|
+ const showContract = function(type, contractType, id) {
|
|
|
+ initSpread();
|
|
|
+ loadContractTree(type, contractType, id);
|
|
|
+ $('#select-contract').modal('show');
|
|
|
+ };
|
|
|
+ return { showContract, update };
|
|
|
+})();
|