change_information_set.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  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])) {
  19. return code1[i].charCodeAt() - code2[i].charCodeAt();
  20. } else {
  21. return parseInt(code1[i]) - parseInt(code2[i]);
  22. }
  23. } else if (i+1 == code1length && code1[i] == code2[i]) {
  24. if (code1length == code2length) {
  25. return 0;
  26. } else {
  27. return code1length - code2length;
  28. }
  29. }
  30. } else {
  31. if (i+1 >= code1length) {
  32. return 1;
  33. } else {
  34. return -1;
  35. }
  36. }
  37. }
  38. }
  39. $.event.special.valuechange = {
  40. teardown: function (namespaces) {
  41. $(this).unbind('.valuechange');
  42. },
  43. handler: function (e) {
  44. $.event.special.valuechange.triggerChanged($(this));
  45. },
  46. add: function (obj) {
  47. $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
  48. },
  49. triggerChanged: function (element) {
  50. var current = element[0].contentEditable === 'true' ? element.html() : element.val()
  51. , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
  52. if (current !== previous) {
  53. element.trigger('valuechange', [element.data('previous')]);
  54. element.data('previous', current);
  55. }
  56. }
  57. };
  58. $(document).ready(() => {
  59. const changeSpreadSetting = {
  60. cols: [
  61. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit'},
  62. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  63. {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  64. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: false},
  65. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits},
  66. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
  67. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
  68. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  69. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: false, getValue: 'getValue.camount'},
  70. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  71. {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
  72. ],
  73. emptyRows: 0,
  74. headRows: 2,
  75. headRowHeight: [25, 25],
  76. defaultRowHeight: 21,
  77. headerFont: '12px 微软雅黑',
  78. font: '12px 微软雅黑',
  79. readOnly: readOnly,
  80. rowHeader:[
  81. {
  82. rowHeaderType: 'circle',
  83. setting: {
  84. size: 5,
  85. indent: 16,
  86. getColor: function (index, data) {
  87. if (!data) return;
  88. if(data.lid != 0) return;
  89. return '#007bff';
  90. }
  91. },
  92. },
  93. ],
  94. };
  95. const changeCol = {
  96. getValue: {
  97. unit_price: function(data) {
  98. return ZhCalc.round(data.unit_price, unitPriceUnit);
  99. },
  100. oa_tp: function (data) {
  101. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
  102. },
  103. ca_tp: function (data) {
  104. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
  105. },
  106. oamount: function (data) {
  107. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  108. },
  109. camount: function (data) {
  110. return ZhCalc.round(data.camount, findDecimal(data.unit));
  111. },
  112. del_list: function (data) {
  113. return '移除';
  114. }
  115. },
  116. readOnly: {
  117. isEdit: function (data) {
  118. return !readOnly && data.lid != 0;
  119. },
  120. },
  121. };
  122. const changeSpreadObj = {
  123. makeSjsFooter: function () {
  124. // 增加汇总行并设为锁定禁止编辑状态
  125. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  126. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  127. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  128. changeSpreadObj.countSum();
  129. },
  130. countSum: function() {
  131. const rowCount = changeSpreadSheet.getRowCount();
  132. let oSum = 0,
  133. cSum = 0;
  134. for(var i = 0; i < rowCount - 1; i++){
  135. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
  136. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
  137. }
  138. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
  139. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
  140. },
  141. add: function () {
  142. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  143. if (result) {
  144. changeList.push(result);
  145. changeSpreadSheet.addRows(changeList.length - 1, 1);
  146. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  147. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  148. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  149. }
  150. });
  151. },
  152. del: function () {
  153. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  154. const index = changeList.indexOf(select);
  155. if (index > -1) {
  156. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  157. changeList.splice(index, 1);
  158. changeSpreadSheet.deleteRows(index, 1);
  159. const sel = changeSpreadSheet.getSelections();
  160. changeSpreadSheet.setSelection(0, 0, 1, 1);
  161. if (select.lid != 0) {
  162. tableDataRemake(changeListData);
  163. }
  164. changeSpreadObj.countSum();
  165. });
  166. }
  167. },
  168. selectionChanged: function (e, info) {
  169. const sel = info.sheet.getSelections()[0];
  170. const col = info.sheet.zh_setting.cols[sel.col];
  171. const data = SpreadJsObj.getSelectObject(info.sheet);
  172. if (col && col.field === 'del_list') {
  173. changeSpreadObj.del();
  174. }
  175. },
  176. deletePress: function (sheet) {
  177. return;
  178. },
  179. editEnded: function (e, info) {
  180. if (info.sheet.zh_setting) {
  181. const select = SpreadJsObj.getSelectObject(info.sheet);
  182. const col = info.sheet.zh_setting.cols[info.col];
  183. if (col.field === 'del_list') {
  184. return;
  185. }
  186. // 未改变值则不提交
  187. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  188. const orgValue = select[col.field];
  189. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  190. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  191. return;
  192. }
  193. // 判断部分值是否输入的是数字判断和数据计算
  194. if (col.type === 'Number') {
  195. if (isNaN(validText)) {
  196. toastr.error('不能输入其它非数字类型字符');
  197. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  198. return;
  199. }
  200. if (col.field === 'unit_price') {
  201. validText = ZhCalc.round(validText, unitPriceUnit);
  202. } else {
  203. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  204. }
  205. }
  206. if (col.field === 'unit') {
  207. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  208. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  209. }
  210. select[col.field] = validText;
  211. if(col.field === 'camount') {
  212. select.spamount = ZhCalc.round(select.camount, findDecimal(select.unit)) || 0;
  213. }
  214. console.log(select);
  215. // 更新至服务器
  216. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  217. changeList.splice(info.row, 1, select);
  218. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  219. changeSpreadObj.countSum();
  220. }, function () {
  221. select[col.field] = orgValue;
  222. if(col.field === 'camount') {
  223. select.spamount = orgValue;
  224. }
  225. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  226. });
  227. }
  228. },
  229. clipboardPasted(e, info) {
  230. const hint = {
  231. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  232. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  233. };
  234. const range = info.cellRange;
  235. const sortData = info.sheet.zh_data || [];
  236. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  237. toastMessageUniq(hint.cellError);
  238. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  239. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  240. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  241. changeSpreadObj.makeSjsFooter();
  242. return;
  243. }
  244. if (sortData.length > 0 && range.col + range.colCount > 10) {
  245. toastMessageUniq(hint.cellError);
  246. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  247. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  248. changeSpreadObj.makeSjsFooter();
  249. return;
  250. }
  251. const data = [];
  252. // const rowData = [];
  253. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  254. let bPaste = true;
  255. const curRow = range.row + iRow;
  256. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  257. const cLData = { id: sortData[curRow].id };
  258. const hintRow = range.rowCount > 1 ? curRow : '';
  259. let sameCol = 0;
  260. for (let iCol = 0; iCol < range.colCount; iCol++) {
  261. const curCol = range.col + iCol;
  262. const colSetting = info.sheet.zh_setting.cols[curCol];
  263. if (!colSetting) continue;
  264. let validText = info.sheet.getText(curRow, curCol);
  265. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  266. const orgValue = sortData[curRow][colSetting.field];
  267. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  268. sameCol++;
  269. if (range.colCount === sameCol) {
  270. bPaste = false;
  271. }
  272. continue;
  273. }
  274. if (colSetting.type === 'Number') {
  275. if (isNaN(validText)) {
  276. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  277. bPaste = false;
  278. continue;
  279. }
  280. if (colSetting.field === 'unit_price') {
  281. validText = ZhCalc.round(validText, unitPriceUnit);
  282. } else {
  283. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  284. }
  285. }
  286. if (colSetting.field === 'unit') {
  287. //粘贴内容要为下拉列表里所有的单位,不然为空
  288. if (changeUnits.indexOf(validText) === -1) {
  289. validText = '';
  290. }
  291. cLData.camount = ZhCalc.round(sortData[curRow].camount, findDecimal(validText)) || 0;
  292. cLData.oamount = ZhCalc.round(sortData[curRow].oamount, findDecimal(validText)) || 0;
  293. }
  294. cLData[colSetting.field] = validText;
  295. sortData[curRow][colSetting.field] = validText;
  296. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(validText)) || 0;
  297. }
  298. if (bPaste) {
  299. data.push(cLData);
  300. // rowData.push(curRow);
  301. } else {
  302. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  303. }
  304. }
  305. if (data.length === 0) {
  306. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  307. return;
  308. }
  309. console.log(data);
  310. // 更新至服务器
  311. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  312. changeList = result;
  313. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  314. changeSpreadObj.makeSjsFooter();
  315. }, function () {
  316. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  317. return;
  318. });
  319. },
  320. };
  321. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  322. let changeListData;
  323. let gclGatherData;
  324. postData(preUrl + '/defaultBills', {}, function (result) {
  325. gclGatherModel.loadLedgerData(result.bills);
  326. gclGatherModel.loadPosData(result.pos);
  327. gclGatherData = gclGatherModel.gatherGclData();
  328. gclGatherData = _.filter(gclGatherData, function (item) {
  329. return item.leafXmjs && item.leafXmjs.length !== 0;
  330. });
  331. for (const ggd in gclGatherData) {
  332. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  333. gclGatherData.splice(ggd, 1);
  334. }
  335. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  336. }
  337. // 数组去重
  338. const dealBillList = result.dealBills;
  339. for (const db of gclGatherData) {
  340. const exist_index = dealBillList.findIndex(function (item) {
  341. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  342. });
  343. if (exist_index !== -1) {
  344. dealBillList.splice(exist_index, 1);
  345. }
  346. }
  347. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  348. // 先加载台账数据
  349. let listHtml = '';
  350. let list_index = 1;
  351. let gcl_index = 0;
  352. for (const gcl of changeListData) {
  353. const unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
  354. const quantity = gcl.quantity !== null && gcl.quantity !== undefined ? (unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity) : 0;
  355. const unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? gcl.unit_price : 0;
  356. let gclhtml = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? ' data-gcl="' + gcl_index + '"' : '';
  357. gcl_index = gclhtml !== '' ? ++gcl_index : gcl_index;
  358. const lid = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? (gcl.leafXmjs.length !== 0 ? gcl.leafXmjs[0].gcl_id : false) : gcl.id;
  359. if (lid) {
  360. listHtml += '<tr data-lid="' + lid + '"' + gclhtml + ' data-index="' + list_index + '" data-bwmx="">' +
  361. '<td class="text-center">' + list_index + '</td>' +
  362. '<td>' + gcl.code + '</td>' +
  363. '<td class="text-left">' + gcl.name + '</td>' +
  364. '<td class="text-center">' + unit + '</td>' +
  365. '<td class="text-right">' + (ZhCalc.round(unit_price, unitPriceUnit) ? ZhCalc.round(unit_price, unitPriceUnit) : 0) + '</td>' +
  366. '<td class="text-right">' + quantity + '</td>' +
  367. '</tr>';
  368. list_index++;
  369. }
  370. }
  371. $('#table-list-select').html(listHtml);
  372. tableDataRemake(changeListData);
  373. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  374. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  375. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  376. changeSpreadObj.makeSjsFooter();
  377. // for (const cl of changeList) {
  378. // if (cl.lid == 0) {
  379. // console.log(cl);
  380. // SpreadJsObj.repaintNodesRowHeader(changeSpreadSheet, cl);
  381. // }
  382. // }
  383. });
  384. if (!readOnly) {
  385. $('#add-white-btn').click(changeSpreadObj.add);
  386. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  387. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  388. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  389. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  390. changeSpreadSheet.getCell(-1, 10).foreColor('#dc3545');
  391. // 右键菜单
  392. $.contextMenu({
  393. selector: '#change-spread',
  394. build: function ($trigger, e) {
  395. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  396. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  397. },
  398. items: {
  399. 'createList': {
  400. name: '添加台账清单',
  401. icon: 'fa-sign-in',
  402. callback: function (key, opt) {
  403. $('#addlist').modal('show');
  404. },
  405. },
  406. 'createAdd': {
  407. name: '添加空白清单',
  408. icon: 'fa-sign-in',
  409. callback: function (key, opt) {
  410. changeSpreadObj.add(changeSpreadSheet);
  411. },
  412. },
  413. 'delete': {
  414. name: '删除',
  415. icon: 'fa-remove',
  416. callback: function (key, opt) {
  417. changeSpreadObj.del(changeSpreadSheet);
  418. },
  419. disabled: function (key, opt) {
  420. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  421. const sel = changeSpreadSheet.getSelections()[0];
  422. console.log(select, sel);
  423. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  424. return false;
  425. } else {
  426. return true;
  427. }
  428. }
  429. },
  430. }
  431. });
  432. }
  433. // 清单选中和移除
  434. $('body').on('click', '#table-list-select tr', function () {
  435. $('#table-list-select tr').removeClass('table-warning');
  436. $(this).addClass('table-warning');
  437. const isCheck = $(this).hasClass('table-success') ? true : false;
  438. const data_bwmx = $(this).attr('data-bwmx').split('$#$');
  439. const isDeal = $(this).data('gcl') !== undefined ? true : false;
  440. 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>';
  441. if (isDeal) {
  442. const lid = $(this).data('lid');
  443. let gcl = _.find(gclGatherData, function (item) {
  444. return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
  445. });
  446. if (!gcl) {
  447. gcl = gclGatherData[$(this).data('gcl')];
  448. }
  449. codeHtml = '';
  450. for (const leaf of gcl.leafXmjs) {
  451. const quantity = leaf.quantity !== undefined && leaf.quantity !== null ? leaf.quantity : 0;
  452. const gcl_id = leaf.gcl_id ? leaf.gcl_id : '';
  453. const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : '';
  454. const isChecked = data_bwmx.indexOf(leaf.code + '!_!' + (leaf.jldy ? leaf.jldy : '') + '!_!' + (leaf.gcl_id ? leaf.gcl_id : '0') + '!_!' + (bwmx !== '' ? bwmx : leaf.jldy ? leaf.jldy : '') + '*;*' + quantity) !== -1 && isCheck ? 'checked' : '';
  455. codeHtml += '<tr quantity="' + quantity + '" gcl_id="' + gcl_id + '"><td>' + leaf.code + '</td>' +
  456. '<td>' + (leaf.jldy ? leaf.jldy: '') + '</td>' +
  457. '<td>' + (leaf.dwgc ? leaf.dwgc : '') + '</td>' +
  458. '<td>' + (leaf.fbgc ? leaf.fbgc : '') + '</td>' +
  459. '<td>' + (leaf.fxgc ? leaf.fxgc : '') + '</td>' +
  460. '<td>' + bwmx + '</td>' +
  461. '<td class="text-right">' + (ZhCalc.round(quantity, findDecimal(gcl.unit)) ? ZhCalc.round(quantity, findDecimal(gcl.unit)) : 0) + '</td>' +
  462. '<td class="text-center"><input type="checkbox"' + isChecked +
  463. '></td></tr>';
  464. }
  465. } else if (!isDeal && isCheck) {
  466. 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>';
  467. }
  468. $('#code-list').attr('data-index', $(this).children('td').eq(0).text());
  469. $('#code-input').val('');
  470. $('#code-input').siblings('a').hide();
  471. $('#code-list').html(codeHtml);
  472. });
  473. // 右边项目节选择
  474. $('body').on('click', '#code-list input', function () {
  475. let index = $('#code-list').attr('data-index');
  476. if ($(this).is(':checked')) {
  477. // 去除其它可能已选的checked
  478. // $('#code-list input').prop('checked', false);
  479. $(this).prop('checked', true);
  480. // 左边表单传值并添加class
  481. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  482. // 去除部分data-detail值
  483. let data_bwmx = [];
  484. $('#code-list input:checked').each(function () {
  485. const tr = $(this).parents('tr');
  486. const length = tr.children('td').length;
  487. const gcl_id = tr.attr('gcl_id');
  488. const bwmx = length === 8 ? tr.children('td').eq(0).text() + '!_!' + tr.children('td').eq(1).text() + '!_!' + gcl_id + '!_!' + (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  489. const quantity = tr.attr('quantity');
  490. const de_qu = bwmx + '*;*' + quantity;
  491. data_bwmx.push(de_qu);
  492. });
  493. data_bwmx = data_bwmx.join('$#$');
  494. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  495. } else {
  496. // 判断还有无选中项目节编号
  497. if ($('#code-list input').is(':checked')) {
  498. // 去除部分data-detail值
  499. let data_bwmx = [];
  500. $('#code-list input:checked').each(function () {
  501. const tr = $(this).parents('tr');
  502. const length = tr.children('td').length;
  503. const gcl_id = tr.attr('gcl_id');
  504. const bwmx = length === 8 ? tr.children('td').eq(0).text() + '!_!'+ tr.children('td').eq(1).text() + '!_!' + gcl_id + '!_!' + (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  505. const quantity = tr.attr('quantity');
  506. const de_qu = bwmx + '*;*' + quantity;
  507. data_bwmx.push(de_qu);
  508. });
  509. data_bwmx = data_bwmx.join('$#$');
  510. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  511. } else {
  512. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  513. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  514. }
  515. }
  516. });
  517. // 添加空白清单or签约清单
  518. $('.add-list-btn').on('click', function () {
  519. const newLedgerList = remakeChangeSpread();
  520. // 更新至服务器
  521. postData(window.location.pathname + '/save', { type:'ledger_list', updateData: newLedgerList }, function (result) {
  522. changeList = result;
  523. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  524. changeSpreadObj.makeSjsFooter();
  525. $('#addlist').modal('hide');
  526. }, function () {
  527. $('#addlist').modal('hide');
  528. });
  529. });
  530. // 选中input所有值
  531. $('body').on('focus', ".clist input", function() {
  532. $(this).select();
  533. });
  534. // 取消选中清单
  535. $('#cancel-list-btn').click(function () {
  536. // $('#table-list-select tr').removeClass('table-success');
  537. // $('#table-list-select tr').attr('data-bwmx', '');
  538. // $('#code-list').html('');
  539. tableDataRemake(changeListData);
  540. });
  541. // 自动编号
  542. $('.reduction-code').click(function () {
  543. const code = $(this).attr('data-code');
  544. $('input[name="code"]').val(code);
  545. });
  546. $('#list-input').on('valuechange', function (e, previous) {
  547. const value = $(this).val();
  548. let showListData = changeListData;
  549. if (value !== '') {
  550. $(this).siblings('a').show();
  551. showListData = _.filter(changeListData, function (c) {
  552. return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  553. });
  554. } else {
  555. $(this).siblings('a').hide();
  556. }
  557. makeListTable(changeListData, showListData);
  558. $('#table-list-select tr').removeClass('table-warning');
  559. $('#code-input').val('');
  560. $('#code-input').siblings('a').hide();
  561. $('#code-list').html('');
  562. });
  563. $('#code-input').on('valuechange', function (e, previous) {
  564. const value = $(this).val();
  565. if (value !== '') {
  566. $(this).siblings('a').show();
  567. } else {
  568. $(this).siblings('a').hide();
  569. }
  570. makeCodeTable($(this).val());
  571. });
  572. $('.remove-btn').on('click', function () {
  573. $(this).hide();
  574. $(this).siblings('input').val('');
  575. if ($(this).data('btn') === 'list') {
  576. makeListTable(changeListData);
  577. $('#table-list-select tr').removeClass('table-warning');
  578. $('#code-list').html('');
  579. } else {
  580. makeCodeTable();
  581. }
  582. });
  583. // 记录变更信息操作
  584. $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
  585. changeInfo[$(this).attr('name')] = $(this).val();
  586. judgeChange();
  587. });
  588. $('body').on('valuechange', '#change_form textarea', function (e, previous) {
  589. changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
  590. judgeChange();
  591. });
  592. $('body').on('change', '#change_form select', function (e, previous) {
  593. changeInfo[$(this).attr('name')] = $(this).val();
  594. judgeChange();
  595. });
  596. $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
  597. changeInfo[$(this).attr('name')] = $(this).val();
  598. judgeChange();
  599. });
  600. $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
  601. const typecheck = [];
  602. $.each($('#change_form input[name="type[]"]:checked'), function () {
  603. typecheck.push($(this).val());
  604. });
  605. changeInfo.type = typecheck.join(',');
  606. judgeChange();
  607. });
  608. // 保存修改ajax提交(不刷新页面)
  609. $('.save_change_btn').on('click', function () {
  610. // 保存修改modal
  611. if ($('input[name="code"]').val() === '') {
  612. toastr.error('申请编号不能为空!');
  613. return;
  614. }
  615. if ($('input[name="name"]').val() === '') {
  616. toastr.error('工程名称不能为空!');
  617. return;
  618. }
  619. // 更新至服务器
  620. postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
  621. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  622. toastr.success(result);
  623. $('#show-save-btn').hide();
  624. $('#sp-btn').show();
  625. $('.title-main').removeClass('bg-warning');
  626. back_changeInfo = Object.assign({}, changeInfo);
  627. });
  628. return false;
  629. });
  630. $('#cancel_change').on('click', function () {
  631. $('#show-save-btn').hide();
  632. $('#sp-btn').show();
  633. $('.title-main').removeClass('bg-warning');
  634. if (!isObjEqual(changeInfo, back_changeInfo)) {
  635. changeFormRemake();
  636. }
  637. toastr.success('已还原到上次保存状态');
  638. });
  639. });
  640. function checkChangeFrom() {
  641. let returnFlag = false;
  642. // 表单判断
  643. if ($('input[name="code"]').val() === '') {
  644. toastr.error('申请编号不能为空!');
  645. returnFlag = true;
  646. }
  647. if ($('input[name="name"]').val() === '') {
  648. toastr.error('工程名称不能为空!');
  649. returnFlag = true;
  650. }
  651. if ($('textarea[name="content"]').val() === '') {
  652. toastr.error('工程变更理由及内容不能为空!');
  653. returnFlag = true;
  654. }
  655. if (changeList.length === 0) {
  656. toastr.error('请添加变更清单!');
  657. returnFlag = true;
  658. } else {
  659. for (const [i,cl] of changeList.entries()) {
  660. if (cl.code === '' || cl.name === '' || cl.oamount === '') {
  661. toastr.error('变更清单第' + (i+1) + '行未完整填写数据(变更部位、变更详情、单位、单价可空)');
  662. returnFlag = true;
  663. }
  664. }
  665. }
  666. if(!checkAuditorFrom ()) {
  667. returnFlag = true;
  668. }
  669. if (returnFlag) {
  670. return false;
  671. }
  672. }
  673. // 检查上报情况
  674. function checkAuditorFrom () {
  675. if ($('#auditList li').length === 0) {
  676. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  677. toastr.error('请联系管理员添加审批人');
  678. } else {
  679. toastr.error('请先选择审批人,再上报数据');
  680. }
  681. return false;
  682. }
  683. return true;
  684. }
  685. function tableDataRemake(changeListData) {
  686. $('#table-list-select tr').removeClass('table-warning');
  687. $('#table-list-select tr').removeClass('table-success');
  688. $('#table-list-select tr').attr('data-bwmx', '');
  689. $('#code-list').html('');
  690. // 根据已添加的清单显示
  691. if (changeList.length > 0 && changeList[0]) {
  692. for (const [index,clinfo] of changeList.entries()) {
  693. if (clinfo.lid != 0) {
  694. let listinfo = changeListData.find(function (item) {
  695. 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);
  696. });
  697. if (listinfo === undefined) {
  698. // 针对旧数据获取清单信息
  699. listinfo = changeListData[clinfo.lid - 1];
  700. if (listinfo === undefined) {
  701. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  702. changeList.splice(index, 1);
  703. continue;
  704. }
  705. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').addClass('table-success');
  706. let pushbwmx = '0*;*0';
  707. if (listinfo.leafXmjs !== undefined) {
  708. const leafInfo = listinfo.leafXmjs.find(function (item) {
  709. return (item.bwmx === undefined || item.bwmx === clinfo.bwmx) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  710. });
  711. console.log(leafInfo);
  712. if (leafInfo) {
  713. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' + (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' + (leafInfo.bwmx !== undefined ? leafInfo.bwmx : '') + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  714. } else {
  715. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  716. changeList.splice(index, 1);
  717. continue;
  718. }
  719. } else {
  720. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  721. }
  722. const bwmx = $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx');
  723. if (bwmx) {
  724. const bwmxArray = bwmx.split('$#$');
  725. bwmxArray.push(pushbwmx);
  726. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  727. } else {
  728. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  729. }
  730. } else {
  731. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').addClass('table-success');
  732. let pushbwmx = '0*;*0';
  733. if (listinfo.leafXmjs !== undefined) {
  734. const leafInfo = listinfo.leafXmjs.find(function (item) {
  735. return (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  736. });
  737. if (leafInfo) {
  738. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' + (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' + (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (leafInfo.jldy ? leafInfo.jldy : '')) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  739. } else {
  740. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  741. changeList.splice(index, 1);
  742. continue;
  743. }
  744. } else {
  745. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  746. }
  747. const bwmx = $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx');
  748. if (bwmx) {
  749. const bwmxArray = bwmx.split('$#$');
  750. bwmxArray.push(pushbwmx);
  751. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  752. } else {
  753. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  754. }
  755. }
  756. }
  757. }
  758. }
  759. }
  760. // 清单搜索隐藏清单table部分值
  761. function makeListTable(changeListData, showListData = changeListData) {
  762. // 先加载台账数据
  763. let listHtml = '';
  764. let list_index = 1;
  765. let gcl_index = 0;
  766. for (const [index,gcl] of changeListData.entries()) {
  767. const isShow = _.find(showListData, gcl);
  768. $('#table-list-select tr').eq(index).css('display', (isShow ? 'table-row' : 'none'));
  769. }
  770. }
  771. // 项目节搜索隐藏code-table部分值
  772. function makeCodeTable(search = '') {
  773. if (search === '') {
  774. $('#code-list tr').css('display', 'table-row');
  775. return;
  776. }
  777. for(let i = 0; i < $('#code-list tr').length; i++) {
  778. const length = $('#code-list tr').eq(i).children('td').length;
  779. if (length === 8) {
  780. const code = $('#code-list tr').eq(i).children('td').eq(0).text();
  781. const name = $('#code-list tr').eq(i).children('td').eq(1).text();
  782. const jldy = $('#code-list tr').eq(i).children('td').eq(5).text();
  783. const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
  784. $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
  785. } else {
  786. return;
  787. }
  788. }
  789. }
  790. function remakeChangeSpread() {
  791. const newTableList = [];
  792. // 获取选中的签约清单判断并插入到原有清单中
  793. $('#table-list-select .table-success').each(function(){
  794. let code = $(this).children('td').eq(1).text();
  795. let name = $(this).children('td').eq(2).text();
  796. let unit = $(this).children('td').eq(3).text();
  797. let price = $(this).children('td').eq(4).text();
  798. // let oamount = $(this).children('td').eq(5).text();
  799. // 根据单位获取数量的位数,并得出
  800. // let numdecimal = findDecimal(unit);
  801. // let scnum = makedecimalzero(numdecimal);
  802. let scnum = 0;
  803. // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
  804. let lid = $(this).data('lid');
  805. let lindex = $(this).data('index');
  806. // 原清单和数量改变
  807. let data_bwmx = $(this).attr('data-bwmx').split('$#$');
  808. for (const b of data_bwmx) {
  809. const oamount = b.split('*;*')[1] != '' ? b.split('*;*')[1] : 0;
  810. let bwmx = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[3] : '';
  811. let xmj_code = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[0] : '';
  812. let xmj_jldy = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[1] : '';
  813. let gcl_id = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[2] : '';
  814. let trlist = {
  815. code,
  816. name,
  817. bwmx,
  818. unit,
  819. unit_price: price,
  820. oamount,
  821. camount: scnum,
  822. detail: '',
  823. lid,
  824. xmj_code,
  825. xmj_jldy,
  826. gcl_id,
  827. };
  828. const radionInfo = changeList.find(function (info) {
  829. return info.code === code && (info.lid == lid || parseInt(info.lid) === parseInt(lindex)) && gcl_id == info.gcl_id && info.bwmx === bwmx;
  830. });
  831. if (radionInfo) {
  832. trlist.camount = radionInfo.camount;
  833. trlist.detail = radionInfo.detail;
  834. }
  835. newTableList.push(trlist);
  836. }
  837. });
  838. // const changeWhiteList = _.filter(changeList, function (item) {
  839. // return item.lid == 0;
  840. // });
  841. // console.log(newTableList);
  842. // changeList = newTableList.concat(changeWhiteList);
  843. return newTableList;
  844. }
  845. //判断元素是否在数组中,相当于php的in_array();
  846. function in_array(arr, obj) {
  847. let i = arr.length;
  848. while (i--) {
  849. if (arr[i] == obj) {
  850. return true;
  851. }
  852. }
  853. return false;
  854. }
  855. function isObjEqual(o1,o2){
  856. var props1 = Object.getOwnPropertyNames(o1);
  857. var props2 = Object.getOwnPropertyNames(o2);
  858. if (props1.length != props2.length) {
  859. return false;
  860. }
  861. for (var i = 0,max = props1.length; i < max; i++) {
  862. var propName = props1[i];
  863. if (o1[propName] !== o2[propName]) {
  864. return false;
  865. }
  866. }
  867. return true;
  868. }
  869. // 判断是否有更改过
  870. function judgeChange() {
  871. let change = false;
  872. if (!isObjEqual(changeInfo, back_changeInfo)) {
  873. change = true;
  874. }
  875. if (change) {
  876. $('#show-save-btn').show();
  877. $('#sp-btn').hide();
  878. $('.title-main').addClass('bg-warning');
  879. } else {
  880. $('#show-save-btn').hide();
  881. $('#sp-btn').show();
  882. $('.title-main').removeClass('bg-warning');
  883. }
  884. }
  885. function changeFormRemake() {
  886. changeInfo = Object.assign({}, back_changeInfo);
  887. $('#change_form input[name="code"]').val(changeInfo.code);
  888. $('#change_form input[name="name"]').val(changeInfo.name);
  889. $('#change_form input[name="peg"]').val(changeInfo.peg);
  890. $('#change_form input[name="org_name"]').val(changeInfo.org_name);
  891. $('#change_form input[name="org_code"]').val(changeInfo.org_code);
  892. $('#change_form input[name="new_name"]').val(changeInfo.new_name);
  893. $('#change_form input[name="new_code"]').val(changeInfo.new_code);
  894. $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
  895. $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
  896. $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
  897. $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
  898. $('#change_form select[name="type"]').val(changeInfo.type);
  899. $('#change_form select[name="class"]').val(changeInfo.class);
  900. $('#change_form select[name="quality"]').val(changeInfo.quality);
  901. $('#change_form select[name="company"]').val(changeInfo.company);
  902. $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
  903. $('#change_form input[name="type[]"]').prop('checked', false);
  904. const typecheck = changeInfo.type.split(',');
  905. for (const type of typecheck) {
  906. $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
  907. }
  908. }