schedule_plan.js 27 KB

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