change_information_set.js 43 KB

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