change_information_set.js 116 KB

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