change_information_set.js 42 KB

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