123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- const TenderSelectMulti = function (setting) {
- $('#tsm-title').html(setting.title);
- if (setting.type === 'gather' && setting.type === 'stage') {
- $('#tsm-stage-info').show();
- }
- $('[name=tsm-source]').click(function() {
- $('[name=gather-type]').hide();
- const type = this.value;
- const gatherBy = $(`#gather-by-${type}`);
- if (gatherBy.length > 0) {
- $('#tsm-stage-info-detail').show();
- $(`#gather-by-${type}`).show();
- } else {
- $('#tsm-stage-info-detail').hide();
- }
- });
- $('.datepicker-here').datepicker({
- autoClose: true,
- });
- const tsObj = {
- setting,
- selectSpread: null,
- selectSheet: null,
- resultSpread: null,
- resultSheet: null,
- tenderSourceTree: null,
- orgHistroy: {},
- trHistory: {},
- trArray: [],
- _rebuildStageSelect: function () {
- if (tsObj.setting.type === 'compare') {
- const getItems = function (data) {
- if (!data) return [];
- const items = [];
- for (let i = 1; i <= data.stageCount; i++) {
- items.push({value: i, text: `第${i}期`});
- }
- return items;
- };
- for (let i = 0; i < tsObj.resultSheet.getRowCount(); i++) {
- const cellType2 = new spreadNS.CellTypes.ComboBox().itemHeight(10).editorValueType(spreadNS.CellTypes.EditorValueType.value).items(getItems(tsObj.trArray[i]));
- tsObj.resultSheet.getCell(i, 1).cellType(cellType2);
- }
- }
- },
- _initSelected: function () {
- for (const node of this.tenderSourceTree.nodes) {
- node.selected = this.trArray.findIndex(x => { return node.tid === x.tid; }) >= 0;
- }
- },
- _addTender: function (tender) {
- const tr = tsObj.trArray.find(x => { return x.tid === tender.tid; });
- const t = { tid: tender.tid, name: tender.name, stageCount: tender.stageCount };
- if (!tr) tsObj.trArray.push(t);
- return t;
- },
- _removeTender: function (tender) {
- const gri = tsObj.trArray.findIndex(function (x, i, arr) {
- return x.tid === tender.tid;
- });
- if (gri >= 0) tsObj.trArray.splice(gri, 1);
- },
- reloadResultData: function () {
- SpreadJsObj.reLoadSheetData(tsObj.resultSheet);
- this._rebuildStageSelect();
- },
- tsButtonClicked: function (e, info) {
- if (!info.sheet.zh_setting) return;
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field !== 'selected') return;
- const node = SpreadJsObj.getSelectObject(info.sheet);
- if (setting.type === 'compare') {
- if (node.children && node.children.length > 0) {
- toastr.warning('对比标段请直接勾选需要对比的标段');
- return;
- }
- if (!node.selected && tsObj.trArray.length >= 2) {
- toastr.warning('仅可选择两个标段进行对比');
- return;
- }
- }
- node.selected = !node.selected;
- if (node.children && node.children.length > 0) {
- const posterity = tsObj.tenderSourceTree.getPosterity(node);
- for (const p of posterity) {
- p.selected = node.selected;
- if (!p.children || p.children.length === 0){
- if (p.selected) {
- tsObj._addTender(p);
- } else {
- tsObj._removeTender(p);
- }
- }
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
- } else {
- if (node.selected) {
- tsObj._addTender(node);
- } else {
- tsObj._removeTender(node);
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
- }
- tsObj.reloadResultData();
- },
- trEditEnded: function (e, info) {
- const data = SpreadJsObj.getSelectObject(info.sheet);
- if (!data) return;
- const col = info.sheet.zh_setting.cols[info.col];
- data[col.field] = info.sheet.getValue(info.row, info.col);
- },
- loadTenders: function () {
- postData(`/sp/${spid}/list/load2`, {type: this.setting.dataType + '-checked' }, data => {
- tsObj.tenderSourceTree = Tender2Tree.convert(data.category, data.tenders, data.ledgerAuditConst, data.stageAuditConst);
- SpreadJsObj.loadSheetData(tsObj.selectSheet, SpreadJsObj.DataType.Tree, tsObj.tenderSourceTree);
- SpreadJsObj.loadSheetData(tsObj.resultSheet, SpreadJsObj.DataType.Data, tsObj.trArray);
- });
- },
- getSelectData: function() {
- const selectData = tsObj.trArray;
- if (selectData.length === 0) {
- toastr.warning('请选择标段');
- return;
- }
- if (this.setting.type === 'compare') {
- if (selectData.length !== 2) {
- toastr.warning('请选择两个标段进行对比');
- return;
- }
- if (this.setting.dataType === 'stage') {
- for (const s of selectData) {
- if (!s.stage) {
- toastr.warning('请选择标段进行对比的期');
- return;
- }
- s.stageInfo = { type: 'stage', stage: s.stage };
- }
- }
- }
- if (this.setting.type === 'gather' && this.setting.dataType === 'stage') {
- // todo 检查汇总选项
- const stage = { type: $('[name=tsm-source]:checked').val() };
- if (stage.type === 'stage') {
- stage.stage = _.toInteger($('#gather-stage').val()) || 0;
- if (!stage.stage) {
- toastr.warning('请选择 汇总期');
- return;
- }
- const validStage = _.min(_.map(tsObj.trArray, 'stageCount'));
- if (stage.stage > validStage) {
- toastr.warning('选择的期无效,请重新选择');
- return;
- }
- } else if (stage.type === 'month') {
- stage.month = $('#gather-month').val();
- if (stage.month === '') {
- toastr.warning('请选择 汇总年月');
- return;
- }
- } else if (stage.type === 'zone') {
- stage.zone = $('#gather-zone').val();
- if (stage.zone === '') {
- toastr.warning('请选择 汇总周期');
- return;
- } else if(stage.zone.indexOf(' - ') < 0) {
- toastr.warning('请选择 完整汇总周期');
- return;
- }
- } else if (stage.type === 'stage-zone') {
- const stageBegin = _.toInteger($('#gather-stage-begin').val()) || 0;
- const stageEnd = _.toInteger($('#gather-stage-end').val()) || 0;
- const validStage = _.max(_.map(tsObj.trArray, 'stageCount'));
- if (!stageBegin || !stageEnd) {
- toastr.warning('请选择 汇总开始期与结束期');
- return;
- }
- if (stageEnd <= stageBegin) {
- toastr.warning('结束期应大于开始期');
- return;
- }
- if (stageEnd > validStage) {
- toastr.warning('选择的期无效,请重新选择');
- return;
- }
- stage.stage_zone = stageBegin + ':' + stageEnd;
- } else if (stage.type === 'custom-zone') {
- stage.custom_zone = $('#gather-custom-zone').val();
- if (stage.custom_zone === '') {
- toastr.warning('请选择 汇总周期');
- return;
- } else if(stage.custom_zone.indexOf(' - ') < 0) {
- toastr.warning('请选择 完整汇总周期');
- return;
- }
- }
- selectData.forEach(s => { s.stageInfo = stage; });
- }
- return selectData;
- },
- initTenderSelect: function () {
- if (this.selectSpread) return;
- this.selectSpread = SpreadJsObj.createNewSpread($('#tsm-select-spread')[0]);
- this.selectSheet = this.selectSpread.getActiveSheet();
- SpreadJsObj.initSheet(this.selectSheet, {
- cols: [
- {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox'},
- {title: '名称', field: 'name', hAlign: 0, width: 300, formatter: '@', cellType: 'tree'},
- {title: '期数', field: 'phase', hAlign: 1, width: 80, formatter: '@'},
- {title: '状态', field: 'status', hAlign: 1, width: 80, formatter: '@'}
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- headColWidth: [30],
- selectedBackColor: '#fffacd',
- readOnly: true,
- });
- this.resultSpread = SpreadJsObj.createNewSpread($('#tsm-result-spread')[0]);
- this.resultSheet = this.resultSpread.getActiveSheet();
- const resultSpreadSetting = {
- cols: [
- {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@', readOnly: true, cellType: 'ellipsisAutoTip'}
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- headColWidth: [30],
- getColor: function (sheet, data, row, col, defaultColor) {
- if (data) {
- return data.invalid ? '#ddd' : defaultColor;
- } else {
- return defaultColor;
- }
- }
- };
- if (this.setting.type === 'compare' && this.setting.dataType === 'stage') {
- resultSpreadSetting.cols.push({ title: '可选期', colSpan: '1', rowSpan: '1', field: 'stage', hAlign: 0, width: 60 });
- }
- SpreadJsObj.initSheet(this.resultSheet, resultSpreadSetting);
- this.selectSpread.bind(spreadNS.Events.ButtonClicked, tsObj.tsButtonClicked);
- if (this.setting.type === 'compare' && this.setting.dataType === 'stage') {
- this.resultSpread.bind(spreadNS.Events.EditEnded, tsObj.trEditEnded);
- }
- $('#tender-select-multi-ok').click(() => {
- const selectData = tsObj.getSelectData();
- if (!selectData) return;
- this.setting.afterSelect(selectData);
- $('#tender-select-multi').modal('hide');
- });
- this.loadTenders();
- },
- };
- $('#tender-select-multi').on('shown.bs.modal', () => {
- tsObj.initTenderSelect();
- });
- const showSelect = function () {
- $('#tender-select-multi').modal('show');
- };
- return { showSelect }
- };
|