change_information_set.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  1. 'use strict';
  2. /**
  3. * 变更令详细页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. // 编号排序,多重判断
  10. function sortByCode(a, b) {
  11. let code1 = a.code.split('-');
  12. let code2 = b.code.split('-');
  13. let code1length = code1.length;
  14. let code2length = code2.length;
  15. for (let i = 0; i < code1length; i ++) {
  16. if (i+1 <= code2length) {
  17. if (code1[i] != code2[i]) {
  18. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  19. return parseInt(code1[i]) - parseInt(code2[i]);
  20. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  21. return 1;
  22. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  23. return -1;
  24. } else {
  25. const str1length = code1[i].length;
  26. const str2length = code2[i].length;
  27. for (let j = 0; j < str1length; j++) {
  28. if (j+1 <= str2length) {
  29. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  30. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  31. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  32. if (str1length == str2length) {
  33. return 0;
  34. } else {
  35. return str1length - str2length;
  36. }
  37. }
  38. } else {
  39. if (j+1 >= str1length) {
  40. return 1;
  41. } else {
  42. return -1;
  43. }
  44. }
  45. }
  46. }
  47. } else if (i+1 == code1length && code1[i] == code2[i]) {
  48. if (code1length == code2length) {
  49. return 0;
  50. } else {
  51. return code1length - code2length;
  52. }
  53. }
  54. } else {
  55. if (i+1 >= code1length) {
  56. return 1;
  57. } else {
  58. return -1;
  59. }
  60. }
  61. }
  62. }
  63. $.event.special.valuechange = {
  64. teardown: function (namespaces) {
  65. $(this).unbind('.valuechange');
  66. },
  67. handler: function (e) {
  68. $.event.special.valuechange.triggerChanged($(this));
  69. },
  70. add: function (obj) {
  71. $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
  72. },
  73. triggerChanged: function (element) {
  74. var current = element[0].contentEditable === 'true' ? element.html() : element.val()
  75. , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
  76. if (current !== previous) {
  77. element.trigger('valuechange', [element.data('previous')]);
  78. element.data('previous', current);
  79. }
  80. }
  81. };
  82. function getPasteHint (str, row = '') {
  83. let returnObj = str;
  84. if (row) {
  85. returnObj.msg = '清单第' + (row+1) + '行' + str.msg;
  86. }
  87. return returnObj;
  88. }
  89. $(document).ready(() => {
  90. const changeSpreadSetting = {
  91. cols: [
  92. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit2'},
  93. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit2'},
  94. {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  95. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: false},
  96. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit2', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  97. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit2', getValue: 'getValue.unit_price'},
  98. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
  99. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  100. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: false, getValue: 'getValue.camount'},
  101. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  102. {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
  103. ],
  104. emptyRows: 0,
  105. headRows: 2,
  106. headRowHeight: [25, 25],
  107. defaultRowHeight: 21,
  108. headerFont: '12px 微软雅黑',
  109. font: '12px 微软雅黑',
  110. readOnly: readOnly,
  111. rowHeader:[
  112. {
  113. rowHeaderType: 'circle',
  114. setting: {
  115. size: 5,
  116. indent: 16,
  117. getColor: function (index, data) {
  118. if (!data) return;
  119. if(data.lid != 0) return;
  120. return '#007bff';
  121. }
  122. },
  123. },
  124. ],
  125. localCache: {
  126. key: 'changes-spread',
  127. colWidth: true,
  128. }
  129. };
  130. const changeCol = {
  131. getValue: {
  132. unit_price: function(data) {
  133. return ZhCalc.round(data.unit_price, unitPriceUnit);
  134. },
  135. oa_tp: function (data) {
  136. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
  137. },
  138. ca_tp: function (data) {
  139. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
  140. },
  141. oamount: function (data) {
  142. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  143. },
  144. camount: function (data) {
  145. return ZhCalc.round(data.camount, findDecimal(data.unit));
  146. },
  147. del_list: function (data) {
  148. return !_.find(changeUsedData, { id: data.id }) ? '移除' : '';
  149. }
  150. },
  151. readOnly: {
  152. isEdit: function (data) {
  153. return !readOnly && data.lid != 0;
  154. },
  155. isEdit2: function (data) {
  156. return !readOnly && (data.lid != 0 || (data.lid == 0 && _.findIndex(changeUsedData, { id: data.id }) !== -1));
  157. },
  158. },
  159. };
  160. const changeSpreadObj = {
  161. makeSjsFooter: function () {
  162. // 增加汇总行并设为锁定禁止编辑状态
  163. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  164. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  165. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  166. changeSpreadObj.countSum();
  167. },
  168. countSum: function() {
  169. const rowCount = changeSpreadSheet.getRowCount();
  170. let oSum = 0,
  171. cSum = 0;
  172. for(var i = 0; i < rowCount - 1; i++){
  173. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
  174. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
  175. }
  176. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
  177. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
  178. },
  179. add: function () {
  180. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  181. if (result) {
  182. changeList.push(result);
  183. changeSpreadSheet.addRows(changeList.length - 1, 1);
  184. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  185. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  186. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  187. changeSpreadObj.resetXmjSpread();
  188. }
  189. });
  190. },
  191. batchAdd: function(num) {
  192. postData(window.location.pathname + '/save', {type: 'batchadd', num}, function (result) {
  193. if (result) {
  194. changeList = _.concat(changeList, result);
  195. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  196. changeSpreadObj.makeSjsFooter();
  197. changeSpreadObj.resetXmjSpread();
  198. }
  199. });
  200. },
  201. del: function () {
  202. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  203. const index = changeList.indexOf(select);
  204. if (index > -1 && !_.find(changeUsedData, { id: select.id })) {
  205. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  206. changeList.splice(index, 1);
  207. changeSpreadSheet.deleteRows(index, 1);
  208. const sel = changeSpreadSheet.getSelections();
  209. changeSpreadSheet.setSelection(0, 0, 1, 1);
  210. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  211. if (select.lid != 0) {
  212. tableDataRemake(changeListData);
  213. }
  214. changeSpreadObj.countSum();
  215. });
  216. }
  217. },
  218. resetXmjSpread: function(data = null) {
  219. const xmj = [];
  220. if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) {
  221. const newData = JSON.parse(JSON.stringify(data));
  222. if (newData.bwmx === newData.xmj_jldy) {
  223. newData.bwmx = '';
  224. }
  225. xmj.push(newData);
  226. }
  227. SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);
  228. },
  229. selectionChanged: function (e, info) {
  230. const sel = info.sheet.getSelections()[0];
  231. const col = info.sheet.zh_setting.cols[sel.col];
  232. const data = SpreadJsObj.getSelectObject(info.sheet);
  233. if (col && col.field === 'del_list' && !_.find(changeUsedData, { id: data.id })) {
  234. changeSpreadObj.del();
  235. }
  236. changeSpreadObj.resetXmjSpread(data);
  237. },
  238. deletePress: function (sheet) {
  239. return;
  240. },
  241. editEnded: function (e, info) {
  242. if (info.sheet.zh_setting) {
  243. const select = SpreadJsObj.getSelectObject(info.sheet);
  244. const col = info.sheet.zh_setting.cols[info.col];
  245. if (col.field === 'del_list') {
  246. return;
  247. }
  248. // 未改变值则不提交
  249. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  250. const orgValue = select[col.field];
  251. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  252. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  253. return;
  254. }
  255. // 判断部分值是否输入的是数字判断和数据计算
  256. if (col.type === 'Number') {
  257. if (isNaN(validText)) {
  258. toastr.error('不能输入其它非数字类型字符');
  259. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  260. return;
  261. }
  262. if (col.field === 'unit_price') {
  263. validText = ZhCalc.round(validText, unitPriceUnit);
  264. } else {
  265. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  266. }
  267. }
  268. if (col.field === 'unit') {
  269. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  270. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  271. }
  272. if(col.field === 'camount') {
  273. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  274. const usedInfo = _.find(changeUsedData, { id: select.id });
  275. if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
  276. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  277. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  278. return;
  279. } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
  280. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  281. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  282. return;
  283. }
  284. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  285. }
  286. select[col.field] = validText;
  287. console.log(select);
  288. delete select.waitingLoading;
  289. // 更新至服务器
  290. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  291. changeList.splice(info.row, 1, select);
  292. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  293. changeSpreadObj.countSum();
  294. }, function () {
  295. select[col.field] = orgValue;
  296. if(col.field === 'camount') {
  297. select.spamount = orgValue;
  298. }
  299. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  300. });
  301. }
  302. },
  303. clipboardPasted(e, info) {
  304. const hint = {
  305. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  306. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  307. };
  308. const range = info.cellRange;
  309. const sortData = info.sheet.zh_data || [];
  310. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  311. toastMessageUniq(hint.cellError);
  312. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  313. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  314. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  315. changeSpreadObj.makeSjsFooter();
  316. return;
  317. }
  318. if (sortData.length > 0 && range.col + range.colCount > 10) {
  319. toastMessageUniq(hint.cellError);
  320. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  321. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  322. changeSpreadObj.makeSjsFooter();
  323. return;
  324. }
  325. const data = [];
  326. // const rowData = [];
  327. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  328. let bPaste = true;
  329. const curRow = range.row + iRow;
  330. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  331. const cLData = { id: sortData[curRow].id };
  332. const hintRow = range.rowCount > 1 ? curRow : '';
  333. let sameCol = 0;
  334. for (let iCol = 0; iCol < range.colCount; iCol++) {
  335. const curCol = range.col + iCol;
  336. const colSetting = info.sheet.zh_setting.cols[curCol];
  337. if (!colSetting) continue;
  338. let validText = info.sheet.getText(curRow, curCol);
  339. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  340. const orgValue = sortData[curRow][colSetting.field];
  341. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  342. sameCol++;
  343. if (range.colCount === sameCol) {
  344. bPaste = false;
  345. }
  346. continue;
  347. }
  348. if (colSetting.type === 'Number') {
  349. if (isNaN(validText)) {
  350. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  351. bPaste = false;
  352. continue;
  353. }
  354. if (colSetting.field === 'unit_price') {
  355. validText = ZhCalc.round(validText, unitPriceUnit);
  356. } else {
  357. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  358. }
  359. if(colSetting.field === 'camount') {
  360. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  361. const usedInfo = _.find(changeUsedData, { id: sortData[curRow].id });
  362. if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
  363. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  364. bPaste = false;
  365. continue;
  366. } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
  367. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  368. bPaste = false;
  369. continue;
  370. }
  371. }
  372. }
  373. let unitdecimal = validText;
  374. if (colSetting.field === 'unit') {
  375. //粘贴内容要为下拉列表里所有的单位,不然为空
  376. if (changeUnits.indexOf(validText) === -1) {
  377. unitdecimal = '';
  378. }
  379. cLData.camount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  380. cLData.oamount = ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
  381. }
  382. cLData[colSetting.field] = validText;
  383. sortData[curRow][colSetting.field] = validText;
  384. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  385. }
  386. if (bPaste) {
  387. data.push(cLData);
  388. // rowData.push(curRow);
  389. } else {
  390. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  391. }
  392. }
  393. if (data.length === 0) {
  394. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  395. return;
  396. }
  397. console.log(data);
  398. // 更新至服务器
  399. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  400. changeList = result;
  401. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  402. changeSpreadObj.makeSjsFooter();
  403. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  404. }, function () {
  405. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  406. return;
  407. });
  408. },
  409. valueChanged(e, info) {
  410. // 防止ctrl+z撤销数据
  411. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  412. }
  413. };
  414. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  415. let changeListData;
  416. let gclGatherData;
  417. postData(preUrl + '/defaultBills', {}, function (result) {
  418. gclGatherModel.loadLedgerData(result.bills);
  419. gclGatherModel.loadPosData(result.pos);
  420. gclGatherData = gclGatherModel.gatherGclData();
  421. gclGatherData = _.filter(gclGatherData, function (item) {
  422. return item.leafXmjs && item.leafXmjs.length !== 0;
  423. });
  424. for (const ggd in gclGatherData) {
  425. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  426. gclGatherData.splice(ggd, 1);
  427. }
  428. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  429. }
  430. // 数组去重
  431. const dealBillList = result.dealBills;
  432. for (const db of gclGatherData) {
  433. const exist_index = dealBillList.findIndex(function (item) {
  434. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  435. });
  436. if (exist_index !== -1) {
  437. dealBillList.splice(exist_index, 1);
  438. }
  439. }
  440. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  441. console.log(changeListData);
  442. // 先加载台账数据
  443. let listHtml = '';
  444. let list_index = 1;
  445. let gcl_index = 0;
  446. for (const gcl of changeListData) {
  447. const unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
  448. const quantity = gcl.quantity !== 0 && gcl.quantity !== null && gcl.quantity !== undefined ? (unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity) : 0;
  449. const unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? gcl.unit_price : 0;
  450. let gclhtml = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? ' data-gcl="' + gcl_index + '"' : '';
  451. gcl_index = gclhtml !== '' ? ++gcl_index : gcl_index;
  452. const lid = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? (gcl.leafXmjs.length !== 0 ? gcl.leafXmjs[0].gcl_id : false) : gcl.id;
  453. if (lid) {
  454. listHtml += '<tr data-lid="' + lid + '"' + gclhtml + ' data-index="' + list_index + '" data-bwmx="">' +
  455. '<td class="text-center">' + list_index + '</td>' +
  456. '<td>' + gcl.code + '</td>' +
  457. '<td class="text-left">' + gcl.name + '</td>' +
  458. '<td class="text-center">' + unit + '</td>' +
  459. '<td class="text-right">' + (ZhCalc.round(unit_price, unitPriceUnit) ? ZhCalc.round(unit_price, unitPriceUnit) : 0) + '</td>' +
  460. '<td class="text-right">' + quantity + '</td>' +
  461. '</tr>';
  462. list_index++;
  463. }
  464. }
  465. $('#table-list-select').html(listHtml);
  466. tableDataRemake(changeListData);
  467. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  468. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  469. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  470. // changeSpreadSheet.options.protectionOptions = {
  471. // allowSort: true,
  472. // allowFilter: true
  473. // };
  474. // var option = changeSpreadSheet.options.protectionOptions;
  475. // changeSpreadSheet.rowFilter(new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, 0, -1, changeSpreadSetting.cols.length)));
  476. // // changeSpreadSheet.rowFilter(new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, 0, -1, 3)));
  477. // const filter = changeSpreadSheet.rowFilter();
  478. // filter.filterButtonVisible(false);
  479. // filter.filterButtonVisible(0, true);
  480. // filter.filterButtonVisible(2, true);
  481. // filter.filterDialogVisibleInfo({
  482. // sortByValue: true, //SortByValue item is visible.
  483. // sortByColor: false, //SortByColor item is visible.
  484. // filterByColor: false, //FilterByColor item is visible.
  485. // filterByValue: false, //FilterByValue item is visible.
  486. // listFilterArea: false //ListFilterArea item is visible.
  487. // });
  488. // function compareList(obj1, obj2) {
  489. // console.log(obj1, obj2);
  490. // var list = ["", '204-1-b', '合计'];
  491. // var index1 = list.indexOf(obj1), index2 = list.indexOf(obj2);
  492. // if (index1 > index2) {
  493. // return 1;
  494. // } else if (index1 < index2) {
  495. // return -1;
  496. // } else {
  497. // return 0;
  498. // }
  499. // }
  500. // changeSpreadSheet.sortRange(0, 0, changeSpreadSetting.cols.length, 1, true, [{index: 0, ascending: true, compareFunction: compareList}]);
  501. // changeSpreadSheet.bind(GC.Spread.Sheets.Events.RangeSorting, function (e, info) {
  502. // info.compareFunction = compareList;
  503. // });
  504. // filter.sortColumn(0, true);
  505. changeSpreadObj.makeSjsFooter();
  506. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  507. });
  508. if (!readOnly) {
  509. $('#add-white-btn').click(changeSpreadObj.add);
  510. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  511. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  512. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  513. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  514. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  515. changeSpreadSheet.getCell(-1, 10).foreColor('#dc3545');
  516. let batchInsertObj;
  517. $.contextMenu.types.batchInsert = function (item, opt, root) {
  518. const self = this;
  519. if ($.isFunction(item.icon)) {
  520. item._icon = item.icon.call(this, this, $t, key, item);
  521. } else {
  522. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  523. // to enable font awesome
  524. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  525. } else {
  526. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  527. }
  528. }
  529. this.addClass(item._icon);
  530. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="100" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  531. .appendTo(this);
  532. const $input = $obj.find('input');
  533. const event = () => {
  534. if (self.hasClass('context-menu-disabled')) return;
  535. item.batchInsert($input[0], root);
  536. };
  537. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  538. $input.click((e) => {e.stopPropagation();})
  539. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  540. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  541. };
  542. // 右键菜单
  543. $.contextMenu({
  544. selector: '#change-spread',
  545. build: function ($trigger, e) {
  546. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  547. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  548. },
  549. items: {
  550. 'createList': {
  551. name: '添加台账清单',
  552. icon: 'fa-sign-in',
  553. callback: function (key, opt) {
  554. $('#addlist').modal('show');
  555. },
  556. },
  557. 'createAdd': {
  558. name: '添加空白清单',
  559. icon: 'fa-sign-in',
  560. callback: function (key, opt) {
  561. changeSpreadObj.add(changeSpreadSheet);
  562. },
  563. },
  564. 'batchInsert': {
  565. name: '批量添加空白清单',
  566. type: 'batchInsert',
  567. value: '2',
  568. icon: 'fa-sign-in',
  569. batchInsert: function (obj, root) {
  570. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  571. obj.value = obj.max;
  572. toastr.warning('批量添加不可多于' + obj.max);
  573. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  574. obj.value = obj.min;
  575. toastr.warning('批量添加不可少于' + obj.min);
  576. } else {
  577. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  578. changeSpreadObj.batchAdd(obj.value);
  579. root.$menu.trigger('contextmenu:hide');
  580. }
  581. },
  582. },
  583. 'delete': {
  584. name: '删除',
  585. icon: 'fa-remove',
  586. callback: function (key, opt) {
  587. changeSpreadObj.del(changeSpreadSheet);
  588. },
  589. disabled: function (key, opt) {
  590. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  591. const sel = changeSpreadSheet.getSelections()[0];
  592. changeSpreadObj.resetXmjSpread(select);
  593. console.log(select, sel);
  594. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1 && !_.find(changeUsedData, { id: select.id })) {
  595. return false;
  596. } else {
  597. return true;
  598. }
  599. }
  600. },
  601. }
  602. });
  603. }
  604. // 清单选中和移除
  605. $('body').on('click', '#table-list-select tr', function () {
  606. $('#table-list-select tr').removeClass('table-warning');
  607. $(this).addClass('table-warning');
  608. const isCheck = $(this).hasClass('table-success') ? true : false;
  609. const data_bwmx = $(this).attr('data-bwmx').split('$#$');
  610. const isDeal = $(this).data('gcl') !== undefined ? true : false;
  611. let codeHtml = '<tr quantity="'+ $(this).children('td').eq(5).text() +'" gcl_id=""><td colspan="7" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox"></td></tr>';
  612. if (isDeal) {
  613. const lid = $(this).data('lid');
  614. let gcl = _.find(gclGatherData, function (item) {
  615. return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
  616. });
  617. if (!gcl) {
  618. gcl = gclGatherData[$(this).data('gcl')];
  619. }
  620. codeHtml = '';
  621. for (const leaf of gcl.leafXmjs) {
  622. const quantity = leaf.quantity !== undefined && leaf.quantity !== null ? leaf.quantity : 0;
  623. const gcl_id = leaf.gcl_id ? leaf.gcl_id : '';
  624. const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : (gcl.leafXmjs.length > 1 && gcl.name ? gcl.name : '');
  625. const isChecked = data_bwmx.indexOf(
  626. leaf.code + '!_!' + (leaf.jldy ? leaf.jldy : '') + '!_!' +
  627. (leaf.dwgc ? leaf.dwgc : '') + '!_!' + (leaf.fbgc ? leaf.fbgc : '') + '!_!' + (leaf.fxgc ? leaf.fxgc : '')
  628. + '!_!' + (leaf.gcl_id ? leaf.gcl_id : '0') + '!_!' +
  629. (bwmx !== '' ? bwmx : leaf.jldy ? leaf.jldy : '') + '*;*' + quantity) !== -1 && isCheck ?
  630. 'checked' : '';
  631. const isUsed = _.find(changeUsedData, { gcl_id: leaf.gcl_id, bwmx: (bwmx ? bwmx : leaf.jldy ? leaf.jldy : ''), oamount: leaf.quantity });
  632. const isDisabled = isUsed ? 'disabled ' : '';
  633. codeHtml += '<tr quantity="' + quantity + '" gcl_id="' + gcl_id + '"><td>' + leaf.code + '</td>' +
  634. '<td>' + (leaf.jldy ? leaf.jldy: '') + '</td>' +
  635. '<td>' + (leaf.dwgc ? leaf.dwgc : '') + '</td>' +
  636. '<td>' + (leaf.fbgc ? leaf.fbgc : '') + '</td>' +
  637. '<td>' + (leaf.fxgc ? leaf.fxgc : '') + '</td>' +
  638. '<td>' + bwmx + '</td>' +
  639. '<td class="text-right">' + (ZhCalc.round(quantity, findDecimal(gcl.unit)) ? ZhCalc.round(quantity, findDecimal(gcl.unit)) : 0) + '</td>' +
  640. '<td class="text-center"><input type="checkbox" ' + isDisabled + isChecked +
  641. '></td></tr>';
  642. }
  643. } else if (!isDeal && isCheck) {
  644. codeHtml = '<tr quantity="'+ $(this).children('td').eq(5).text() +'" gcl_id=""><td colspan="7" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox" checked></td></tr>';
  645. }
  646. $('#code-list').attr('data-index', $(this).children('td').eq(0).text());
  647. $('#code-input').val('');
  648. $('#code-input').siblings('a').hide();
  649. $('#code-list').html(codeHtml);
  650. checkSelectAll();
  651. });
  652. // 右边项目节选择
  653. $('body').on('click', '#code-list input', function () {
  654. let index = $('#code-list').attr('data-index');
  655. if ($(this).is(':checked')) {
  656. // 去除其它可能已选的checked
  657. // $('#code-list input').prop('checked', false);
  658. $(this).prop('checked', true);
  659. // 左边表单传值并添加class
  660. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  661. // 去除部分data-detail值
  662. let data_bwmx = [];
  663. $('#code-list input:checked').each(function () {
  664. const tr = $(this).parents('tr');
  665. const length = tr.children('td').length;
  666. const gcl_id = tr.attr('gcl_id');
  667. const bwmx = length === 8 ?
  668. tr.children('td').eq(0).text() + '!_!' +
  669. tr.children('td').eq(1).text() + '!_!' +
  670. tr.children('td').eq(2).text() + '!_!' +
  671. tr.children('td').eq(3).text() + '!_!' +
  672. tr.children('td').eq(4).text() + '!_!' + gcl_id + '!_!' +
  673. (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  674. const quantity = tr.attr('quantity');
  675. const de_qu = bwmx + '*;*' + quantity;
  676. data_bwmx.push(de_qu);
  677. });
  678. data_bwmx = data_bwmx.join('$#$');
  679. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  680. } else {
  681. // 判断还有无选中项目节编号
  682. if ($('#code-list input').is(':checked')) {
  683. // 去除部分data-detail值
  684. let data_bwmx = [];
  685. $('#code-list input:checked').each(function () {
  686. const tr = $(this).parents('tr');
  687. const length = tr.children('td').length;
  688. const gcl_id = tr.attr('gcl_id');
  689. const bwmx = length === 8 ?
  690. tr.children('td').eq(0).text() + '!_!' +
  691. tr.children('td').eq(1).text() + '!_!' +
  692. tr.children('td').eq(2).text() + '!_!' +
  693. tr.children('td').eq(3).text() + '!_!' +
  694. tr.children('td').eq(4).text() + '!_!' + gcl_id + '!_!' +
  695. (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  696. const quantity = tr.attr('quantity');
  697. const de_qu = bwmx + '*;*' + quantity;
  698. data_bwmx.push(de_qu);
  699. });
  700. data_bwmx = data_bwmx.join('$#$');
  701. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  702. } else {
  703. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  704. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  705. }
  706. }
  707. checkSelectAll();
  708. });
  709. // 添加空白清单or签约清单
  710. $('.add-list-btn').on('click', function () {
  711. const newLedgerList = remakeChangeSpread();
  712. // 更新至服务器
  713. postData(window.location.pathname + '/save', { type:'ledger_list', updateData: newLedgerList }, function (result) {
  714. changeList = result.changeList;
  715. changeUsedData = result.usedList;
  716. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  717. changeSpreadObj.makeSjsFooter();
  718. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  719. changeSpreadObj.resetXmjSpread(select);
  720. $('#addlist').modal('hide');
  721. }, function () {
  722. $('#addlist').modal('hide');
  723. });
  724. });
  725. // 选中input所有值
  726. $('body').on('focus', ".clist input", function() {
  727. $(this).select();
  728. });
  729. // 取消选中清单
  730. $('#cancel-list-btn').click(function () {
  731. // $('#table-list-select tr').removeClass('table-success');
  732. // $('#table-list-select tr').attr('data-bwmx', '');
  733. // $('#code-list').html('');
  734. tableDataRemake(changeListData);
  735. });
  736. // 自动编号
  737. $('.reduction-code').click(function () {
  738. const code = $(this).attr('data-code');
  739. $('input[name="code"]').val(code);
  740. });
  741. $('#list-input').on('valuechange', function (e, previous) {
  742. const value = $(this).val();
  743. let showListData = changeListData;
  744. if (value !== '') {
  745. $(this).siblings('a').show();
  746. showListData = _.filter(changeListData, function (c) {
  747. return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  748. });
  749. } else {
  750. $(this).siblings('a').hide();
  751. }
  752. makeListTable(changeListData, showListData);
  753. $('#table-list-select tr').removeClass('table-warning');
  754. $('#code-input').val('');
  755. $('#code-input').siblings('a').hide();
  756. $('#code-list').html('');
  757. $('#code-select-all').prop('checked', false);
  758. });
  759. $('#code-input').on('valuechange', function (e, previous) {
  760. const value = $(this).val();
  761. if (value !== '') {
  762. $(this).siblings('a').show();
  763. } else {
  764. $(this).siblings('a').hide();
  765. }
  766. makeCodeTable($(this).val());
  767. checkSelectAll();
  768. });
  769. $('.remove-btn').on('click', function () {
  770. $(this).hide();
  771. $(this).siblings('input').val('');
  772. if ($(this).data('btn') === 'list') {
  773. makeListTable(changeListData);
  774. $('#table-list-select tr').removeClass('table-warning');
  775. $('#code-list').html('');
  776. } else {
  777. makeCodeTable();
  778. }
  779. checkSelectAll();
  780. });
  781. // 全选及取消
  782. $('#code-select-all').click(function () {
  783. // 全选checkbox
  784. let index = $('#code-list').attr('data-index');
  785. if (index) {
  786. if ($(this).is(':checked')){
  787. $('#code-list tr').each(function () {
  788. if ($(this).css('display') !== 'none') {
  789. $(this).find('input').prop('checked', true);
  790. }
  791. })
  792. } else {
  793. $('#code-list tr').each(function () {
  794. if ($(this).css('display') !== 'none' && $(this).find('input').prop('disabled') !== true) {
  795. $(this).find('input').prop('checked', false);
  796. }
  797. });
  798. }
  799. // 判断还有无选中项目节编号
  800. if ($('#code-list input').is(':checked')) {
  801. // 去除部分data-detail值
  802. let data_bwmx = [];
  803. $('#code-list input:checked').each(function () {
  804. const tr = $(this).parents('tr');
  805. const length = tr.children('td').length;
  806. const gcl_id = tr.attr('gcl_id');
  807. const bwmx = length === 8 ?
  808. tr.children('td').eq(0).text() + '!_!' +
  809. tr.children('td').eq(1).text() + '!_!' +
  810. tr.children('td').eq(2).text() + '!_!' +
  811. tr.children('td').eq(3).text() + '!_!' +
  812. tr.children('td').eq(4).text() + '!_!' + gcl_id + '!_!' +
  813. (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  814. const quantity = tr.attr('quantity');
  815. const de_qu = bwmx + '*;*' + quantity;
  816. data_bwmx.push(de_qu);
  817. });
  818. data_bwmx = data_bwmx.join('$#$');
  819. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  820. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  821. } else {
  822. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  823. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  824. }
  825. }
  826. });
  827. // 记录变更信息操作
  828. $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
  829. changeInfo[$(this).attr('name')] = $(this).val();
  830. judgeChange();
  831. });
  832. $('body').on('valuechange', '#change_form textarea', function (e, previous) {
  833. changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
  834. judgeChange();
  835. });
  836. $('body').on('change', '#change_form select', function (e, previous) {
  837. changeInfo[$(this).attr('name')] = $(this).val();
  838. judgeChange();
  839. });
  840. $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
  841. changeInfo[$(this).attr('name')] = $(this).val();
  842. judgeChange();
  843. });
  844. $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
  845. const typecheck = [];
  846. $.each($('#change_form input[name="type[]"]:checked'), function () {
  847. typecheck.push($(this).val());
  848. });
  849. changeInfo.type = typecheck.join(',');
  850. judgeChange();
  851. });
  852. // 保存修改ajax提交(不刷新页面)
  853. $('.save_change_btn').on('click', function () {
  854. // 保存修改modal
  855. if ($('input[name="code"]').val() === '') {
  856. toastr.error('申请编号不能为空!');
  857. return;
  858. }
  859. if ($('input[name="name"]').val() === '') {
  860. toastr.error('工程名称不能为空!');
  861. return;
  862. }
  863. // 换行更改并提交
  864. changeInfo.content = changeInfo.content.replace(/<br><br>/g, '\r\n');
  865. changeInfo.basis = changeInfo.basis.replace(/<br><br>/g, '\r\n');
  866. changeInfo.expr = changeInfo.expr.replace(/<br><br>/g, '\r\n');
  867. changeInfo.memo = changeInfo.memo.replace(/<br><br>/g, '\r\n');
  868. // 后改为br
  869. // 更新至服务器
  870. postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
  871. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  872. toastr.success(result);
  873. $('#show-save-btn').hide();
  874. $('#sp-btn').show();
  875. $('.title-main').removeClass('bg-warning');
  876. changeInfo.content = changeInfo.content.replace(/[\r\n]/g, '<br>');
  877. changeInfo.basis = changeInfo.basis.replace(/[\r\n]/g, '<br>');
  878. changeInfo.expr = changeInfo.expr.replace(/[\r\n]/g, '<br>');
  879. changeInfo.memo = changeInfo.memo.replace(/[\r\n]/g, '<br>');
  880. back_changeInfo = Object.assign({}, changeInfo);
  881. });
  882. return false;
  883. });
  884. $('#cancel_change').on('click', function () {
  885. $('#show-save-btn').hide();
  886. $('#sp-btn').show();
  887. $('.title-main').removeClass('bg-warning');
  888. if (!isObjEqual(changeInfo, back_changeInfo)) {
  889. changeFormRemake();
  890. }
  891. toastr.success('已还原到上次保存状态');
  892. });
  893. });
  894. function checkSelectAll() {
  895. let check = $('#code-list tr').length > 0 ? true : false;
  896. $('#code-list tr').each(function () {
  897. if ($(this).css('display') !== 'none' && !$(this).find('input').is(':checked')) {
  898. check = false;
  899. }
  900. });
  901. $('#code-select-all').prop('checked', check);
  902. }
  903. function checkChangeFrom() {
  904. let returnFlag = false;
  905. // 表单判断
  906. if ($('input[name="code"]').val() === '') {
  907. toastr.error('申请编号不能为空!');
  908. returnFlag = true;
  909. }
  910. if ($('input[name="name"]').val() === '') {
  911. toastr.error('工程名称不能为空!');
  912. returnFlag = true;
  913. }
  914. if ($('textarea[name="content"]').val() === '') {
  915. toastr.error('工程变更理由及内容不能为空!');
  916. returnFlag = true;
  917. }
  918. if (changeList.length === 0) {
  919. toastr.error('请添加变更清单!');
  920. returnFlag = true;
  921. } else {
  922. for (const [i,cl] of changeList.entries()) {
  923. if (cl.code === '' || cl.name === '' || cl.oamount === '') {
  924. toastr.error('变更清单第' + (i+1) + '行未完整填写数据(变更部位、变更详情、单位、单价可空)');
  925. returnFlag = true;
  926. }
  927. }
  928. }
  929. if(!checkAuditorFrom ()) {
  930. returnFlag = true;
  931. }
  932. if (returnFlag) {
  933. return false;
  934. }
  935. }
  936. // 检查上报情况
  937. function checkAuditorFrom () {
  938. if ($('#auditList li').length === 0) {
  939. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  940. toastr.error('请联系管理员添加审批人');
  941. } else {
  942. toastr.error('请先选择审批人,再上报数据');
  943. }
  944. return false;
  945. }
  946. return true;
  947. }
  948. function tableDataRemake(changeListData) {
  949. $('#table-list-select tr').removeClass('table-warning');
  950. $('#table-list-select tr').removeClass('table-success');
  951. $('#table-list-select tr').attr('data-bwmx', '');
  952. $('#code-list').html('');
  953. $('#code-list').attr('data-index', '');
  954. $('#code-input').val('');
  955. $('#code-select-all').prop('checked', false);
  956. $('#code-input').siblings('a').hide();
  957. // 根据已添加的清单显示
  958. if (changeList.length > 0 && changeList[0]) {
  959. const removeList = [];
  960. for (const [index,clinfo] of changeList.entries()) {
  961. if (clinfo.lid != 0) {
  962. let listinfo = changeListData.find(function (item) {
  963. return (item.id !== undefined && item.id == clinfo.lid) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && item.leafXmjs[0].gcl_id == clinfo.lid);
  964. });
  965. if (listinfo === undefined) {
  966. // 针对旧数据获取清单信息
  967. listinfo = changeListData[clinfo.lid - 1];
  968. if (listinfo === undefined) {
  969. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  970. // changeList.splice(index, 1);
  971. removeList.push(clinfo);
  972. continue;
  973. }
  974. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').addClass('table-success');
  975. let pushbwmx = '0*;*0';
  976. if (listinfo.leafXmjs !== undefined) {
  977. const leafInfo = listinfo.leafXmjs.find(function (item) {
  978. const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  979. if (flag && item.code === clinfo.xmj_code) {
  980. return flag && item.code === clinfo.xmj_code;
  981. }
  982. return flag;
  983. });
  984. if (leafInfo) {
  985. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
  986. (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
  987. (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
  988. (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
  989. (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
  990. (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (listinfo.leafXmjs.length > 1 && listinfo.name ? listinfo.name : (leafInfo.jldy !== undefined ? leafInfo.jldy : ''))) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  991. } else {
  992. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  993. // changeList.splice(index, 1);
  994. removeList.push(clinfo);
  995. continue;
  996. }
  997. } else {
  998. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  999. }
  1000. const bwmx = $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx');
  1001. if (bwmx) {
  1002. const bwmxArray = bwmx.split('$#$');
  1003. bwmxArray.push(pushbwmx);
  1004. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  1005. } else {
  1006. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  1007. }
  1008. } else {
  1009. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').addClass('table-success');
  1010. let pushbwmx = '0*;*0';
  1011. if (listinfo.leafXmjs !== undefined) {
  1012. const leafInfo = listinfo.leafXmjs.find(function (item) {
  1013. const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  1014. if (flag && item.code === clinfo.xmj_code) {
  1015. return flag && item.code === clinfo.xmj_code;
  1016. }
  1017. return flag;
  1018. });
  1019. if (leafInfo) {
  1020. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
  1021. (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
  1022. (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
  1023. (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
  1024. (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
  1025. (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (listinfo.leafXmjs.length > 1 && listinfo.name ? listinfo.name : (leafInfo.jldy !== undefined ? leafInfo.jldy : ''))) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  1026. } else {
  1027. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  1028. // changeList.splice(index, 1);
  1029. removeList.push(clinfo);
  1030. continue;
  1031. }
  1032. } else {
  1033. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  1034. }
  1035. const bwmx = $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx');
  1036. if (bwmx) {
  1037. const bwmxArray = bwmx.split('$#$');
  1038. bwmxArray.push(pushbwmx);
  1039. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  1040. } else {
  1041. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  1042. }
  1043. }
  1044. }
  1045. }
  1046. if(removeList.length > 0) {
  1047. _.pullAll(changeList, removeList);
  1048. postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
  1049. }, function () {
  1050. });
  1051. }
  1052. }
  1053. }
  1054. // 清单搜索隐藏清单table部分值
  1055. function makeListTable(changeListData, showListData = changeListData) {
  1056. // 先加载台账数据
  1057. let listHtml = '';
  1058. let list_index = 1;
  1059. let gcl_index = 0;
  1060. for (const [index,gcl] of changeListData.entries()) {
  1061. const isShow = _.find(showListData, gcl);
  1062. $('#table-list-select tr').eq(index).css('display', (isShow ? 'table-row' : 'none'));
  1063. }
  1064. }
  1065. // 项目节搜索隐藏code-table部分值
  1066. function makeCodeTable(search = '') {
  1067. if (search === '') {
  1068. $('#code-list tr').css('display', 'table-row');
  1069. return;
  1070. }
  1071. for(let i = 0; i < $('#code-list tr').length; i++) {
  1072. const length = $('#code-list tr').eq(i).children('td').length;
  1073. if (length === 8) {
  1074. const code = $('#code-list tr').eq(i).children('td').eq(0).text();
  1075. const name = $('#code-list tr').eq(i).children('td').eq(1).text();
  1076. const jldy = $('#code-list tr').eq(i).children('td').eq(5).text();
  1077. const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
  1078. $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
  1079. } else {
  1080. return;
  1081. }
  1082. }
  1083. }
  1084. function remakeChangeSpread() {
  1085. const newTableList = [];
  1086. // 获取选中的签约清单判断并插入到原有清单中
  1087. $('#table-list-select .table-success').each(function(){
  1088. let code = $(this).children('td').eq(1).text();
  1089. let name = $(this).children('td').eq(2).text();
  1090. let unit = $(this).children('td').eq(3).text();
  1091. let price = $(this).children('td').eq(4).text();
  1092. // let oamount = $(this).children('td').eq(5).text();
  1093. // 根据单位获取数量的位数,并得出
  1094. // let numdecimal = findDecimal(unit);
  1095. // let scnum = makedecimalzero(numdecimal);
  1096. let scnum = 0;
  1097. // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
  1098. let lid = $(this).data('lid');
  1099. let lindex = $(this).data('index');
  1100. // 原清单和数量改变
  1101. let data_bwmx = $(this).attr('data-bwmx').split('$#$');
  1102. for (const b of data_bwmx) {
  1103. const oamount = b.split('*;*')[1] != '' ? b.split('*;*')[1] : 0;
  1104. let bwmx = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[6] : '';
  1105. let xmj_code = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[0] : '';
  1106. let xmj_jldy = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[1] : '';
  1107. let xmj_dwgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[2] : '';
  1108. let xmj_fbgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[3] : '';
  1109. let xmj_fxgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[4] : '';
  1110. let gcl_id = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[5] : '';
  1111. let trlist = {
  1112. code,
  1113. name,
  1114. bwmx,
  1115. unit,
  1116. unit_price: price,
  1117. oamount,
  1118. camount: scnum,
  1119. detail: '',
  1120. lid,
  1121. xmj_code,
  1122. xmj_jldy,
  1123. xmj_dwgc,
  1124. xmj_fbgc,
  1125. xmj_fxgc,
  1126. gcl_id,
  1127. };
  1128. const radionInfo = changeList.find(function (info) {
  1129. return info.code === code && (info.lid == lid || parseInt(info.lid) === parseInt(lindex)) && gcl_id == info.gcl_id && (info.bwmx === bwmx || info.bwmx === xmj_jldy) && parseInt(info.oamount) === parseInt(oamount);
  1130. });
  1131. if (radionInfo) {
  1132. trlist.camount = radionInfo.camount;
  1133. trlist.detail = radionInfo.detail;
  1134. }
  1135. newTableList.push(trlist);
  1136. }
  1137. });
  1138. // const changeWhiteList = _.filter(changeList, function (item) {
  1139. // return item.lid == 0;
  1140. // });
  1141. // console.log(newTableList);
  1142. // changeList = newTableList.concat(changeWhiteList);
  1143. return newTableList;
  1144. }
  1145. //判断元素是否在数组中,相当于php的in_array();
  1146. function in_array(arr, obj) {
  1147. let i = arr.length;
  1148. while (i--) {
  1149. if (arr[i] == obj) {
  1150. return true;
  1151. }
  1152. }
  1153. return false;
  1154. }
  1155. function isObjEqual(o1,o2){
  1156. var props1 = Object.getOwnPropertyNames(o1);
  1157. var props2 = Object.getOwnPropertyNames(o2);
  1158. if (props1.length != props2.length) {
  1159. return false;
  1160. }
  1161. for (var i = 0,max = props1.length; i < max; i++) {
  1162. var propName = props1[i];
  1163. if (o1[propName] !== o2[propName]) {
  1164. return false;
  1165. }
  1166. }
  1167. return true;
  1168. }
  1169. // 判断是否有更改过
  1170. function judgeChange() {
  1171. let change = false;
  1172. if (!isObjEqual(changeInfo, back_changeInfo)) {
  1173. change = true;
  1174. }
  1175. if (change) {
  1176. $('#show-save-btn').show();
  1177. $('#sp-btn').hide();
  1178. $('.title-main').addClass('bg-warning');
  1179. } else {
  1180. $('#show-save-btn').hide();
  1181. $('#sp-btn').show();
  1182. $('.title-main').removeClass('bg-warning');
  1183. }
  1184. }
  1185. function changeFormRemake() {
  1186. changeInfo = Object.assign({}, back_changeInfo);
  1187. $('#change_form input[name="code"]').val(changeInfo.code);
  1188. $('#change_form input[name="name"]').val(changeInfo.name);
  1189. $('#change_form input[name="peg"]').val(changeInfo.peg);
  1190. $('#change_form input[name="org_name"]').val(changeInfo.org_name);
  1191. $('#change_form input[name="org_code"]').val(changeInfo.org_code);
  1192. $('#change_form input[name="new_name"]').val(changeInfo.new_name);
  1193. $('#change_form input[name="new_code"]').val(changeInfo.new_code);
  1194. $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
  1195. $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
  1196. $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
  1197. $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
  1198. $('#change_form select[name="type"]').val(changeInfo.type);
  1199. $('#change_form select[name="class"]').val(changeInfo.class);
  1200. $('#change_form select[name="quality"]').val(changeInfo.quality);
  1201. $('#change_form select[name="company"]').val(changeInfo.company);
  1202. $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
  1203. $('#change_form input[name="type[]"]').prop('checked', false);
  1204. const typecheck = changeInfo.type.split(',');
  1205. for (const type of typecheck) {
  1206. $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
  1207. }
  1208. }