change_information_set.js 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  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]) && /^\d+$/.test(code2[i])) {
  19. return parseInt(code1[i]) - parseInt(code2[i]);
  20. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  21. return 1;
  22. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  23. return -1;
  24. } else {
  25. const str1length = code1[i].length;
  26. const str2length = code2[i].length;
  27. for (let j = 0; j < str1length; j++) {
  28. if (j+1 <= str2length) {
  29. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  30. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  31. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  32. if (str1length == str2length) {
  33. return 0;
  34. } else {
  35. return str1length - str2length;
  36. }
  37. }
  38. } else {
  39. if (j+1 >= str1length) {
  40. return 1;
  41. } else {
  42. return -1;
  43. }
  44. }
  45. }
  46. }
  47. } else if (i+1 == code1length && code1[i] == code2[i]) {
  48. if (code1length == code2length) {
  49. return 0;
  50. } else {
  51. return code1length - code2length;
  52. }
  53. }
  54. } else {
  55. if (i+1 >= code1length) {
  56. return 1;
  57. } else {
  58. return -1;
  59. }
  60. }
  61. }
  62. }
  63. $.event.special.valuechange = {
  64. teardown: function (namespaces) {
  65. $(this).unbind('.valuechange');
  66. },
  67. handler: function (e) {
  68. $.event.special.valuechange.triggerChanged($(this));
  69. },
  70. add: function (obj) {
  71. $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
  72. },
  73. triggerChanged: function (element) {
  74. var current = element[0].contentEditable === 'true' ? element.html() : element.val()
  75. , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
  76. if (current !== previous) {
  77. element.trigger('valuechange', [element.data('previous')]);
  78. element.data('previous', current);
  79. }
  80. }
  81. };
  82. function getPasteHint (str, row = '') {
  83. let returnObj = str;
  84. if (row) {
  85. returnObj.msg = '清单第' + (row+1) + '行' + str.msg;
  86. }
  87. return returnObj;
  88. }
  89. $(document).ready(() => {
  90. const changeSpreadSetting = {
  91. cols: [
  92. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit2'},
  93. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit2'},
  94. {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  95. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: false},
  96. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit2', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  97. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit2', getValue: 'getValue.unit_price'},
  98. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
  99. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  100. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: false, getValue: 'getValue.camount'},
  101. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  102. {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
  103. ],
  104. emptyRows: 0,
  105. headRows: 2,
  106. headRowHeight: [25, 25],
  107. defaultRowHeight: 21,
  108. headerFont: '12px 微软雅黑',
  109. font: '12px 微软雅黑',
  110. readOnly: readOnly,
  111. rowHeader:[
  112. {
  113. rowHeaderType: 'circle',
  114. setting: {
  115. size: 5,
  116. indent: 16,
  117. getColor: function (index, data) {
  118. if (!data) return;
  119. if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
  120. return '#dc3545';
  121. }
  122. if(data.lid != 0) return;
  123. return '#007bff';
  124. }
  125. },
  126. },
  127. ],
  128. localCache: {
  129. key: 'changes-spread',
  130. colWidth: true,
  131. }
  132. };
  133. const changeCol = {
  134. getValue: {
  135. unit_price: function(data) {
  136. return ZhCalc.round(data.unit_price, unitPriceUnit);
  137. },
  138. oa_tp: function (data) {
  139. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
  140. },
  141. ca_tp: function (data) {
  142. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
  143. },
  144. oamount: function (data) {
  145. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  146. },
  147. camount: function (data) {
  148. return ZhCalc.round(data.camount, findDecimal(data.unit));
  149. },
  150. del_list: function (data) {
  151. return !_.find(changeUsedData, { id: data.id }) ? '移除' : '';
  152. }
  153. },
  154. readOnly: {
  155. isEdit: function (data) {
  156. return !readOnly && data.lid != 0;
  157. },
  158. isEdit2: function (data) {
  159. return !readOnly && (data.lid != 0 || (data.lid == 0 && _.findIndex(changeUsedData, { id: data.id }) !== -1));
  160. },
  161. },
  162. };
  163. const changeSpreadObj = {
  164. makeSjsFooter: function () {
  165. // 增加汇总行并设为锁定禁止编辑状态
  166. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  167. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  168. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  169. changeSpreadObj.countSum();
  170. },
  171. countSum: function() {
  172. const rowCount = changeSpreadSheet.getRowCount();
  173. let oSum = 0,
  174. cSum = 0;
  175. for(var i = 0; i < rowCount - 1; i++){
  176. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
  177. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
  178. }
  179. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
  180. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
  181. },
  182. add: function () {
  183. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  184. if (result) {
  185. changeList.push(result);
  186. changeSpreadSheet.addRows(changeList.length - 1, 1);
  187. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  188. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  189. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  190. changeSpreadObj.resetXmjSpread();
  191. }
  192. });
  193. },
  194. batchAdd: function(num) {
  195. postData(window.location.pathname + '/save', {type: 'batchadd', num}, function (result) {
  196. if (result) {
  197. changeList = _.concat(changeList, result);
  198. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  199. changeSpreadObj.makeSjsFooter();
  200. changeSpreadObj.resetXmjSpread();
  201. }
  202. });
  203. },
  204. del: function () {
  205. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  206. const index = changeList.indexOf(select);
  207. if (index > -1 && !_.find(changeUsedData, { id: select.id })) {
  208. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  209. changeList.splice(index, 1);
  210. changeSpreadSheet.deleteRows(index, 1);
  211. const sel = changeSpreadSheet.getSelections();
  212. changeSpreadSheet.setSelection(0, 0, 1, 1);
  213. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  214. if (select.lid != 0) {
  215. tableDataRemake(changeListData);
  216. }
  217. changeSpreadObj.countSum();
  218. });
  219. }
  220. },
  221. resetXmjSpread: function(data = null) {
  222. const xmj = [];
  223. if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) {
  224. const newData = JSON.parse(JSON.stringify(data));
  225. if (newData.bwmx === newData.xmj_jldy) {
  226. newData.bwmx = '';
  227. }
  228. xmj.push(newData);
  229. }
  230. SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);
  231. },
  232. selectionChanged: function (e, info) {
  233. const sel = info.sheet.getSelections()[0];
  234. const col = info.sheet.zh_setting.cols[sel.col];
  235. const data = SpreadJsObj.getSelectObject(info.sheet);
  236. if (col && col.field === 'del_list' && !_.find(changeUsedData, { id: data.id })) {
  237. changeSpreadObj.del();
  238. }
  239. changeSpreadObj.resetXmjSpread(data);
  240. },
  241. deletePress: function (sheet) {
  242. return;
  243. },
  244. editEnded: function (e, info) {
  245. if (info.sheet.zh_setting) {
  246. const select = SpreadJsObj.getSelectObject(info.sheet);
  247. const col = info.sheet.zh_setting.cols[info.col];
  248. if (col.field === 'del_list') {
  249. return;
  250. }
  251. // 未改变值则不提交
  252. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  253. const orgValue = select[col.field];
  254. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  255. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  256. return;
  257. }
  258. // 判断部分值是否输入的是数字判断和数据计算
  259. if (col.type === 'Number') {
  260. if (isNaN(validText)) {
  261. toastr.error('不能输入其它非数字类型字符');
  262. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  263. return;
  264. }
  265. if (col.field === 'unit_price') {
  266. validText = ZhCalc.round(validText, unitPriceUnit);
  267. } else {
  268. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  269. }
  270. }
  271. if (col.field === 'unit') {
  272. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  273. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  274. }
  275. if(col.field === 'camount') {
  276. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  277. const usedInfo = _.find(changeUsedData, { id: select.id });
  278. if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
  279. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  280. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  281. return;
  282. } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
  283. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  284. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  285. return;
  286. }
  287. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  288. }
  289. select[col.field] = validText;
  290. console.log(select);
  291. delete select.waitingLoading;
  292. // 更新至服务器
  293. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  294. changeList.splice(info.row, 1, select);
  295. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  296. changeSpreadObj.countSum();
  297. }, function () {
  298. select[col.field] = orgValue;
  299. if(col.field === 'camount') {
  300. select.spamount = orgValue;
  301. }
  302. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  303. });
  304. }
  305. },
  306. clipboardPasted(e, info) {
  307. const hint = {
  308. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  309. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  310. };
  311. const range = info.cellRange;
  312. const sortData = info.sheet.zh_data || [];
  313. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  314. toastMessageUniq(hint.cellError);
  315. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  316. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  317. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  318. changeSpreadObj.makeSjsFooter();
  319. return;
  320. }
  321. if (sortData.length > 0 && range.col + range.colCount > 10) {
  322. toastMessageUniq(hint.cellError);
  323. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  324. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  325. changeSpreadObj.makeSjsFooter();
  326. return;
  327. }
  328. const data = [];
  329. // const rowData = [];
  330. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  331. let bPaste = true;
  332. const curRow = range.row + iRow;
  333. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  334. const cLData = { id: sortData[curRow].id };
  335. const hintRow = range.rowCount > 1 ? curRow : '';
  336. let sameCol = 0;
  337. for (let iCol = 0; iCol < range.colCount; iCol++) {
  338. const curCol = range.col + iCol;
  339. const colSetting = info.sheet.zh_setting.cols[curCol];
  340. if (!colSetting) continue;
  341. let validText = info.sheet.getText(curRow, curCol);
  342. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  343. const orgValue = sortData[curRow][colSetting.field];
  344. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  345. sameCol++;
  346. if (range.colCount === sameCol) {
  347. bPaste = false;
  348. }
  349. continue;
  350. }
  351. if (colSetting.type === 'Number') {
  352. if (isNaN(validText)) {
  353. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  354. bPaste = false;
  355. continue;
  356. }
  357. if (colSetting.field === 'unit_price') {
  358. validText = ZhCalc.round(validText, unitPriceUnit);
  359. } else {
  360. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  361. }
  362. if(colSetting.field === 'camount') {
  363. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  364. const usedInfo = _.find(changeUsedData, { id: sortData[curRow].id });
  365. if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
  366. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  367. bPaste = false;
  368. continue;
  369. } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
  370. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  371. bPaste = false;
  372. continue;
  373. }
  374. }
  375. }
  376. let unitdecimal = validText;
  377. if (colSetting.field === 'unit') {
  378. //粘贴内容要为下拉列表里所有的单位,不然为空
  379. if (changeUnits.indexOf(validText) === -1) {
  380. unitdecimal = '';
  381. }
  382. cLData.camount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  383. cLData.oamount = ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
  384. }
  385. cLData[colSetting.field] = validText;
  386. sortData[curRow][colSetting.field] = validText;
  387. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  388. }
  389. if (bPaste) {
  390. data.push(cLData);
  391. // rowData.push(curRow);
  392. } else {
  393. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  394. }
  395. }
  396. if (data.length === 0) {
  397. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  398. return;
  399. }
  400. console.log(data);
  401. // 更新至服务器
  402. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  403. changeList = result;
  404. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  405. changeSpreadObj.makeSjsFooter();
  406. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  407. }, function () {
  408. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  409. return;
  410. });
  411. },
  412. valueChanged(e, info) {
  413. // 防止ctrl+z撤销数据
  414. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  415. }
  416. };
  417. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  418. let changeListData;
  419. let gclGatherData;
  420. postData(preUrl + '/defaultBills', {}, function (result) {
  421. gclGatherModel.loadLedgerData(result.bills);
  422. gclGatherModel.loadPosData(result.pos);
  423. gclGatherData = gclGatherModel.gatherGclData();
  424. gclGatherData = _.filter(gclGatherData, function (item) {
  425. return item.leafXmjs && item.leafXmjs.length !== 0;
  426. });
  427. for (const ggd in gclGatherData) {
  428. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  429. gclGatherData.splice(ggd, 1);
  430. }
  431. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  432. let hadcid = 0;
  433. for (const xmj of gclGatherData[ggd].leafXmjs) {
  434. if (_.findIndex(changeLedgerList, { id: xmj.gcl_id }) !== -1 || _.findIndex(changePosList, { id: xmj.mx_id, lid: xmj.gcl_id }) !== -1) {
  435. xmj.cid = 1;
  436. hadcid = 1;
  437. }
  438. }
  439. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  440. }
  441. // 数组去重
  442. const dealBillList = result.dealBills;
  443. for (const db of gclGatherData) {
  444. const exist_index = dealBillList.findIndex(function (item) {
  445. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  446. });
  447. if (exist_index !== -1) {
  448. dealBillList.splice(exist_index, 1);
  449. }
  450. }
  451. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  452. console.log(changeListData);
  453. // 先加载台账数据
  454. let listHtml = '';
  455. let list_index = 1;
  456. let gcl_index = 0;
  457. for (const gcl of changeListData) {
  458. const unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
  459. const quantity = gcl.quantity !== 0 && gcl.quantity !== null && gcl.quantity !== undefined ? (unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity) : 0;
  460. const unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? gcl.unit_price : 0;
  461. let gclhtml = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? ' data-gcl="' + gcl_index + '"' : '';
  462. gcl_index = gclhtml !== '' ? ++gcl_index : gcl_index;
  463. const lid = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? (gcl.leafXmjs.length !== 0 ? gcl.leafXmjs[0].gcl_id : false) : gcl.id;
  464. if (lid) {
  465. listHtml += '<tr data-lid="' + lid + '"' + gclhtml + ' data-index="' + list_index + '" data-bwmx="">' +
  466. '<td class="text-center">' + list_index + (gcl.cid ? '<i class="text-danger" style="font-weight: 900">*</i>' : '') + '</td>' +
  467. '<td>' + gcl.code + '</td>' +
  468. '<td class="text-left">' + gcl.name + '</td>' +
  469. '<td class="text-center">' + unit + '</td>' +
  470. '<td class="text-right">' + (ZhCalc.round(unit_price, unitPriceUnit) ? ZhCalc.round(unit_price, unitPriceUnit) : 0) + '</td>' +
  471. '<td class="text-right">' + quantity + '</td>' +
  472. '</tr>';
  473. list_index++;
  474. }
  475. }
  476. $('#table-list-select').html(listHtml);
  477. tableDataRemake(changeListData);
  478. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  479. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  480. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  481. // changeSpreadSheet.options.protectionOptions = {
  482. // allowSort: true,
  483. // allowFilter: true
  484. // };
  485. // var option = changeSpreadSheet.options.protectionOptions;
  486. // changeSpreadSheet.rowFilter(new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, 0, -1, changeSpreadSetting.cols.length)));
  487. // // changeSpreadSheet.rowFilter(new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, 0, -1, 3)));
  488. // const filter = changeSpreadSheet.rowFilter();
  489. // filter.filterButtonVisible(false);
  490. // filter.filterButtonVisible(0, true);
  491. // filter.filterButtonVisible(2, true);
  492. // filter.filterDialogVisibleInfo({
  493. // sortByValue: true, //SortByValue item is visible.
  494. // sortByColor: false, //SortByColor item is visible.
  495. // filterByColor: false, //FilterByColor item is visible.
  496. // filterByValue: false, //FilterByValue item is visible.
  497. // listFilterArea: false //ListFilterArea item is visible.
  498. // });
  499. // function compareList(obj1, obj2) {
  500. // console.log(obj1, obj2);
  501. // var list = ["", '204-1-b', '合计'];
  502. // var index1 = list.indexOf(obj1), index2 = list.indexOf(obj2);
  503. // if (index1 > index2) {
  504. // return 1;
  505. // } else if (index1 < index2) {
  506. // return -1;
  507. // } else {
  508. // return 0;
  509. // }
  510. // }
  511. // changeSpreadSheet.sortRange(0, 0, changeSpreadSetting.cols.length, 1, true, [{index: 0, ascending: true, compareFunction: compareList}]);
  512. // changeSpreadSheet.bind(GC.Spread.Sheets.Events.RangeSorting, function (e, info) {
  513. // info.compareFunction = compareList;
  514. // });
  515. // filter.sortColumn(0, true);
  516. changeSpreadObj.makeSjsFooter();
  517. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  518. });
  519. if (!readOnly) {
  520. $('#add-white-btn').click(changeSpreadObj.add);
  521. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  522. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  523. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  524. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  525. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  526. changeSpreadSheet.getCell(-1, 10).foreColor('#dc3545');
  527. let batchInsertObj;
  528. $.contextMenu.types.batchInsert = function (item, opt, root) {
  529. const self = this;
  530. if ($.isFunction(item.icon)) {
  531. item._icon = item.icon.call(this, this, $t, key, item);
  532. } else {
  533. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  534. // to enable font awesome
  535. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  536. } else {
  537. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  538. }
  539. }
  540. this.addClass(item._icon);
  541. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="100" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  542. .appendTo(this);
  543. const $input = $obj.find('input');
  544. const event = () => {
  545. if (self.hasClass('context-menu-disabled')) return;
  546. item.batchInsert($input[0], root);
  547. };
  548. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  549. $input.click((e) => {e.stopPropagation();})
  550. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  551. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  552. };
  553. // 右键菜单
  554. $.contextMenu({
  555. selector: '#change-spread',
  556. build: function ($trigger, e) {
  557. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  558. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  559. },
  560. items: {
  561. 'createList': {
  562. name: '添加台账清单',
  563. icon: 'fa-sign-in',
  564. callback: function (key, opt) {
  565. $('#addlist').modal('show');
  566. },
  567. },
  568. 'createAdd': {
  569. name: '添加空白清单',
  570. icon: 'fa-sign-in',
  571. callback: function (key, opt) {
  572. changeSpreadObj.add(changeSpreadSheet);
  573. },
  574. },
  575. 'batchInsert': {
  576. name: '批量添加空白清单',
  577. type: 'batchInsert',
  578. value: '2',
  579. icon: 'fa-sign-in',
  580. batchInsert: function (obj, root) {
  581. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  582. obj.value = obj.max;
  583. toastr.warning('批量添加不可多于' + obj.max);
  584. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  585. obj.value = obj.min;
  586. toastr.warning('批量添加不可少于' + obj.min);
  587. } else {
  588. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  589. changeSpreadObj.batchAdd(obj.value);
  590. root.$menu.trigger('contextmenu:hide');
  591. }
  592. },
  593. },
  594. 'delete': {
  595. name: '删除',
  596. icon: 'fa-remove',
  597. callback: function (key, opt) {
  598. changeSpreadObj.del(changeSpreadSheet);
  599. },
  600. disabled: function (key, opt) {
  601. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  602. const sel = changeSpreadSheet.getSelections()[0];
  603. changeSpreadObj.resetXmjSpread(select);
  604. console.log(select, sel);
  605. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1 && !_.find(changeUsedData, { id: select.id })) {
  606. return false;
  607. } else {
  608. return true;
  609. }
  610. }
  611. },
  612. }
  613. });
  614. }
  615. // 清单选中和移除
  616. $('body').on('click', '#table-list-select tr', function () {
  617. $('#table-list-select tr').removeClass('table-warning');
  618. $(this).addClass('table-warning');
  619. const isCheck = $(this).hasClass('table-success') ? true : false;
  620. const data_bwmx = $(this).attr('data-bwmx').split('$#$');
  621. const isDeal = $(this).data('gcl') !== undefined ? true : false;
  622. let codeHtml = '<tr quantity="'+ $(this).children('td').eq(5).text() +'" gcl_id="" mx_id=""><td class="text-center">1</td><td colspan="7" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox"></td></tr>';
  623. if (isDeal) {
  624. const lid = $(this).data('lid');
  625. let gcl = _.find(gclGatherData, function (item) {
  626. return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
  627. });
  628. if (!gcl) {
  629. gcl = gclGatherData[$(this).data('gcl')];
  630. }
  631. codeHtml = '';
  632. for (const [index, leaf] of gcl.leafXmjs.entries()) {
  633. const quantity = leaf.quantity !== undefined && leaf.quantity !== null ? leaf.quantity : 0;
  634. const gcl_id = leaf.gcl_id ? leaf.gcl_id : '';
  635. const mx_id = leaf.mx_id ? leaf.mx_id : '';
  636. const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : (gcl.leafXmjs.length > 1 && gcl.name ? gcl.name : undefined);
  637. const isChecked = data_bwmx.indexOf(
  638. leaf.code + '!_!' + (leaf.jldy ? leaf.jldy : '') + '!_!' +
  639. (leaf.dwgc ? leaf.dwgc : '') + '!_!' + (leaf.fbgc ? leaf.fbgc : '') + '!_!' + (leaf.fxgc ? leaf.fxgc : '')
  640. + '!_!' + (leaf.gcl_id ? leaf.gcl_id : '0') + '!_!' + (leaf.mx_id ? leaf.mx_id : '') + '!_!' +
  641. (bwmx !== undefined ? bwmx : leaf.jldy ? leaf.jldy : '') + '*;*' + quantity) !== -1 && isCheck ?
  642. 'checked' : '';
  643. const isUsed = _.find(changeUsedData, { gcl_id: leaf.gcl_id, bwmx: (bwmx ? bwmx : leaf.jldy ? leaf.jldy : ''), oamount: leaf.quantity });
  644. const isDisabled = isUsed ? 'disabled ' : '';
  645. codeHtml += '<tr quantity="' + quantity + '" gcl_id="' + gcl_id + '" mx_id="' + mx_id + '">' +
  646. '<td class="text-center">' + (index+1) + (leaf.cid ? '<i class="text-danger" style="font-weight: 900">*</i>' : '') + '</td>' +
  647. '<td>' + leaf.code + '</td>' +
  648. '<td>' + (leaf.jldy ? leaf.jldy: '') + '</td>' +
  649. '<td>' + (leaf.dwgc ? leaf.dwgc : '') + '</td>' +
  650. '<td>' + (leaf.fbgc ? leaf.fbgc : '') + '</td>' +
  651. '<td>' + (leaf.fxgc ? leaf.fxgc : '') + '</td>' +
  652. '<td>' + (bwmx !== undefined ? bwmx : '') + '</td>' +
  653. '<td class="text-right">' + (ZhCalc.round(quantity, findDecimal(gcl.unit)) ? ZhCalc.round(quantity, findDecimal(gcl.unit)) : 0) + '</td>' +
  654. '<td class="text-center"><input type="checkbox" ' + isDisabled + isChecked +
  655. '></td></tr>';
  656. }
  657. } else if (!isDeal && isCheck) {
  658. codeHtml = '<tr quantity="'+ $(this).children('td').eq(5).text() +'" gcl_id="" mx_id=""><td class="text-center">1</td><td colspan="7" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox" checked></td></tr>';
  659. }
  660. $('#code-list').attr('data-index', parseInt($(this).children('td').eq(0).text()));
  661. $('#code-input').val('');
  662. $('#code-input').siblings('a').hide();
  663. $('#code-list').html(codeHtml);
  664. checkSelectAll();
  665. });
  666. // 右边项目节选择
  667. $('body').on('click', '#code-list input', function () {
  668. let index = $('#code-list').attr('data-index');
  669. if ($(this).is(':checked')) {
  670. // 去除其它可能已选的checked
  671. // $('#code-list input').prop('checked', false);
  672. $(this).prop('checked', true);
  673. // 左边表单传值并添加class
  674. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  675. // 去除部分data-detail值
  676. let data_bwmx = [];
  677. $('#code-list input:checked').each(function () {
  678. const tr = $(this).parents('tr');
  679. const length = tr.children('td').length;
  680. const gcl_id = tr.attr('gcl_id');
  681. const mx_id = tr.attr('mx_id');
  682. const bwmx = length === 9 ?
  683. tr.children('td').eq(1).text() + '!_!' +
  684. tr.children('td').eq(2).text() + '!_!' +
  685. tr.children('td').eq(3).text() + '!_!' +
  686. tr.children('td').eq(4).text() + '!_!' +
  687. tr.children('td').eq(5).text() + '!_!' + gcl_id + '!_!' + mx_id + '!_!' +
  688. (tr.children('td').eq(6).text() !== '' ? tr.children('td').eq(6).text() : tr.children('td').eq(2).text()) : '0';
  689. const quantity = tr.attr('quantity');
  690. const de_qu = bwmx + '*;*' + quantity;
  691. data_bwmx.push(de_qu);
  692. });
  693. data_bwmx = data_bwmx.join('$#$');
  694. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  695. } else {
  696. // 判断还有无选中项目节编号
  697. if ($('#code-list input').is(':checked')) {
  698. // 去除部分data-detail值
  699. let data_bwmx = [];
  700. $('#code-list input:checked').each(function () {
  701. const tr = $(this).parents('tr');
  702. const length = tr.children('td').length;
  703. const gcl_id = tr.attr('gcl_id');
  704. const mx_id = tr.attr('mx_id');
  705. const bwmx = length === 9 ?
  706. tr.children('td').eq(1).text() + '!_!' +
  707. tr.children('td').eq(2).text() + '!_!' +
  708. tr.children('td').eq(3).text() + '!_!' +
  709. tr.children('td').eq(4).text() + '!_!' +
  710. tr.children('td').eq(5).text() + '!_!' + gcl_id + '!_!' + mx_id + '!_!' +
  711. (tr.children('td').eq(6).text() !== '' ? tr.children('td').eq(6).text() : tr.children('td').eq(2).text()) : '0';
  712. const quantity = tr.attr('quantity');
  713. const de_qu = bwmx + '*;*' + quantity;
  714. data_bwmx.push(de_qu);
  715. });
  716. data_bwmx = data_bwmx.join('$#$');
  717. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  718. } else {
  719. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  720. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  721. }
  722. }
  723. checkSelectAll();
  724. });
  725. // 添加空白清单or签约清单
  726. $('.add-list-btn').on('click', function () {
  727. const newLedgerList = remakeChangeSpread();
  728. // 更新至服务器
  729. postData(window.location.pathname + '/save', { type:'ledger_list', updateData: newLedgerList }, function (result) {
  730. changeList = result.changeList;
  731. changeUsedData = result.usedList;
  732. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  733. changeSpreadObj.makeSjsFooter();
  734. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  735. changeSpreadObj.resetXmjSpread(select);
  736. $('#addlist').modal('hide');
  737. }, function () {
  738. $('#addlist').modal('hide');
  739. });
  740. });
  741. // 选中input所有值
  742. $('body').on('focus', ".clist input", function() {
  743. $(this).select();
  744. });
  745. // 取消选中清单
  746. $('#cancel-list-btn').click(function () {
  747. // $('#table-list-select tr').removeClass('table-success');
  748. // $('#table-list-select tr').attr('data-bwmx', '');
  749. // $('#code-list').html('');
  750. tableDataRemake(changeListData);
  751. });
  752. // 自动编号
  753. $('.reduction-code').click(function () {
  754. const code = $(this).attr('data-code');
  755. $('input[name="code"]').val(code);
  756. });
  757. $('#select-list').change(function () {
  758. const select = parseInt($(this).val());
  759. let showListData = changeListData;
  760. const value = $('#list-input').val();
  761. if (select === 1) {
  762. if (value !== '') {
  763. $('#list-input').siblings('a').show();
  764. showListData = _.filter(changeListData, function (c) {
  765. return ((c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1)) && c.cid;
  766. });
  767. } else {
  768. $('#list-input').siblings('a').hide();
  769. showListData = _.filter(changeListData, function (c) {
  770. return c.cid;
  771. });
  772. }
  773. } else {
  774. if (value !== '') {
  775. $('#list-input').siblings('a').show();
  776. showListData = _.filter(changeListData, function (c) {
  777. return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  778. });
  779. } else {
  780. $('#list-input').siblings('a').hide();
  781. }
  782. }
  783. makeListTable(changeListData, showListData);
  784. $('#table-list-select tr').removeClass('table-warning');
  785. $('#code-input').val('');
  786. $('#code-input').siblings('a').hide();
  787. $('#code-list').html('');
  788. $('#code-select-all').prop('checked', false);
  789. });
  790. $('#list-input').on('valuechange', function (e, previous) {
  791. const select = parseInt($('#select-list').val());
  792. const value = $(this).val();
  793. let showListData = changeListData;
  794. if (select === 1 && value !== '') {
  795. $(this).siblings('a').show();
  796. showListData = _.filter(changeListData, function (c) {
  797. return ((c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1)) && c.cid;
  798. });
  799. } else if (select === 1 && value === '') {
  800. $(this).siblings('a').hide();
  801. showListData = _.filter(changeListData, function (c) {
  802. return c.cid;
  803. });
  804. } else if (value !== '') {
  805. $(this).siblings('a').show();
  806. showListData = _.filter(changeListData, function (c) {
  807. return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  808. });
  809. } else {
  810. $(this).siblings('a').hide();
  811. }
  812. makeListTable(changeListData, showListData);
  813. $('#table-list-select tr').removeClass('table-warning');
  814. $('#code-input').val('');
  815. $('#code-input').siblings('a').hide();
  816. $('#code-list').html('');
  817. $('#code-select-all').prop('checked', false);
  818. });
  819. $('#code-input').on('valuechange', function (e, previous) {
  820. const value = $(this).val();
  821. if (value !== '') {
  822. $(this).siblings('a').show();
  823. } else {
  824. $(this).siblings('a').hide();
  825. }
  826. makeCodeTable($(this).val());
  827. checkSelectAll();
  828. });
  829. $('.remove-btn').on('click', function () {
  830. $(this).hide();
  831. $(this).siblings('input').val('');
  832. if ($(this).data('btn') === 'list') {
  833. const select = parseInt($('#select-list').val());
  834. let showListData = changeListData;
  835. if (select === 1) {
  836. showListData = _.filter(changeListData, function (c) {
  837. return c.cid;
  838. });
  839. }
  840. makeListTable(changeListData, showListData);
  841. $('#table-list-select tr').removeClass('table-warning');
  842. $('#code-list').html('');
  843. } else {
  844. makeCodeTable();
  845. }
  846. checkSelectAll();
  847. });
  848. // 全选及取消
  849. $('#code-select-all').click(function () {
  850. // 全选checkbox
  851. let index = $('#code-list').attr('data-index');
  852. if (index) {
  853. if ($(this).is(':checked')){
  854. $('#code-list tr').each(function () {
  855. if ($(this).css('display') !== 'none') {
  856. $(this).find('input').prop('checked', true);
  857. }
  858. })
  859. } else {
  860. $('#code-list tr').each(function () {
  861. if ($(this).css('display') !== 'none' && $(this).find('input').prop('disabled') !== true) {
  862. $(this).find('input').prop('checked', false);
  863. }
  864. });
  865. }
  866. // 判断还有无选中项目节编号
  867. if ($('#code-list input').is(':checked')) {
  868. // 去除部分data-detail值
  869. let data_bwmx = [];
  870. $('#code-list input:checked').each(function () {
  871. const tr = $(this).parents('tr');
  872. const length = tr.children('td').length;
  873. const gcl_id = tr.attr('gcl_id');
  874. const mx_id = tr.attr('mx_id');
  875. const bwmx = length === 9 ?
  876. tr.children('td').eq(1).text() + '!_!' +
  877. tr.children('td').eq(2).text() + '!_!' +
  878. tr.children('td').eq(3).text() + '!_!' +
  879. tr.children('td').eq(4).text() + '!_!' +
  880. tr.children('td').eq(5).text() + '!_!' + gcl_id + '!_!' + mx_id + '!_!' +
  881. (tr.children('td').eq(6).text() !== '' ? tr.children('td').eq(6).text() : tr.children('td').eq(2).text()) : '0';
  882. const quantity = tr.attr('quantity');
  883. const de_qu = bwmx + '*;*' + quantity;
  884. data_bwmx.push(de_qu);
  885. });
  886. data_bwmx = data_bwmx.join('$#$');
  887. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  888. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  889. } else {
  890. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  891. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  892. }
  893. }
  894. });
  895. // 记录变更信息操作
  896. $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
  897. changeInfo[$(this).attr('name')] = $(this).val();
  898. judgeChange();
  899. });
  900. $('body').on('valuechange', '#change_form textarea', function (e, previous) {
  901. changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
  902. judgeChange();
  903. });
  904. $('body').on('change', '#change_form select', function (e, previous) {
  905. changeInfo[$(this).attr('name')] = $(this).val();
  906. judgeChange();
  907. });
  908. $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
  909. changeInfo[$(this).attr('name')] = $(this).val();
  910. judgeChange();
  911. });
  912. $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
  913. const typecheck = [];
  914. $.each($('#change_form input[name="type[]"]:checked'), function () {
  915. typecheck.push($(this).val());
  916. });
  917. changeInfo.type = typecheck.join(',');
  918. judgeChange();
  919. });
  920. // 保存修改ajax提交(不刷新页面)
  921. $('.save_change_btn').on('click', function () {
  922. // 保存修改modal
  923. if ($('input[name="code"]').val() === '') {
  924. toastr.error('申请编号不能为空!');
  925. return;
  926. }
  927. if ($('input[name="name"]').val() === '') {
  928. toastr.error('工程名称不能为空!');
  929. return;
  930. }
  931. // 换行更改并提交
  932. changeInfo.content = changeInfo.content.replace(/<br><br>/g, '\r\n');
  933. changeInfo.basis = changeInfo.basis.replace(/<br><br>/g, '\r\n');
  934. changeInfo.expr = changeInfo.expr.replace(/<br><br>/g, '\r\n');
  935. changeInfo.memo = changeInfo.memo.replace(/<br><br>/g, '\r\n');
  936. // 后改为br
  937. // 更新至服务器
  938. postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
  939. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  940. toastr.success(result);
  941. $('#show-save-btn').hide();
  942. $('#sp-btn').show();
  943. $('.title-main').removeClass('bg-warning');
  944. changeInfo.content = changeInfo.content.replace(/[\r\n]/g, '<br>');
  945. changeInfo.basis = changeInfo.basis.replace(/[\r\n]/g, '<br>');
  946. changeInfo.expr = changeInfo.expr.replace(/[\r\n]/g, '<br>');
  947. changeInfo.memo = changeInfo.memo.replace(/[\r\n]/g, '<br>');
  948. back_changeInfo = Object.assign({}, changeInfo);
  949. });
  950. return false;
  951. });
  952. $('#cancel_change').on('click', function () {
  953. $('#show-save-btn').hide();
  954. $('#sp-btn').show();
  955. $('.title-main').removeClass('bg-warning');
  956. if (!isObjEqual(changeInfo, back_changeInfo)) {
  957. changeFormRemake();
  958. }
  959. toastr.success('已还原到上次保存状态');
  960. });
  961. });
  962. function checkSelectAll() {
  963. let check = $('#code-list tr').length > 0 ? true : false;
  964. const codeNum = $('#code-list tr').length;
  965. let i = 0;
  966. $('#code-list tr').each(function () {
  967. if ($(this).css('display') !== 'none' && !$(this).find('input').is(':checked')) {
  968. check = false;
  969. return;
  970. }
  971. else if ($(this).css('display') === 'none') {
  972. i++;
  973. }
  974. });
  975. if (check && i === codeNum) {
  976. check = false;
  977. }
  978. $('#code-select-all').prop('checked', check);
  979. }
  980. function checkChangeFrom() {
  981. let returnFlag = false;
  982. // 表单判断
  983. if ($('input[name="code"]').val() === '') {
  984. toastr.error('申请编号不能为空!');
  985. returnFlag = true;
  986. }
  987. if ($('input[name="name"]').val() === '') {
  988. toastr.error('工程名称不能为空!');
  989. returnFlag = true;
  990. }
  991. if ($('textarea[name="content"]').val() === '') {
  992. toastr.error('工程变更理由及内容不能为空!');
  993. returnFlag = true;
  994. }
  995. if (changeList.length === 0) {
  996. toastr.error('请添加变更清单!');
  997. returnFlag = true;
  998. } else {
  999. for (const [i,cl] of changeList.entries()) {
  1000. if (cl.code === '' || cl.name === '' || cl.oamount === '') {
  1001. toastr.error('变更清单第' + (i+1) + '行未完整填写数据(变更部位、变更详情、单位、单价可空)');
  1002. returnFlag = true;
  1003. }
  1004. }
  1005. }
  1006. if(!checkAuditorFrom ()) {
  1007. returnFlag = true;
  1008. }
  1009. if (returnFlag) {
  1010. return false;
  1011. }
  1012. }
  1013. // 检查上报情况
  1014. function checkAuditorFrom () {
  1015. if ($('#auditList li').length === 0) {
  1016. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  1017. toastr.error('请联系管理员添加审批人');
  1018. } else {
  1019. toastr.error('请先选择审批人,再上报数据');
  1020. }
  1021. return false;
  1022. }
  1023. return true;
  1024. }
  1025. function tableDataRemake(changeListData) {
  1026. $('#table-list-select tr').removeClass('table-warning');
  1027. $('#table-list-select tr').removeClass('table-success');
  1028. $('#table-list-select tr').attr('data-bwmx', '');
  1029. $('#code-list').html('');
  1030. $('#code-list').attr('data-index', '');
  1031. $('#code-input').val('');
  1032. $('#code-select-all').prop('checked', false);
  1033. $('#code-input').siblings('a').hide();
  1034. // 根据已添加的清单显示
  1035. if (changeList.length > 0 && changeList[0]) {
  1036. const removeList = [];
  1037. const updateList = [];
  1038. const updateGclIdList = [];
  1039. for (const [index,clinfo] of changeList.entries()) {
  1040. if (clinfo.lid != 0) {
  1041. let listinfo = changeListData.find(function (item) {
  1042. 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);
  1043. });
  1044. let info = '';
  1045. if (listinfo === undefined || (clinfo.lid && clinfo.gcl_id && clinfo.lid !== clinfo.gcl_id)) {
  1046. // 有可能这部分台账发生变化,此时要更新清单lid信息,防止数据丢失
  1047. const newlistinfo = changeListData.find(function (item) {
  1048. return (item.id !== undefined && item.id == clinfo.gcl_id) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && _.find(item.leafXmjs, {gcl_id: clinfo.gcl_id }));
  1049. });
  1050. if (listinfo === undefined && newlistinfo || (listinfo && newlistinfo && !isObjEqual(listinfo, newlistinfo))) {
  1051. listinfo = newlistinfo;
  1052. updateList.push({id: clinfo.id, lid: newlistinfo.leafXmjs[0].gcl_id});
  1053. // 更新lid
  1054. changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
  1055. }
  1056. }
  1057. if (listinfo === undefined) {
  1058. // 针对旧数据获取清单信息
  1059. listinfo = changeListData[clinfo.lid - 1];
  1060. if (listinfo === undefined) {
  1061. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  1062. // changeList.splice(index, 1);
  1063. removeList.push(clinfo);
  1064. continue;
  1065. }
  1066. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').addClass('table-success');
  1067. let pushbwmx = '0*;*0';
  1068. if (listinfo.leafXmjs !== undefined) {
  1069. const leafInfo = listinfo.leafXmjs.find(function (item) {
  1070. const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  1071. if (flag && item.code === clinfo.xmj_code) {
  1072. return flag && item.code === clinfo.xmj_code;
  1073. }
  1074. return flag;
  1075. });
  1076. if (leafInfo) {
  1077. info = leafInfo;
  1078. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
  1079. (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
  1080. (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
  1081. (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
  1082. (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
  1083. (leafInfo.mx_id ? leafInfo.mx_id : '') + '!_!' +
  1084. (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (listinfo.leafXmjs.length > 1 && listinfo.name ? listinfo.name : (leafInfo.jldy !== undefined ? leafInfo.jldy : ''))) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  1085. } else {
  1086. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  1087. // changeList.splice(index, 1);
  1088. removeList.push(clinfo);
  1089. continue;
  1090. }
  1091. } else {
  1092. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  1093. }
  1094. const bwmx = $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx');
  1095. if (bwmx) {
  1096. const bwmxArray = bwmx.split('$#$');
  1097. bwmxArray.push(pushbwmx);
  1098. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  1099. } else {
  1100. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  1101. }
  1102. } else {
  1103. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').addClass('table-success');
  1104. let pushbwmx = '0*;*0';
  1105. if (listinfo.leafXmjs !== undefined) {
  1106. const leafInfo = listinfo.leafXmjs.find(function (item) {
  1107. const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  1108. if (flag && item.code === clinfo.xmj_code) {
  1109. return flag && item.code === clinfo.xmj_code;
  1110. }
  1111. return flag;
  1112. });
  1113. if (leafInfo) {
  1114. info = leafInfo;
  1115. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
  1116. (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
  1117. (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
  1118. (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
  1119. (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
  1120. (leafInfo.mx_id ? leafInfo.mx_id : '') + '!_!' +
  1121. (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (listinfo.leafXmjs.length > 1 && listinfo.name ? listinfo.name : (leafInfo.jldy !== undefined ? leafInfo.jldy : ''))) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  1122. } else {
  1123. console.log(clinfo, listinfo.leafXmjs);
  1124. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  1125. // changeList.splice(index, 1);
  1126. removeList.push(clinfo);
  1127. continue;
  1128. }
  1129. } else {
  1130. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  1131. }
  1132. const bwmx = $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx');
  1133. if (bwmx) {
  1134. const bwmxArray = bwmx.split('$#$');
  1135. bwmxArray.push(pushbwmx);
  1136. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  1137. } else {
  1138. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  1139. }
  1140. }
  1141. if (info && _.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
  1142. // 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
  1143. const updateInfo = {};
  1144. if (info.code !== clinfo.xmj_code) {
  1145. updateInfo.xmj_code = info.code;
  1146. changeList[index].xmj_code = info.code;
  1147. }
  1148. if (info.jldy !== clinfo.xmj_jldy) {
  1149. updateInfo.xmj_jldy = info.jldy;
  1150. changeList[index].xmj_jldy = info.jldy;
  1151. }
  1152. if (info.dwgc !== clinfo.xmj_dwgc) {
  1153. updateInfo.xmj_dwgc = info.dwgc;
  1154. changeList[index].xmj_dwgc = info.dwgc;
  1155. }
  1156. if (info.fbgc !== clinfo.xmj_fbgc) {
  1157. updateInfo.xmj_fbgc = info.fbgc;
  1158. changeList[index].xmj_fbgc = info.fbgc;
  1159. }
  1160. if (info.fxgc !== clinfo.xmj_fxgc) {
  1161. updateInfo.xmj_fxgc = info.fxgc;
  1162. changeList[index].xmj_fxgc = info.fxgc;
  1163. }
  1164. if (!_.isEmpty(updateInfo) && _.indexOf(updateGclIdList, clinfo.gcl_id) === -1) {
  1165. updateGclIdList.push(clinfo.gcl_id);
  1166. // updateInfo.gcl_id = info.id;
  1167. updateList.push({ row: updateInfo, where: { tid: tenderId, gcl_id: clinfo.gcl_id } });
  1168. }
  1169. }
  1170. }
  1171. }
  1172. if(updateList.length > 0) {
  1173. console.log(updateList);
  1174. postData(window.location.pathname + '/save', { type:'update_list', updateData: updateList }, function (result) {
  1175. }, function () {
  1176. });
  1177. }
  1178. if(removeList.length > 0) {
  1179. _.pullAll(changeList, removeList);
  1180. postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
  1181. }, function () {
  1182. });
  1183. }
  1184. }
  1185. }
  1186. // 清单搜索隐藏清单table部分值
  1187. function makeListTable(changeListData, showListData = changeListData) {
  1188. // 先加载台账数据
  1189. let listHtml = '';
  1190. let list_index = 1;
  1191. let gcl_index = 0;
  1192. for (const [index,gcl] of changeListData.entries()) {
  1193. const isShow = _.find(showListData, gcl);
  1194. $('#table-list-select tr').eq(index).css('display', (isShow ? 'table-row' : 'none'));
  1195. }
  1196. }
  1197. // 项目节搜索隐藏code-table部分值
  1198. function makeCodeTable(search = '') {
  1199. if (search === '') {
  1200. $('#code-list tr').css('display', 'table-row');
  1201. return;
  1202. }
  1203. for(let i = 0; i < $('#code-list tr').length; i++) {
  1204. const length = $('#code-list tr').eq(i).children('td').length;
  1205. if (length === 9) {
  1206. const code = $('#code-list tr').eq(i).children('td').eq(1).text();
  1207. const name = $('#code-list tr').eq(i).children('td').eq(2).text();
  1208. const jldy = $('#code-list tr').eq(i).children('td').eq(6).text();
  1209. const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
  1210. $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
  1211. } else {
  1212. return;
  1213. }
  1214. }
  1215. }
  1216. function remakeChangeSpread() {
  1217. const newTableList = [];
  1218. // 获取选中的签约清单判断并插入到原有清单中
  1219. $('#table-list-select .table-success').each(function(){
  1220. let code = $(this).children('td').eq(1).text();
  1221. let name = $(this).children('td').eq(2).text();
  1222. let unit = $(this).children('td').eq(3).text();
  1223. let price = $(this).children('td').eq(4).text();
  1224. // let oamount = $(this).children('td').eq(5).text();
  1225. // 根据单位获取数量的位数,并得出
  1226. // let numdecimal = findDecimal(unit);
  1227. // let scnum = makedecimalzero(numdecimal);
  1228. let scnum = 0;
  1229. // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
  1230. let lid = $(this).data('lid');
  1231. let lindex = $(this).data('index');
  1232. // 原清单和数量改变
  1233. let data_bwmx = $(this).attr('data-bwmx').split('$#$');
  1234. for (const b of data_bwmx) {
  1235. const oamount = b.split('*;*')[1] != '' ? b.split('*;*')[1] : 0;
  1236. let bwmx = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[7] : '';
  1237. let xmj_code = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[0] : '';
  1238. let xmj_jldy = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[1] : '';
  1239. let xmj_dwgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[2] : '';
  1240. let xmj_fbgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[3] : '';
  1241. let xmj_fxgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[4] : '';
  1242. let gcl_id = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[5] : '';
  1243. let mx_id = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[6] : '';
  1244. let trlist = {
  1245. code,
  1246. name,
  1247. bwmx,
  1248. unit,
  1249. unit_price: price,
  1250. oamount,
  1251. camount: scnum,
  1252. detail: '',
  1253. lid,
  1254. xmj_code,
  1255. xmj_jldy,
  1256. xmj_dwgc,
  1257. xmj_fbgc,
  1258. xmj_fxgc,
  1259. gcl_id,
  1260. mx_id,
  1261. };
  1262. const radionInfo = changeList.find(function (info) {
  1263. return info.code === code && (info.lid == lid || parseInt(info.lid) === parseInt(lindex)) && gcl_id == info.gcl_id && (info.bwmx === bwmx || info.bwmx === xmj_jldy) && parseInt(info.oamount) === parseInt(oamount);
  1264. });
  1265. if (radionInfo) {
  1266. trlist.camount = radionInfo.camount;
  1267. trlist.detail = radionInfo.detail;
  1268. }
  1269. newTableList.push(trlist);
  1270. }
  1271. });
  1272. // const changeWhiteList = _.filter(changeList, function (item) {
  1273. // return item.lid == 0;
  1274. // });
  1275. // console.log(newTableList);
  1276. // changeList = newTableList.concat(changeWhiteList);
  1277. return newTableList;
  1278. }
  1279. //判断元素是否在数组中,相当于php的in_array();
  1280. function in_array(arr, obj) {
  1281. let i = arr.length;
  1282. while (i--) {
  1283. if (arr[i] == obj) {
  1284. return true;
  1285. }
  1286. }
  1287. return false;
  1288. }
  1289. function isObjEqual(o1,o2){
  1290. var props1 = Object.getOwnPropertyNames(o1);
  1291. var props2 = Object.getOwnPropertyNames(o2);
  1292. if (props1.length != props2.length) {
  1293. return false;
  1294. }
  1295. for (var i = 0,max = props1.length; i < max; i++) {
  1296. var propName = props1[i];
  1297. if (o1[propName] !== o2[propName]) {
  1298. return false;
  1299. }
  1300. }
  1301. return true;
  1302. }
  1303. // 判断是否有更改过
  1304. function judgeChange() {
  1305. let change = false;
  1306. if (!isObjEqual(changeInfo, back_changeInfo)) {
  1307. change = true;
  1308. }
  1309. if (change) {
  1310. $('#show-save-btn').show();
  1311. $('#sp-btn').hide();
  1312. $('.title-main').addClass('bg-warning');
  1313. } else {
  1314. $('#show-save-btn').hide();
  1315. $('#sp-btn').show();
  1316. $('.title-main').removeClass('bg-warning');
  1317. }
  1318. }
  1319. function changeFormRemake() {
  1320. changeInfo = Object.assign({}, back_changeInfo);
  1321. $('#change_form input[name="code"]').val(changeInfo.code);
  1322. $('#change_form input[name="name"]').val(changeInfo.name);
  1323. $('#change_form input[name="peg"]').val(changeInfo.peg);
  1324. $('#change_form input[name="org_name"]').val(changeInfo.org_name);
  1325. $('#change_form input[name="org_code"]').val(changeInfo.org_code);
  1326. $('#change_form input[name="new_name"]').val(changeInfo.new_name);
  1327. $('#change_form input[name="new_code"]').val(changeInfo.new_code);
  1328. $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
  1329. $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
  1330. $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
  1331. $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
  1332. $('#change_form select[name="type"]').val(changeInfo.type);
  1333. $('#change_form select[name="class"]').val(changeInfo.class);
  1334. $('#change_form select[name="quality"]').val(changeInfo.quality);
  1335. $('#change_form select[name="company"]').val(changeInfo.company);
  1336. $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
  1337. $('#change_form input[name="type[]"]').prop('checked', false);
  1338. const typecheck = changeInfo.type.split(',');
  1339. for (const type of typecheck) {
  1340. $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
  1341. }
  1342. }