change_information_set.js 42 KB

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