schedule_plan.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. /**
  2. * 进度台账相关js
  3. *
  4. * @author Ellisran
  5. * @date 2020/11/6
  6. * @version
  7. */
  8. function getTenderId() {
  9. return window.location.pathname.split('/')[2];
  10. }
  11. $(function () {
  12. autoFlashHeight();
  13. if(schedule && !schedule.mode && !revising && !schedule.revising) {
  14. $('#mode').modal('show');
  15. }
  16. // 初始化台账
  17. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  18. const treeSetting = {
  19. id: 'ledger_id',
  20. pid: 'ledger_pid',
  21. order: 'order',
  22. level: 'level',
  23. rootId: -1,
  24. fullPath: 'full_path',
  25. calcFun: function (node) {
  26. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  27. if (node.children && node.children.length > 0) {
  28. for (const sm of scheduleMonth) {
  29. node[sm.yearmonth+'_gcl'] = ZhCalc.round(ZhCalc.div(node[sm.yearmonth+'_tp'], node.dgn_price), 3);
  30. }
  31. }
  32. }
  33. //treeCacheKey: 'ledger_bills_fold' + '_' + getTenderId(),
  34. // markFoldKey: 'bills-fold',
  35. // markFoldSubKey: window.location.pathname.split('/')[2],
  36. };
  37. const static_cols = [
  38. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', readOnly: true, cellType: 'tree'},
  39. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@', readOnly: true},
  40. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  41. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'dgn_price', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  42. {title: '总设计|工程量', colSpan: '2|1', rowSpan: '1|1', field: 'dgn_qty1', hAlign: 2, width: 70, type: 'Number', readOnly: true},
  43. {title: '|金额(元)', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 70, type: 'Number', readOnly: true},
  44. ];
  45. const ledgerSpreadSetting = {
  46. emptyRows: 0,
  47. headRows: 2,
  48. headRowHeight: [25, 25],
  49. defaultRowHeight: 21,
  50. headerFont: '12px 微软雅黑',
  51. font: '12px 微软雅黑',
  52. // readOnly: true,
  53. localCache: {
  54. key: 'ledger-plan',
  55. colWidth: true,
  56. }
  57. };
  58. const monthsCols = [];
  59. const calcCols = ['total_price'];
  60. if(scheduleMonth.length > 0) {
  61. for (const sm of scheduleMonth) {
  62. const readOnly = sm.stage_gcl_used !== 0 || sm.stage_tp_used !== 0;
  63. const yearmonth = sm.yearmonth.split('-')[0] + '年' + parseInt(sm.yearmonth.split('-')[1]) + '月';
  64. const cols = {title: yearmonth + '|计划工程量', colSpan: '2|1', rowSpan: '1|1', field: sm.yearmonth+'_gcl', hAlign: 2, width: 90, type: 'Number', readOnly: readOnly ? readOnly : 'readOnly.gcl'};
  65. const cols2 = {title: '|计划金额(元)', colSpan: '|1', rowSpan: '|1', field: sm.yearmonth+'_tp', hAlign: 2, width: 90, type: 'Number', readOnly: readOnly ? readOnly : 'readOnly.tp'};
  66. monthsCols.push(cols);
  67. monthsCols.push(cols2);
  68. // calcCols.push(sm.yearmonth+'_gcl');
  69. calcCols.push(sm.yearmonth+'_tp');
  70. }
  71. }
  72. treeSetting.calcFields = calcCols;
  73. const ledgerTree = createNewPathTree('filter', treeSetting);
  74. const spreadHeaderCols = static_cols.concat(monthsCols);
  75. ledgerSpreadSetting.cols = spreadHeaderCols;
  76. const ledgerCol = {
  77. readOnly: {
  78. tp: function (data) {
  79. let flag = data.is_leaf;
  80. if (data.is_leaf) {
  81. flag = schedule && schedule.mode === mode.tp;
  82. }
  83. return !(flag && !revising);
  84. },
  85. gcl: function (data) {
  86. let flag = data.is_leaf;
  87. if (data.is_leaf) {
  88. flag = schedule && schedule.mode === mode.gcl;
  89. }
  90. return !(flag && !revising);
  91. },
  92. },
  93. };
  94. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  95. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  96. SpreadJsObj.initSpreadSettingEvents(ledgerSpreadSetting, ledgerCol);
  97. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  98. SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
  99. ledgerSpread.getActiveSheet().frozenColumnCount(6);
  100. ledgerSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';
  101. postData('/tender/' + getTenderId() + '/schedule/ledger/load', {}, function (data) {
  102. // let treeData = [];
  103. // for(const sl of selectedLedgerList) {
  104. // const one = _.find(data, { 'ledger_id' : sl });
  105. // treeData.push(one);
  106. // }
  107. // treeData = setLeafData(treeData);
  108. // console.log(treeData);
  109. // let treeData = data;
  110. const calcList = ['total_price'];
  111. const showList = ['ledger_id', 'ledger_pid', 'order', 'level', 'tender_id', 'full_path',
  112. 'code', 'name', 'unit', 'dgn_qty1', 'dgn_qty2', 'dgn_price', 'quantity', 'total_price'];
  113. for (const m of monthList) {
  114. showList.push(m + '_tp');
  115. showList.push(m + '_gcl');
  116. // calcList.push(m + '_tp');
  117. // calcList.push(m + '_gcl');
  118. }
  119. const baseLedgerTree = createNewPathTree('base', {
  120. id: 'ledger_id',
  121. pid: 'ledger_pid',
  122. order: 'order',
  123. level: 'level',
  124. rootId: -1,
  125. fullPath: 'full_path',
  126. calcFields: calcList,
  127. calcFun: function (node) {
  128. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  129. }
  130. });
  131. const newLedgerList = setMonthToLedger(data.bills, data.slm);
  132. baseLedgerTree.loadDatas(newLedgerList);
  133. treeCalc.calculateAll(baseLedgerTree);
  134. console.log(baseLedgerTree);
  135. for (const d of baseLedgerTree.nodes) {
  136. if (!d.b_code) {
  137. const one = _.find(selectedLedgerList, function (item) {
  138. return item === d.ledger_id;
  139. });
  140. if(one) {
  141. ledgerTree.addData(d, showList);
  142. }
  143. }
  144. }
  145. // console.log(ledgerTree);
  146. ledgerTree.sortTreeNode(true);
  147. treeCalc.calculateAll(ledgerTree);
  148. console.log(ledgerTree);
  149. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree);
  150. }, null, true);
  151. const ledgerSpreadObj = {
  152. refreshTree: function (sheet, data) {
  153. SpreadJsObj.massOperationSheet(sheet, function () {
  154. const tree = sheet.zh_tree;
  155. // 处理删除
  156. if (data.delete) {
  157. data.delete.sort(function (x, y) {
  158. return y.deleteIndex - x.deleteIndex;
  159. });
  160. for (const d of data.delete) {
  161. sheet.deleteRows(d.deleteIndex, 1);
  162. }
  163. }
  164. // 处理新增
  165. if (data.create) {
  166. const newNodes = data.create;
  167. if (newNodes) {
  168. newNodes.sort(function (a, b) {
  169. return a.index - b.index;
  170. });
  171. for (const node of newNodes) {
  172. sheet.addRows(node.index, 1);
  173. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  174. }
  175. }
  176. }
  177. // 处理更新
  178. if (data.update) {
  179. const rows = [];
  180. for (const u of data.update) {
  181. rows.push(tree.nodes.indexOf(u));
  182. }
  183. SpreadJsObj.reLoadRowsData(sheet, rows);
  184. }
  185. // 处理展开
  186. if (data.expand) {
  187. const expanded = [];
  188. for (const e of data.expand) {
  189. if (expanded.indexOf(e) === -1) {
  190. const posterity = tree.getPosterity(e);
  191. for (const p of posterity) {
  192. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  193. expanded.push(p);
  194. }
  195. }
  196. }
  197. }
  198. });
  199. },
  200. editEnded: function (e, info) {
  201. if (info.sheet.zh_setting) {
  202. const select = SpreadJsObj.getSelectObject(info.sheet);
  203. const col = info.sheet.zh_setting.cols[info.col];
  204. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  205. const orgValue = select[col.field];
  206. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  207. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  208. return;
  209. }
  210. if (isNaN(validText)) {
  211. toastr.error('不能输入其它非数字类型字符');
  212. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  213. return;
  214. }
  215. const yearmonth = col.field.split('_')[0];
  216. const mode = col.field.split('_')[1];
  217. let plan_gcl = 0;
  218. let plan_tp = 0;
  219. // 判断输入位数,提示
  220. if (mode === 'tp') {
  221. const reg = new RegExp('^([-]?)\\d+$');
  222. if (validText !== null && (!reg.test(validText))) {
  223. // toastr.error('输入金额请为整数');
  224. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  225. // return;
  226. validText = ZhCalc.round(validText, 0);
  227. }
  228. plan_gcl = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(validText, select.dgn_price), 3) : 0;
  229. plan_tp = validText;
  230. } else {
  231. const reg = new RegExp('^([-]?)\\d+$');
  232. if (validText !== null && (!reg.test(validText))) {
  233. // toastr.error('输入工程量小数位数不能大于3位');
  234. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  235. // return;
  236. validText = ZhCalc.round(validText, 3);
  237. }
  238. plan_gcl = validText;
  239. plan_tp = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, select.dgn_price), 0) : 0;
  240. }
  241. select[col.field] = validText;
  242. const updateData = {
  243. lid: select.ledger_id,
  244. yearmonth,
  245. plan_gcl,
  246. plan_tp,
  247. };
  248. console.log(updateData);
  249. postData(window.location.pathname + '/save', {type: 'ledger_edit', postData: updateData}, function (result) {
  250. if (mode === 'tp') {
  251. select[yearmonth + '_gcl'] = plan_gcl;
  252. } else {
  253. select[yearmonth + '_tp'] = plan_tp;
  254. }
  255. const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select);
  256. const refreshNode = ledgerTree.loadPostData({update: nodes});
  257. ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
  258. },function () {
  259. select[col.field] = orgValue;
  260. const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select);
  261. const refreshNode = ledgerTree.loadPostData({update: nodes});
  262. ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
  263. })
  264. }
  265. },
  266. deletePress: function (sheet) {
  267. if (!sheet.zh_setting || sheet.zh_setting.readOnly) return;
  268. if (sheet.zh_setting && sheet.zh_tree) {
  269. const sel = sheet.getSelections()[0];
  270. if (!sel) return;
  271. if(sel.rowCount > 1 || sel.colCount > 1) {
  272. return;
  273. }
  274. const select = SpreadJsObj.getSelectObject(sheet);
  275. const col = sheet.zh_setting.cols[sel.col];
  276. const orgValue = select[col.field];
  277. if (!orgValue) {
  278. return;
  279. }
  280. const yearmonth = col.field.split('_')[0];
  281. const modes = col.field.split('_')[1];
  282. if(col.readOnly === true || !select.is_leaf || mode[modes] !== schedule.mode) {
  283. return;
  284. }
  285. let plan_gcl = 0;
  286. let plan_tp = 0;
  287. select[col.field] = 0;
  288. const updateData = {
  289. lid: select.ledger_id,
  290. yearmonth,
  291. plan_gcl,
  292. plan_tp,
  293. };
  294. postData(window.location.pathname + '/save', {type: 'ledger_edit', postData: updateData}, function (result) {
  295. if (modes === 'tp') {
  296. select[yearmonth + '_gcl'] = plan_gcl;
  297. } else {
  298. select[yearmonth + '_tp'] = plan_tp;
  299. }
  300. const nodes = treeCalc.calculateParent(sheet.zh_tree, select);
  301. const refreshNode = ledgerTree.loadPostData({update: nodes});
  302. ledgerSpreadObj.refreshTree(sheet, refreshNode);
  303. },function () {
  304. select[col.field] = orgValue;
  305. const nodes = treeCalc.calculateParent(sheet.zh_tree, select);
  306. const refreshNode = ledgerTree.loadPostData({update: nodes});
  307. ledgerSpreadObj.refreshTree(sheet, refreshNode);
  308. })
  309. }
  310. },
  311. clipboardPasted(e, info) {
  312. const hint = {
  313. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  314. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  315. };
  316. console.log(info);
  317. const range = info.cellRange;
  318. if (range.rowCount > 1 || range.colCount > 1) {
  319. toastMessageUniq(hint.cellError);
  320. SpreadJsObj.reLoadSheetHeader(ledgerSpread.getActiveSheet());
  321. SpreadJsObj.reLoadSheetData(ledgerSpread.getActiveSheet());
  322. return;
  323. }
  324. const select = SpreadJsObj.getSelectObject(info.sheet);
  325. const col = info.sheet.zh_setting.cols[range.col];
  326. let validText = is_numeric(info.pasteData.text) ? parseFloat(info.pasteData.text) : (info.pasteData.text ? trimInvalidChar(info.pasteData.text) : null);
  327. const orgValue = select[col.field];
  328. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  329. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  330. return;
  331. }
  332. if (isNaN(validText)) {
  333. toastr.error('不能粘贴其它非数字类型字符');
  334. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  335. return;
  336. }
  337. const yearmonth = col.field.split('_')[0];
  338. const mode = col.field.split('_')[1];
  339. let plan_gcl = 0;
  340. let plan_tp = 0;
  341. // 判断输入位数,提示
  342. if (mode === 'tp') {
  343. const reg = new RegExp('^([-]?)\\d+$');
  344. if (validText !== null && (!reg.test(validText))) {
  345. // toastr.error('粘贴的金额小数位数不能大于0位');
  346. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  347. // return;
  348. validText = ZhCalc.round(validText, 0);
  349. }
  350. plan_gcl = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(validText, select.dgn_price), 3) : 0;
  351. plan_tp = validText;
  352. } else {
  353. // const reg = new RegExp('^([-]?)\\d+(\\.\\d{0,3})?$');
  354. const reg = new RegExp('^([-]?)\\d+$');
  355. if (validText !== null && (!reg.test(validText))) {
  356. // toastr.error('粘贴的工程量小数位数不能大于3位');
  357. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  358. // return;
  359. validText = ZhCalc.round(validText, 3);
  360. }
  361. plan_gcl = validText;
  362. plan_tp = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, select.dgn_price), 0) : 0;
  363. }
  364. select[col.field] = validText;
  365. const updateData = {
  366. lid: select.ledger_id,
  367. yearmonth,
  368. plan_gcl,
  369. plan_tp,
  370. };
  371. postData(window.location.pathname + '/save', {type: 'ledger_edit', postData: updateData}, function (result) {
  372. if (mode === 'tp') {
  373. select[yearmonth + '_gcl'] = plan_gcl;
  374. } else {
  375. select[yearmonth + '_tp'] = plan_tp;
  376. }
  377. const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select);
  378. const refreshNode = ledgerTree.loadPostData({update: nodes});
  379. ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
  380. },function () {
  381. select[col.field] = orgValue;
  382. const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select);
  383. const refreshNode = ledgerTree.loadPostData({update: nodes});
  384. ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
  385. })
  386. },
  387. };
  388. ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerSpreadObj.editEnded);
  389. SpreadJsObj.addDeleteBind(ledgerSpread, ledgerSpreadObj.deletePress);
  390. ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerSpreadObj.clipboardPasted);
  391. // 进度计算方式选择
  392. $('.mode-select').on('click', function () {
  393. const _self = $(this);
  394. const this_mode = _self.data('mode');
  395. // 重新计算所有未使用的月份数据
  396. const under_ledger = _.filter(ledgerTree.nodes, { is_leaf: true});
  397. const update_nodes = [];
  398. const newMonthList = _.map(_.filter(scheduleMonth, function (item) {
  399. return item.stage_gcl_used === 0 && item.stage_tp_used === 0;
  400. }), 'yearmonth');
  401. for (const ul of under_ledger) {
  402. for (const m of newMonthList) {
  403. if (ul[m+'_tp'] || ul[m+'_gcl']) {
  404. update_nodes.push(ul);
  405. break;
  406. }
  407. }
  408. }
  409. const update_under_ledger = [];
  410. if(update_nodes.length > 0) {
  411. for (const un of update_nodes) {
  412. if (this_mode === mode.gcl) {
  413. for (const m of newMonthList) {
  414. if(un[m+'_tp']) {
  415. un[m+'_tp'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(un[m+'_gcl'], un.dgn_price), 0) : 0;
  416. update_under_ledger.push({lid: un.ledger_id, yearmonth: m, plan_tp: un[m+'_tp'], plan_gcl: un[m+'_gcl']});
  417. }
  418. }
  419. } else {
  420. for (const m of newMonthList) {
  421. if(un[m+'_gcl']) {
  422. un[m+'_gcl'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(un[m+'_tp'], un.dgn_price), 3) : 0;
  423. update_under_ledger.push({lid: un.ledger_id, yearmonth: m, plan_tp: un[m+'_tp'], plan_gcl: un[m+'_gcl']});
  424. }
  425. }
  426. }
  427. }
  428. }
  429. console.log(update_under_ledger);
  430. postData(window.location.pathname + '/save', {type: 'mode', postData: {mode: this_mode, update_under_ledger}}, function (result) {
  431. _self.addClass('disabled').attr('disabled', true);
  432. _self.text('当前');
  433. _self.parents('.col-6').siblings('.col-6').find('button').removeClass('disabled').removeAttr('disabled');
  434. _self.parents('.col-6').siblings('.col-6').find('button').text('选择');
  435. $('#mode-tips').show();
  436. $('#mode-cancel').show();
  437. $('#mode').modal('hide');
  438. schedule.mode = this_mode;
  439. if (update_nodes.length > 0) {
  440. for (const uul of update_nodes) {
  441. const nodes = treeCalc.calculateParent(ledgerSpread.getActiveSheet().zh_tree, uul);
  442. const refreshNode = ledgerTree.loadPostData({update: nodes});
  443. ledgerSpreadObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  444. }
  445. }
  446. SpreadJsObj.reLoadSheetData(ledgerSpread.getActiveSheet());
  447. })
  448. });
  449. // 月份添加
  450. $('#add-month').click(function () {
  451. const range = $('#month-range').val();
  452. if(range === '') {
  453. toastr.error('请选择计划周期时间');
  454. return;
  455. }
  456. const addMonthList = [];
  457. const cycle = range.split(' ~ ');
  458. if(cycle.length === 1) {
  459. addMonthList.push(cycle[0]);
  460. } else {
  461. // 多个月份
  462. const back_year = parseInt(cycle[1].split('-')[0]);
  463. const back_month = parseInt(cycle[1].split('-')[1]);
  464. const front_year = parseInt(cycle[0].split('-')[0]);
  465. const front_month = parseInt(cycle[0].split('-')[1]);
  466. if(back_year > front_year) {
  467. const num = getDistanceMonth(cycle[0], cycle[1]);
  468. let j = 1;
  469. for (let i = 0; i <= num; i++) {
  470. if(front_month + i > 12*j) {
  471. j = j + 1;
  472. }
  473. const m = (front_month + i)%12 === 0 ? 12 : (front_month + i)%12;
  474. addMonthList.push((front_year + (j-1)) + '-' + (m < 10 ? '0' + m : m));
  475. }
  476. } else if (back_year === front_year) {
  477. // 小于1年并没有跨年
  478. for (let i = front_month; i <= back_month; i++) {
  479. addMonthList.push(back_year + '-' + (i < 10 ? '0' + i : i));
  480. }
  481. }
  482. }
  483. // 判断是否已添加本月份
  484. if (addMonthList.length > 0) {
  485. const hadmonth = [];
  486. for (const m of addMonthList) {
  487. const one = _.find(scheduleMonth, { yearmonth: m });
  488. console.log(one, m);
  489. if (one) {
  490. hadmonth.push(m);
  491. }
  492. }
  493. if (hadmonth.length > 0) {
  494. let html = '';
  495. for (const hm of hadmonth) {
  496. html += `<div class="alert alert-danger">${hm} 已创建</div>`;
  497. }
  498. $('#add-month-error-list').html(html);
  499. $('#add-month-error-list').show();
  500. return;
  501. }
  502. } else {
  503. toastr.error('请选择计划周期时间');
  504. return;
  505. }
  506. $('#add-month-error-list').html('');
  507. $('#add-month-error-list').hide();
  508. const _self = $(this);
  509. postData(window.location.pathname + '/save', {type: 'addmonth', postData: addMonthList}, function (result) {
  510. _self.addClass('disabled').attr('disabled', true);
  511. toastr.success('新增成功');
  512. setTimeout(function () {
  513. window.location.reload();
  514. }, 500)
  515. })
  516. });
  517. $('#month-table input[type="checkbox"]').click(function () {
  518. const selectedMonth = [];
  519. $('#month-table input:checkbox:checked').each(function () {
  520. selectedMonth.push('「' + $(this).parents('td').siblings('td').text() + '」');
  521. });
  522. if(selectedMonth.length > 0) {
  523. $('#del-month-list').text(selectedMonth.join(''));
  524. $('#del-month-list').parent().show();
  525. $('#del-month').removeAttr('disabled');
  526. } else {
  527. $('#del-month-list').parent().hide();
  528. $('#del-month').attr('disabled', true);
  529. }
  530. });
  531. $('#del-month').click(function () {
  532. const selectedMonth = [];
  533. $('#month-table input:checkbox:checked').each(function () {
  534. selectedMonth.push($(this).parents('td').siblings().text());
  535. });
  536. if (selectedMonth.length === 0) {
  537. toastr.error('请选择删除的计划周期');
  538. return;
  539. }
  540. const _self = $(this);
  541. postData(window.location.pathname + '/save', {type: 'delmonth', postData: selectedMonth}, function (result) {
  542. _self.addClass('disabled').attr('disabled', true);
  543. toastr.success('删除成功');
  544. setTimeout(function () {
  545. window.location.reload();
  546. }, 500)
  547. })
  548. });
  549. $.subMenu({
  550. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  551. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  552. key: 'menu.1.0.0',
  553. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  554. callback: function (info) {
  555. if (info.mini) {
  556. $('.panel-title').addClass('fluid');
  557. $('#sub-menu').removeClass('panel-sidebar');
  558. } else {
  559. $('.panel-title').removeClass('fluid');
  560. $('#sub-menu').addClass('panel-sidebar');
  561. }
  562. ledgerSpread.refresh();
  563. autoFlashHeight();
  564. }
  565. });
  566. });
  567. // 月份间隔
  568. function getDistanceMonth(startTime,endTime){
  569. startTime = new Date(startTime);
  570. endTime = new Date(endTime);
  571. var dateToMonth = 0;
  572. var startDate=startTime.getDate() + startTime.getHours()/24 + startTime.getMinutes()/24/60;
  573. var endDate=endTime.getDate() +endTime.getHours()/24 + endTime.getMinutes()/24/60;
  574. if(endDate >= startDate){
  575. dateToMonth = 0;
  576. }else{
  577. dateToMonth = -1;
  578. }
  579. let yearToMonth = (endTime.getYear() - startTime.getYear()) * 12;
  580. let monthToMonth = endTime.getMonth() - startTime.getMonth();
  581. return yearToMonth + monthToMonth + dateToMonth;
  582. }
  583. function setLeafData(tree) {
  584. const newtree = [];
  585. for (const t of tree) {
  586. const child = _.find(tree, { 'ledger_pid': t.ledger_id });
  587. if (!child && !t.is_leaf) {
  588. t.is_leaf = true;
  589. }
  590. newtree.push(t);
  591. }
  592. return newtree;
  593. }
  594. function setMonthToLedger(ledgerList, slm) {
  595. if (slm.length > 0) {
  596. for(const s of slm) {
  597. const index = _.findIndex(ledgerList, { 'ledger_id': s.lid });
  598. if (index && index !== -1) {
  599. ledgerList[index][s.yearmonth + '_tp'] = s.plan_tp;
  600. ledgerList[index][s.yearmonth + '_gcl'] = s.plan_gcl;
  601. }
  602. }
  603. }
  604. return ledgerList;
  605. }
  606. const is_numeric = (value) => {
  607. if (typeof(value) === 'object') {
  608. return false;
  609. } else {
  610. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  611. }
  612. };