schedule_plan.js 27 KB

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