schedule_plan.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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);
  253. const refreshNode = ledgerTree.loadPostData({update: nodes});
  254. ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
  255. },function () {
  256. select[col.field] = orgValue;
  257. const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select);
  258. const refreshNode = ledgerTree.loadPostData({update: nodes});
  259. ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
  260. })
  261. }
  262. },
  263. deletePress: function (sheet) {
  264. if (!sheet.zh_setting) return;
  265. if (sheet.zh_setting && sheet.zh_tree) {
  266. const sel = sheet.getSelections()[0], datas = [], filterNodes = [];
  267. if (!sel) return;
  268. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  269. let bDel = false;
  270. const node = sheet.zh_tree.nodes[iRow];
  271. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  272. const col = sheet.zh_setting.cols[iCol];
  273. const orgValue = node[col.field];
  274. if (!orgValue) {
  275. continue;
  276. }
  277. const yearmonth = col.field.split('_')[0];
  278. const modes = col.field.split('_')[1];
  279. if(col.readOnly === true || !node.is_leaf || mode[modes] !== schedule.mode) {
  280. continue;
  281. }
  282. const updateData = {
  283. lid: node.ledger_id,
  284. yearmonth,
  285. plan_gcl: null,
  286. plan_tp: null,
  287. };
  288. datas.push(updateData);
  289. node[yearmonth+'_gcl'] = null;
  290. node[yearmonth+'_tp'] = null;
  291. bDel = true;
  292. }
  293. if (bDel) filterNodes.push(node);
  294. }
  295. if (datas.length > 0) {
  296. postData(window.location.pathname + '/save', {type: 'ledger_paste', postData: datas}, function (result) {
  297. for (const uul of filterNodes) {
  298. const nodes = treeCalc.calculateParent(sheet.zh_tree, uul);
  299. const refreshNode = ledgerTree.loadPostData({update: nodes});
  300. ledgerSpreadObj.refreshTree(sheet, refreshNode);
  301. }
  302. SpreadJsObj.reLoadSheetData(sheet);
  303. }, function () {
  304. SpreadJsObj.reLoadSheetData(sheet);
  305. });
  306. }
  307. }
  308. },
  309. clipboardPasted(e, info) {
  310. const hint = {
  311. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  312. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  313. };
  314. const tree = info.sheet.zh_tree;
  315. if (!tree) { return; }
  316. const sortData = info.sheet.zh_tree.nodes;
  317. const datas = [], filterNodes = [];
  318. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  319. let bPaste = false;
  320. const curRow = info.cellRange.row + iRow;
  321. const node = sortData[curRow];
  322. if (node) {
  323. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  324. const curCol = info.cellRange.col + iCol;
  325. const colSetting = info.sheet.zh_setting.cols[curCol];
  326. 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);
  327. const orgValue = node[colSetting.field];
  328. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  329. continue;
  330. }
  331. if (isNaN(validText)) {
  332. toastMessageUniq(hint.numberExpr);
  333. continue;
  334. }
  335. const yearmonth = colSetting.field.split('_')[0];
  336. const mode = colSetting.field.split('_')[1];
  337. let plan_gcl = 0;
  338. let plan_tp = 0;
  339. // 判断输入位数,提示
  340. if (mode === 'tp') {
  341. const reg = new RegExp('^([-]?)\\d+$');
  342. if (validText !== null && (!reg.test(validText))) {
  343. validText = ZhCalc.round(validText, 0);
  344. }
  345. plan_gcl = node.dgn_price && node.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(validText, node.dgn_price), 3) : 0;
  346. plan_tp = validText;
  347. } else {
  348. const reg = new RegExp('^([-]?)\\d+$');
  349. if (validText !== null && (!reg.test(validText))) {
  350. validText = ZhCalc.round(validText, 3);
  351. }
  352. plan_gcl = validText;
  353. plan_tp = node.dgn_price && node.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, node.dgn_price), 0) : 0;
  354. }
  355. const updateData = {
  356. lid: node.ledger_id,
  357. yearmonth,
  358. plan_gcl,
  359. plan_tp,
  360. };
  361. datas.push(updateData);
  362. node[yearmonth+'_gcl'] = plan_gcl;
  363. node[yearmonth+'_tp'] = plan_tp;
  364. bPaste = true;
  365. }
  366. if (bPaste) {
  367. filterNodes.push(node);
  368. }
  369. }
  370. }
  371. if (datas.length > 0) {
  372. postData(window.location.pathname + '/save', {type: 'ledger_paste', postData: datas}, function (result) {
  373. for (const uul of filterNodes) {
  374. const nodes = treeCalc.calculateParent(info.sheet.zh_tree, uul);
  375. const refreshNode = ledgerTree.loadPostData({update: nodes});
  376. ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
  377. }
  378. SpreadJsObj.reLoadSheetData(info.sheet);
  379. }, function () {
  380. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  381. });
  382. } else {
  383. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  384. }
  385. },
  386. };
  387. ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerSpreadObj.editEnded);
  388. SpreadJsObj.addDeleteBind(ledgerSpread, ledgerSpreadObj.deletePress);
  389. ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerSpreadObj.clipboardPasted);
  390. // 进度计算方式选择
  391. $('.mode-select').on('click', function () {
  392. const _self = $(this);
  393. const this_mode = _self.data('mode');
  394. // 重新计算所有未使用的月份数据
  395. const under_ledger = _.filter(ledgerTree.nodes, { is_leaf: true});
  396. const update_nodes = [];
  397. const newMonthList = _.map(_.filter(scheduleMonth, function (item) {
  398. return item.stage_gcl_used === 0 && item.stage_tp_used === 0;
  399. }), 'yearmonth');
  400. for (const ul of under_ledger) {
  401. for (const m of newMonthList) {
  402. if (ul[m+'_tp'] || ul[m+'_gcl']) {
  403. update_nodes.push(ul);
  404. break;
  405. }
  406. }
  407. }
  408. const update_under_ledger = [];
  409. if(update_nodes.length > 0) {
  410. for (const un of update_nodes) {
  411. if (this_mode === mode.gcl) {
  412. for (const m of newMonthList) {
  413. if(un[m+'_tp']) {
  414. un[m+'_tp'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(un[m+'_gcl'], un.dgn_price), 0) : 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. } else {
  419. for (const m of newMonthList) {
  420. if(un[m+'_gcl']) {
  421. un[m+'_gcl'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(un[m+'_tp'], un.dgn_price), 3) : 0;
  422. update_under_ledger.push({lid: un.ledger_id, yearmonth: m, plan_tp: un[m+'_tp'], plan_gcl: un[m+'_gcl']});
  423. }
  424. }
  425. }
  426. }
  427. }
  428. postData(window.location.pathname + '/save', {type: 'mode', postData: {mode: this_mode, update_under_ledger}}, function (result) {
  429. _self.addClass('disabled').attr('disabled', true);
  430. _self.text('当前');
  431. _self.parents('.col-6').siblings('.col-6').find('button').removeClass('disabled').removeAttr('disabled');
  432. _self.parents('.col-6').siblings('.col-6').find('button').text('选择');
  433. $('#mode-tips').show();
  434. $('#mode-cancel').show();
  435. $('#mode').modal('hide');
  436. schedule.mode = this_mode;
  437. if (update_nodes.length > 0) {
  438. for (const uul of update_nodes) {
  439. const nodes = treeCalc.calculateParent(ledgerSpread.getActiveSheet().zh_tree, uul);
  440. const refreshNode = ledgerTree.loadPostData({update: nodes});
  441. ledgerSpreadObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  442. }
  443. }
  444. SpreadJsObj.reLoadSheetData(ledgerSpread.getActiveSheet());
  445. })
  446. });
  447. // 月份添加
  448. $('#add-month').click(function () {
  449. const range = $('#month-range').val();
  450. if(range === '') {
  451. toastr.error('请选择计划周期时间');
  452. return;
  453. }
  454. const addMonthList = [];
  455. const cycle = range.split(' ~ ');
  456. if(cycle.length === 1) {
  457. addMonthList.push(cycle[0]);
  458. } else {
  459. // 多个月份
  460. const back_year = parseInt(cycle[1].split('-')[0]);
  461. const back_month = parseInt(cycle[1].split('-')[1]);
  462. const front_year = parseInt(cycle[0].split('-')[0]);
  463. const front_month = parseInt(cycle[0].split('-')[1]);
  464. if(back_year > front_year) {
  465. const num = getDistanceMonth(cycle[0], cycle[1]);
  466. let j = 1;
  467. for (let i = 0; i <= num; i++) {
  468. if(front_month + i > 12*j) {
  469. j = j + 1;
  470. }
  471. const m = (front_month + i)%12 === 0 ? 12 : (front_month + i)%12;
  472. addMonthList.push((front_year + (j-1)) + '-' + (m < 10 ? '0' + m : m));
  473. }
  474. } else if (back_year === front_year) {
  475. // 小于1年并没有跨年
  476. for (let i = front_month; i <= back_month; i++) {
  477. addMonthList.push(back_year + '-' + (i < 10 ? '0' + i : i));
  478. }
  479. }
  480. }
  481. // 判断是否已添加本月份
  482. if (addMonthList.length > 0) {
  483. const hadmonth = [];
  484. for (const m of addMonthList) {
  485. const one = _.find(scheduleMonth, { yearmonth: m });
  486. if (one) {
  487. hadmonth.push(m);
  488. }
  489. }
  490. if (hadmonth.length > 0) {
  491. let html = '';
  492. for (const hm of hadmonth) {
  493. html += `<div class="alert alert-danger">${hm} 已创建</div>`;
  494. }
  495. $('#add-month-error-list').html(html);
  496. $('#add-month-error-list').show();
  497. return;
  498. }
  499. } else {
  500. toastr.error('请选择计划周期时间');
  501. return;
  502. }
  503. $('#add-month-error-list').html('');
  504. $('#add-month-error-list').hide();
  505. const _self = $(this);
  506. postData(window.location.pathname + '/save', {type: 'addmonth', postData: addMonthList}, function (result) {
  507. _self.addClass('disabled').attr('disabled', true);
  508. toastr.success('新增成功');
  509. setTimeout(function () {
  510. window.location.reload();
  511. }, 500)
  512. })
  513. });
  514. $('#month-table input[type="checkbox"]').click(function () {
  515. const selectedMonth = [];
  516. $('#month-table input:checkbox:checked').each(function () {
  517. selectedMonth.push('「' + $(this).parents('td').siblings('td').text() + '」');
  518. });
  519. if(selectedMonth.length > 0) {
  520. $('#del-month-list').text(selectedMonth.join(''));
  521. $('#del-month-list').parent().show();
  522. $('#del-month').removeAttr('disabled');
  523. } else {
  524. $('#del-month-list').parent().hide();
  525. $('#del-month').attr('disabled', true);
  526. }
  527. });
  528. $('#del-month').click(function () {
  529. const selectedMonth = [];
  530. $('#month-table input:checkbox:checked').each(function () {
  531. selectedMonth.push($(this).parents('td').siblings().text());
  532. });
  533. if (selectedMonth.length === 0) {
  534. toastr.error('请选择删除的计划周期');
  535. return;
  536. }
  537. const _self = $(this);
  538. postData(window.location.pathname + '/save', {type: 'delmonth', postData: selectedMonth}, function (result) {
  539. _self.addClass('disabled').attr('disabled', true);
  540. toastr.success('删除成功');
  541. setTimeout(function () {
  542. window.location.reload();
  543. }, 500)
  544. })
  545. });
  546. $.subMenu({
  547. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  548. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  549. key: 'menu.1.0.0',
  550. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  551. callback: function (info) {
  552. if (info.mini) {
  553. $('.panel-title').addClass('fluid');
  554. $('#sub-menu').removeClass('panel-sidebar');
  555. } else {
  556. $('.panel-title').removeClass('fluid');
  557. $('#sub-menu').addClass('panel-sidebar');
  558. }
  559. ledgerSpread.refresh();
  560. autoFlashHeight();
  561. }
  562. });
  563. });
  564. // 月份间隔
  565. function getDistanceMonth(startTime,endTime){
  566. startTime = new Date(startTime);
  567. endTime = new Date(endTime);
  568. var dateToMonth = 0;
  569. var startDate=startTime.getDate() + startTime.getHours()/24 + startTime.getMinutes()/24/60;
  570. var endDate=endTime.getDate() +endTime.getHours()/24 + endTime.getMinutes()/24/60;
  571. if(endDate >= startDate){
  572. dateToMonth = 0;
  573. }else{
  574. dateToMonth = -1;
  575. }
  576. let yearToMonth = (endTime.getYear() - startTime.getYear()) * 12;
  577. let monthToMonth = endTime.getMonth() - startTime.getMonth();
  578. return yearToMonth + monthToMonth + dateToMonth;
  579. }
  580. function setLeafData(tree) {
  581. const newtree = [];
  582. for (const t of tree) {
  583. const child = _.find(tree, { 'ledger_pid': t.ledger_id });
  584. if (!child && !t.is_leaf) {
  585. t.is_leaf = true;
  586. }
  587. newtree.push(t);
  588. }
  589. return newtree;
  590. }
  591. function setMonthToLedger(ledgerList, slm) {
  592. if (slm.length > 0) {
  593. for(const s of slm) {
  594. const index = _.findIndex(ledgerList, { 'ledger_id': s.lid });
  595. if (index && index !== -1) {
  596. ledgerList[index][s.yearmonth + '_tp'] = s.plan_tp;
  597. ledgerList[index][s.yearmonth + '_gcl'] = s.plan_gcl;
  598. }
  599. }
  600. }
  601. return ledgerList;
  602. }
  603. const is_numeric = (value) => {
  604. if (typeof(value) === 'object') {
  605. return false;
  606. } else {
  607. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  608. }
  609. };