change_information_set.js 43 KB

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