change_information_set.js 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868
  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. let searchCodeList = [];
  90. $(document).ready(() => {
  91. const changeSpreadSetting = {
  92. cols: [
  93. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit2'},
  94. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit2'},
  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: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit2'},
  99. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
  100. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  101. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: false, getValue: 'getValue.camount'},
  102. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  103. {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
  104. ],
  105. emptyRows: 0,
  106. headRows: 2,
  107. headRowHeight: [25, 25],
  108. defaultRowHeight: 21,
  109. headerFont: '12px 微软雅黑',
  110. font: '12px 微软雅黑',
  111. readOnly: readOnly,
  112. rowHeader:[
  113. {
  114. rowHeaderType: 'circle',
  115. setting: {
  116. size: 5,
  117. indent: 16,
  118. getColor: function (index, data) {
  119. if (!data) return;
  120. if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
  121. return '#dc3545';
  122. }
  123. if(data.lid != 0) return;
  124. return '#007bff';
  125. }
  126. },
  127. },
  128. ],
  129. localCache: {
  130. key: 'changes-spread',
  131. colWidth: true,
  132. }
  133. };
  134. const changeCol = {
  135. getValue: {
  136. unit_price: function(data) {
  137. return ZhCalc.round(data.unit_price, unitPriceUnit);
  138. },
  139. oa_tp: function (data) {
  140. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount, findDecimal(data.unit))), totalPriceUnit);
  141. },
  142. ca_tp: function (data) {
  143. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
  144. },
  145. oamount: function (data) {
  146. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  147. },
  148. camount: function (data) {
  149. return ZhCalc.round(data.camount, findDecimal(data.unit));
  150. },
  151. del_list: function (data) {
  152. return !_.find(changeUsedData, { cbid: data.id }) ? '移除' : '';
  153. }
  154. },
  155. readOnly: {
  156. isEdit: function (data) {
  157. return !readOnly && data.lid != 0;
  158. },
  159. isEdit2: function (data) {
  160. return !readOnly && (data.lid != 0 || (data.lid == 0 && _.findIndex(changeUsedData, { cbid: data.id }) !== -1));
  161. },
  162. },
  163. };
  164. const changeSpreadObj = {
  165. makeSjsFooter: function () {
  166. // 增加汇总行并设为锁定禁止编辑状态
  167. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  168. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  169. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  170. changeSpreadObj.countSum();
  171. },
  172. countSum: function() {
  173. const rowCount = changeSpreadSheet.getRowCount();
  174. let oSum = 0,
  175. cSum = 0;
  176. for(var i = 0; i < rowCount - 1; i++){
  177. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
  178. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
  179. }
  180. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
  181. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
  182. },
  183. add: function () {
  184. let select = null;
  185. if (changeOrder) {
  186. select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  187. }
  188. postData(window.location.pathname + '/save', {type: 'add', postData: select ? select.order : null}, function (result) {
  189. if (result) {
  190. if (changeOrder === 1 && select) {
  191. // 批量更新changeList的order值
  192. _.forEach(changeList, function (item) {
  193. item.order = item.order > select.order ? item.order + 1 : item.order;
  194. });
  195. changeList.splice(select.order, 0, result);
  196. changeSpreadSheet.addRows(select.order, 1);
  197. SpreadJsObj.reLoadRowData(changeSpreadSheet, select.order);
  198. changeSpreadSheet.setSelection(select.order, 0, 1, 1);
  199. console.log(changeList);
  200. } else {
  201. changeList.push(result);
  202. changeSpreadSheet.addRows(changeList.length - 1, 1);
  203. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  204. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  205. }
  206. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  207. changeSpreadObj.resetXmjSpread();
  208. changeSpreadObj.refreshActn();
  209. }
  210. });
  211. },
  212. batchAdd: function(num) {
  213. let select = null;
  214. if (changeOrder) {
  215. select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  216. }
  217. postData(window.location.pathname + '/save', {type: 'batchadd', num, postData: select ? select.order : null}, function (result) {
  218. if (result) {
  219. changeList = result;
  220. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  221. changeSpreadObj.makeSjsFooter();
  222. changeSpreadObj.resetXmjSpread();
  223. changeSpreadObj.refreshActn();
  224. }
  225. });
  226. },
  227. del: function () {
  228. const selection = changeSpreadSheet.getSelections();
  229. const sel = selection ? selection[0] : changeSpreadSheet.getSelections()[0];
  230. const row = sel && sel.row !== undefined ? sel.row : -1;
  231. if (readOnly || row === -1 || sel.row + sel.rowCount > changeList.length) {
  232. return false;
  233. }
  234. const delList = [];
  235. let lastSelect = null;
  236. let hadTaiZhang = false;
  237. for (let r = 0; r < sel.rowCount; r++) {
  238. const select = changeList[row + r];
  239. if(!select || _.find(changeUsedData, { cbid: select.id })) {
  240. return false;
  241. }
  242. if (r === sel.rowCount - 1 && changeOrder) {
  243. lastSelect = select;
  244. }
  245. if (select.lid != 0) {
  246. hadTaiZhang = true;
  247. }
  248. delList.push(select.id);
  249. }
  250. console.log(lastSelect, delList);
  251. if (delList.length) {
  252. postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null}, function (result) {
  253. changeList.splice(row, delList.length);
  254. changeSpreadSheet.deleteRows(row, delList.length);
  255. const sel = changeSpreadSheet.getSelections();
  256. changeSpreadSheet.setSelection(0, 0, 1, 1);
  257. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  258. if (hadTaiZhang) {
  259. tableDataRemake(changeListData);
  260. }
  261. changeSpreadObj.countSum();
  262. changeSpreadObj.refreshActn();
  263. });
  264. }
  265. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  266. // const index = changeList.indexOf(select);
  267. // if (index > -1 && !_.find(changeUsedData, { cbid: select.id })) {
  268. // postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  269. // changeList.splice(index, 1);
  270. // changeSpreadSheet.deleteRows(index, 1);
  271. // const sel = changeSpreadSheet.getSelections();
  272. // changeSpreadSheet.setSelection(0, 0, 1, 1);
  273. // changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  274. // if (select.lid != 0) {
  275. // tableDataRemake(changeListData);
  276. // }
  277. // changeSpreadObj.countSum();
  278. // changeSpreadObj.refreshActn();
  279. // });
  280. // }
  281. },
  282. upMove: function () {
  283. const data = {
  284. type: 'changeOrder',
  285. postData: [],
  286. };
  287. const selection = changeSpreadSheet.getSelections();
  288. const row = selection[0].row, count = selection[0].rowCount;
  289. const first = changeSpreadSheet.zh_data[row];
  290. if (!first) {
  291. changeSpreadObj.refreshActn();
  292. return false;
  293. }
  294. const pre = changeSpreadSheet.zh_data[row - 1], preUpdate = {id: pre.id};
  295. for (let iRow = 0; iRow < count; iRow++) {
  296. const posData = changeSpreadSheet.zh_data[iRow + row];
  297. if (posData) {
  298. data.postData.push({id: posData.id, order: changeSpreadSheet.zh_data[iRow + row - 1].order});
  299. preUpdate.order = posData.order;
  300. }
  301. }
  302. data.postData.push(preUpdate);
  303. console.log(data);
  304. if (data.postData.length > 0) {
  305. postData(window.location.pathname + '/save', data, function () {
  306. _.forEach(data.postData, function (item) {
  307. const cl = _.find(changeList, { id: item.id });
  308. cl.order = item.order;
  309. });
  310. changeList.sort(function (a, b) {
  311. return a.order - b.order
  312. });
  313. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  314. changeSpreadObj.makeSjsFooter();
  315. const sel = selection[0];
  316. if (sel) {
  317. changeSpreadSheet.setSelection(changeSpreadSheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  318. }
  319. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  320. changeSpreadObj.refreshActn();
  321. });
  322. }
  323. },
  324. downMove: function () {
  325. const data = {
  326. type: 'changeOrder',
  327. postData: [],
  328. };
  329. const selection = changeSpreadSheet.getSelections();
  330. const row = selection[0].row, count = selection[0].rowCount;
  331. const first = changeSpreadSheet.zh_data[row];
  332. if (!first) {
  333. changeSpreadObj.refreshActn();
  334. return false;
  335. }
  336. const next = changeSpreadSheet.zh_data[row + count], nextUpdate = {id: next.id};
  337. for (let iRow = count - 1; iRow >= 0; iRow--) {
  338. const posData = changeSpreadSheet.zh_data[iRow + row];
  339. if (posData) {
  340. data.postData.push({id: posData.id, order: changeSpreadSheet.zh_data[iRow + row + 1].order});
  341. nextUpdate.order = posData.order;
  342. }
  343. }
  344. data.postData.push(nextUpdate);
  345. console.log(data);
  346. if (data.postData.length > 0) {
  347. postData(window.location.pathname + '/save', data, function () {
  348. _.forEach(data.postData, function (item) {
  349. const cl = _.find(changeList, { id: item.id });
  350. cl.order = item.order;
  351. });
  352. changeList.sort(function (a, b) {
  353. return a.order - b.order
  354. });
  355. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  356. changeSpreadObj.makeSjsFooter();
  357. const sel = selection[0];
  358. if (sel) {
  359. changeSpreadSheet.setSelection(changeSpreadSheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  360. }
  361. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  362. changeSpreadObj.refreshActn();
  363. });
  364. }
  365. },
  366. resetXmjSpread: function(data = null) {
  367. const xmj = [];
  368. if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) {
  369. const newData = JSON.parse(JSON.stringify(data));
  370. if (newData.bwmx === newData.xmj_jldy) {
  371. newData.bwmx = '';
  372. }
  373. xmj.push(newData);
  374. }
  375. SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);
  376. },
  377. selectionChanged: function (e, info) {
  378. const sel = info.sheet.getSelections()[0];
  379. const col = info.sheet.zh_setting.cols[sel.col];
  380. const data = SpreadJsObj.getSelectObject(info.sheet);
  381. if (col && col.field === 'del_list' && !_.find(changeUsedData, { cbid: data.id })) {
  382. changeSpreadObj.del();
  383. }
  384. changeSpreadObj.resetXmjSpread(data);
  385. changeSpreadObj.refreshActn();
  386. },
  387. refreshActn: function (rowCount = 1) {
  388. const setObjEnable = function (obj, enable) {
  389. if (enable) {
  390. obj.removeClass('disabled');
  391. } else {
  392. obj.addClass('disabled');
  393. }
  394. };
  395. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  396. // 还需判断是否已被调差清单调用
  397. const selection = changeSpreadSheet.getSelections();
  398. const sel = selection ? selection[0] : changeSpreadSheet.getSelections()[0];
  399. const row = sel ? sel.row : -1;
  400. const first = changeList[row];
  401. let last = first;
  402. if (sel.rowCount > 1 && first) {
  403. for (let r = 1; r < sel.rowCount; r++) {
  404. const rNode = changeList[sel.row + r];
  405. if (!rNode) break;
  406. last = rNode;
  407. }
  408. }
  409. const preNode = changeList[row - 1];
  410. setObjEnable($('#up-move'), !readOnly && first && preNode && changeList.indexOf(last) > 0 && sel.row + sel.rowCount <= changeList.length);
  411. setObjEnable($('#down-move'), !readOnly && first && changeList.indexOf(last) < changeList.length - 1 && sel.row + sel.rowCount <= changeList.length);
  412. // setObjEnable($('#open-list-modal'), !readOnly && select && changeList.indexOf(select) !== -1);
  413. // setObjEnable($('#add-white-btn'), !readOnly && select && changeList.indexOf(select) !== -1);
  414. },
  415. deletePress: function (sheet) {
  416. return;
  417. },
  418. editEnded: function (e, info) {
  419. if (info.sheet.zh_setting) {
  420. const select = SpreadJsObj.getSelectObject(info.sheet);
  421. const col = info.sheet.zh_setting.cols[info.col];
  422. if (col.field === 'del_list') {
  423. return;
  424. }
  425. // 未改变值则不提交
  426. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  427. const orgValue = select[col.field];
  428. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  429. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  430. return;
  431. }
  432. // 判断部分值是否输入的是数字判断和数据计算
  433. if (col.type === 'Number') {
  434. if (isNaN(validText)) {
  435. toastr.error('不能输入其它非数字类型字符');
  436. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  437. return;
  438. }
  439. if (col.field === 'unit_price') {
  440. validText = ZhCalc.round(validText, unitPriceUnit);
  441. } else {
  442. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  443. }
  444. }
  445. if (col.field === 'unit') {
  446. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  447. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  448. }
  449. if(col.field === 'camount') {
  450. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  451. const usedInfo = _.find(changeUsedData, { cbid: select.id });
  452. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  453. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  454. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  455. return;
  456. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  457. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  458. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  459. return;
  460. }
  461. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  462. }
  463. select[col.field] = validText;
  464. console.log(select);
  465. delete select.waitingLoading;
  466. // 更新至服务器
  467. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  468. changeList.splice(info.row, 1, select);
  469. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  470. changeSpreadObj.countSum();
  471. }, function () {
  472. select[col.field] = orgValue;
  473. if(col.field === 'camount') {
  474. select.spamount = orgValue;
  475. }
  476. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  477. });
  478. }
  479. },
  480. clipboardPasted(e, info) {
  481. const hint = {
  482. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  483. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  484. };
  485. const range = info.cellRange;
  486. const sortData = info.sheet.zh_data || [];
  487. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  488. toastMessageUniq(hint.cellError);
  489. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  490. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  491. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  492. changeSpreadObj.makeSjsFooter();
  493. return;
  494. }
  495. if (sortData.length > 0 && range.col + range.colCount > 10) {
  496. toastMessageUniq(hint.cellError);
  497. SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  498. SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  499. changeSpreadObj.makeSjsFooter();
  500. return;
  501. }
  502. const data = [];
  503. // const rowData = [];
  504. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  505. let bPaste = true;
  506. const curRow = range.row + iRow;
  507. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  508. const cLData = { id: sortData[curRow].id };
  509. const hintRow = range.rowCount > 1 ? curRow : '';
  510. let sameCol = 0;
  511. for (let iCol = 0; iCol < range.colCount; iCol++) {
  512. const curCol = range.col + iCol;
  513. const colSetting = info.sheet.zh_setting.cols[curCol];
  514. if (!colSetting) continue;
  515. let validText = info.sheet.getText(curRow, curCol);
  516. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  517. const orgValue = sortData[curRow][colSetting.field];
  518. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  519. sameCol++;
  520. if (range.colCount === sameCol) {
  521. bPaste = false;
  522. }
  523. continue;
  524. }
  525. if (colSetting.type === 'Number') {
  526. if (isNaN(validText)) {
  527. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  528. bPaste = false;
  529. continue;
  530. }
  531. if (colSetting.field === 'unit_price') {
  532. validText = ZhCalc.round(validText, unitPriceUnit);
  533. } else {
  534. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  535. }
  536. if(colSetting.field === 'camount') {
  537. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  538. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
  539. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  540. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  541. bPaste = false;
  542. continue;
  543. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  544. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  545. bPaste = false;
  546. continue;
  547. }
  548. }
  549. }
  550. let unitdecimal = validText;
  551. if (colSetting.field === 'unit') {
  552. //粘贴内容要为下拉列表里所有的单位,不然为空
  553. if (changeUnits.indexOf(validText) === -1) {
  554. unitdecimal = '';
  555. }
  556. cLData.camount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  557. cLData.oamount = ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
  558. }
  559. cLData[colSetting.field] = validText;
  560. sortData[curRow][colSetting.field] = validText;
  561. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  562. }
  563. if (bPaste) {
  564. data.push(cLData);
  565. // rowData.push(curRow);
  566. } else {
  567. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  568. }
  569. }
  570. if (data.length === 0) {
  571. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  572. return;
  573. }
  574. console.log(data);
  575. // 更新至服务器
  576. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  577. changeList = result;
  578. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  579. changeSpreadObj.makeSjsFooter();
  580. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  581. }, function () {
  582. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  583. return;
  584. });
  585. },
  586. valueChanged(e, info) {
  587. // 防止ctrl+z撤销数据
  588. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  589. }
  590. };
  591. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  592. let changeListData;
  593. let gclGatherData;
  594. postData(preUrl + '/defaultBills', {}, function (result) {
  595. gclGatherModel.loadLedgerData(result.bills);
  596. gclGatherModel.loadPosData(result.pos);
  597. gclGatherData = gclGatherModel.gatherGclData();
  598. gclGatherData = _.filter(gclGatherData, function (item) {
  599. return item.leafXmjs && item.leafXmjs.length !== 0;
  600. });
  601. for (const ggd in gclGatherData) {
  602. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  603. gclGatherData.splice(ggd, 1);
  604. }
  605. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  606. let hadcid = 0;
  607. for (const xmj of gclGatherData[ggd].leafXmjs) {
  608. if (_.findIndex(changeLedgerList, { id: xmj.gcl_id }) !== -1 || _.findIndex(changePosList, { id: xmj.mx_id, lid: xmj.gcl_id }) !== -1) {
  609. xmj.cid = 1;
  610. hadcid = 1;
  611. }
  612. }
  613. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  614. }
  615. // 数组去重
  616. const dealBillList = result.dealBills;
  617. for (const db of gclGatherData) {
  618. const exist_index = dealBillList.findIndex(function (item) {
  619. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  620. });
  621. if (exist_index !== -1) {
  622. dealBillList.splice(exist_index, 1);
  623. }
  624. }
  625. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  626. console.log(changeListData);
  627. // 先加载台账数据
  628. let listHtml = '';
  629. let list_index = 1;
  630. let gcl_index = 0;
  631. for (const gcl of changeListData) {
  632. const unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
  633. const quantity = gcl.quantity !== 0 && gcl.quantity !== null && gcl.quantity !== undefined ? (unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity) : 0;
  634. const unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? gcl.unit_price : 0;
  635. let gclhtml = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? ' data-gcl="' + gcl_index + '"' : '';
  636. gcl_index = gclhtml !== '' ? ++gcl_index : gcl_index;
  637. const lid = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? (gcl.leafXmjs.length !== 0 ? gcl.leafXmjs[0].gcl_id : false) : gcl.id;
  638. if (lid) {
  639. listHtml += '<tr data-lid="' + lid + '"' + gclhtml + ' data-index="' + list_index + '" data-bwmx="">' +
  640. '<td class="text-center">' + list_index + (gcl.cid ? '<i class="text-danger" style="font-weight: 900">*</i>' : '') + '</td>' +
  641. '<td>' + gcl.code + '</td>' +
  642. '<td class="text-left">' + gcl.name + '</td>' +
  643. '<td class="text-center">' + unit + '</td>' +
  644. '<td class="text-right">' + (ZhCalc.round(unit_price, unitPriceUnit) ? ZhCalc.round(unit_price, unitPriceUnit) : 0) + '</td>' +
  645. '<td class="text-right">' + quantity + '</td>' +
  646. '</tr>';
  647. list_index++;
  648. }
  649. }
  650. $('#table-list-select').html(listHtml);
  651. tableDataRemake(changeListData);
  652. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  653. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  654. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  655. // changeSpreadSheet.options.protectionOptions = {
  656. // allowSort: true,
  657. // allowFilter: true
  658. // };
  659. // var option = changeSpreadSheet.options.protectionOptions;
  660. // changeSpreadSheet.rowFilter(new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, 0, -1, changeSpreadSetting.cols.length)));
  661. // // changeSpreadSheet.rowFilter(new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, 0, -1, 3)));
  662. // const filter = changeSpreadSheet.rowFilter();
  663. // filter.filterButtonVisible(false);
  664. // filter.filterButtonVisible(0, true);
  665. // filter.filterButtonVisible(2, true);
  666. // filter.filterDialogVisibleInfo({
  667. // sortByValue: true, //SortByValue item is visible.
  668. // sortByColor: false, //SortByColor item is visible.
  669. // filterByColor: false, //FilterByColor item is visible.
  670. // filterByValue: false, //FilterByValue item is visible.
  671. // listFilterArea: false //ListFilterArea item is visible.
  672. // });
  673. // function compareList(obj1, obj2) {
  674. // console.log(obj1, obj2);
  675. // var list = ["", '204-1-b', '合计'];
  676. // var index1 = list.indexOf(obj1), index2 = list.indexOf(obj2);
  677. // if (index1 > index2) {
  678. // return 1;
  679. // } else if (index1 < index2) {
  680. // return -1;
  681. // } else {
  682. // return 0;
  683. // }
  684. // }
  685. // changeSpreadSheet.sortRange(0, 0, changeSpreadSetting.cols.length, 1, true, [{index: 0, ascending: true, compareFunction: compareList}]);
  686. // changeSpreadSheet.bind(GC.Spread.Sheets.Events.RangeSorting, function (e, info) {
  687. // info.compareFunction = compareList;
  688. // });
  689. // filter.sortColumn(0, true);
  690. changeSpreadObj.makeSjsFooter();
  691. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  692. changeSpreadObj.refreshActn();
  693. });
  694. if (!readOnly) {
  695. $('#add-white-btn').click(changeSpreadObj.add);
  696. $('#up-move').click(changeSpreadObj.upMove);
  697. $('#down-move').click(changeSpreadObj.downMove);
  698. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  699. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  700. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  701. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  702. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  703. changeSpreadSheet.getCell(-1, 10).foreColor('#dc3545');
  704. let batchInsertObj;
  705. $.contextMenu.types.batchInsert = function (item, opt, root) {
  706. const self = this;
  707. if ($.isFunction(item.icon)) {
  708. item._icon = item.icon.call(this, this, $t, key, item);
  709. } else {
  710. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  711. // to enable font awesome
  712. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  713. } else {
  714. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  715. }
  716. }
  717. this.addClass(item._icon);
  718. 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>')
  719. .appendTo(this);
  720. const $input = $obj.find('input');
  721. const event = () => {
  722. if (self.hasClass('context-menu-disabled')) return;
  723. item.batchInsert($input[0], root);
  724. };
  725. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  726. $input.click((e) => {e.stopPropagation();})
  727. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  728. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  729. };
  730. // 右键菜单
  731. $.contextMenu({
  732. selector: '#change-spread',
  733. build: function ($trigger, e) {
  734. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  735. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  736. },
  737. items: {
  738. 'createList': {
  739. name: '添加台账清单',
  740. icon: 'fa-sign-in',
  741. visible: function () {
  742. return changeOrder === 0;
  743. },
  744. callback: function (key, opt) {
  745. $('#addlist').modal('show');
  746. },
  747. },
  748. 'createAdd': {
  749. name: '添加空白清单',
  750. icon: 'fa-sign-in',
  751. visible: function () {
  752. return changeOrder === 0;
  753. },
  754. callback: function (key, opt) {
  755. changeSpreadObj.add(changeSpreadSheet);
  756. },
  757. },
  758. 'batchInsert': {
  759. name: '批量添加空白清单',
  760. type: 'batchInsert',
  761. value: '2',
  762. icon: 'fa-sign-in',
  763. visible: function () {
  764. return changeOrder === 0;
  765. },
  766. batchInsert: function (obj, root) {
  767. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  768. obj.value = obj.max;
  769. toastr.warning('批量添加不可多于' + obj.max);
  770. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  771. obj.value = obj.min;
  772. toastr.warning('批量添加不可少于' + obj.min);
  773. } else {
  774. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  775. changeSpreadObj.batchAdd(obj.value);
  776. root.$menu.trigger('contextmenu:hide');
  777. }
  778. },
  779. },
  780. 'createList1': {
  781. name: '插入台账清单',
  782. icon: 'fa-sign-in',
  783. visible: function () {
  784. return changeOrder === 1;
  785. },
  786. // disabled: function (key, opt) {
  787. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  788. // const sel = changeSpreadSheet.getSelections()[0];
  789. // changeSpreadObj.resetXmjSpread(select);
  790. // // console.log(select, sel);
  791. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  792. // return false;
  793. // } else {
  794. // return true;
  795. // }
  796. // },
  797. callback: function (key, opt) {
  798. $('#addlist').modal('show');
  799. },
  800. },
  801. 'createAdd1': {
  802. name: '插入空白清单',
  803. icon: 'fa-sign-in',
  804. visible: function () {
  805. return changeOrder === 1;
  806. },
  807. // disabled: function (key, opt) {
  808. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  809. // const sel = changeSpreadSheet.getSelections()[0];
  810. // changeSpreadObj.resetXmjSpread(select);
  811. // // console.log(select, sel);
  812. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  813. // return false;
  814. // } else {
  815. // return true;
  816. // }
  817. // },
  818. callback: function (key, opt) {
  819. changeSpreadObj.add(changeSpreadSheet);
  820. },
  821. },
  822. 'batchInsert1': {
  823. name: '批量插入空白清单',
  824. type: 'batchInsert',
  825. value: '2',
  826. icon: 'fa-sign-in',
  827. visible: function () {
  828. return changeOrder === 1;
  829. },
  830. // disabled: function (key, opt) {
  831. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  832. // const sel = changeSpreadSheet.getSelections()[0];
  833. // changeSpreadObj.resetXmjSpread(select);
  834. // // console.log(select, sel);
  835. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  836. // return false;
  837. // } else {
  838. // return true;
  839. // }
  840. // },
  841. batchInsert: function (obj, root) {
  842. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  843. obj.value = obj.max;
  844. toastr.warning('批量插入不可多于' + obj.max);
  845. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  846. obj.value = obj.min;
  847. toastr.warning('批量插入不可少于' + obj.min);
  848. } else {
  849. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  850. changeSpreadObj.batchAdd(obj.value);
  851. root.$menu.trigger('contextmenu:hide');
  852. }
  853. },
  854. },
  855. 'delete': {
  856. name: '删除',
  857. icon: 'fa-remove',
  858. callback: function (key, opt) {
  859. changeSpreadObj.del(changeSpreadSheet);
  860. },
  861. disabled: function (key, opt) {
  862. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  863. // const sel = changeSpreadSheet.getSelections()[0];
  864. // changeSpreadObj.resetXmjSpread(select);
  865. // // console.log(select, sel);
  866. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1 && !_.find(changeUsedData, { cbid: select.id })) {
  867. // return false;
  868. // } else {
  869. // return true;
  870. // }
  871. const selection = changeSpreadSheet.getSelections();
  872. const sel = selection ? selection[0] : changeSpreadSheet.getSelections()[0];
  873. const row = sel && sel.row !== undefined ? sel.row : -1;
  874. if (readOnly || row === -1 || sel.row + sel.rowCount > changeList.length) {
  875. return true;
  876. }
  877. let isUsed = false;
  878. for (let r = 0; r < sel.rowCount; r++) {
  879. const select = changeList[row + r];
  880. if(!select || _.find(changeUsedData, { cbid: select.id })) {
  881. isUsed = true;
  882. }
  883. }
  884. return isUsed;
  885. }
  886. },
  887. }
  888. });
  889. }
  890. // 清单选中和移除
  891. $('body').on('click', '#table-list-select tr', function () {
  892. searchCodeList = [];
  893. $('#table-list-select tr').removeClass('table-warning');
  894. $(this).addClass('table-warning');
  895. const isCheck = $(this).hasClass('table-success') ? true : false;
  896. const data_bwmx = $(this).attr('data-bwmx').split('$#$');
  897. const data_charu = $(this).attr('data-charu') ? $(this).attr('data-charu').split('$#$') : [];
  898. const isDeal = $(this).data('gcl') !== undefined ? true : false;
  899. 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 text-center"><input type="checkbox"></td></tr>';
  900. if (isDeal) {
  901. const lid = $(this).data('lid');
  902. let gcl = _.find(gclGatherData, function (item) {
  903. return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
  904. });
  905. if (!gcl) {
  906. gcl = gclGatherData[$(this).data('gcl')];
  907. }
  908. codeHtml = '';
  909. for (const [index, leaf] of gcl.leafXmjs.entries()) {
  910. const quantity = leaf.quantity !== undefined && leaf.quantity !== null ? leaf.quantity : 0;
  911. const gcl_id = leaf.gcl_id ? leaf.gcl_id : '';
  912. const mx_id = leaf.mx_id ? leaf.mx_id : '';
  913. const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : (gcl.leafXmjs.length > 1 && gcl.name ? gcl.name : undefined);
  914. const pushMsg = leaf.code + '!_!' + (leaf.jldy ? leaf.jldy : '') + '!_!' +
  915. (leaf.dwgc ? leaf.dwgc : '') + '!_!' + (leaf.fbgc ? leaf.fbgc : '') + '!_!' + (leaf.fxgc ? leaf.fxgc : '')
  916. + '!_!' + (leaf.gcl_id ? leaf.gcl_id : '0') + '!_!' + (leaf.mx_id ? leaf.mx_id : '') + '!_!' +
  917. (bwmx !== undefined ? bwmx : leaf.jldy ? leaf.jldy : '') + '*;*' + quantity;
  918. const isChecked = data_bwmx.indexOf(pushMsg) !== -1 && isCheck ? 'checked ' : '';
  919. const existGcl = _.find(changeList, {gcl_id: leaf.gcl_id, bwmx: (bwmx ? bwmx : leaf.jldy ? leaf.jldy : ''), oamount: leaf.quantity});
  920. const isUsed = existGcl ? _.find(changeUsedData, { cbid: existGcl.id }) : null;
  921. const isOldChaRu = changeOrder && isChecked && data_charu.indexOf(pushMsg) === -1;
  922. const isDisabled = isUsed || isOldChaRu ? 'disabled ' : '';
  923. codeHtml += '<tr quantity="' + quantity + '" gcl_id="' + gcl_id + '" mx_id="' + mx_id + '">' +
  924. '<td class="text-center">' + (index+1) + (leaf.cid ? '<i class="text-danger" style="font-weight: 900">*</i>' : '') + '</td>' +
  925. '<td>' + leaf.code + '</td>' +
  926. '<td>' + (leaf.jldy ? leaf.jldy: '') + '</td>' +
  927. '<td>' + (leaf.dwgc ? leaf.dwgc : '') + '</td>' +
  928. '<td>' + (leaf.fbgc ? leaf.fbgc : '') + '</td>' +
  929. '<td>' + (leaf.fxgc ? leaf.fxgc : '') + '</td>' +
  930. '<td>' + (bwmx !== undefined ? bwmx : '') + '</td>' +
  931. '<td class="text-right">' + (ZhCalc.round(quantity, findDecimal(gcl.unit)) ? ZhCalc.round(quantity, findDecimal(gcl.unit)) : 0) + '</td>' +
  932. '<td class="text-center"><input type="checkbox" ' + isDisabled + isChecked +
  933. '></td></tr>';
  934. searchCodeList.push(leaf.code + '|!|' + (leaf.jldy ? leaf.jldy: '') + '|!|' + (bwmx !== undefined ? bwmx : ''));
  935. }
  936. } else if (!isDeal && isCheck) {
  937. const pushMsg = '0*;*' + $(this).children('td').eq(5).text();
  938. const isChecked = data_bwmx.indexOf(pushMsg) !== -1 && isCheck ? 'checked ' : '';
  939. const isDisabeld = changeOrder && isChecked && data_charu.indexOf(pushMsg) === -1 ? 'disabled ' : '';
  940. 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 text-center"><input type="checkbox" ' + isChecked + isDisabeld +'></td></tr>';
  941. }
  942. $('#code-list').attr('data-index', parseInt($(this).children('td').eq(0).text()));
  943. $('#code-input').val('');
  944. $('#code-input').siblings('a').hide();
  945. $('#code-list').html(codeHtml);
  946. checkSelectAll();
  947. });
  948. // 右边项目节选择
  949. $('body').on('click', '#code-list input', function () {
  950. let index = $('#code-list').attr('data-index');
  951. // 判断是否是自定义排序,是则另外保存一份到tr中,和data-bwmx不相通,最后提交再清除所有的data-charu清单
  952. if ($(this).is(':checked')) {
  953. // 去除其它可能已选的checked
  954. // $('#code-list input').prop('checked', false);
  955. $(this).prop('checked', true);
  956. // 左边表单传值并添加class
  957. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  958. // 去除部分data-detail值
  959. let data_bwmx = [];
  960. let data_charu = [];
  961. $('#code-list input:checked').each(function () {
  962. const tr = $(this).parents('tr');
  963. const length = tr.children('td').length;
  964. const gcl_id = tr.attr('gcl_id');
  965. const mx_id = tr.attr('mx_id');
  966. const bwmx = length === 9 ?
  967. tr.children('td').eq(1).text() + '!_!' +
  968. tr.children('td').eq(2).text() + '!_!' +
  969. tr.children('td').eq(3).text() + '!_!' +
  970. tr.children('td').eq(4).text() + '!_!' +
  971. tr.children('td').eq(5).text() + '!_!' + gcl_id + '!_!' + mx_id + '!_!' +
  972. (tr.children('td').eq(6).text() !== '' ? tr.children('td').eq(6).text() : tr.children('td').eq(2).text()) : '0';
  973. const quantity = tr.attr('quantity');
  974. const de_qu = bwmx + '*;*' + quantity;
  975. data_bwmx.push(de_qu);
  976. if (changeOrder && $(this).prop('disabled') !== true) {
  977. data_charu.push(de_qu);
  978. }
  979. });
  980. data_bwmx = data_bwmx.join('$#$');
  981. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  982. if (changeOrder) {
  983. data_charu = data_charu.join('$#$');
  984. $('#table-list-select tr[data-index="' + index + '"]').attr('data-charu', data_charu);
  985. }
  986. } else {
  987. // 判断还有无选中项目节编号
  988. if ($('#code-list input').is(':checked')) {
  989. // 去除部分data-detail值
  990. let data_bwmx = [];
  991. let data_charu = [];
  992. $('#code-list input:checked').each(function () {
  993. const tr = $(this).parents('tr');
  994. const length = tr.children('td').length;
  995. const gcl_id = tr.attr('gcl_id');
  996. const mx_id = tr.attr('mx_id');
  997. const bwmx = length === 9 ?
  998. tr.children('td').eq(1).text() + '!_!' +
  999. tr.children('td').eq(2).text() + '!_!' +
  1000. tr.children('td').eq(3).text() + '!_!' +
  1001. tr.children('td').eq(4).text() + '!_!' +
  1002. tr.children('td').eq(5).text() + '!_!' + gcl_id + '!_!' + mx_id + '!_!' +
  1003. (tr.children('td').eq(6).text() !== '' ? tr.children('td').eq(6).text() : tr.children('td').eq(2).text()) : '0';
  1004. const quantity = tr.attr('quantity');
  1005. const de_qu = bwmx + '*;*' + quantity;
  1006. data_bwmx.push(de_qu);
  1007. if (changeOrder && $(this).prop('disabled') !== true) {
  1008. data_charu.push(de_qu);
  1009. }
  1010. });
  1011. data_bwmx = data_bwmx.join('$#$');
  1012. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  1013. if (changeOrder) {
  1014. data_charu = data_charu.join('$#$');
  1015. $('#table-list-select tr[data-index="' + index + '"]').attr('data-charu', data_charu);
  1016. }
  1017. } else {
  1018. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  1019. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  1020. if (changeOrder) {
  1021. $('#table-list-select tr[data-index="' + index + '"]').attr('data-charu', '');
  1022. }
  1023. }
  1024. }
  1025. checkSelectAll();
  1026. });
  1027. // 添加空白清单or签约清单
  1028. $('.add-list-btn').on('click', function () {
  1029. let select = null;
  1030. if (changeOrder) {
  1031. select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1032. }
  1033. const newLedgerList = remakeChangeSpread();
  1034. console.log(newLedgerList, select);
  1035. // 更新至服务器
  1036. postData(window.location.pathname + '/save', { type:'ledger_list', updateData: newLedgerList, postData: select ? select.order : null }, function (result) {
  1037. changeList = result.changeList;
  1038. changeUsedData = result.usedList;
  1039. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  1040. changeSpreadObj.makeSjsFooter();
  1041. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1042. changeSpreadObj.resetXmjSpread(select);
  1043. changeSpreadObj.refreshActn();
  1044. $('#table-list-select tr').attr('data-charu', '');
  1045. if(changeOrder) {
  1046. $('#code-list input:checked').each(function () {
  1047. $(this).attr('disabled', true);
  1048. })
  1049. }
  1050. $('#addlist').modal('hide');
  1051. }, function () {
  1052. $('#table-list-select tr').attr('data-charu', '');
  1053. $('#addlist').modal('hide');
  1054. });
  1055. });
  1056. // 选中input所有值
  1057. $('body').on('focus', ".clist input", function() {
  1058. $(this).select();
  1059. });
  1060. // 取消选中清单
  1061. $('#cancel-list-btn').click(function () {
  1062. // $('#table-list-select tr').removeClass('table-success');
  1063. // $('#table-list-select tr').attr('data-bwmx', '');
  1064. // $('#code-list').html('');
  1065. tableDataRemake(changeListData);
  1066. });
  1067. // 自动编号
  1068. $('.reduction-code').click(function () {
  1069. const code = $(this).attr('data-code');
  1070. $('input[name="code"]').val(code);
  1071. });
  1072. $('#select-list').change(function () {
  1073. const select = parseInt($(this).val());
  1074. let showListData = changeListData;
  1075. const value = $('#list-input').val();
  1076. if (select === 1) {
  1077. if (value !== '') {
  1078. $('#list-input').siblings('a').show();
  1079. showListData = _.filter(changeListData, function (c) {
  1080. return ((c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1)) && c.cid;
  1081. });
  1082. } else {
  1083. $('#list-input').siblings('a').hide();
  1084. showListData = _.filter(changeListData, function (c) {
  1085. return c.cid;
  1086. });
  1087. }
  1088. } else {
  1089. if (value !== '') {
  1090. $('#list-input').siblings('a').show();
  1091. showListData = _.filter(changeListData, function (c) {
  1092. return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  1093. });
  1094. } else {
  1095. $('#list-input').siblings('a').hide();
  1096. }
  1097. }
  1098. makeListTable(changeListData, showListData);
  1099. $('#table-list-select tr').removeClass('table-warning');
  1100. $('#code-input').val('');
  1101. $('#code-input').siblings('a').hide();
  1102. $('#code-list').html('');
  1103. $('#code-select-all').prop('checked', false);
  1104. });
  1105. // 回车提交
  1106. $('#list-input').on('keypress', function () {
  1107. if(window.event.keyCode === 13) {
  1108. $(this).blur();
  1109. }
  1110. });
  1111. $('#list-input').on('blur', function () {
  1112. const select = parseInt($('#select-list').val());
  1113. const value = _.trim($(this).val());
  1114. const valueList = _.slice(_.without(_.uniq(_.replace(value, /\t/g, ' ').split(' ')), ''), 0, 10);
  1115. console.log(valueList);
  1116. // 判断是否存在多个分词,以换行或空格分隔,多个则显示左侧菜单
  1117. if (value !== '' && valueList.length > 1) {
  1118. if (_.without(_.uniq(value.split(' ')), '').length > 10) {
  1119. toastr.warning('最多筛选以空格分割的前10个不重复关键词');
  1120. }
  1121. $('#table-list').addClass('col-9').removeClass('col-12');
  1122. $('#table-list').siblings('.col-3').show();
  1123. $('#list-search-keyword').html('<tr data-keyword="" class="text-white bg-primary"><td class="border-primary">全部</td></tr>');
  1124. for (const v of valueList) {
  1125. $('#list-search-keyword').append(`<tr data-keyword="${v}" class=""><td>${v}</td></tr>`);
  1126. }
  1127. $('#list-input').val(valueList.join(' '));
  1128. } else {
  1129. $('#table-list').addClass('col-12').removeClass('col-9');
  1130. $('#table-list').siblings('.col-3').hide();
  1131. $('#list-search-keyword').html('<tr data-keyword="" class="text-white bg-primary border-primary"><td class="border-primary">全部</td></tr>');
  1132. }
  1133. let showListData = changeListData;
  1134. if (select === 1 && value !== '') {
  1135. $(this).siblings('a').show();
  1136. showListData = _.filter(changeListData, function (c) {
  1137. let flag = false;
  1138. if (c.cid) {
  1139. for(const v of valueList) {
  1140. if ((c.code && c.code.indexOf(v) !== -1) || (c.name && c.name.indexOf(v) !== -1)) {
  1141. flag = true;
  1142. break;
  1143. }
  1144. }
  1145. }
  1146. return flag;
  1147. // return ((c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1)) && c.cid;
  1148. });
  1149. } else if (select === 1 && value === '') {
  1150. $(this).siblings('a').hide();
  1151. showListData = _.filter(changeListData, function (c) {
  1152. return c.cid;
  1153. });
  1154. } else if (value !== '') {
  1155. $(this).siblings('a').show();
  1156. showListData = _.filter(changeListData, function (c) {
  1157. let flag = false;
  1158. for(const v of valueList) {
  1159. if ((c.code && c.code.indexOf(v) !== -1) || (c.name && c.name.indexOf(v) !== -1)) {
  1160. flag = true;
  1161. break;
  1162. }
  1163. }
  1164. return flag;
  1165. // return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  1166. });
  1167. } else {
  1168. $(this).siblings('a').hide();
  1169. }
  1170. makeListTable(changeListData, showListData);
  1171. $('#table-list-select tr').removeClass('table-warning');
  1172. $('#code-input').val('');
  1173. $('#code-input').siblings('a').hide();
  1174. $('#code-list').html('');
  1175. $('#code-select-all').prop('checked', false);
  1176. });
  1177. // 双击编辑搜索值
  1178. $('body').on('dblclick', '#list-search-keyword tr', function () {
  1179. if ($(this).attr('data-keyword') !== '') {
  1180. $(this).children('td').html(`<input class="form-control form-control-sm" value="">`);
  1181. $(this).find('input').focus();
  1182. $(this).find('input').val($(this).attr('data-keyword'));
  1183. }
  1184. });
  1185. // 光标离开
  1186. $('body').on('blur', '#list-search-keyword tr td input', function () {
  1187. let val = $(this).val();
  1188. const oldVal = $(this).parents('tr').attr('data-keyword');
  1189. if (_.trim(val) === '') {
  1190. toastr.warning('不能为空');
  1191. val = oldVal;
  1192. } else if (_.trim(val) === oldVal) {
  1193. val = oldVal;
  1194. } else {
  1195. const value = _.trim($('#list-input').val());
  1196. const valueList = _.slice(_.without(_.uniq(_.replace(value, /\t/g, ' ').split(' ')), ''), 0, 10);
  1197. console.log(_.indexOf(valueList, oldVal), valueList, val, oldVal);
  1198. if (_.indexOf(valueList, val) !== -1) {
  1199. toastr.warning('已存在相同的检索词');
  1200. val = oldVal;
  1201. }
  1202. valueList.splice(_.indexOf(valueList, oldVal), 1, val);
  1203. $('#list-input').val(valueList.join(' '));
  1204. const select = parseInt($('#select-list').val());
  1205. const showListData = _.filter(changeListData, function (c) {
  1206. return ((c.code && c.code.indexOf(val) !== -1) || (c.name && c.name.indexOf(val) !== -1)) && (select === 1 ? c.cid : 1);
  1207. });
  1208. makeListTable(changeListData, showListData);
  1209. $('#table-list-select tr').removeClass('table-warning');
  1210. $('#code-input').val('');
  1211. $('#code-input').siblings('a').hide();
  1212. $('#code-list').html('');
  1213. $('#code-select-all').prop('checked', false);
  1214. }
  1215. $(this).parents('tr').attr('data-keyword', val);
  1216. $(this).parents('td').html(`${val}`);
  1217. });
  1218. $('body').on('keypress', '#list-search-keyword tr td input', function () {
  1219. if(window.event.keyCode === 13) {
  1220. $(this).blur();
  1221. }
  1222. });
  1223. $("#addlist").draggable({ handle: '.modal-header, .modal-footer'});
  1224. // 检索关键字切换
  1225. $('body').on('click', '#list-search-keyword tr', function () {
  1226. if (!$(this).hasClass('bg-primary')) {
  1227. const keyword = $(this).attr('data-keyword');
  1228. $(this).siblings().removeClass('text-white bg-primary');
  1229. $(this).siblings().children('td').removeClass('border-primary');
  1230. $(this).addClass('text-white bg-primary');
  1231. $(this).children('td').addClass('border-primary');
  1232. if (keyword === '') {
  1233. $('#list-input').blur();
  1234. } else {
  1235. const select = parseInt($('#select-list').val());
  1236. const showListData = _.filter(changeListData, function (c) {
  1237. return ((c.code && c.code.indexOf(keyword) !== -1) || (c.name && c.name.indexOf(keyword) !== -1)) && (select === 1 ? c.cid : 1);
  1238. });
  1239. makeListTable(changeListData, showListData);
  1240. $('#table-list-select tr').removeClass('table-warning');
  1241. $('#code-input').val('');
  1242. $('#code-input').siblings('a').hide();
  1243. $('#code-list').html('');
  1244. $('#code-select-all').prop('checked', false);
  1245. }
  1246. }
  1247. });
  1248. // 回车提交
  1249. $('#code-input').on('keypress', function () {
  1250. if(window.event.keyCode === 13) {
  1251. $(this).blur();
  1252. }
  1253. });
  1254. $('#code-input').on('blur', function () {
  1255. const value = $(this).val();
  1256. if (value !== '') {
  1257. $(this).siblings('a').show();
  1258. } else {
  1259. $(this).siblings('a').hide();
  1260. }
  1261. makeCodeTable($(this).val());
  1262. checkSelectAll();
  1263. });
  1264. $('.remove-btn').on('click', function () {
  1265. $(this).hide();
  1266. $(this).siblings('input').val('');
  1267. if ($(this).data('btn') === 'list') {
  1268. const select = parseInt($('#select-list').val());
  1269. let showListData = changeListData;
  1270. if (select === 1) {
  1271. showListData = _.filter(changeListData, function (c) {
  1272. return c.cid;
  1273. });
  1274. }
  1275. makeListTable(changeListData, showListData);
  1276. $('#table-list-select tr').removeClass('table-warning');
  1277. $('#code-list').html('');
  1278. $('#table-list').addClass('col-12').removeClass('col-9');
  1279. $('#table-list').siblings('.col-3').hide();
  1280. $('#list-search-keyword').html('');
  1281. $('#list-search-keyword').siblings('a').addClass('active');
  1282. } else {
  1283. makeCodeTable();
  1284. }
  1285. checkSelectAll();
  1286. });
  1287. // 全选及取消
  1288. $('#code-select-all').click(function () {
  1289. // 全选checkbox
  1290. let index = $('#code-list').attr('data-index');
  1291. if (index) {
  1292. if ($(this).is(':checked')){
  1293. $('#code-list tr').each(function () {
  1294. if ($(this).css('display') !== 'none') {
  1295. $(this).find('input').prop('checked', true);
  1296. }
  1297. })
  1298. } else {
  1299. $('#code-list tr').each(function () {
  1300. if ($(this).css('display') !== 'none' && $(this).find('input').prop('disabled') !== true) {
  1301. $(this).find('input').prop('checked', false);
  1302. }
  1303. });
  1304. }
  1305. // 判断还有无选中项目节编号
  1306. if ($('#code-list input').is(':checked')) {
  1307. // 去除部分data-detail值
  1308. let data_bwmx = [];
  1309. let data_charu = [];
  1310. $('#code-list input:checked').each(function () {
  1311. const tr = $(this).parents('tr');
  1312. const length = tr.children('td').length;
  1313. const gcl_id = tr.attr('gcl_id');
  1314. const mx_id = tr.attr('mx_id');
  1315. const bwmx = length === 9 ?
  1316. tr.children('td').eq(1).text() + '!_!' +
  1317. tr.children('td').eq(2).text() + '!_!' +
  1318. tr.children('td').eq(3).text() + '!_!' +
  1319. tr.children('td').eq(4).text() + '!_!' +
  1320. tr.children('td').eq(5).text() + '!_!' + gcl_id + '!_!' + mx_id + '!_!' +
  1321. (tr.children('td').eq(6).text() !== '' ? tr.children('td').eq(6).text() : tr.children('td').eq(2).text()) : '0';
  1322. const quantity = tr.attr('quantity');
  1323. const de_qu = bwmx + '*;*' + quantity;
  1324. data_bwmx.push(de_qu);
  1325. if (changeOrder && $(this).prop('disabled') !== true) {
  1326. data_charu.push(de_qu);
  1327. }
  1328. });
  1329. data_bwmx = data_bwmx.join('$#$');
  1330. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  1331. if (changeOrder) {
  1332. data_charu = data_charu.join('$#$');
  1333. $('#table-list-select tr[data-index="' + index + '"]').attr('data-charu', data_charu);
  1334. }
  1335. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  1336. } else {
  1337. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  1338. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  1339. if (changeOrder) {
  1340. $('#table-list-select tr[data-index="' + index + '"]').attr('data-charu', '');
  1341. }
  1342. }
  1343. }
  1344. });
  1345. // 记录变更信息操作
  1346. $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
  1347. changeInfo[$(this).attr('name')] = $(this).val();
  1348. judgeChange();
  1349. });
  1350. $('body').on('valuechange', '#change_form textarea', function (e, previous) {
  1351. changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
  1352. judgeChange();
  1353. });
  1354. $('body').on('change', '#change_form select', function (e, previous) {
  1355. changeInfo[$(this).attr('name')] = $(this).val();
  1356. judgeChange();
  1357. });
  1358. $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
  1359. changeInfo[$(this).attr('name')] = $(this).val();
  1360. judgeChange();
  1361. });
  1362. $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
  1363. const typecheck = [];
  1364. $.each($('#change_form input[name="type[]"]:checked'), function () {
  1365. typecheck.push($(this).val());
  1366. });
  1367. changeInfo.type = typecheck.join(',');
  1368. judgeChange();
  1369. });
  1370. // 保存修改ajax提交(不刷新页面)
  1371. $('.save_change_btn').on('click', function () {
  1372. // 保存修改modal
  1373. if ($('input[name="code"]').val() === '') {
  1374. toastr.error('申请编号不能为空!');
  1375. return;
  1376. }
  1377. if ($('input[name="name"]').val() === '') {
  1378. toastr.error('变更工程名称不能为空!');
  1379. return;
  1380. }
  1381. // 换行更改并提交
  1382. changeInfo.content = changeInfo.content.replace(/<br><br>/g, '\r\n');
  1383. changeInfo.basis = changeInfo.basis.replace(/<br><br>/g, '\r\n');
  1384. changeInfo.expr = changeInfo.expr.replace(/<br><br>/g, '\r\n');
  1385. changeInfo.memo = changeInfo.memo.replace(/<br><br>/g, '\r\n');
  1386. // 后改为br
  1387. // 更新至服务器
  1388. postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
  1389. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  1390. toastr.success(result);
  1391. $('#show-save-btn').hide();
  1392. $('#sp-btn').show();
  1393. $('.title-main').removeClass('bg-warning');
  1394. changeInfo.content = changeInfo.content.replace(/[\r\n]/g, '<br>');
  1395. changeInfo.basis = changeInfo.basis.replace(/[\r\n]/g, '<br>');
  1396. changeInfo.expr = changeInfo.expr.replace(/[\r\n]/g, '<br>');
  1397. changeInfo.memo = changeInfo.memo.replace(/[\r\n]/g, '<br>');
  1398. back_changeInfo = Object.assign({}, changeInfo);
  1399. });
  1400. return false;
  1401. });
  1402. $('#cancel_change').on('click', function () {
  1403. $('#show-save-btn').hide();
  1404. $('#sp-btn').show();
  1405. $('.title-main').removeClass('bg-warning');
  1406. if (!isObjEqual(changeInfo, back_changeInfo)) {
  1407. changeFormRemake();
  1408. }
  1409. toastr.success('已还原到上次保存状态');
  1410. });
  1411. $('.dropdown-menu input[name="paixu"]').on('click', function () {
  1412. const newChangeOrder = parseInt($(this).val());
  1413. if (newChangeOrder !== changeOrder) {
  1414. const newLedgerList = changeOrder ? remakeChangeSpread(0) : [];
  1415. // 更新至服务器
  1416. postData(window.location.pathname + '/save', { type:'order_by', updateData: newChangeOrder, newLedgerList }, function (result) {
  1417. if (newChangeOrder === 0) {
  1418. $('#bpaixu').text('清单排序:清单编号');
  1419. $('#upAndMoveBtn').attr('style', 'display: none !important');
  1420. $('.order_text').text('添加');
  1421. changeOrder = newChangeOrder;
  1422. } else if (newChangeOrder === 1) {
  1423. $('#bpaixu').text('清单排序:添加顺序');
  1424. $('#upAndMoveBtn').show();
  1425. $('.order_text').text('插入');
  1426. changeOrder = newChangeOrder;
  1427. }
  1428. changeList = result;
  1429. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  1430. changeSpreadObj.makeSjsFooter();
  1431. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  1432. });
  1433. }
  1434. });
  1435. });
  1436. function checkSelectAll() {
  1437. let check = $('#code-list tr').length > 0 ? true : false;
  1438. const codeNum = $('#code-list tr').length;
  1439. let i = 0;
  1440. $('#code-list tr').each(function () {
  1441. if ($(this).css('display') !== 'none' && !$(this).find('input').is(':checked')) {
  1442. check = false;
  1443. return;
  1444. }
  1445. else if ($(this).css('display') === 'none') {
  1446. i++;
  1447. }
  1448. });
  1449. if (check && i === codeNum) {
  1450. check = false;
  1451. }
  1452. $('#code-select-all').prop('checked', check);
  1453. }
  1454. function checkChangeFrom() {
  1455. let returnFlag = false;
  1456. // 表单判断
  1457. if ($('input[name="code"]').val() === '') {
  1458. toastr.error('申请编号不能为空!');
  1459. returnFlag = true;
  1460. }
  1461. if ($('input[name="name"]').val() === '') {
  1462. toastr.error('变更工程名称不能为空!');
  1463. returnFlag = true;
  1464. }
  1465. if ($('textarea[name="content"]').val() === '') {
  1466. toastr.error('工程变更理由及内容不能为空!');
  1467. returnFlag = true;
  1468. }
  1469. if (changeList.length === 0) {
  1470. toastr.error('请添加变更清单!');
  1471. returnFlag = true;
  1472. } else {
  1473. for (const [i,cl] of changeList.entries()) {
  1474. if (cl.code === '' || cl.name === '' || cl.oamount === '') {
  1475. toastr.error('变更清单第' + (i+1) + '行未完整填写数据(变更部位、变更详情、单位、单价可空)');
  1476. returnFlag = true;
  1477. }
  1478. }
  1479. }
  1480. if(!checkAuditorFrom ()) {
  1481. returnFlag = true;
  1482. }
  1483. if (returnFlag) {
  1484. return false;
  1485. }
  1486. }
  1487. // 检查上报情况
  1488. function checkAuditorFrom () {
  1489. if ($('#auditList li').length === 0) {
  1490. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  1491. toastr.error('请联系管理员添加审批人');
  1492. } else {
  1493. toastr.error('请先选择审批人,再上报数据');
  1494. }
  1495. return false;
  1496. }
  1497. return true;
  1498. }
  1499. function tableDataRemake(changeListData) {
  1500. $('#table-list-select tr').removeClass('table-warning');
  1501. $('#table-list-select tr').removeClass('table-success');
  1502. $('#table-list-select tr').attr('data-bwmx', '');
  1503. $('#table-list-select tr').attr('data-charu', '');
  1504. $('#code-list').html('');
  1505. $('#code-list').attr('data-index', '');
  1506. $('#code-input').val('');
  1507. $('#code-select-all').prop('checked', false);
  1508. $('#code-input').siblings('a').hide();
  1509. // 根据已添加的清单显示
  1510. if (changeList.length > 0 && changeList[0]) {
  1511. const removeList = [];
  1512. const updateList = [];
  1513. const updateGclIdList = [];
  1514. for (const [index,clinfo] of changeList.entries()) {
  1515. if (clinfo.lid != 0) {
  1516. let listinfo = changeListData.find(function (item) {
  1517. 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);
  1518. });
  1519. let info = '';
  1520. if (listinfo === undefined || (clinfo.lid && clinfo.gcl_id && clinfo.lid !== clinfo.gcl_id)) {
  1521. // 有可能这部分台账发生变化,此时要更新清单lid信息,防止数据丢失
  1522. const newlistinfo = changeListData.find(function (item) {
  1523. 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 }));
  1524. });
  1525. if (listinfo === undefined && newlistinfo || (listinfo && newlistinfo && !isObjEqual(listinfo, newlistinfo))) {
  1526. listinfo = newlistinfo;
  1527. updateList.push({id: clinfo.id, lid: newlistinfo.leafXmjs[0].gcl_id});
  1528. // 更新lid
  1529. changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
  1530. }
  1531. }
  1532. if (listinfo === undefined) {
  1533. // 针对旧数据获取清单信息
  1534. listinfo = changeListData[clinfo.lid - 1];
  1535. if (listinfo === undefined) {
  1536. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  1537. // changeList.splice(index, 1);
  1538. removeList.push(clinfo);
  1539. continue;
  1540. }
  1541. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').addClass('table-success');
  1542. let pushbwmx = '0*;*0';
  1543. if (listinfo.leafXmjs !== undefined) {
  1544. const leafInfo = listinfo.leafXmjs.find(function (item) {
  1545. 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));
  1546. if (flag && item.code === clinfo.xmj_code) {
  1547. return flag && item.code === clinfo.xmj_code;
  1548. }
  1549. return flag;
  1550. });
  1551. if (leafInfo) {
  1552. info = leafInfo;
  1553. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
  1554. (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
  1555. (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
  1556. (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
  1557. (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
  1558. (leafInfo.mx_id ? leafInfo.mx_id : '') + '!_!' +
  1559. (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (listinfo.leafXmjs.length > 1 && listinfo.name ? listinfo.name : (leafInfo.jldy !== undefined ? leafInfo.jldy : ''))) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  1560. } else {
  1561. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  1562. // changeList.splice(index, 1);
  1563. removeList.push(clinfo);
  1564. continue;
  1565. }
  1566. } else {
  1567. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  1568. }
  1569. const bwmx = $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx');
  1570. if (bwmx) {
  1571. const bwmxArray = bwmx.split('$#$');
  1572. bwmxArray.push(pushbwmx);
  1573. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  1574. } else {
  1575. $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  1576. }
  1577. } else {
  1578. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').addClass('table-success');
  1579. let pushbwmx = '0*;*0';
  1580. if (listinfo.leafXmjs !== undefined) {
  1581. const leafInfo = listinfo.leafXmjs.find(function (item) {
  1582. 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));
  1583. if (flag && item.code === clinfo.xmj_code) {
  1584. return flag && item.code === clinfo.xmj_code;
  1585. }
  1586. return flag;
  1587. });
  1588. if (leafInfo) {
  1589. info = leafInfo;
  1590. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
  1591. (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
  1592. (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
  1593. (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
  1594. (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
  1595. (leafInfo.mx_id ? leafInfo.mx_id : '') + '!_!' +
  1596. (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (listinfo.leafXmjs.length > 1 && listinfo.name ? listinfo.name : (leafInfo.jldy !== undefined ? leafInfo.jldy : ''))) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  1597. } else {
  1598. // console.log(clinfo, listinfo.leafXmjs);
  1599. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  1600. // changeList.splice(index, 1);
  1601. removeList.push(clinfo);
  1602. continue;
  1603. }
  1604. } else {
  1605. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  1606. }
  1607. const bwmx = $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx');
  1608. if (bwmx) {
  1609. const bwmxArray = bwmx.split('$#$');
  1610. bwmxArray.push(pushbwmx);
  1611. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  1612. } else {
  1613. $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
  1614. }
  1615. }
  1616. if (info && _.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
  1617. // 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
  1618. const updateInfo = {};
  1619. if (info.code !== clinfo.xmj_code) {
  1620. updateInfo.xmj_code = info.code;
  1621. changeList[index].xmj_code = info.code;
  1622. }
  1623. if (info.jldy !== clinfo.xmj_jldy) {
  1624. updateInfo.xmj_jldy = info.jldy;
  1625. changeList[index].xmj_jldy = info.jldy;
  1626. }
  1627. if (info.dwgc !== clinfo.xmj_dwgc) {
  1628. updateInfo.xmj_dwgc = info.dwgc;
  1629. changeList[index].xmj_dwgc = info.dwgc;
  1630. }
  1631. if (info.fbgc !== clinfo.xmj_fbgc) {
  1632. updateInfo.xmj_fbgc = info.fbgc;
  1633. changeList[index].xmj_fbgc = info.fbgc;
  1634. }
  1635. if (info.fxgc !== clinfo.xmj_fxgc) {
  1636. updateInfo.xmj_fxgc = info.fxgc;
  1637. changeList[index].xmj_fxgc = info.fxgc;
  1638. }
  1639. if (!_.isEmpty(updateInfo) && _.indexOf(updateGclIdList, clinfo.gcl_id) === -1) {
  1640. updateGclIdList.push(clinfo.gcl_id);
  1641. // updateInfo.gcl_id = info.id;
  1642. updateList.push({ row: updateInfo, where: { tid: tenderId, gcl_id: clinfo.gcl_id } });
  1643. }
  1644. }
  1645. }
  1646. }
  1647. if(updateList.length > 0) {
  1648. // console.log(updateList);
  1649. postData(window.location.pathname + '/save', { type:'update_list', updateData: updateList }, function (result) {
  1650. }, function () {
  1651. });
  1652. }
  1653. if(removeList.length > 0) {
  1654. _.pullAll(changeList, removeList);
  1655. postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
  1656. }, function () {
  1657. });
  1658. }
  1659. }
  1660. }
  1661. // 清单搜索隐藏清单table部分值
  1662. function makeListTable(changeListData, showListData = changeListData) {
  1663. // 先加载台账数据
  1664. let listHtml = '';
  1665. let list_index = 1;
  1666. let gcl_index = 0;
  1667. for (const [index,gcl] of changeListData.entries()) {
  1668. const isShow = _.find(showListData, gcl);
  1669. $('#table-list-select tr').eq(index).css('display', (isShow ? 'table-row' : 'none'));
  1670. }
  1671. }
  1672. // 项目节搜索隐藏code-table部分值
  1673. function makeCodeTable(search = '') {
  1674. if (search === '') {
  1675. $('#code-list tr').css('display', 'table-row');
  1676. return;
  1677. }
  1678. $('#code-list tr').css('display', 'none');
  1679. if (searchCodeList.length > 0) {
  1680. for (const [index,list] of searchCodeList.entries()) {
  1681. if (list.indexOf(search) !== -1) {
  1682. $('#code-list tr').eq(index).css('display', 'table-row');
  1683. }
  1684. }
  1685. } else {
  1686. for(let i = 0; i < $('#code-list tr').length; i++) {
  1687. const length = $('#code-list tr').eq(i).children('td').length;
  1688. if (length === 9) {
  1689. const code = $('#code-list tr').eq(i).children('td').eq(1).text();
  1690. const name = $('#code-list tr').eq(i).children('td').eq(2).text();
  1691. const jldy = $('#code-list tr').eq(i).children('td').eq(6).text();
  1692. const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
  1693. if (isShow) {
  1694. $('#code-list tr').eq(i).css('display', 'table-row');
  1695. }
  1696. // $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
  1697. } else {
  1698. return;
  1699. }
  1700. }
  1701. }
  1702. }
  1703. function remakeChangeSpread(cOrder = changeOrder) {
  1704. const newTableList = [];
  1705. // 获取选中的签约清单判断并插入到原有清单中
  1706. $('#table-list-select .table-success').each(function(){
  1707. let code = $(this).children('td').eq(1).text();
  1708. let name = $(this).children('td').eq(2).text();
  1709. let unit = $(this).children('td').eq(3).text();
  1710. let price = $(this).children('td').eq(4).text();
  1711. // let oamount = $(this).children('td').eq(5).text();
  1712. // 根据单位获取数量的位数,并得出
  1713. // let numdecimal = findDecimal(unit);
  1714. // let scnum = makedecimalzero(numdecimal);
  1715. let scnum = 0;
  1716. // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
  1717. let lid = $(this).data('lid');
  1718. let lindex = $(this).data('index');
  1719. // 原清单和数量改变
  1720. let data_bwmx = cOrder ? ($(this).attr('data-charu') ? $(this).attr('data-charu').split('$#$') : []) : $(this).attr('data-bwmx').split('$#$');
  1721. for (const b of data_bwmx) {
  1722. const oamount = b.split('*;*')[1] != '' ? b.split('*;*')[1] : 0;
  1723. let bwmx = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[7] : '';
  1724. let xmj_code = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[0] : '';
  1725. let xmj_jldy = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[1] : '';
  1726. let xmj_dwgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[2] : '';
  1727. let xmj_fbgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[3] : '';
  1728. let xmj_fxgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[4] : '';
  1729. let gcl_id = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[5] : '';
  1730. let mx_id = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[6] : '';
  1731. let trlist = {
  1732. code,
  1733. name,
  1734. bwmx,
  1735. unit,
  1736. unit_price: price,
  1737. oamount,
  1738. camount: scnum,
  1739. detail: '',
  1740. lid,
  1741. xmj_code,
  1742. xmj_jldy,
  1743. xmj_dwgc,
  1744. xmj_fbgc,
  1745. xmj_fxgc,
  1746. gcl_id,
  1747. mx_id,
  1748. };
  1749. const radionInfo = changeList.find(function (info) {
  1750. 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);
  1751. });
  1752. if (radionInfo) {
  1753. trlist.camount = radionInfo.camount;
  1754. trlist.detail = radionInfo.detail;
  1755. }
  1756. newTableList.push(trlist);
  1757. }
  1758. });
  1759. // const changeWhiteList = _.filter(changeList, function (item) {
  1760. // return item.lid == 0;
  1761. // });
  1762. // console.log(newTableList);
  1763. // changeList = newTableList.concat(changeWhiteList);
  1764. return newTableList;
  1765. }
  1766. //判断元素是否在数组中,相当于php的in_array();
  1767. function in_array(arr, obj) {
  1768. let i = arr.length;
  1769. while (i--) {
  1770. if (arr[i] == obj) {
  1771. return true;
  1772. }
  1773. }
  1774. return false;
  1775. }
  1776. function isObjEqual(o1,o2){
  1777. var props1 = Object.getOwnPropertyNames(o1);
  1778. var props2 = Object.getOwnPropertyNames(o2);
  1779. if (props1.length != props2.length) {
  1780. return false;
  1781. }
  1782. for (var i = 0,max = props1.length; i < max; i++) {
  1783. var propName = props1[i];
  1784. if (o1[propName] !== o2[propName]) {
  1785. return false;
  1786. }
  1787. }
  1788. return true;
  1789. }
  1790. // 判断是否有更改过
  1791. function judgeChange() {
  1792. let change = false;
  1793. if (!isObjEqual(changeInfo, back_changeInfo)) {
  1794. change = true;
  1795. }
  1796. if (change) {
  1797. $('#show-save-btn').show();
  1798. $('#sp-btn').hide();
  1799. $('.title-main').addClass('bg-warning');
  1800. } else {
  1801. $('#show-save-btn').hide();
  1802. $('#sp-btn').show();
  1803. $('.title-main').removeClass('bg-warning');
  1804. }
  1805. }
  1806. function changeFormRemake() {
  1807. changeInfo = Object.assign({}, back_changeInfo);
  1808. $('#change_form input[name="code"]').val(changeInfo.code);
  1809. $('#change_form input[name="name"]').val(changeInfo.name);
  1810. $('#change_form input[name="peg"]').val(changeInfo.peg);
  1811. $('#change_form input[name="org_name"]').val(changeInfo.org_name);
  1812. $('#change_form input[name="org_code"]').val(changeInfo.org_code);
  1813. $('#change_form input[name="new_name"]').val(changeInfo.new_name);
  1814. $('#change_form input[name="new_code"]').val(changeInfo.new_code);
  1815. $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
  1816. $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
  1817. $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
  1818. $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
  1819. $('#change_form select[name="type"]').val(changeInfo.type);
  1820. $('#change_form select[name="class"]').val(changeInfo.class);
  1821. $('#change_form select[name="quality"]').val(changeInfo.quality);
  1822. $('#change_form select[name="company"]').val(changeInfo.company);
  1823. $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
  1824. $('#change_form input[name="type[]"]').prop('checked', false);
  1825. const typecheck = changeInfo.type.split(',');
  1826. for (const type of typecheck) {
  1827. $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
  1828. }
  1829. }