schedule_plan.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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-plan',
  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. const newMonthList = _.map(_.filter(scheduleMonth, function (item) {
  394. return item.stage_gcl_used === 0 && item.stage_tp_used === 0;
  395. }), 'yearmonth');
  396. for (const ul of under_ledger) {
  397. for (const m of newMonthList) {
  398. if (ul[m+'_tp'] || ul[m+'_gcl']) {
  399. update_nodes.push(ul);
  400. break;
  401. }
  402. }
  403. }
  404. const update_under_ledger = [];
  405. if(update_nodes.length > 0) {
  406. for (const un of update_nodes) {
  407. if (this_mode === mode.gcl) {
  408. for (const m of newMonthList) {
  409. if(un[m+'_tp']) {
  410. un[m+'_tp'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(un[m+'_gcl'], un.dgn_price), 0) : 0;
  411. update_under_ledger.push({lid: un.ledger_id, yearmonth: m, plan_tp: un[m+'_tp'], plan_gcl: un[m+'_gcl']});
  412. }
  413. }
  414. } else {
  415. for (const m of newMonthList) {
  416. if(un[m+'_gcl']) {
  417. un[m+'_gcl'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(un[m+'_tp'], un.dgn_price), 3) : 0;
  418. update_under_ledger.push({lid: un.ledger_id, yearmonth: m, plan_tp: un[m+'_tp'], plan_gcl: un[m+'_gcl']});
  419. }
  420. }
  421. }
  422. }
  423. }
  424. console.log(update_under_ledger);
  425. postData(window.location.pathname + '/save', {type: 'mode', postData: {mode: this_mode, update_under_ledger}}, function (result) {
  426. _self.addClass('disabled').attr('disabled', true);
  427. _self.text('当前');
  428. _self.parents('.col-6').siblings('.col-6').find('button').removeClass('disabled').removeAttr('disabled');
  429. _self.parents('.col-6').siblings('.col-6').find('button').text('选择');
  430. $('#mode-tips').show();
  431. $('#mode-cancel').show();
  432. $('#mode').modal('hide');
  433. schedule.mode = this_mode;
  434. if (update_nodes.length > 0) {
  435. for (const uul of update_nodes) {
  436. const nodes = treeCalc.calculateParent(ledgerSpread.getActiveSheet().zh_tree, uul);
  437. const refreshNode = ledgerTree.loadPostData({update: nodes});
  438. ledgerSpreadObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  439. }
  440. }
  441. SpreadJsObj.reLoadSheetData(ledgerSpread.getActiveSheet());
  442. })
  443. });
  444. // 月份添加
  445. $('#add-month').click(function () {
  446. const range = $('#month-range').val();
  447. if(range === '') {
  448. toastr.error('请选择计划周期时间');
  449. return;
  450. }
  451. const addMonthList = [];
  452. const cycle = range.split(' ~ ');
  453. if(cycle.length === 1) {
  454. addMonthList.push(cycle[0]);
  455. } else {
  456. // 多个月份
  457. const back_year = parseInt(cycle[1].split('-')[0]);
  458. const back_month = parseInt(cycle[1].split('-')[1]);
  459. const front_year = parseInt(cycle[0].split('-')[0]);
  460. const front_month = parseInt(cycle[0].split('-')[1]);
  461. if(back_year > front_year) {
  462. const num = getDistanceMonth(cycle[0], cycle[1]);
  463. let j = 1;
  464. for (let i = 0; i <= num; i++) {
  465. if(front_month + i > 12*j) {
  466. j = j + 1;
  467. }
  468. const m = (front_month + i)%12 === 0 ? 12 : (front_month + i)%12;
  469. addMonthList.push((front_year + (j-1)) + '-' + (m < 10 ? '0' + m : m));
  470. }
  471. } else if (back_year === front_year) {
  472. // 小于1年并没有跨年
  473. for (let i = front_month; i <= back_month; i++) {
  474. addMonthList.push(back_year + '-' + (i < 10 ? '0' + i : i));
  475. }
  476. }
  477. }
  478. // 判断是否已添加本月份
  479. if (addMonthList.length > 0) {
  480. const hadmonth = [];
  481. for (const m of addMonthList) {
  482. const one = _.find(scheduleMonth, { yearmonth: m });
  483. console.log(one, m);
  484. if (one) {
  485. hadmonth.push(m);
  486. }
  487. }
  488. if (hadmonth.length > 0) {
  489. let html = '';
  490. for (const hm of hadmonth) {
  491. html += `<div class="alert alert-danger">${hm} 已创建</div>`;
  492. }
  493. $('#add-month-error-list').html(html);
  494. $('#add-month-error-list').show();
  495. return;
  496. }
  497. } else {
  498. toastr.error('请选择计划周期时间');
  499. return;
  500. }
  501. $('#add-month-error-list').html('');
  502. $('#add-month-error-list').hide();
  503. const _self = $(this);
  504. postData(window.location.pathname + '/save', {type: 'addmonth', postData: addMonthList}, function (result) {
  505. _self.addClass('disabled').attr('disabled', true);
  506. toastr.success('新增成功');
  507. setTimeout(function () {
  508. window.location.reload();
  509. }, 500)
  510. })
  511. });
  512. $('#month-table input[type="checkbox"]').click(function () {
  513. const selectedMonth = [];
  514. $('#month-table input:checkbox:checked').each(function () {
  515. selectedMonth.push('「' + $(this).parents('td').siblings('td').text() + '」');
  516. });
  517. if(selectedMonth.length > 0) {
  518. $('#del-month-list').text(selectedMonth.join(''));
  519. $('#del-month-list').parent().show();
  520. $('#del-month').removeAttr('disabled');
  521. } else {
  522. $('#del-month-list').parent().hide();
  523. $('#del-month').attr('disabled', true);
  524. }
  525. });
  526. $('#del-month').click(function () {
  527. const selectedMonth = [];
  528. $('#month-table input:checkbox:checked').each(function () {
  529. selectedMonth.push($(this).parents('td').siblings().text());
  530. });
  531. if (selectedMonth.length === 0) {
  532. toastr.error('请选择删除的计划周期');
  533. return;
  534. }
  535. const _self = $(this);
  536. postData(window.location.pathname + '/save', {type: 'delmonth', postData: selectedMonth}, function (result) {
  537. _self.addClass('disabled').attr('disabled', true);
  538. toastr.success('删除成功');
  539. setTimeout(function () {
  540. window.location.reload();
  541. }, 500)
  542. })
  543. });
  544. $.subMenu({
  545. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  546. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  547. key: 'menu.1.0.0',
  548. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  549. callback: function (info) {
  550. if (info.mini) {
  551. $('.panel-title').addClass('fluid');
  552. $('#sub-menu').removeClass('panel-sidebar');
  553. } else {
  554. $('.panel-title').removeClass('fluid');
  555. $('#sub-menu').addClass('panel-sidebar');
  556. }
  557. ledgerSpread.refresh();
  558. autoFlashHeight();
  559. }
  560. });
  561. });
  562. // 月份间隔
  563. function getDistanceMonth(startTime,endTime){
  564. startTime = new Date(startTime);
  565. endTime = new Date(endTime);
  566. var dateToMonth = 0;
  567. var startDate=startTime.getDate() + startTime.getHours()/24 + startTime.getMinutes()/24/60;
  568. var endDate=endTime.getDate() +endTime.getHours()/24 + endTime.getMinutes()/24/60;
  569. if(endDate >= startDate){
  570. dateToMonth = 0;
  571. }else{
  572. dateToMonth = -1;
  573. }
  574. let yearToMonth = (endTime.getYear() - startTime.getYear()) * 12;
  575. let monthToMonth = endTime.getMonth() - startTime.getMonth();
  576. return yearToMonth + monthToMonth + dateToMonth;
  577. }
  578. function setLeafData(tree) {
  579. const newtree = [];
  580. for (const t of tree) {
  581. const child = _.find(tree, { 'ledger_pid': t.ledger_id });
  582. if (!child && !t.is_leaf) {
  583. t.is_leaf = true;
  584. }
  585. newtree.push(t);
  586. }
  587. return newtree;
  588. }
  589. function setMonthToLedger(ledgerList, slm) {
  590. if (slm.length > 0) {
  591. for(const s of slm) {
  592. const index = _.findIndex(ledgerList, { 'ledger_id': s.lid });
  593. if (index && index !== -1) {
  594. ledgerList[index][s.yearmonth + '_tp'] = s.plan_tp;
  595. ledgerList[index][s.yearmonth + '_gcl'] = s.plan_gcl;
  596. }
  597. }
  598. }
  599. return ledgerList;
  600. }
  601. const is_numeric = (value) => {
  602. if (typeof(value) === 'object') {
  603. return false;
  604. } else {
  605. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  606. }
  607. };