change_information_set.js 67 KB

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