change_information_set.js 92 KB

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