tender_select_multi.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. const TenderSelectMulti = function (setting) {
  2. $('#tsm-title').html(setting.title);
  3. if (setting.type === 'gather' && setting.dataType === 'stage') {
  4. $('#tsm-stage-info').show();
  5. }
  6. if (setting.zoneValid === false) {
  7. $('[stage-type=zone]').hide();
  8. }
  9. $('[name=tsm-source]').click(function() {
  10. $('[name=gather-type]').hide();
  11. const type = this.value;
  12. const gatherBy = $(`#gather-by-${type}`);
  13. if (gatherBy.length > 0) {
  14. $('#tsm-stage-info-detail').show();
  15. $(`#gather-by-${type}`).show();
  16. } else {
  17. $('#tsm-stage-info-detail').hide();
  18. }
  19. });
  20. $('.datepicker-here').datepicker({
  21. autoClose: true,
  22. });
  23. const tsObj = {
  24. setting,
  25. selectSpread: null,
  26. selectSheet: null,
  27. resultSpread: null,
  28. resultSheet: null,
  29. tenderSourceTree: null,
  30. orgHistroy: {},
  31. trHistory: {},
  32. trArray: [],
  33. _rebuildStageSelect: function () {
  34. if (tsObj.setting.type === 'compare') {
  35. const getItems = function (data) {
  36. if (!data) return [];
  37. const items = [];
  38. for (let i = 1; i <= data.stageCount; i++) {
  39. items.push({value: i, text: `第${i}期`});
  40. }
  41. return items;
  42. };
  43. for (let i = 0; i < tsObj.resultSheet.getRowCount(); i++) {
  44. const cellType2 = new spreadNS.CellTypes.ComboBox().itemHeight(10).editorValueType(spreadNS.CellTypes.EditorValueType.value).items(getItems(tsObj.trArray[i]));
  45. tsObj.resultSheet.getCell(i, 1).cellType(cellType2);
  46. }
  47. }
  48. },
  49. _initSelected: function () {
  50. for (const node of this.tenderSourceTree.nodes) {
  51. node.selected = this.trArray.findIndex(x => { return node.tid === x.tid; }) >= 0;
  52. }
  53. },
  54. _addTender: function (tender) {
  55. const tr = tsObj.trArray.find(x => { return x.tid === tender.tid; });
  56. const t = { tid: tender.tid, name: tender.name, stageCount: tender.stageCount };
  57. if (!tr) tsObj.trArray.push(t);
  58. return t;
  59. },
  60. _removeTender: function (tender) {
  61. const gri = tsObj.trArray.findIndex(function (x, i, arr) {
  62. return x.tid === tender.tid;
  63. });
  64. if (gri >= 0) tsObj.trArray.splice(gri, 1);
  65. },
  66. reloadResultData: function () {
  67. SpreadJsObj.reLoadSheetData(tsObj.resultSheet);
  68. this._rebuildStageSelect();
  69. },
  70. tsButtonClicked: function (e, info) {
  71. if (!info.sheet.zh_setting) return;
  72. const col = info.sheet.zh_setting.cols[info.col];
  73. if (col.field !== 'selected') return;
  74. const node = SpreadJsObj.getSelectObject(info.sheet);
  75. if (setting.type === 'compare') {
  76. if (node.children && node.children.length > 0) {
  77. toastr.warning('对比标段请直接勾选需要对比的标段');
  78. return;
  79. }
  80. if (!node.selected && tsObj.trArray.length >= 2) {
  81. toastr.warning('仅可选择两个标段进行对比');
  82. return;
  83. }
  84. }
  85. node.selected = !node.selected;
  86. if (node.children && node.children.length > 0) {
  87. const posterity = tsObj.tenderSourceTree.getPosterity(node);
  88. for (const p of posterity) {
  89. p.selected = node.selected;
  90. if (!p.children || p.children.length === 0){
  91. if (p.selected) {
  92. tsObj._addTender(p);
  93. } else {
  94. tsObj._removeTender(p);
  95. }
  96. }
  97. }
  98. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  99. } else {
  100. if (node.selected) {
  101. tsObj._addTender(node);
  102. } else {
  103. tsObj._removeTender(node);
  104. }
  105. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  106. }
  107. tsObj.reloadResultData();
  108. },
  109. trEditEnded: function (e, info) {
  110. const data = SpreadJsObj.getSelectObject(info.sheet);
  111. if (!data) return;
  112. const col = info.sheet.zh_setting.cols[info.col];
  113. data[col.field] = info.sheet.getValue(info.row, info.col);
  114. },
  115. loadTenders: function () {
  116. postData(`/sp/${spid}/list/load2`, {type: this.setting.dataType + '-checked' }, data => {
  117. tsObj.tenderSourceTree = Tender2Tree.convert(data.category, data.tenders, data.ledgerAuditConst, data.stageAuditConst);
  118. SpreadJsObj.loadSheetData(tsObj.selectSheet, SpreadJsObj.DataType.Tree, tsObj.tenderSourceTree);
  119. SpreadJsObj.loadSheetData(tsObj.resultSheet, SpreadJsObj.DataType.Data, tsObj.trArray);
  120. });
  121. },
  122. getSelectData: function() {
  123. const selectData = tsObj.trArray;
  124. if (selectData.length === 0) {
  125. toastr.warning('请选择标段');
  126. return;
  127. }
  128. if (this.setting.type === 'compare') {
  129. if (selectData.length !== 2) {
  130. toastr.warning('请选择两个标段进行对比');
  131. return;
  132. }
  133. if (this.setting.dataType === 'stage') {
  134. for (const s of selectData) {
  135. if (!s.stage) {
  136. toastr.warning('请选择标段进行对比的期');
  137. return;
  138. }
  139. s.stageInfo = { type: 'stage', stage: s.stage };
  140. }
  141. }
  142. }
  143. if (this.setting.type === 'gather' && this.setting.dataType === 'stage') {
  144. // todo 检查汇总选项
  145. const stage = { type: $('[name=tsm-source]:checked').val() };
  146. if (stage.type === 'stage') {
  147. stage.stage = _.toInteger($('#gather-stage').val()) || 0;
  148. if (!stage.stage) {
  149. toastr.warning('请选择 汇总期');
  150. return;
  151. }
  152. const validStage = _.min(_.map(tsObj.trArray, 'stageCount'));
  153. if (stage.stage > validStage) {
  154. toastr.warning('选择的期无效,请重新选择');
  155. return;
  156. }
  157. } else if (stage.type === 'month') {
  158. stage.month = $('#gather-month').val();
  159. if (stage.month === '') {
  160. toastr.warning('请选择 汇总年月');
  161. return;
  162. }
  163. } else if (stage.type === 'zone') {
  164. stage.zone = $('#gather-zone').val();
  165. if (stage.zone === '') {
  166. toastr.warning('请选择 汇总周期');
  167. return;
  168. } else if(stage.zone.indexOf(' - ') < 0) {
  169. toastr.warning('请选择 完整汇总周期');
  170. return;
  171. }
  172. } else if (stage.type === 'stage-zone') {
  173. const stageBegin = _.toInteger($('#gather-stage-begin').val()) || 0;
  174. const stageEnd = _.toInteger($('#gather-stage-end').val()) || 0;
  175. const validStage = _.max(_.map(tsObj.trArray, 'stageCount'));
  176. if (!stageBegin || !stageEnd) {
  177. toastr.warning('请选择 汇总开始期与结束期');
  178. return;
  179. }
  180. if (stageEnd <= stageBegin) {
  181. toastr.warning('结束期应大于开始期');
  182. return;
  183. }
  184. if (stageEnd > validStage) {
  185. toastr.warning('选择的期无效,请重新选择');
  186. return;
  187. }
  188. stage.stage_zone = stageBegin + ':' + stageEnd;
  189. } else if (stage.type === 'custom-zone') {
  190. stage.custom_zone = $('#gather-custom-zone').val();
  191. if (stage.custom_zone === '') {
  192. toastr.warning('请选择 汇总周期');
  193. return;
  194. } else if(stage.custom_zone.indexOf(' - ') < 0) {
  195. toastr.warning('请选择 完整汇总周期');
  196. return;
  197. }
  198. }
  199. selectData.forEach(s => { s.stageInfo = stage; });
  200. }
  201. return selectData;
  202. },
  203. initTenderSelect: function () {
  204. if (this.selectSpread) return;
  205. this.selectSpread = SpreadJsObj.createNewSpread($('#tsm-select-spread')[0]);
  206. this.selectSheet = this.selectSpread.getActiveSheet();
  207. SpreadJsObj.initSheet(this.selectSheet, {
  208. cols: [
  209. {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox'},
  210. {title: '名称', field: 'name', hAlign: 0, width: 300, formatter: '@', cellType: 'tree'},
  211. {title: '期数', field: 'phase', hAlign: 1, width: 80, formatter: '@'},
  212. {title: '状态', field: 'status', hAlign: 1, width: 80, formatter: '@'}
  213. ],
  214. emptyRows: 0,
  215. headRows: 1,
  216. headRowHeight: [32],
  217. defaultRowHeight: 21,
  218. headerFont: '12px 微软雅黑',
  219. font: '12px 微软雅黑',
  220. headColWidth: [30],
  221. selectedBackColor: '#fffacd',
  222. readOnly: true,
  223. });
  224. this.resultSpread = SpreadJsObj.createNewSpread($('#tsm-result-spread')[0]);
  225. this.resultSheet = this.resultSpread.getActiveSheet();
  226. const resultSpreadSetting = {
  227. cols: [
  228. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@', readOnly: true, cellType: 'ellipsisAutoTip'}
  229. ],
  230. emptyRows: 0,
  231. headRows: 1,
  232. headRowHeight: [32],
  233. defaultRowHeight: 21,
  234. headerFont: '12px 微软雅黑',
  235. font: '12px 微软雅黑',
  236. headColWidth: [30],
  237. getColor: function (sheet, data, row, col, defaultColor) {
  238. if (data) {
  239. return data.invalid ? '#ddd' : defaultColor;
  240. } else {
  241. return defaultColor;
  242. }
  243. }
  244. };
  245. if (this.setting.type === 'compare' && this.setting.dataType === 'stage') {
  246. resultSpreadSetting.cols.push({ title: '可选期', colSpan: '1', rowSpan: '1', field: 'stage', hAlign: 0, width: 60 });
  247. }
  248. SpreadJsObj.initSheet(this.resultSheet, resultSpreadSetting);
  249. this.selectSpread.bind(spreadNS.Events.ButtonClicked, tsObj.tsButtonClicked);
  250. if (this.setting.type === 'compare' && this.setting.dataType === 'stage') {
  251. this.resultSpread.bind(spreadNS.Events.EditEnded, tsObj.trEditEnded);
  252. }
  253. $('#tender-select-multi-ok').click(() => {
  254. const selectData = tsObj.getSelectData();
  255. if (!selectData) return;
  256. this.setting.afterSelect(selectData);
  257. $('#tender-select-multi').modal('hide');
  258. });
  259. this.loadTenders();
  260. },
  261. };
  262. $('#tender-select-multi').on('shown.bs.modal', () => {
  263. tsObj.initTenderSelect();
  264. });
  265. const showSelect = function () {
  266. $('#tender-select-multi').modal('show');
  267. };
  268. return { showSelect }
  269. };