schedule_plan.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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. for (const d of baseLedgerTree.nodes) {
  135. if (!d.b_code) {
  136. const one = _.find(selectedLedgerList, function (item) {
  137. return item === d.ledger_id;
  138. });
  139. if(one) {
  140. ledgerTree.addData(d, showList);
  141. }
  142. }
  143. }
  144. ledgerTree.sortTreeNode(true);
  145. treeCalc.calculateAll(ledgerTree);
  146. console.log(ledgerTree);
  147. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree);
  148. }, null, true);
  149. const ledgerSpreadObj = {
  150. refreshTree: function (sheet, data) {
  151. SpreadJsObj.massOperationSheet(sheet, function () {
  152. const tree = sheet.zh_tree;
  153. // 处理删除
  154. if (data.delete) {
  155. data.delete.sort(function (x, y) {
  156. return y.deleteIndex - x.deleteIndex;
  157. });
  158. for (const d of data.delete) {
  159. sheet.deleteRows(d.deleteIndex, 1);
  160. }
  161. }
  162. // 处理新增
  163. if (data.create) {
  164. const newNodes = data.create;
  165. if (newNodes) {
  166. newNodes.sort(function (a, b) {
  167. return a.index - b.index;
  168. });
  169. for (const node of newNodes) {
  170. sheet.addRows(node.index, 1);
  171. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  172. }
  173. }
  174. }
  175. // 处理更新
  176. if (data.update) {
  177. const rows = [];
  178. for (const u of data.update) {
  179. rows.push(tree.nodes.indexOf(u));
  180. }
  181. SpreadJsObj.reLoadRowsData(sheet, rows);
  182. }
  183. // 处理展开
  184. if (data.expand) {
  185. const expanded = [];
  186. for (const e of data.expand) {
  187. if (expanded.indexOf(e) === -1) {
  188. const posterity = tree.getPosterity(e);
  189. for (const p of posterity) {
  190. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  191. expanded.push(p);
  192. }
  193. }
  194. }
  195. }
  196. });
  197. },
  198. editEnded: function (e, info) {
  199. if (info.sheet.zh_setting) {
  200. const select = SpreadJsObj.getSelectObject(info.sheet);
  201. const col = info.sheet.zh_setting.cols[info.col];
  202. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  203. const orgValue = select[col.field];
  204. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  205. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  206. return;
  207. }
  208. if (isNaN(validText)) {
  209. toastr.error('不能输入其它非数字类型字符');
  210. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  211. return;
  212. }
  213. const yearmonth = col.field.split('_')[0];
  214. const mode = col.field.split('_')[1];
  215. let plan_gcl = 0;
  216. let plan_tp = 0;
  217. // 判断输入位数,提示
  218. if (mode === 'tp') {
  219. const reg = new RegExp('^([-]?)\\d+$');
  220. if (validText !== null && (!reg.test(validText))) {
  221. // toastr.error('输入金额请为整数');
  222. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  223. // return;
  224. validText = ZhCalc.round(validText, 0);
  225. }
  226. plan_gcl = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(validText, select.dgn_price), 3) : 0;
  227. plan_tp = validText;
  228. } else {
  229. const reg = new RegExp('^([-]?)\\d+$');
  230. if (validText !== null && (!reg.test(validText))) {
  231. // toastr.error('输入工程量小数位数不能大于3位');
  232. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  233. // return;
  234. validText = ZhCalc.round(validText, 3);
  235. }
  236. plan_gcl = validText;
  237. plan_tp = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, select.dgn_price), 0) : 0;
  238. }
  239. select[col.field] = validText;
  240. const updateData = {
  241. lid: select.ledger_id,
  242. yearmonth,
  243. plan_gcl,
  244. plan_tp,
  245. };
  246. postData(window.location.pathname + '/save', {type: 'ledger_edit', postData: updateData}, function (result) {
  247. if (mode === 'tp') {
  248. select[yearmonth + '_gcl'] = plan_gcl;
  249. } else {
  250. select[yearmonth + '_tp'] = plan_tp;
  251. }
  252. const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select, 1);
  253. console.log(nodes, select);
  254. const refreshNode = ledgerTree.loadPostData({update: nodes});
  255. console.log(refreshNode);
  256. ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
  257. },function () {
  258. select[col.field] = orgValue;
  259. const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select, 1);
  260. const refreshNode = ledgerTree.loadPostData({update: nodes});
  261. ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
  262. })
  263. }
  264. },
  265. deletePress: function (sheet) {
  266. if (!sheet.zh_setting) return;
  267. if (sheet.zh_setting && sheet.zh_tree) {
  268. const sel = sheet.getSelections()[0], datas = [], filterNodes = [];
  269. if (!sel) return;
  270. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  271. let bDel = false;
  272. const node = sheet.zh_tree.nodes[iRow];
  273. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  274. const col = sheet.zh_setting.cols[iCol];
  275. const orgValue = node[col.field];
  276. if (!orgValue) {
  277. continue;
  278. }
  279. const yearmonth = col.field.split('_')[0];
  280. const modes = col.field.split('_')[1];
  281. if(col.readOnly === true || !node.is_leaf || mode[modes] !== schedule.mode) {
  282. continue;
  283. }
  284. const updateData = {
  285. lid: node.ledger_id,
  286. yearmonth,
  287. plan_gcl: null,
  288. plan_tp: null,
  289. };
  290. datas.push(updateData);
  291. node[yearmonth+'_gcl'] = null;
  292. node[yearmonth+'_tp'] = null;
  293. bDel = true;
  294. }
  295. if (bDel) filterNodes.push(node);
  296. }
  297. if (datas.length > 0) {
  298. postData(window.location.pathname + '/save', {type: 'ledger_paste', postData: datas}, function (result) {
  299. for (const uul of filterNodes) {
  300. const nodes = treeCalc.calculateParent(sheet.zh_tree, uul, 1);
  301. const refreshNode = ledgerTree.loadPostData({update: nodes});
  302. ledgerSpreadObj.refreshTree(sheet, refreshNode);
  303. }
  304. SpreadJsObj.reLoadSheetData(sheet);
  305. }, function () {
  306. SpreadJsObj.reLoadSheetData(sheet);
  307. });
  308. }
  309. }
  310. },
  311. clipboardPasted(e, info) {
  312. const hint = {
  313. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  314. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  315. };
  316. const tree = info.sheet.zh_tree;
  317. if (!tree) { return; }
  318. const sortData = info.sheet.zh_tree.nodes;
  319. const datas = [], filterNodes = [];
  320. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  321. let bPaste = false;
  322. const curRow = info.cellRange.row + iRow;
  323. const node = sortData[curRow];
  324. if (node) {
  325. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  326. const curCol = info.cellRange.col + iCol;
  327. const colSetting = info.sheet.zh_setting.cols[curCol];
  328. let validText = is_numeric(info.sheet.getText(curRow, curCol)) ? parseFloat(info.sheet.getText(curRow, curCol)) : (info.sheet.getText(curRow, curCol) ? trimInvalidChar(info.sheet.getText(curRow, curCol)) : null);
  329. const orgValue = node[colSetting.field];
  330. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  331. continue;
  332. }
  333. if (isNaN(validText)) {
  334. toastMessageUniq(hint.numberExpr);
  335. continue;
  336. }
  337. const yearmonth = colSetting.field.split('_')[0];
  338. const mode = colSetting.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. validText = ZhCalc.round(validText, 0);
  346. }
  347. plan_gcl = node.dgn_price && node.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(validText, node.dgn_price), 3) : 0;
  348. plan_tp = validText;
  349. } else {
  350. const reg = new RegExp('^([-]?)\\d+$');
  351. if (validText !== null && (!reg.test(validText))) {
  352. validText = ZhCalc.round(validText, 3);
  353. }
  354. plan_gcl = validText;
  355. plan_tp = node.dgn_price && node.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, node.dgn_price), 0) : 0;
  356. }
  357. const updateData = {
  358. lid: node.ledger_id,
  359. yearmonth,
  360. plan_gcl,
  361. plan_tp,
  362. };
  363. datas.push(updateData);
  364. node[yearmonth+'_gcl'] = plan_gcl;
  365. node[yearmonth+'_tp'] = plan_tp;
  366. bPaste = true;
  367. }
  368. if (bPaste) {
  369. filterNodes.push(node);
  370. }
  371. }
  372. }
  373. if (datas.length > 0) {
  374. postData(window.location.pathname + '/save', {type: 'ledger_paste', postData: datas}, function (result) {
  375. for (const uul of filterNodes) {
  376. const nodes = treeCalc.calculateParent(info.sheet.zh_tree, uul, 1);
  377. const refreshNode = ledgerTree.loadPostData({update: nodes});
  378. ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
  379. }
  380. SpreadJsObj.reLoadSheetData(info.sheet);
  381. }, function () {
  382. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  383. });
  384. } else {
  385. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  386. }
  387. },
  388. };
  389. ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerSpreadObj.editEnded);
  390. SpreadJsObj.addDeleteBind(ledgerSpread, ledgerSpreadObj.deletePress);
  391. ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerSpreadObj.clipboardPasted);
  392. // 进度计算方式选择
  393. $('.mode-select').on('click', function () {
  394. const _self = $(this);
  395. const this_mode = _self.data('mode');
  396. // 重新计算所有未使用的月份数据
  397. const under_ledger = _.filter(ledgerTree.nodes, { is_leaf: true});
  398. const update_nodes = [];
  399. const newMonthList = _.map(_.filter(scheduleMonth, function (item) {
  400. return item.stage_gcl_used === 0 && item.stage_tp_used === 0;
  401. }), 'yearmonth');
  402. for (const ul of under_ledger) {
  403. for (const m of newMonthList) {
  404. if (ul[m+'_tp'] || ul[m+'_gcl']) {
  405. update_nodes.push(ul);
  406. break;
  407. }
  408. }
  409. }
  410. const update_under_ledger = [];
  411. if(update_nodes.length > 0) {
  412. for (const un of update_nodes) {
  413. if (this_mode === mode.gcl) {
  414. for (const m of newMonthList) {
  415. if(un[m+'_tp']) {
  416. un[m+'_tp'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(un[m+'_gcl'], un.dgn_price), 0) : 0;
  417. update_under_ledger.push({lid: un.ledger_id, yearmonth: m, plan_tp: un[m+'_tp'], plan_gcl: un[m+'_gcl']});
  418. }
  419. }
  420. } else {
  421. for (const m of newMonthList) {
  422. if(un[m+'_gcl']) {
  423. un[m+'_gcl'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(un[m+'_tp'], un.dgn_price), 3) : 0;
  424. update_under_ledger.push({lid: un.ledger_id, yearmonth: m, plan_tp: un[m+'_tp'], plan_gcl: un[m+'_gcl']});
  425. }
  426. }
  427. }
  428. }
  429. }
  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, 1);
  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. if (one) {
  489. hadmonth.push(m);
  490. }
  491. }
  492. if (hadmonth.length > 0) {
  493. let html = '';
  494. for (const hm of hadmonth) {
  495. html += `<div class="alert alert-danger">${hm} 已创建</div>`;
  496. }
  497. $('#add-month-error-list').html(html);
  498. $('#add-month-error-list').show();
  499. return;
  500. }
  501. } else {
  502. toastr.error('请选择计划周期时间');
  503. return;
  504. }
  505. $('#add-month-error-list').html('');
  506. $('#add-month-error-list').hide();
  507. const _self = $(this);
  508. postData(window.location.pathname + '/save', {type: 'addmonth', postData: addMonthList}, function (result) {
  509. _self.addClass('disabled').attr('disabled', true);
  510. toastr.success('新增成功');
  511. setTimeout(function () {
  512. window.location.reload();
  513. }, 500)
  514. })
  515. });
  516. $('#month-table input[type="checkbox"]').click(function () {
  517. const selectedMonth = [];
  518. $('#month-table input:checkbox:checked').each(function () {
  519. selectedMonth.push('「' + $(this).parents('td').siblings('td').text() + '」');
  520. });
  521. if(selectedMonth.length > 0) {
  522. $('#del-month-list').text(selectedMonth.join(''));
  523. $('#del-month-list').parent().show();
  524. $('#del-month').removeAttr('disabled');
  525. } else {
  526. $('#del-month-list').parent().hide();
  527. $('#del-month').attr('disabled', true);
  528. }
  529. });
  530. $('#del-month').click(function () {
  531. const selectedMonth = [];
  532. $('#month-table input:checkbox:checked').each(function () {
  533. selectedMonth.push($(this).parents('td').siblings().text());
  534. });
  535. if (selectedMonth.length === 0) {
  536. toastr.error('请选择删除的计划周期');
  537. return;
  538. }
  539. const _self = $(this);
  540. postData(window.location.pathname + '/save', {type: 'delmonth', postData: selectedMonth}, function (result) {
  541. _self.addClass('disabled').attr('disabled', true);
  542. toastr.success('删除成功');
  543. setTimeout(function () {
  544. window.location.reload();
  545. }, 500)
  546. })
  547. });
  548. $.subMenu({
  549. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  550. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  551. key: 'menu.1.0.0',
  552. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  553. callback: function (info) {
  554. if (info.mini) {
  555. $('.panel-title').addClass('fluid');
  556. $('#sub-menu').removeClass('panel-sidebar');
  557. } else {
  558. $('.panel-title').removeClass('fluid');
  559. $('#sub-menu').addClass('panel-sidebar');
  560. }
  561. ledgerSpread.refresh();
  562. autoFlashHeight();
  563. }
  564. });
  565. });
  566. // 月份间隔
  567. function getDistanceMonth(startTime,endTime){
  568. startTime = new Date(startTime);
  569. endTime = new Date(endTime);
  570. var dateToMonth = 0;
  571. var startDate=startTime.getDate() + startTime.getHours()/24 + startTime.getMinutes()/24/60;
  572. var endDate=endTime.getDate() +endTime.getHours()/24 + endTime.getMinutes()/24/60;
  573. if(endDate >= startDate){
  574. dateToMonth = 0;
  575. }else{
  576. dateToMonth = -1;
  577. }
  578. let yearToMonth = (endTime.getYear() - startTime.getYear()) * 12;
  579. let monthToMonth = endTime.getMonth() - startTime.getMonth();
  580. return yearToMonth + monthToMonth + dateToMonth;
  581. }
  582. function setLeafData(tree) {
  583. const newtree = [];
  584. for (const t of tree) {
  585. const child = _.find(tree, { 'ledger_pid': t.ledger_id });
  586. if (!child && !t.is_leaf) {
  587. t.is_leaf = true;
  588. }
  589. newtree.push(t);
  590. }
  591. return newtree;
  592. }
  593. function setMonthToLedger(ledgerList, slm) {
  594. if (slm.length > 0) {
  595. for(const s of slm) {
  596. const index = _.findIndex(ledgerList, { 'ledger_id': s.lid });
  597. if (index && index !== -1) {
  598. ledgerList[index][s.yearmonth + '_tp'] = s.plan_tp;
  599. ledgerList[index][s.yearmonth + '_gcl'] = s.plan_gcl;
  600. }
  601. }
  602. }
  603. return ledgerList;
  604. }
  605. const is_numeric = (value) => {
  606. if (typeof(value) === 'object') {
  607. return false;
  608. } else {
  609. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  610. }
  611. };