change_information_set.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  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 !== 0 && 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. });
  378. if (!readOnly) {
  379. $('#add-white-btn').click(changeSpreadObj.add);
  380. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  381. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  382. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  383. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  384. changeSpreadSheet.getCell(-1, 10).foreColor('#dc3545');
  385. // 右键菜单
  386. $.contextMenu({
  387. selector: '#change-spread',
  388. build: function ($trigger, e) {
  389. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  390. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  391. },
  392. items: {
  393. 'createList': {
  394. name: '添加台账清单',
  395. icon: 'fa-sign-in',
  396. callback: function (key, opt) {
  397. $('#addlist').modal('show');
  398. },
  399. },
  400. 'createAdd': {
  401. name: '添加空白清单',
  402. icon: 'fa-sign-in',
  403. callback: function (key, opt) {
  404. changeSpreadObj.add(changeSpreadSheet);
  405. },
  406. },
  407. 'delete': {
  408. name: '删除',
  409. icon: 'fa-remove',
  410. callback: function (key, opt) {
  411. changeSpreadObj.del(changeSpreadSheet);
  412. },
  413. disabled: function (key, opt) {
  414. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  415. const sel = changeSpreadSheet.getSelections()[0];
  416. console.log(select, sel);
  417. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  418. return false;
  419. } else {
  420. return true;
  421. }
  422. }
  423. },
  424. }
  425. });
  426. }
  427. // 清单选中和移除
  428. $('body').on('click', '#table-list-select tr', function () {
  429. $('#table-list-select tr').removeClass('table-warning');
  430. $(this).addClass('table-warning');
  431. const isCheck = $(this).hasClass('table-success') ? true : false;
  432. const data_bwmx = $(this).attr('data-bwmx').split('$#$');
  433. const isDeal = $(this).data('gcl') !== undefined ? true : false;
  434. 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>';
  435. if (isDeal) {
  436. const lid = $(this).data('lid');
  437. let gcl = _.find(gclGatherData, function (item) {
  438. return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
  439. });
  440. if (!gcl) {
  441. gcl = gclGatherData[$(this).data('gcl')];
  442. }
  443. codeHtml = '';
  444. for (const leaf of gcl.leafXmjs) {
  445. const quantity = leaf.quantity !== undefined && leaf.quantity !== null ? leaf.quantity : 0;
  446. const gcl_id = leaf.gcl_id ? leaf.gcl_id : '';
  447. const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : '';
  448. const isChecked = data_bwmx.indexOf(
  449. leaf.code + '!_!' + (leaf.jldy ? leaf.jldy : '') + '!_!' +
  450. (leaf.dwgc ? leaf.dwgc : '') + '!_!' + (leaf.fbgc ? leaf.fbgc : '') + '!_!' + (leaf.fxgc ? leaf.fxgc : '')
  451. + '!_!' + (leaf.gcl_id ? leaf.gcl_id : '0') + '!_!' +
  452. (bwmx !== '' ? bwmx : leaf.jldy ? leaf.jldy : '') + '*;*' + quantity) !== -1 && isCheck ?
  453. 'checked' : '';
  454. codeHtml += '<tr quantity="' + quantity + '" gcl_id="' + gcl_id + '"><td>' + leaf.code + '</td>' +
  455. '<td>' + (leaf.jldy ? leaf.jldy: '') + '</td>' +
  456. '<td>' + (leaf.dwgc ? leaf.dwgc : '') + '</td>' +
  457. '<td>' + (leaf.fbgc ? leaf.fbgc : '') + '</td>' +
  458. '<td>' + (leaf.fxgc ? leaf.fxgc : '') + '</td>' +
  459. '<td>' + bwmx + '</td>' +
  460. '<td class="text-right">' + (ZhCalc.round(quantity, findDecimal(gcl.unit)) ? ZhCalc.round(quantity, findDecimal(gcl.unit)) : 0) + '</td>' +
  461. '<td class="text-center"><input type="checkbox"' + isChecked +
  462. '></td></tr>';
  463. }
  464. } else if (!isDeal && isCheck) {
  465. 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>';
  466. }
  467. $('#code-list').attr('data-index', $(this).children('td').eq(0).text());
  468. $('#code-input').val('');
  469. $('#code-input').siblings('a').hide();
  470. $('#code-list').html(codeHtml);
  471. });
  472. // 右边项目节选择
  473. $('body').on('click', '#code-list input', function () {
  474. let index = $('#code-list').attr('data-index');
  475. if ($(this).is(':checked')) {
  476. // 去除其它可能已选的checked
  477. // $('#code-list input').prop('checked', false);
  478. $(this).prop('checked', true);
  479. // 左边表单传值并添加class
  480. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  481. // 去除部分data-detail值
  482. let data_bwmx = [];
  483. $('#code-list input:checked').each(function () {
  484. const tr = $(this).parents('tr');
  485. const length = tr.children('td').length;
  486. const gcl_id = tr.attr('gcl_id');
  487. const bwmx = length === 8 ?
  488. tr.children('td').eq(0).text() + '!_!' +
  489. tr.children('td').eq(1).text() + '!_!' +
  490. tr.children('td').eq(2).text() + '!_!' +
  491. tr.children('td').eq(3).text() + '!_!' +
  492. tr.children('td').eq(4).text() + '!_!' + gcl_id + '!_!' +
  493. (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  494. const quantity = tr.attr('quantity');
  495. const de_qu = bwmx + '*;*' + quantity;
  496. data_bwmx.push(de_qu);
  497. });
  498. data_bwmx = data_bwmx.join('$#$');
  499. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  500. } else {
  501. // 判断还有无选中项目节编号
  502. if ($('#code-list input').is(':checked')) {
  503. // 去除部分data-detail值
  504. let data_bwmx = [];
  505. $('#code-list input:checked').each(function () {
  506. const tr = $(this).parents('tr');
  507. const length = tr.children('td').length;
  508. const gcl_id = tr.attr('gcl_id');
  509. const bwmx = length === 8 ?
  510. tr.children('td').eq(0).text() + '!_!' +
  511. tr.children('td').eq(1).text() + '!_!' +
  512. tr.children('td').eq(2).text() + '!_!' +
  513. tr.children('td').eq(3).text() + '!_!' +
  514. tr.children('td').eq(4).text() + '!_!' + gcl_id + '!_!' +
  515. (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  516. const quantity = tr.attr('quantity');
  517. const de_qu = bwmx + '*;*' + quantity;
  518. data_bwmx.push(de_qu);
  519. });
  520. data_bwmx = data_bwmx.join('$#$');
  521. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  522. } else {
  523. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  524. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  525. }
  526. }
  527. });
  528. // 添加空白清单or签约清单
  529. $('.add-list-btn').on('click', function () {
  530. const newLedgerList = remakeChangeSpread();
  531. // 更新至服务器
  532. postData(window.location.pathname + '/save', { type:'ledger_list', updateData: newLedgerList }, function (result) {
  533. changeList = result;
  534. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  535. changeSpreadObj.makeSjsFooter();
  536. $('#addlist').modal('hide');
  537. }, function () {
  538. $('#addlist').modal('hide');
  539. });
  540. });
  541. // 选中input所有值
  542. $('body').on('focus', ".clist input", function() {
  543. $(this).select();
  544. });
  545. // 取消选中清单
  546. $('#cancel-list-btn').click(function () {
  547. // $('#table-list-select tr').removeClass('table-success');
  548. // $('#table-list-select tr').attr('data-bwmx', '');
  549. // $('#code-list').html('');
  550. tableDataRemake(changeListData);
  551. });
  552. // 自动编号
  553. $('.reduction-code').click(function () {
  554. const code = $(this).attr('data-code');
  555. $('input[name="code"]').val(code);
  556. });
  557. $('#list-input').on('valuechange', function (e, previous) {
  558. const value = $(this).val();
  559. let showListData = changeListData;
  560. if (value !== '') {
  561. $(this).siblings('a').show();
  562. showListData = _.filter(changeListData, function (c) {
  563. return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  564. });
  565. } else {
  566. $(this).siblings('a').hide();
  567. }
  568. makeListTable(changeListData, showListData);
  569. $('#table-list-select tr').removeClass('table-warning');
  570. $('#code-input').val('');
  571. $('#code-input').siblings('a').hide();
  572. $('#code-list').html('');
  573. });
  574. $('#code-input').on('valuechange', function (e, previous) {
  575. const value = $(this).val();
  576. if (value !== '') {
  577. $(this).siblings('a').show();
  578. } else {
  579. $(this).siblings('a').hide();
  580. }
  581. makeCodeTable($(this).val());
  582. });
  583. $('.remove-btn').on('click', function () {
  584. $(this).hide();
  585. $(this).siblings('input').val('');
  586. if ($(this).data('btn') === 'list') {
  587. makeListTable(changeListData);
  588. $('#table-list-select tr').removeClass('table-warning');
  589. $('#code-list').html('');
  590. } else {
  591. makeCodeTable();
  592. }
  593. });
  594. // 记录变更信息操作
  595. $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
  596. changeInfo[$(this).attr('name')] = $(this).val();
  597. judgeChange();
  598. });
  599. $('body').on('valuechange', '#change_form textarea', function (e, previous) {
  600. changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
  601. judgeChange();
  602. });
  603. $('body').on('change', '#change_form select', function (e, previous) {
  604. changeInfo[$(this).attr('name')] = $(this).val();
  605. judgeChange();
  606. });
  607. $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
  608. changeInfo[$(this).attr('name')] = $(this).val();
  609. judgeChange();
  610. });
  611. $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
  612. const typecheck = [];
  613. $.each($('#change_form input[name="type[]"]:checked'), function () {
  614. typecheck.push($(this).val());
  615. });
  616. changeInfo.type = typecheck.join(',');
  617. judgeChange();
  618. });
  619. // 保存修改ajax提交(不刷新页面)
  620. $('.save_change_btn').on('click', function () {
  621. // 保存修改modal
  622. if ($('input[name="code"]').val() === '') {
  623. toastr.error('申请编号不能为空!');
  624. return;
  625. }
  626. if ($('input[name="name"]').val() === '') {
  627. toastr.error('工程名称不能为空!');
  628. return;
  629. }
  630. // 更新至服务器
  631. postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
  632. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  633. toastr.success(result);
  634. $('#show-save-btn').hide();
  635. $('#sp-btn').show();
  636. $('.title-main').removeClass('bg-warning');
  637. back_changeInfo = Object.assign({}, changeInfo);
  638. });
  639. return false;
  640. });
  641. $('#cancel_change').on('click', function () {
  642. $('#show-save-btn').hide();
  643. $('#sp-btn').show();
  644. $('.title-main').removeClass('bg-warning');
  645. if (!isObjEqual(changeInfo, back_changeInfo)) {
  646. changeFormRemake();
  647. }
  648. toastr.success('已还原到上次保存状态');
  649. });
  650. });
  651. function checkChangeFrom() {
  652. let returnFlag = false;
  653. // 表单判断
  654. if ($('input[name="code"]').val() === '') {
  655. toastr.error('申请编号不能为空!');
  656. returnFlag = true;
  657. }
  658. if ($('input[name="name"]').val() === '') {
  659. toastr.error('工程名称不能为空!');
  660. returnFlag = true;
  661. }
  662. if ($('textarea[name="content"]').val() === '') {
  663. toastr.error('工程变更理由及内容不能为空!');
  664. returnFlag = true;
  665. }
  666. if (changeList.length === 0) {
  667. toastr.error('请添加变更清单!');
  668. returnFlag = true;
  669. } else {
  670. for (const [i,cl] of changeList.entries()) {
  671. if (cl.code === '' || cl.name === '' || cl.oamount === '') {
  672. toastr.error('变更清单第' + (i+1) + '行未完整填写数据(变更部位、变更详情、单位、单价可空)');
  673. returnFlag = true;
  674. }
  675. }
  676. }
  677. if(!checkAuditorFrom ()) {
  678. returnFlag = true;
  679. }
  680. if (returnFlag) {
  681. return false;
  682. }
  683. }
  684. // 检查上报情况
  685. function checkAuditorFrom () {
  686. if ($('#auditList li').length === 0) {
  687. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  688. toastr.error('请联系管理员添加审批人');
  689. } else {
  690. toastr.error('请先选择审批人,再上报数据');
  691. }
  692. return false;
  693. }
  694. return true;
  695. }
  696. function tableDataRemake(changeListData) {
  697. $('#table-list-select tr').removeClass('table-warning');
  698. $('#table-list-select tr').removeClass('table-success');
  699. $('#table-list-select tr').attr('data-bwmx', '');
  700. $('#code-list').html('');
  701. // 根据已添加的清单显示
  702. if (changeList.length > 0 && changeList[0]) {
  703. for (const [index,clinfo] of changeList.entries()) {
  704. if (clinfo.lid != 0) {
  705. let listinfo = changeListData.find(function (item) {
  706. 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);
  707. });
  708. if (listinfo === undefined) {
  709. // 针对旧数据获取清单信息
  710. listinfo = changeListData[clinfo.lid - 1];
  711. if (listinfo === undefined) {
  712. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  713. changeList.splice(index, 1);
  714. continue;
  715. }
  716. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').addClass('table-success');
  717. let pushbwmx = '0*;*0';
  718. if (listinfo.leafXmjs !== undefined) {
  719. const leafInfo = listinfo.leafXmjs.find(function (item) {
  720. return (item.bwmx === undefined || item.bwmx === clinfo.bwmx) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  721. });
  722. console.log(leafInfo);
  723. if (leafInfo) {
  724. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
  725. (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
  726. (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
  727. (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
  728. (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
  729. (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (leafInfo.jldy !== undefined ? leafInfo.jldy : '')) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  730. } else {
  731. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  732. changeList.splice(index, 1);
  733. continue;
  734. }
  735. } else {
  736. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  737. }
  738. const bwmx = $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx');
  739. if (bwmx) {
  740. const bwmxArray = bwmx.split('$#$');
  741. bwmxArray.push(pushbwmx);
  742. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  743. } else {
  744. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  745. }
  746. } else {
  747. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').addClass('table-success');
  748. let pushbwmx = '0*;*0';
  749. if (listinfo.leafXmjs !== undefined) {
  750. const leafInfo = listinfo.leafXmjs.find(function (item) {
  751. return (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  752. });
  753. if (leafInfo) {
  754. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
  755. (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
  756. (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
  757. (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
  758. (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
  759. (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (leafInfo.jldy !== undefined ? leafInfo.jldy : '')) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  760. } else {
  761. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  762. changeList.splice(index, 1);
  763. continue;
  764. }
  765. } else {
  766. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  767. }
  768. const bwmx = $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx');
  769. if (bwmx) {
  770. const bwmxArray = bwmx.split('$#$');
  771. bwmxArray.push(pushbwmx);
  772. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  773. } else {
  774. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  775. }
  776. }
  777. }
  778. }
  779. }
  780. }
  781. // 清单搜索隐藏清单table部分值
  782. function makeListTable(changeListData, showListData = changeListData) {
  783. // 先加载台账数据
  784. let listHtml = '';
  785. let list_index = 1;
  786. let gcl_index = 0;
  787. for (const [index,gcl] of changeListData.entries()) {
  788. const isShow = _.find(showListData, gcl);
  789. $('#table-list-select tr').eq(index).css('display', (isShow ? 'table-row' : 'none'));
  790. }
  791. }
  792. // 项目节搜索隐藏code-table部分值
  793. function makeCodeTable(search = '') {
  794. if (search === '') {
  795. $('#code-list tr').css('display', 'table-row');
  796. return;
  797. }
  798. for(let i = 0; i < $('#code-list tr').length; i++) {
  799. const length = $('#code-list tr').eq(i).children('td').length;
  800. if (length === 8) {
  801. const code = $('#code-list tr').eq(i).children('td').eq(0).text();
  802. const name = $('#code-list tr').eq(i).children('td').eq(1).text();
  803. const jldy = $('#code-list tr').eq(i).children('td').eq(5).text();
  804. const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
  805. $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
  806. } else {
  807. return;
  808. }
  809. }
  810. }
  811. function remakeChangeSpread() {
  812. const newTableList = [];
  813. // 获取选中的签约清单判断并插入到原有清单中
  814. $('#table-list-select .table-success').each(function(){
  815. let code = $(this).children('td').eq(1).text();
  816. let name = $(this).children('td').eq(2).text();
  817. let unit = $(this).children('td').eq(3).text();
  818. let price = $(this).children('td').eq(4).text();
  819. // let oamount = $(this).children('td').eq(5).text();
  820. // 根据单位获取数量的位数,并得出
  821. // let numdecimal = findDecimal(unit);
  822. // let scnum = makedecimalzero(numdecimal);
  823. let scnum = 0;
  824. // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
  825. let lid = $(this).data('lid');
  826. let lindex = $(this).data('index');
  827. // 原清单和数量改变
  828. let data_bwmx = $(this).attr('data-bwmx').split('$#$');
  829. for (const b of data_bwmx) {
  830. const oamount = b.split('*;*')[1] != '' ? b.split('*;*')[1] : 0;
  831. let bwmx = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[6] : '';
  832. let xmj_code = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[0] : '';
  833. let xmj_jldy = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[1] : '';
  834. let xmj_dwgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[2] : '';
  835. let xmj_fbgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[3] : '';
  836. let xmj_fxgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[4] : '';
  837. let gcl_id = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[5] : '';
  838. let trlist = {
  839. code,
  840. name,
  841. bwmx,
  842. unit,
  843. unit_price: price,
  844. oamount,
  845. camount: scnum,
  846. detail: '',
  847. lid,
  848. xmj_code,
  849. xmj_jldy,
  850. xmj_dwgc,
  851. xmj_fbgc,
  852. xmj_fxgc,
  853. gcl_id,
  854. };
  855. const radionInfo = changeList.find(function (info) {
  856. return info.code === code && (info.lid == lid || parseInt(info.lid) === parseInt(lindex)) && gcl_id == info.gcl_id && info.bwmx === bwmx;
  857. });
  858. if (radionInfo) {
  859. trlist.camount = radionInfo.camount;
  860. trlist.detail = radionInfo.detail;
  861. }
  862. newTableList.push(trlist);
  863. }
  864. });
  865. // const changeWhiteList = _.filter(changeList, function (item) {
  866. // return item.lid == 0;
  867. // });
  868. // console.log(newTableList);
  869. // changeList = newTableList.concat(changeWhiteList);
  870. return newTableList;
  871. }
  872. //判断元素是否在数组中,相当于php的in_array();
  873. function in_array(arr, obj) {
  874. let i = arr.length;
  875. while (i--) {
  876. if (arr[i] == obj) {
  877. return true;
  878. }
  879. }
  880. return false;
  881. }
  882. function isObjEqual(o1,o2){
  883. var props1 = Object.getOwnPropertyNames(o1);
  884. var props2 = Object.getOwnPropertyNames(o2);
  885. if (props1.length != props2.length) {
  886. return false;
  887. }
  888. for (var i = 0,max = props1.length; i < max; i++) {
  889. var propName = props1[i];
  890. if (o1[propName] !== o2[propName]) {
  891. return false;
  892. }
  893. }
  894. return true;
  895. }
  896. // 判断是否有更改过
  897. function judgeChange() {
  898. let change = false;
  899. if (!isObjEqual(changeInfo, back_changeInfo)) {
  900. change = true;
  901. }
  902. if (change) {
  903. $('#show-save-btn').show();
  904. $('#sp-btn').hide();
  905. $('.title-main').addClass('bg-warning');
  906. } else {
  907. $('#show-save-btn').hide();
  908. $('#sp-btn').show();
  909. $('.title-main').removeClass('bg-warning');
  910. }
  911. }
  912. function changeFormRemake() {
  913. changeInfo = Object.assign({}, back_changeInfo);
  914. $('#change_form input[name="code"]').val(changeInfo.code);
  915. $('#change_form input[name="name"]').val(changeInfo.name);
  916. $('#change_form input[name="peg"]').val(changeInfo.peg);
  917. $('#change_form input[name="org_name"]').val(changeInfo.org_name);
  918. $('#change_form input[name="org_code"]').val(changeInfo.org_code);
  919. $('#change_form input[name="new_name"]').val(changeInfo.new_name);
  920. $('#change_form input[name="new_code"]').val(changeInfo.new_code);
  921. $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
  922. $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
  923. $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
  924. $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
  925. $('#change_form select[name="type"]').val(changeInfo.type);
  926. $('#change_form select[name="class"]').val(changeInfo.class);
  927. $('#change_form select[name="quality"]').val(changeInfo.quality);
  928. $('#change_form select[name="company"]').val(changeInfo.company);
  929. $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
  930. $('#change_form input[name="type[]"]').prop('checked', false);
  931. const typecheck = changeInfo.type.split(',');
  932. for (const type of typecheck) {
  933. $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
  934. }
  935. }