material_list.js 141 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673
  1. 'use strict';
  2. /**
  3. * 材料调差 - 调差清单
  4. *
  5. * @author EllisRan
  6. * @date 2019/10/25
  7. * @version
  8. */
  9. function getStageId() {
  10. return window.location.pathname.split('/')[5];
  11. }
  12. function findNotJoinLeafXmj(x, type = '') {
  13. if (type === 'index') {
  14. return notJoinList.findIndex(function (item) {
  15. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  16. });
  17. }
  18. return notJoinList.find(function (item) {
  19. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  20. });
  21. }
  22. function findNotChangeLeafXmj(x, type = '') {
  23. if (type === 'index') {
  24. return notChangeList.findIndex(function (item) {
  25. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  26. });
  27. }
  28. return notChangeList.find(function (item) {
  29. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  30. });
  31. }
  32. function findSelfLeafXmj(x, type = '') {
  33. if (type === 'index') {
  34. return selfList.findIndex(function (item) {
  35. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  36. });
  37. }
  38. return selfList.find(function (item) {
  39. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  40. });
  41. }
  42. function findQtyLeafXmj(x, type = '', get_ms_id = null) {
  43. const ms_id = get_ms_id ? get_ms_id : (isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null);
  44. if (type === 'index') {
  45. return qtyList.findIndex(function (item) {
  46. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (ms_id ? item.ms_id === ms_id : true) && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  47. });
  48. }
  49. return qtyList.find(function (item) {
  50. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (ms_id ? item.ms_id === ms_id : true) && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  51. });
  52. }
  53. function getMpSpreadByMBData(id) {
  54. const info = materialBillsData.find(function (item) {
  55. return item.id === parseInt(id);
  56. });
  57. return info ? info.m_spread : 0;
  58. }
  59. function getMaterialListByLeafXmj(gcl_id, xmj_id, mx_id = '') {
  60. const list = [];
  61. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  62. for (const ml of materialListData) {
  63. if (gcl_id === ml.gcl_id && xmj_id === ml.xmj_id && (mx_id === '' || mx_id === ml.mx_id) && (ms_id === null || ms_id === ml.ms_id)) {
  64. list.push(ml);
  65. }
  66. }
  67. return list;
  68. }
  69. function getOneQtyByLeafXmj(xmj) {
  70. const qtyInfo = findQtyLeafXmj(xmj);
  71. if (qtyInfo && qtyInfo.qty !== null) {
  72. return qtyInfo.qty;
  73. }
  74. const notx2 = findNotChangeLeafXmj(xmj);
  75. return calcQty(xmj, notx2 !== undefined ? 2 : 1);
  76. }
  77. function calcOneBQJC(xmj) {
  78. let jiacha = 0;
  79. const notx = findNotJoinLeafXmj(xmj);
  80. if (notx === undefined) {
  81. const list = xmj.mx_id !== undefined ? getMaterialListByLeafXmj(xmj.gcl_id, xmj.id, xmj.mx_id) : getMaterialListByLeafXmj(xmj.gcl_id, xmj.id);
  82. for (const l of list) {
  83. const qty = getOneQtyByLeafXmj(xmj);
  84. jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
  85. }
  86. // }
  87. }
  88. return ZhCalc.round(jiacha, materialDecimal.tp);
  89. }
  90. function calcQty(info, is_join) {
  91. let qty = '';
  92. switch (qtySource) {
  93. case qtySourceValueConst.gather_qty: qty = info.gather_qty; break;
  94. case qtySourceValueConst.contract_qty: qty = info.contract_qty; break;
  95. case qtySourceValueConst.gather_minus_qty: qty = ZhCalc.add(info.gather_qty, info.qc_minus_qty); break;
  96. default: throw '未配置计量来源出错';
  97. }
  98. if (qtySource !== qtySourceValueConst.contract_qty && is_join === 2) {
  99. qty = info.contract_qty;
  100. }
  101. return qty;
  102. }
  103. function getPasteHint (str, row = '') {
  104. let returnObj = str;
  105. if (row) {
  106. returnObj.msg = '清单第' + (row+1) + '行' + (str.msg ? str.msg : str);
  107. }
  108. return returnObj;
  109. }
  110. // 重新计算列表的价差
  111. function calculateJiaCha(data, index) {
  112. // 计算单条的
  113. if (index) {
  114. const gcld = data[index]
  115. let total_jiacha = 0;
  116. for (const [index, xmj] of gcld.leafXmjs.entries()) {
  117. const jiacha = calcOneBQJC(xmj);
  118. gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
  119. gcld.leafXmjs[index].qty = getOneQtyByLeafXmj(xmj);
  120. total_jiacha += jiacha;
  121. }
  122. gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
  123. } else {
  124. for(const gcld of data) {
  125. let total_jiacha = 0;
  126. for (const [index, xmj] of gcld.leafXmjs.entries()) {
  127. const jiacha = calcOneBQJC(xmj);
  128. gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
  129. gcld.leafXmjs[index].qty = getOneQtyByLeafXmj(xmj);
  130. total_jiacha += jiacha;
  131. }
  132. gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
  133. }
  134. }
  135. }
  136. const is_numeric = (value) => {
  137. if (typeof(value) === 'object') {
  138. return false;
  139. } else {
  140. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  141. }
  142. };
  143. $(document).ready(() => {
  144. function TipCellType()
  145. {
  146. }
  147. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.ColumnHeader();
  148. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  149. return { x: x, y: y, row: context.row, col: context.col, cellRect: cellRect, sheetArea: context.sheetArea, sheet: context.sheet };
  150. };
  151. TipCellType.prototype.processMouseEnter = function (hitInfo){
  152. if (!this._toolTipElement) {
  153. var div = document.createElement("div");
  154. $(div).css("position", "absolute")
  155. .css("border", "1px #C0C0C0 solid")
  156. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  157. .css("font", "9pt Arial")
  158. .css("background", "#fff")
  159. // .css("color", "#fff")
  160. .css("z-index", "1000")
  161. .css("padding", 5);
  162. this._toolTipElement = div;
  163. }
  164. $(this._toolTipElement).text("单位数量:每一单位清单下所需工料消耗量。")
  165. .css("top", hitInfo.y + 15)
  166. .css("left", hitInfo.x - 15);
  167. $(this._toolTipElement).hide();
  168. // document.body.insertBefore(this._toolTipElement, null);
  169. if (hitInfo.sheet.yn === 4) { // 用于区分上下两个工料关联表
  170. $('#material-self-spread-div').append(this._toolTipElement, null);
  171. } else {
  172. $('#material-spread-div').append(this._toolTipElement, null);
  173. }
  174. $(this._toolTipElement).show("fast");
  175. };
  176. TipCellType.prototype.processMouseLeave = function (hitInfo) {
  177. if (this._toolTipElement) {
  178. // document.body.removeChild(this._toolTipElement);
  179. // $('#material-spread-div').removeChild(this._toolTipElement);
  180. this._toolTipElement.remove();
  181. this._toolTipElement = null;
  182. }
  183. };
  184. autoFlashHeight();
  185. // 清单table
  186. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  187. const ledgerCols = [
  188. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 90, formatter: '@'},
  189. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 220, formatter: '@'},
  190. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 80, formatter: '@'},
  191. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 110, type: 'Number'},
  192. ];
  193. if (qtySource === qtySourceValueConst.gather_qty) {
  194. ledgerCols.push({title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'});
  195. ledgerCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'});
  196. ledgerCols.push({title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 110, type: 'Number'});
  197. } else if (qtySource === qtySourceValueConst.contract_qty) {
  198. ledgerCols.push({title: '本期计量数量|合同', colSpan: '1|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'});
  199. } else if (qtySource === qtySourceValueConst.gather_minus_qty) {
  200. ledgerCols.push({title: '本期计量数量|合同', colSpan: '4|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'});
  201. ledgerCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'});
  202. ledgerCols.push({title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 110, type: 'Number'});
  203. ledgerCols.push({title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 110, type: 'Number', getValue: 'getValue.gather_qty'});
  204. }
  205. ledgerCols.push({title: '本期完成金额', colSpan: '1', rowSpan: '2', field: 'gather_tp', hAlign: 2, width: 110, type: 'Number', getValue: 'getValue.gather_tp'});
  206. ledgerCols.push({title: '本期价差', colSpan: '1', rowSpan: '2', field: 'total_jiacha', hAlign:3, width: 110, type: 'Number'});
  207. const ledgerSpreadSetting = {
  208. // cols: [
  209. // {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 90, formatter: '@'},
  210. // {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 220, formatter: '@'},
  211. // {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 80, formatter: '@'},
  212. // {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 110, type: 'Number'},
  213. // {title: '本期计量数量|合同', colSpan: '4|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'},
  214. // {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'},
  215. // {title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 110, type: 'Number'},
  216. // {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 110, type: 'Number'},
  217. // {title: '本期完成金额', colSpan: '1', rowSpan: '2', field: 'gather_tp', hAlign: 2, width: 110, type: 'Number'},
  218. // {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'total_jiacha', hAlign:3, width: 110, type: 'Number'}
  219. // ],
  220. emptyRows: 0,
  221. headRows: 2,
  222. headRowHeight: [25, 25],
  223. defaultRowHeight: 21,
  224. headerFont: '12px 微软雅黑',
  225. font: '12px 微软雅黑',
  226. readOnly: true,
  227. };
  228. const ledgerCol = {
  229. getValue: {
  230. gather_qty: function (data) {
  231. if (qtySource === qtySourceValueConst.gather_minus_qty) {
  232. return ZhCalc.add(data.gather_qty, data.qc_minus_qty);
  233. }
  234. },
  235. gather_tp: function (data) {
  236. if (qtySource === qtySourceValueConst.contract_qty) {
  237. return data.contract_tp;
  238. } else {
  239. return data.gather_tp;
  240. }
  241. },
  242. }
  243. }
  244. ledgerSpreadSetting.cols = ledgerCols;
  245. // let gclGatherData = gclGatherModel.gatherGclData()
  246. // 获取项目节数据
  247. function loadLeafXmjData(iGclRow) {
  248. const gcl = gclGatherData[iGclRow];
  249. if (gcl) {
  250. for (const [index, xmj] of gcl.leafXmjs.entries()) {
  251. const jiacha = calcOneBQJC(xmj);
  252. gcl.leafXmjs[index].jiacha = jiacha !== 0 ? ZhCalc.round(jiacha, materialDecimal.tp) : null;
  253. gcl.leafXmjs[index].qty = getOneQtyByLeafXmj(xmj);
  254. }
  255. const leafXmjs = gcl.leafXmjs.filter(item => {
  256. return item.qc_qty || item.contract_qty || item.qc_minus_qty;
  257. });
  258. console.log(leafXmjs);
  259. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, leafXmjs);
  260. // 对清单调差工料table的单位数量进行改变
  261. // materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  262. // SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  263. } else {
  264. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  265. }
  266. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  267. }
  268. SpreadJsObj.initSpreadSettingEvents(ledgerSpreadSetting, ledgerCol);
  269. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  270. // 项目明细table
  271. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  272. const leafXmjCols = [
  273. {title: '项目节|编号', colSpan: '2|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  274. {title: '|项目节名称', colSpan: '|1', rowSpan: '|1', field: 'jldy', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  275. {title: '计量单元|计量单元', colSpan: '2|1', rowSpan: '1|1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  276. {title: '|复核数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 0, width: 80, type: 'Number', readOnly: true},
  277. {title: '部位信息|单位工程', colSpan: '3|1', rowSpan: '1|1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  278. {title: '|分部工程', colSpan: '|1', rowSpan: '|1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  279. {title: '|分项工程', colSpan: '|1', rowSpan: '|1', field: 'fxgc', hAlign: 0, width: 180, formatter: '@', readOnly: true},
  280. ];
  281. if (qtySource === qtySourceValueConst.gather_qty) {
  282. leafXmjCols.push({title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true});
  283. leafXmjCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true});
  284. leafXmjCols.push({title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true});
  285. } else if (qtySource === qtySourceValueConst.contract_qty) {
  286. leafXmjCols.push({title: '本期计量数量|合同', colSpan: '1|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 100, type: 'Number', readOnly: true});
  287. } else if (qtySource === qtySourceValueConst.gather_minus_qty) {
  288. leafXmjCols.push({title: '本期计量数量|合同', colSpan: '4|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true});
  289. leafXmjCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true});
  290. leafXmjCols.push({title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true});
  291. leafXmjCols.push({title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.gather_qty'});
  292. }
  293. leafXmjCols.push({title: '本期调差数量', colSpan: '1', rowSpan: '2', field: 'qty', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.qty', readOnly: 'readOnly.qty'});
  294. leafXmjCols.push({title: '本期价差', colSpan: '1', rowSpan: '2', field: 'jiacha', hAlign: 2, width: 80, type: 'Number', readOnly: true });
  295. const leafXmjSpreadSetting = {
  296. // cols: [
  297. // {title: '项目节|编号', colSpan: '2|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  298. // {title: '|项目节名称', colSpan: '|1', rowSpan: '|1', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  299. // {title: '计量单元|计量单元', colSpan: '2|1', rowSpan: '1|1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  300. // {title: '|复核数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 0, width: 80, type: 'Number'},
  301. // {title: '部位信息|单位工程', colSpan: '3|1', rowSpan: '1|1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  302. // {title: '|分部工程', colSpan: '|1', rowSpan: '|1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  303. // {title: '|分项工程', colSpan: '|1', rowSpan: '|1', field: 'fxgc', hAlign: 0, width: 180, formatter: '@'},
  304. // {title: '本期计量数量|合同', colSpan: '4|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  305. // {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 80, type: 'Number'},
  306. // {title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 80, type: 'Number'},
  307. // {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  308. // {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'jiacha', hAlign: 2, width: 80, type: 'Number'},
  309. // ],
  310. emptyRows: 0,
  311. headRows: 2,
  312. headRowHeight: [25, 25],
  313. defaultRowHeight: 21,
  314. headerFont: '12px 微软雅黑',
  315. font: '12px 微软雅黑',
  316. // readOnly: true,
  317. rowHeader:[
  318. {
  319. rowHeaderType: 'circle',
  320. setting: {
  321. size: 5,
  322. indent: 16,
  323. getColor: function (index, data) {
  324. if (!data) return;
  325. if (_.findIndex(selfList, { gcl_id: data.gcl_id, xmj_id: data.id, mx_id: (data.mx_id ? data.mx_id : '') }) !== -1) {
  326. return '#dc3545';
  327. }
  328. }
  329. },
  330. },
  331. ],
  332. };
  333. leafXmjSpreadSetting.cols = leafXmjCols;
  334. const qtyColIndex = _.findIndex(leafXmjCols, {field: 'qty'});
  335. const leafXmjCol = {
  336. readOnly: {
  337. qty: function (data) {
  338. return !(!readOnly && editQtyPermission);
  339. }
  340. },
  341. getValue: {
  342. gather_qty: function (data) {
  343. if (qtySource === qtySourceValueConst.gather_minus_qty) {
  344. return ZhCalc.add(data.gather_qty, data.qc_minus_qty);
  345. }
  346. },
  347. qty: function (data) {
  348. if (data.qty !== null) return data.qty;
  349. if (qtySource === qtySourceValueConst.gather_qty) {
  350. return data.gather_qty;
  351. } else if (qtySource === qtySourceValueConst.contract_qty) {
  352. return data.contract_qty;
  353. } else if (qtySource === qtySourceValueConst.gather_minus_qty) {
  354. return ZhCalc.add(data.gather_qty, data.qc_minus_qty);
  355. }
  356. }
  357. }
  358. }
  359. const needUpdateArray = ['quantity', 'msg_tp', 'msg_times', 'msg_spread', 'm_spread', 'm_tp', 'm_tax_tp', 'is_summary', 'remark'];
  360. function getGclList() {
  361. if (gclGatherListData) {
  362. return gclGatherListData;
  363. } else {
  364. const newGclGatherListData = [];
  365. for (const [index,s] of ledgerListData.entries()) {
  366. console.log(index, s);
  367. gclGatherModel.loadLedgerData(ledger, s);
  368. gclGatherModel.loadPosData(pos, posListData[index]);
  369. const oneGclGatherData = gclGatherModel.gatherGclData().filter(item => {
  370. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  371. });
  372. newGclGatherListData.push(oneGclGatherData);
  373. }
  374. return newGclGatherListData;
  375. }
  376. }
  377. let first = true;
  378. function setListsData(sid = null, ms_id = null) {
  379. if (first) {
  380. // 加载清单数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  381. postData(window.location.pathname + '/load', {sid}, async function (result) {
  382. ledger = result.ledger;
  383. curLedgerData = result.curLedgerData;
  384. pos = result.pos;
  385. curPosData = result.curPosData;
  386. materialListData = result.materialListData;
  387. gclList = result.gclList;
  388. notJoinList = result.materialNotJoinListData;
  389. notChangeList = result.materialNotChangeListData;
  390. selfList = result.materialSelfListData;
  391. qtyList = result.materialQtyListData;
  392. materialChecklistData = result.materialChecklistData;
  393. if (isStageSelf) {
  394. updateBillsData(ms_id);
  395. const newGclGatherListData = [];
  396. for (const [index, s] of result.ledgerListData.entries()) {
  397. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), s);
  398. gclGatherModel.loadPosData(_.cloneDeep(pos), result.posListData[index]);
  399. const oneGclGatherData = gclGatherModel.gatherGclData().filter(item => {
  400. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  401. });
  402. newGclGatherListData.push(oneGclGatherData);
  403. }
  404. gclGatherListData = newGclGatherListData;
  405. }
  406. // 解析清单汇总数据
  407. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
  408. gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
  409. gclGatherData = gclGatherModel.gatherGclData();
  410. console.log(gclGatherData);
  411. if (openMaterialChecklist) {
  412. const hadBillsidList = _.uniq(_.map(gclList, 'gcl_id'));
  413. console.log(hadBillsidList);
  414. // 判断是否有修订影响到本次数据,并有几率修改清单设置页的值
  415. const pushData = [];
  416. const updateData = [];
  417. for (const hb of hadBillsidList) {
  418. const gcl = _.find(gclGatherData, function (item) {
  419. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: hb}) !== -1;
  420. });
  421. if (gcl) {
  422. const mc = _.find(materialChecklistData, {
  423. b_code: gcl.b_code,
  424. name: gcl.name,
  425. unit: gcl.unit,
  426. unit_price: gcl.unit_price
  427. });
  428. // const newOrder = _.indexOf(gclGatherData, gcl);
  429. // console.log(newOrder);
  430. if (!mc && _.findIndex(pushData, {
  431. b_code: gcl.b_code,
  432. name: gcl.name,
  433. unit: gcl.unit,
  434. unit_price: gcl.unit_price
  435. }) === -1) {
  436. pushData.push({
  437. b_code: gcl.b_code,
  438. name: gcl.name,
  439. unit: gcl.unit,
  440. unit_price: gcl.unit_price,
  441. quantity: (gcl.quantity ? gcl.quantity : null),
  442. total_price: (gcl.total_price ? gcl.total_price : null),
  443. had_bills: 1
  444. });
  445. }
  446. }
  447. }
  448. const removeData = [];
  449. for (const mc of materialChecklistData) {
  450. const gcl = _.find(gclGatherData, {
  451. b_code: mc.b_code,
  452. name: mc.name,
  453. unit: mc.unit,
  454. unit_price: mc.unit_price
  455. });
  456. // 判断是否已不存在工料清单,台账修改过后删除之
  457. if (!gcl) {
  458. removeData.push(mc.id);
  459. } else {
  460. // 更新had_bills值
  461. const updateObj = {id: mc.id};
  462. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  463. const jiaoji = _.intersection(gcl_ids, hadBillsidList);
  464. if (mc.had_bills === 1) {
  465. if (jiaoji.length === 0) {
  466. updateObj.mid = materialID;
  467. updateObj.had_bills = 0;
  468. // updateData.push({ id: mc.id, mid: materialID, had_bills: 0 });
  469. }
  470. } else if (mc.had_bills === 0) {
  471. if (jiaoji.length !== 0) {
  472. updateObj.had_bills = 1;
  473. }
  474. }
  475. // 更新工程量及台账金额
  476. if (mc.quantity !== (gcl.quantity ? gcl.quantity : null)) {
  477. updateObj.quantity = gcl.quantity ? gcl.quantity : null;
  478. updateObj.total_price = gcl.total_price ? gcl.total_price : null;
  479. }
  480. if (!_.isEqual(updateObj, {id: mc.id})) updateData.push(updateObj);
  481. }
  482. }
  483. console.log(pushData, removeData, updateData);
  484. if (pushData.length > 0 || removeData.length > 0 || updateData.length > 0) {
  485. // materialChecklistData = await postDataAsync('/tender/'+ tenderID +'/measure/material/'+ stage_order +'/checklist/save', { type: 'resetChecklist', pushData, removeData, updateData })
  486. }
  487. gclGatherData = gclGatherData.filter(item => {
  488. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  489. });
  490. // 取交集
  491. const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
  492. gclGatherData = _.filter(gclGatherData, function (item) {
  493. if (_.find(materialChecklistData, {
  494. b_code: item.b_code,
  495. name: item.name,
  496. unit: item.unit,
  497. unit_price: item.unit_price
  498. })) {
  499. return true;
  500. } else {
  501. const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
  502. const jiaoji = _.intersection(gcl_ids, selfListGcl);
  503. if (jiaoji.length > 0) {
  504. return true;
  505. }
  506. }
  507. });
  508. } else {
  509. gclGatherData = gclGatherData.filter(item => {
  510. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  511. });
  512. }
  513. calculateJiaCha(gclGatherData);
  514. SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  515. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  516. // 加载清单数据
  517. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  518. loadLeafXmjData(0);
  519. loadMaterialData(0);
  520. loadXmjMaterialData(0, 0);
  521. const sheet = materialSpread.getActiveSheet();
  522. sheet.suspendPaint();
  523. sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  524. sheet.resumePaint();
  525. const selfSheet = materialSelfSpread.getActiveSheet();
  526. selfSheet.suspendPaint();
  527. selfSheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  528. selfSheet.resumePaint();
  529. checkNotJoinMaterialData();
  530. first = false;
  531. // 判断是否需要更新contract_qty、qc_qty和qc_minus_qty
  532. if (!materialIsNewQty && !readOnly) {
  533. let needUpdateList = [];
  534. if (materialListData.length > 0) {
  535. if (isStageSelf) {
  536. for (const msIndex in materialStageData) {
  537. const materialStageList = _.filter(materialListData, { ms_id: materialStageData[msIndex].id });
  538. const gclIdList = _.uniq(_.map(materialListData, 'gcl_id'));
  539. let leafXmjList = [];
  540. for (const id of gclIdList) {
  541. const gcl = _.find(gclGatherListData[msIndex], function (item) {
  542. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: id}) !== -1;
  543. });
  544. if (gcl) leafXmjList = [...leafXmjList, ...gcl.leafXmjs];
  545. }
  546. for (const ml of materialStageList) {
  547. const leafXmjInfo = _.find(leafXmjList, function (item) {
  548. return item.gcl_id === ml.gcl_id && item.id === ml.xmj_id && (item.mx_id === undefined || (item.mx_id !== undefined && item.mx_id === ml.mx_id));
  549. });
  550. if (leafXmjInfo) {
  551. needUpdateList.push({ id: ml.id, contract_qty: leafXmjInfo.contract_qty, qc_qty: leafXmjInfo.qc_qty, qc_minus_qty: leafXmjInfo.qc_minus_qty });
  552. }
  553. }
  554. }
  555. } else {
  556. // 找出所有gcl相同的,方便搜索gclGatherData值
  557. const gclIdList = _.uniq(_.map(materialListData, 'gcl_id'));
  558. let leafXmjList = [];
  559. for (const id of gclIdList) {
  560. const gcl = _.find(gclGatherData, function (item) {
  561. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: id}) !== -1;
  562. });
  563. if (gcl) leafXmjList = [...leafXmjList, ...gcl.leafXmjs];
  564. }
  565. for (const ml of materialListData) {
  566. const leafXmjInfo = _.find(leafXmjList, function (item) {
  567. return item.gcl_id === ml.gcl_id && item.id === ml.xmj_id && (item.mx_id === undefined || (item.mx_id !== undefined && item.mx_id === ml.mx_id));
  568. });
  569. if (leafXmjInfo) {
  570. needUpdateList.push({ id: ml.id, contract_qty: leafXmjInfo.contract_qty, qc_qty: leafXmjInfo.qc_qty, qc_minus_qty: leafXmjInfo.qc_minus_qty });
  571. }
  572. }
  573. }
  574. }
  575. console.log(needUpdateList);
  576. postData('/tender/' + tenderID + '/measure/material/'+ stage_order + '/save', { type: 'qty_update', needUpdateList }, function (result) {
  577. materialListData = result.materialListData;
  578. });
  579. }
  580. });
  581. } else {
  582. // 解析清单汇总数据
  583. // const ms_id = $('#myTab').find('.active').data('msid');
  584. updateBillsData(ms_id);
  585. const i = _.findIndex(materialStageData, { sid });
  586. gclGatherData = gclGatherListData[i];
  587. if (openMaterialChecklist) {
  588. gclGatherData = gclGatherData.filter(item => {
  589. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  590. });
  591. // 取交集
  592. const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
  593. gclGatherData = _.filter(gclGatherData, function (item) {
  594. if (_.find(materialChecklistData, {
  595. b_code: item.b_code,
  596. name: item.name,
  597. unit: item.unit,
  598. unit_price: item.unit_price
  599. })) {
  600. return true;
  601. } else {
  602. const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
  603. const jiaoji = _.intersection(gcl_ids, selfListGcl);
  604. if (jiaoji.length > 0) {
  605. return true;
  606. }
  607. }
  608. });
  609. } else {
  610. gclGatherData = gclGatherData.filter(item => {
  611. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  612. });
  613. }
  614. if ($('#show_material_gcl').is(':checked')) {
  615. const hadMaterialGclGatherData = [];
  616. const hadGclIdList = [];
  617. for (const ml of materialListData) {
  618. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  619. hadGclIdList.push(ml.gcl_id);
  620. }
  621. }
  622. for (const gcl of gclGatherData) {
  623. for (const index in gcl.leafXmjs) {
  624. const gcl_id = gcl.leafXmjs[index].gcl_id;
  625. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  626. hadMaterialGclGatherData.push(gcl);
  627. break;
  628. }
  629. }
  630. }
  631. gclGatherData = hadMaterialGclGatherData;
  632. }
  633. console.log(gclGatherData);
  634. calculateJiaCha(gclGatherData);
  635. SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  636. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  637. // 加载清单数据
  638. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  639. loadLeafXmjData(0);
  640. loadMaterialData(0);
  641. loadXmjMaterialData(0, 0);
  642. const sheet = materialSpread.getActiveSheet();
  643. sheet.suspendPaint();
  644. sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  645. sheet.resumePaint();
  646. const selfSheet = materialSelfSpread.getActiveSheet();
  647. selfSheet.suspendPaint();
  648. selfSheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  649. selfSheet.resumePaint();
  650. ledgerSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  651. checkNotJoinMaterialData();
  652. }
  653. }
  654. function updateBillsData(ms_id) {
  655. const msbList = _.filter(materialStageBillsData, { ms_id });
  656. for (const mb of materialBillsData) {
  657. mb.ms_id = ms_id;
  658. const msbInfo = _.find(msbList, { mb_id: mb.id });
  659. for (const nu of needUpdateArray) {
  660. mb[nu] = msbInfo[nu];
  661. }
  662. }
  663. }
  664. setListsData(isStageSelf ? materialStageData[0].sid : null, isStageSelf ? materialStageData[0].id : null);
  665. // 期切换
  666. $('#myTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  667. e.preventDefault();
  668. const ms_id = $('#myTab').find('.active').data('msid');
  669. const msInfo = _.find(materialStageData, { id: ms_id });
  670. showWaitingView();
  671. setTimeout(function () {
  672. setListsData(msInfo.sid, ms_id);
  673. closeWaitingView();
  674. }, 500);
  675. });
  676. // const leafXmjCol = {
  677. // getValue: {
  678. // jiacha: function (data) {
  679. // let sum = 0;
  680. // const sheet = leafXmjSpread.getActiveSheet();
  681. // const select = SpreadJsObj.getSelectObject(sheet);
  682. // const notx = findNotJoinLeafXmj(select);
  683. // if (notx === undefined) {
  684. // for(const ml of materialList) {
  685. // sum = ZhCalc.round(ZhCalc.add(sum, ZhCalc.mul(ZhCalc.mul(data.gather_qty, ml.quantity), getMpSpreadByMBData(ml.mb_id))), 2);
  686. // }
  687. // }
  688. // return sum !== 0 ? sum : null;
  689. // }
  690. // }
  691. // };
  692. // SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  693. // 调差清单工料table
  694. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  695. const materialSpreadSetting = {
  696. cols: [
  697. {title: '清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  698. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  699. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  700. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  701. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  702. ],
  703. emptyRows: 0,
  704. headRows: 2,
  705. headRowHeight: [25, 25],
  706. defaultRowHeight: 21,
  707. headerFont: '12px 微软雅黑',
  708. font: '12px 微软雅黑',
  709. };
  710. const materialBase = {
  711. isEdit: function (data, type = 'normal') {
  712. // 是否本期添加的工料
  713. // return data.order === stage_order && !openMaterialChecklist;
  714. let flag = true;
  715. if (type === 'del' || !editListPermission) {
  716. flag = data.order === stage_order;
  717. }
  718. return flag && !openMaterialChecklist;
  719. }
  720. };
  721. const materialCol = {
  722. readOnly: {
  723. isEdit: function (data) {
  724. // const sheet = leafXmjSpread.getActiveSheet();
  725. // const select = SpreadJsObj.getSelectObject(sheet);
  726. // const notx = findNotJoinLeafXmj(select);
  727. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  728. return !(!readOnly && materialBase.isEdit(data));
  729. },
  730. },
  731. };
  732. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  733. // 获取项目节数据
  734. let materialList = [];
  735. function loadMaterialData(iGclRow) {
  736. const gcl = gclGatherData[iGclRow];
  737. if (gcl && gcl.leafXmjs) {
  738. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  739. materialList = [];
  740. const newMaterialList = _.uniqBy(_.filter(gclList, function (m) {
  741. return _.indexOf(gcl_ids, m.gcl_id) !== -1;
  742. }), 'mb_id');
  743. for(const m of newMaterialList) {
  744. const bills = _.find(materialBillsData, { id: m.mb_id });
  745. if(bills) {
  746. m.code = bills.code;
  747. m.name = bills.name;
  748. m.unit = bills.unit;
  749. }
  750. }
  751. console.log(newMaterialList);
  752. materialList = newMaterialList;
  753. // 对清单调差工料table的单位数量进行改变
  754. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  755. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  756. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialList);
  757. } else {
  758. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '数量 �';
  759. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  760. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  761. }
  762. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  763. }
  764. // 调差清单工料table
  765. const materialSelfSpread = SpreadJsObj.createNewSpread($('#material-self-spread')[0]);
  766. const materialSelfSpreadSetting = {
  767. cols: [
  768. {title: '明细清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  769. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  770. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  771. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  772. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  773. ],
  774. emptyRows: 0,
  775. headRows: 2,
  776. headRowHeight: [25, 25],
  777. defaultRowHeight: 21,
  778. headerFont: '12px 微软雅黑',
  779. font: '12px 微软雅黑',
  780. };
  781. const materialSelfBase = {
  782. isEdit: function (data, type = 'normal') {
  783. // 是否本期添加的工料
  784. // return data.order === stage_order && !openMaterialChecklist;
  785. let flag = true;
  786. if (type === 'del' || !editListPermission) {
  787. flag = data.order === stage_order;
  788. }
  789. return flag;
  790. }
  791. };
  792. const materialSelfCol = {
  793. readOnly: {
  794. isEdit: function (data) {
  795. // const sheet = leafXmjSpread.getActiveSheet();
  796. // const select = SpreadJsObj.getSelectObject(sheet);
  797. // const notx = findNotJoinLeafXmj(select);
  798. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  799. return openMaterialSelf && !(!readOnly && materialSelfBase.isEdit(data));
  800. },
  801. },
  802. };
  803. SpreadJsObj.initSpreadSettingEvents(materialSelfSpreadSetting, materialSelfCol);
  804. let materialListSelf = [];
  805. function loadXmjMaterialData(iGclRow, iLXmjRow) {
  806. // 存在单独设置的才展示,不然隐藏
  807. const gcl = gclGatherData[iGclRow];
  808. const leafXmjs = gcl && gcl.leafXmjs ? gcl.leafXmjs.filter(item => {
  809. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  810. }) : null;
  811. if (leafXmjs) {
  812. const xmj = leafXmjs[iLXmjRow];
  813. console.log(xmj, iLXmjRow);
  814. materialListSelf = [];
  815. if (_.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: (xmj.mx_id ? xmj.mx_id : '') }) != -1) {
  816. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  817. for (const m of materialListData) {
  818. if (m.gcl_id === xmj.gcl_id && m.xmj_id === xmj.id && ((xmj.mx_id !==undefined && m.mx_id === xmj.mx_id) || xmj.mx_id === undefined) && (ms_id === null || ms_id === m.ms_id)) {
  819. materialListSelf.push(m);
  820. }
  821. }
  822. $('#material-self-spread-div').addClass('active');
  823. showSelfSideTools(true);
  824. } else {
  825. $('#material-self-spread-div').removeClass('active');
  826. showSelfSideTools(false);
  827. }
  828. // 对清单调差工料table的单位数量进行改变
  829. materialSelfSpreadSetting.cols[materialSelfSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  830. SpreadJsObj.initSheet(materialSelfSpread.getActiveSheet(), materialSelfSpreadSetting);
  831. SpreadJsObj.loadSheetData(materialSelfSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialListSelf);
  832. } else {
  833. $('#material-self-spread-div').removeClass('active');
  834. showSelfSideTools(false);
  835. materialSpreadSetting.cols[materialSelfSpreadSetting.cols.length - 2].title = '数量 �';
  836. SpreadJsObj.initSheet(materialSelfSpread.getActiveSheet(), materialSelfSpreadSetting);
  837. SpreadJsObj.loadSheetData(materialSelfSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  838. }
  839. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  840. leafXmjSpread.refresh();
  841. materialSelfSpread.refresh();
  842. }
  843. // SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), )
  844. // loadLeafXmjData(0);
  845. // loadMaterialData(0, 0);
  846. // const sheet = materialSpread.getActiveSheet();
  847. // sheet.suspendPaint();
  848. // sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  849. // sheet.resumePaint();
  850. // 不参与调差数据值变灰, 数量变更不参与调差数据值变黄
  851. function checkNotJoinMaterialData() {
  852. const sheet = ledgerSpread.getActiveSheet();
  853. const select = SpreadJsObj.getSelectObject(sheet);
  854. const index = gclGatherData.indexOf(select);
  855. if (index !== -1) {
  856. const xmj = gclGatherData[index].leafXmjs.filter(item => {
  857. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  858. });
  859. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  860. for (const [iRow,x] of xmj.entries()) {
  861. const notx = findNotJoinLeafXmj(x);
  862. const color = notx === undefined ? '' : '#d6d8db';
  863. // leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
  864. const notx2 = findNotChangeLeafXmj(x);
  865. const color2 = notx2 === undefined || qtySource === qtySourceValueConst.contract_qty ? color : '#FFE699';
  866. leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color2);
  867. const qtyInfo = findQtyLeafXmj(x);
  868. if (x.qty !== undefined && x.qty !== null && qtyInfo) {
  869. leafXmjSheet.getCell(iRow, qtyColIndex).backColor('#f8d7da');
  870. }
  871. }
  872. }
  873. }
  874. // checkNotJoinMaterialData();
  875. // 对添加工料表格赋值
  876. function changeMaterialTable(from = 'all') {
  877. $('#materialBills tr').removeClass('table-secondary');
  878. $('#materialBills').find('input').removeAttr('disabled');
  879. $('#materialBills').find('input').prop('checked', false);
  880. const searchList = from === 'self' ? materialListSelf : materialList;
  881. console.log(searchList);
  882. for (const [index, ml] of searchList.entries()) {
  883. const mbIndex = materialBillsData.findIndex(function (item) {
  884. return item.id === ml.mb_id;
  885. });
  886. if (mbIndex !== -1) {
  887. $('#materialBills tr').eq(mbIndex).addClass('table-secondary');
  888. $('#materialBills').find('input').eq(mbIndex).attr('disabled', true);
  889. $('#materialBills').find('input').eq(mbIndex).prop('checked', true);
  890. }
  891. }
  892. }
  893. // 添加调差工料
  894. $('#add_material_bill').click(function () {
  895. // 获取已选工料
  896. $('#materialBills').find('input:disabled').prop('checked', false);
  897. const selectList = $('#materialBills').find('input:checked');
  898. if (selectList.length === 0) {
  899. toastr.warning('请选择调差工料');
  900. $('#materialBills').find('input:disabled').prop('checked', true);
  901. return false;
  902. }
  903. const mb_id = [];
  904. for (let s = 0; s < selectList.length; s++) {
  905. mb_id.push($('#materialBills').find('input:checked').eq(s).val());
  906. }
  907. const type = $('#add_type').val();
  908. if (type === 'all') {
  909. // 获取当前项目节或部位明细id
  910. const sheet = ledgerSpread.getActiveSheet();
  911. const select = SpreadJsObj.getSelectObject(sheet);
  912. const index = gclGatherData.indexOf(select);
  913. const gcl = gclGatherData[index].leafXmjs;
  914. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  915. const datas = [];
  916. for (const xmj of gcl) {
  917. const notx = findNotJoinLeafXmj(xmj);
  918. const notx2 = findNotChangeLeafXmj(xmj);
  919. const qtyInfo = findQtyLeafXmj(xmj);
  920. const data = {
  921. xmj_id: xmj.id,
  922. gcl_id: xmj.gcl_id,
  923. mx_id: xmj.mx_id ? xmj.mx_id : '',
  924. contract_qty: xmj.contract_qty,
  925. qc_qty: xmj.qc_qty,
  926. qc_minus_qty: xmj.qc_minus_qty,
  927. gather_qty: xmj.gather_qty,
  928. qty: qtyInfo ? qtyInfo.qty : null,
  929. is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
  930. };
  931. if (ms_id) data.ms_id = ms_id;
  932. datas.push(data);
  933. }
  934. if (isStageSelf) {
  935. // 取所有的gclGatherData才行,然后获取下的值
  936. const gclData = gclGatherData[index];
  937. for (const [index, ms] of materialStageData.entries()) {
  938. if (ms.id !== ms_id) {
  939. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  940. if (gclOther) {
  941. const leafXmjs = gclOther.leafXmjs.filter(item => {
  942. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  943. });
  944. // gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  945. for (const xmj of leafXmjs) {
  946. const notx = findNotJoinLeafXmj(xmj);
  947. const notx2 = findNotChangeLeafXmj(xmj);
  948. const qtyInfo = findQtyLeafXmj(xmj, '', ms.id);
  949. const data = {
  950. xmj_id: xmj.id,
  951. gcl_id: xmj.gcl_id,
  952. mx_id: xmj.mx_id ? xmj.mx_id : '',
  953. contract_qty: xmj.contract_qty,
  954. qc_qty: xmj.qc_qty,
  955. qc_minus_qty: xmj.qc_minus_qty,
  956. gather_qty: xmj.gather_qty,
  957. qty: qtyInfo ? qtyInfo.qty : null,
  958. is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
  959. ms_id: ms.id,
  960. };
  961. datas.push(data);
  962. }
  963. }
  964. }
  965. }
  966. }
  967. console.log(datas, gcl, mb_id);
  968. postData(window.location.pathname + '/save', {type: 'adds', postData: {xmjs: datas, mbIds: mb_id} }, function (result) {
  969. materialListData = result.materialListData;
  970. gclList = result.gclList;
  971. // toastr.success('已成功应用');
  972. calculateJiaCha(gclGatherData);
  973. // const index = gclGatherData.indexOf(ledgerSelect);
  974. loadLeafXmjData(index);
  975. // const xmjSheet = leafXmjSpread.getActiveSheet();
  976. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  977. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  978. loadMaterialData(index);
  979. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  980. $('#addgl').modal('hide');
  981. });
  982. } else if (type === 'self') {
  983. // 获取当前项目节或部位明细id
  984. const sheet = ledgerSpread.getActiveSheet();
  985. const select = SpreadJsObj.getSelectObject(sheet);
  986. const index = gclGatherData.indexOf(select);
  987. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  988. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  989. const gcl = gclGatherData[index].leafXmjs.filter(item => {
  990. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  991. });
  992. const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  993. const xmj = gcl[leafXmjIndex];
  994. const notx = findNotJoinLeafXmj(xmj);
  995. const notx2 = findNotChangeLeafXmj(xmj);
  996. const qtyInfo = findQtyLeafXmj(xmj);
  997. const data = {
  998. xmj_id: xmj.id,
  999. gcl_id: xmj.gcl_id,
  1000. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1001. mb_id: mb_id,
  1002. contract_qty: xmj.contract_qty,
  1003. qc_qty: xmj.qc_qty,
  1004. qc_minus_qty: xmj.qc_minus_qty,
  1005. gather_qty: xmj.gather_qty,
  1006. qty: qtyInfo ? qtyInfo.qty : null,
  1007. is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
  1008. };
  1009. console.log(data);
  1010. postData(window.location.pathname + '/save', {type: 'add', postData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1011. // 添加到materialList里
  1012. materialListData = result;
  1013. loadXmjMaterialData(index, leafXmjIndex);
  1014. $('#addgl').modal('hide');
  1015. });
  1016. }
  1017. $('#materialBills').find('input:disabled').prop('checked', true);
  1018. });
  1019. const leafXmjSpreadObj = {
  1020. getSelect : function () {
  1021. const sheet = ledgerSpread.getActiveSheet();
  1022. const select = SpreadJsObj.getSelectObject(sheet);
  1023. const index = gclGatherData.indexOf(select);
  1024. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  1025. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  1026. const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
  1027. const leafXmjs = gclGatherData[index].leafXmjs.filter(item => {
  1028. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1029. });
  1030. const nRow = leafXmjs.indexOf(leafXmjSelect);
  1031. const leafXmjColor = findNotJoinLeafXmj(leafXmjSelect) ? '#d6d8db' : (findNotChangeLeafXmj(leafXmjSelect) ? '#FFE699' : '');
  1032. return [index, iRow, nRow, leafXmjSheet, leafXmjSelect, leafXmjColor];
  1033. },
  1034. checkJoinMaterial: function (type) {
  1035. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  1036. const color = type === 'join' ? '' : '#d6d8db';
  1037. const data = {
  1038. type: type,
  1039. select: type === 'join' ? findNotJoinLeafXmj(select) : select,
  1040. ms_id: $('#myTab').find('.active').data('msid') || null,
  1041. };
  1042. // 添加到
  1043. postData(window.location.pathname + '/save', data, function (result) {
  1044. if (type === 'join') {
  1045. const index = findNotJoinLeafXmj(select, 'index');
  1046. notJoinList.splice(index, 1);
  1047. } else {
  1048. notJoinList.push(result);
  1049. const index = findNotChangeLeafXmj(select, 'index');
  1050. notChangeList.splice(index, 1);
  1051. }
  1052. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  1053. calculateJiaCha(gclGatherData, iGclRow);
  1054. SpreadJsObj.reLoadRowData(sheet, nRow);
  1055. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  1056. leafXmjSpreadObj.refreshQtyColor(select, nRow);
  1057. loadMaterialData(iGclRow);
  1058. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1059. });
  1060. },
  1061. checkChangeMaterial: function (type) {
  1062. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  1063. const color = type === 'change' ? '' : '#FFE699';
  1064. const data = {
  1065. type: type,
  1066. select: type === 'change' ? findNotChangeLeafXmj(select) : select,
  1067. ms_id: $('#myTab').find('.active').data('msid') || null,
  1068. };
  1069. // 添加到
  1070. postData(window.location.pathname + '/save', data, function (result) {
  1071. if (type === 'change') {
  1072. const index = findNotChangeLeafXmj(select, 'index');
  1073. notChangeList.splice(index, 1);
  1074. } else {
  1075. notChangeList.push(result);
  1076. }
  1077. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  1078. gclGatherData[iGclRow].leafXmjs[iRow].qty = getOneQtyByLeafXmj(select);
  1079. calculateJiaCha(gclGatherData, iGclRow);
  1080. console.log(gclGatherData[iGclRow].leafXmjs[iRow]);
  1081. SpreadJsObj.reLoadRowData(sheet, nRow);
  1082. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  1083. leafXmjSpreadObj.refreshQtyColor(select, nRow);
  1084. loadMaterialData(iGclRow);
  1085. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1086. });
  1087. },
  1088. checkSelfMaterial: function (type) {
  1089. const [iGclRow, iRow, nRow, sheet, select, color] = leafXmjSpreadObj.getSelect();
  1090. // const color = type === 'self' ? '' : '#d6d8db';
  1091. const data = {
  1092. type: type,
  1093. select: type === 'noself' ? findSelfLeafXmj(select) : select,
  1094. ms_id: $('#myTab').find('.active').data('msid') || null,
  1095. };
  1096. if (type === 'noself') {
  1097. if (isStageSelf) {
  1098. data.select.contract_qty = {};
  1099. data.select.qc_qty = {};
  1100. data.select.qc_minus_qty = {};
  1101. data.select.gather_qty = {};
  1102. const ledgerSheet = ledgerSpread.getActiveSheet();
  1103. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1104. const index = gclGatherData.indexOf(ledgerSelect);
  1105. // 取所有的gclGatherData才行,然后获取下的值
  1106. const gclData = gclGatherData[index];
  1107. for (const [index, ms] of materialStageData.entries()) {
  1108. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1109. let gather_qty = null;
  1110. let contract_qty = null;
  1111. let qc_qty = null;
  1112. let qc_minus_qty = null;
  1113. if (gclOther) {
  1114. const leafXmjs = gclOther.leafXmjs.filter(item => {
  1115. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1116. });
  1117. const oneXmj = _.find(leafXmjs, function (item) {
  1118. return item.gcl_id === select.gcl_id && item.id === select.id && (select.mx_id === undefined || item.mx_id === select.mx_id);
  1119. });
  1120. if (oneXmj) {
  1121. gather_qty = oneXmj.gather_qty;
  1122. contract_qty = oneXmj.contract_qty;
  1123. qc_qty = oneXmj.qc_qty;
  1124. qc_minus_qty = oneXmj.qc_minus_qty ? oneXmj.qc_minus_qty : null;
  1125. }
  1126. }
  1127. data.select.gather_qty['ms_id_' + ms.id] = gather_qty;
  1128. data.select.contract_qty['ms_id_' + ms.id] = contract_qty;
  1129. data.select.qc_qty['ms_id_' + ms.id] = qc_qty;
  1130. data.select.qc_minus_qty['ms_id_' + ms.id] = qc_minus_qty;
  1131. }
  1132. } else {
  1133. data.select.gather_qty = select.gather_qty ? select.gather_qty : null;
  1134. data.select.contract_qty = select.contract_qty ? select.contract_qty : null;
  1135. data.select.qc_qty = select.qc_qty ? select.qc_qty : null;
  1136. data.select.qc_minus_qty = select.qc_minus_qty ? select.qc_minus_qty : null;
  1137. }
  1138. }
  1139. console.log(data);
  1140. // 添加到
  1141. postData(window.location.pathname + '/save', data, function (result) {
  1142. if (type === 'noself') {
  1143. const index = findSelfLeafXmj(select, 'index');
  1144. selfList.splice(index, 1);
  1145. materialListData = result;
  1146. $('#cancel-self').modal('hide');
  1147. } else {
  1148. selfList.push(result.info);
  1149. materialListData = result.materialListData;
  1150. }
  1151. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  1152. gclGatherData[iGclRow].leafXmjs[iRow].qty = getOneQtyByLeafXmj(select);
  1153. calculateJiaCha(gclGatherData, iGclRow);
  1154. SpreadJsObj.reLoadRowData(sheet, nRow);
  1155. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  1156. leafXmjSpreadObj.refreshQtyColor(select, nRow);
  1157. loadXmjMaterialData(iGclRow, nRow);
  1158. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1159. });
  1160. },
  1161. refreshQtyColor(xmj, row) {
  1162. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  1163. const qtyInfo = findQtyLeafXmj(xmj);
  1164. if (xmj.qty !== undefined && xmj.qty !== null && qtyInfo) {
  1165. leafXmjSheet.getCell(row, qtyColIndex).backColor('#f8d7da');
  1166. }
  1167. },
  1168. }
  1169. if (!readOnly) {
  1170. // 编辑本期调差数量
  1171. if (editQtyPermission) {
  1172. leafXmjSpreadObj.editEnded = function (e, info) {
  1173. if (info.sheet.zh_setting) {
  1174. const [iGclRow, iRow, nRow, sheet, select, color] = leafXmjSpreadObj.getSelect();
  1175. const col = info.sheet.zh_setting.cols[info.col];
  1176. // 未改变值则不提交
  1177. const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1178. const orgValue = select[col.field];
  1179. if (orgValue == validText || ((orgValue === '' || orgValue === null) && (validText === '' || validText === null))) {
  1180. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1181. return;
  1182. }
  1183. if (isNaN(validText)) {
  1184. toastr.error('不能输入其它非数字类型字符');
  1185. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1186. return;
  1187. }
  1188. const qty = parseFloat(validText) !== 0 ? ZhCalc.round(parseFloat(validText), materialDecimal.qty) : 0;
  1189. console.log(qty);
  1190. let qtyInfo = findQtyLeafXmj(select);
  1191. if (qtyInfo) {
  1192. qtyInfo.qty = qty;
  1193. } else {
  1194. if (qty === null) {
  1195. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1196. return;
  1197. }
  1198. qtyInfo = {
  1199. gcl_id: select.gcl_id,
  1200. xmj_id: select.id,
  1201. mx_id: select.mx_id || '',
  1202. qty: qty,
  1203. }
  1204. }
  1205. postData(window.location.pathname + '/save', { type:'update-qty', updateData: qtyInfo, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1206. if (qtyInfo && qtyInfo.id) {
  1207. const index = findQtyLeafXmj(select, 'index');
  1208. if (result.info === null) {
  1209. qtyList.splice(index, 1);
  1210. } else {
  1211. qtyList.splice(index, 1, result.info);
  1212. }
  1213. } else {
  1214. qtyList.push(result.info);
  1215. }
  1216. materialListData = result.materialListData;
  1217. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  1218. gclGatherData[iGclRow].leafXmjs[iRow].qty = getOneQtyByLeafXmj(select);
  1219. calculateJiaCha(gclGatherData, iGclRow);
  1220. SpreadJsObj.reLoadRowData(sheet, nRow);
  1221. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  1222. leafXmjSpreadObj.refreshQtyColor(select, nRow);
  1223. loadXmjMaterialData(iGclRow, nRow);
  1224. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1225. }, function () {
  1226. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1227. });
  1228. return;
  1229. }
  1230. }
  1231. leafXmjSpreadObj.clipboardPasted = function (e, info) {
  1232. const range = info.cellRange;
  1233. const sortData = info.sheet.zh_data || [];
  1234. const data = [];
  1235. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1236. let bPaste = true;
  1237. const curRow = range.row + iRow;
  1238. const select = sortData[curRow];
  1239. if (!select) continue;
  1240. let qtyInfo = findQtyLeafXmj(select);
  1241. const hintRow = range.rowCount > 1 ? curRow : '';
  1242. let sameCol = 0;
  1243. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1244. const curCol = range.col + iCol;
  1245. const colSetting = info.sheet.zh_setting.cols[curCol];
  1246. if (!colSetting) continue;
  1247. let validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1248. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1249. const orgValue = sortData[curRow][colSetting.field];
  1250. console.log(validText, orgValue);
  1251. if (orgValue == validText || ((orgValue === '' || orgValue === null) && (validText === '' || validText === null))) {
  1252. sameCol++;
  1253. if (range.colCount === sameCol) {
  1254. bPaste = false;
  1255. }
  1256. continue;
  1257. }
  1258. if (isNaN(validText)) {
  1259. toastr.error('不能粘贴其它非数字类型字符');
  1260. bPaste = false;
  1261. continue;
  1262. }
  1263. const qty = parseFloat(validText) !== 0 ? ZhCalc.round(parseFloat(validText), materialDecimal.qty) : 0;
  1264. if (qtyInfo) {
  1265. qtyInfo.qty = qty;
  1266. } else {
  1267. if (qty === null) {
  1268. bPaste = false;
  1269. continue;
  1270. }
  1271. qtyInfo = {
  1272. gcl_id: select.gcl_id,
  1273. xmj_id: select.id,
  1274. mx_id: select.mx_id || '',
  1275. qty: qty,
  1276. }
  1277. }
  1278. sortData[curRow][colSetting.field] = qty;
  1279. }
  1280. if (bPaste) {
  1281. data.push(qtyInfo);
  1282. } else {
  1283. console.log(curRow, info.cellRange);
  1284. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1285. }
  1286. }
  1287. if (data.length === 0) {
  1288. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1289. checkNotJoinMaterialData();
  1290. return;
  1291. }
  1292. console.log(data);
  1293. // 更新至服务器
  1294. postData(window.location.pathname + '/save', { type:'pastes-qty', updateData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1295. const ledgerSheet = ledgerSpread.getActiveSheet();
  1296. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1297. const index = gclGatherData.indexOf(ledgerSelect);
  1298. materialListData = result.materialListData;
  1299. qtyList = result.qtyList;
  1300. calculateJiaCha(gclGatherData);
  1301. loadLeafXmjData(index);
  1302. loadMaterialData(index);
  1303. checkNotJoinMaterialData();
  1304. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1305. // leafXmjSpread.getActiveSheet().setSelection(info.cellRange.row, info.cellRange.col, info.cellRange.rowCount, info.cellRange.colCount);
  1306. }, function () {
  1307. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1308. });
  1309. }
  1310. leafXmjSpreadObj.deletePress = function (sheet) {
  1311. if (!sheet.zh_setting) return;
  1312. // 暂时仅支持移除数量
  1313. const sel = sheet.getSelections()[0], datas = [];
  1314. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1315. let bDel = false;
  1316. const select = sheet.zh_data[iRow];
  1317. if (!select) continue;
  1318. let qtyInfo = findQtyLeafXmj(select);
  1319. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1320. const col = sheet.zh_setting.cols[iCol];
  1321. const orgValue = select[col.field];
  1322. if (orgValue === '' || orgValue === null) {
  1323. continue;
  1324. }
  1325. if (qtyInfo) {
  1326. qtyInfo.qty = null;
  1327. bDel = true;
  1328. }
  1329. }
  1330. if (bDel) datas.push(qtyInfo);
  1331. }
  1332. if (datas.length > 0) {
  1333. // 更新至服务器
  1334. postData(window.location.pathname + '/save', { type:'pastes-qty', updateData: datas, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1335. const ledgerSheet = ledgerSpread.getActiveSheet();
  1336. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1337. const index = gclGatherData.indexOf(ledgerSelect);
  1338. materialListData = result.materialListData;
  1339. qtyList = result.qtyList;
  1340. calculateJiaCha(gclGatherData);
  1341. loadLeafXmjData(index);
  1342. loadMaterialData(index);
  1343. checkNotJoinMaterialData();
  1344. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1345. }, function () {
  1346. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1347. });
  1348. }
  1349. return;
  1350. }
  1351. leafXmjSpreadObj.valueChanged = function (e, info) {
  1352. // 防止ctrl+z撤销数据
  1353. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1354. }
  1355. leafXmjSpread.bind(spreadNS.Events.EditEnded, leafXmjSpreadObj.editEnded);
  1356. leafXmjSpread.bind(spreadNS.Events.ClipboardPasted, leafXmjSpreadObj.clipboardPasted);
  1357. leafXmjSpread.bind(spreadNS.Events.ValueChanged, leafXmjSpreadObj.valueChanged);
  1358. SpreadJsObj.addDeleteBind(leafXmjSpread, leafXmjSpreadObj.deletePress);
  1359. }
  1360. // leafXmj右键功能
  1361. if (!editForAudit) {
  1362. $.contextMenu({
  1363. selector: '#leaf-xmj-spread',
  1364. build: function ($trigger, e) {
  1365. const target = SpreadJsObj.safeRightClickSelection($trigger, e, leafXmjSpread);
  1366. const sheet = ledgerSpread.getActiveSheet();
  1367. const select = SpreadJsObj.getSelectObject(sheet);
  1368. const index = gclGatherData.indexOf(select);
  1369. const xmj = target.row !== undefined ? gclGatherData[index].leafXmjs[target.row] : null;
  1370. if (xmj) leafXmjSpreadObj.refreshQtyColor(xmj, target.row);
  1371. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1372. },
  1373. items: {
  1374. 'stop': {
  1375. name: '当前节点不参与调差',
  1376. icon: 'fa-remove',
  1377. callback: function (key, opt) {
  1378. leafXmjSpreadObj.checkJoinMaterial('notjoin');
  1379. },
  1380. visible: function (key, opt) {
  1381. const sheet = leafXmjSpread.getActiveSheet();
  1382. const select = SpreadJsObj.getSelectObject(sheet);
  1383. const sel = sheet.getSelections()[0];
  1384. if (!select || sel.rowCount !== 1) {
  1385. return false;
  1386. }
  1387. const notx = findNotJoinLeafXmj(select);
  1388. if (!readOnly && select && notx === undefined) {
  1389. return true;
  1390. } else {
  1391. return false;
  1392. }
  1393. }
  1394. },
  1395. 'start': {
  1396. name: '当前节点参与调差',
  1397. icon: 'fa-sign-in',
  1398. callback: function (key, opt) {
  1399. leafXmjSpreadObj.checkJoinMaterial('join');
  1400. },
  1401. visible: function (key, opt) {
  1402. const sheet = leafXmjSpread.getActiveSheet();
  1403. const select = SpreadJsObj.getSelectObject(sheet);
  1404. const sel = sheet.getSelections()[0];
  1405. if (!select || sel.rowCount !== 1) {
  1406. return false;
  1407. }
  1408. const notx = findNotJoinLeafXmj(select);
  1409. if (!readOnly && select && notx === undefined) {
  1410. return false;
  1411. } else {
  1412. return true;
  1413. }
  1414. },
  1415. },
  1416. 'stop2': {
  1417. name: '数量变更不参与调差',
  1418. icon: 'fa-remove',
  1419. callback: function (key, opt) {
  1420. leafXmjSpreadObj.checkChangeMaterial('notchange');
  1421. },
  1422. visible: function (key, opt) {
  1423. const sheet = leafXmjSpread.getActiveSheet();
  1424. const select = SpreadJsObj.getSelectObject(sheet);
  1425. const sel = sheet.getSelections()[0];
  1426. if (!select || sel.rowCount !== 1) {
  1427. return false;
  1428. }
  1429. if (qtySource === qtySourceValueConst.contract_qty) {
  1430. return false;
  1431. }
  1432. const notx = findNotJoinLeafXmj(select);
  1433. if (!(!readOnly && select && notx === undefined)) {
  1434. return false;
  1435. }
  1436. const notx2 = findNotChangeLeafXmj(select);
  1437. if (!readOnly && select && notx2 === undefined) {
  1438. return true;
  1439. } else {
  1440. return false;
  1441. }
  1442. }
  1443. },
  1444. 'start2': {
  1445. name: '数量变更参与调差',
  1446. icon: 'fa-sign-in',
  1447. callback: function (key, opt) {
  1448. leafXmjSpreadObj.checkChangeMaterial('change');
  1449. },
  1450. visible: function (key, opt) {
  1451. const sheet = leafXmjSpread.getActiveSheet();
  1452. const select = SpreadJsObj.getSelectObject(sheet);
  1453. const sel = sheet.getSelections()[0];
  1454. if (!select || sel.rowCount !== 1) {
  1455. return false;
  1456. }
  1457. if (qtySource === qtySourceValueConst.contract_qty) {
  1458. return false;
  1459. }
  1460. const notx = findNotJoinLeafXmj(select);
  1461. if (!(!readOnly && select && notx === undefined)) {
  1462. return false;
  1463. }
  1464. const notx2 = findNotChangeLeafXmj(select);
  1465. if (!readOnly && select && notx2 === undefined) {
  1466. return false;
  1467. } else {
  1468. return true;
  1469. }
  1470. },
  1471. },
  1472. 'self': {
  1473. name: '单独添加工料',
  1474. icon: 'fa-sign-in',
  1475. callback: function (key, opt) {
  1476. leafXmjSpreadObj.checkSelfMaterial('self');
  1477. },
  1478. visible: function (key, opt) {
  1479. if (!openMaterialSelf) {
  1480. return false;
  1481. }
  1482. const sheet = leafXmjSpread.getActiveSheet();
  1483. const select = SpreadJsObj.getSelectObject(sheet);
  1484. const sel = sheet.getSelections()[0];
  1485. if (!select || sel.rowCount !== 1) {
  1486. return false;
  1487. }
  1488. const notx = findSelfLeafXmj(select);
  1489. if (!readOnly && select && notx === undefined) {
  1490. return true;
  1491. } else {
  1492. return false;
  1493. }
  1494. }
  1495. },
  1496. 'noself': {
  1497. name: '取消单独添加工料',
  1498. icon: 'fa-remove',
  1499. callback: function (key, opt) {
  1500. $('#cancel-self').modal('show');
  1501. // leafXmjSpreadObj.checkSelfMaterial('noself');
  1502. },
  1503. visible: function (key, opt) {
  1504. if (!openMaterialSelf) {
  1505. return false;
  1506. }
  1507. const sheet = leafXmjSpread.getActiveSheet();
  1508. const select = SpreadJsObj.getSelectObject(sheet);
  1509. const sel = sheet.getSelections()[0];
  1510. if (!select || sel.rowCount !== 1) {
  1511. return false;
  1512. }
  1513. const notx = findSelfLeafXmj(select);
  1514. if (!readOnly && select && notx === undefined) {
  1515. return false;
  1516. } else {
  1517. return true;
  1518. }
  1519. },
  1520. disabled: function (key, opt) {
  1521. // const sheet = ledgerSpread.getActiveSheet();
  1522. // const select = SpreadJsObj.getSelectObject(sheet);
  1523. // const index = gclGatherData.indexOf(select);
  1524. // const leafXmjSheet = leafXmjSpread.getActiveSheet();
  1525. // const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  1526. // const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
  1527. // const leafXmjs = gclGatherData[index].leafXmjs.filter(item => {
  1528. // return item.qc_qty || item.contract_qty
  1529. // });
  1530. // const nRow = leafXmjs.indexOf(leafXmjSelect);
  1531. // const leafXmjColor = findNotJoinLeafXmj(leafXmjSelect) ? '#d6d8db' : '';
  1532. // return [index, iRow, nRow, leafXmjSheet, leafXmjSelect, leafXmjColor];
  1533. const [iGclRow, iRow, nRow, sheet, select, color] = leafXmjSpreadObj.getSelect();
  1534. const gcl = gclGatherData[iGclRow];
  1535. const leafXmjs = gcl && gcl.leafXmjs ? gcl.leafXmjs.filter(item => {
  1536. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1537. }) : null;
  1538. let flag = false;
  1539. if (leafXmjs) {
  1540. const xmj = leafXmjs[nRow];
  1541. if (_.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: (xmj.mx_id ? xmj.mx_id : '') }) != -1) {
  1542. for (const m of materialListData) {
  1543. if (m.gcl_id === xmj.gcl_id && m.xmj_id === xmj.id && ((xmj.mx_id !==undefined && m.mx_id === xmj.mx_id) || xmj.mx_id === undefined) && m.order !== stage_order) {
  1544. flag = true;
  1545. break;
  1546. }
  1547. }
  1548. }
  1549. }
  1550. return flag;
  1551. },
  1552. },
  1553. }
  1554. });
  1555. $('#cancelSelfBtn').click(function () {
  1556. leafXmjSpreadObj.checkSelfMaterial('noself');
  1557. });
  1558. }
  1559. // material-spread右键功能
  1560. const materialSpreadObj = {
  1561. del: function () {
  1562. const materialSheet = materialSpread.getActiveSheet();
  1563. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  1564. const sheet = ledgerSpread.getActiveSheet();
  1565. const select = SpreadJsObj.getSelectObject(sheet);
  1566. const index = gclGatherData.indexOf(select);
  1567. // const leafXmjSheet = leafXmjSpread.getActiveSheet();
  1568. // const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  1569. const gcl = gclGatherData[index].leafXmjs;
  1570. // const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  1571. const datas = [];
  1572. for (const xmj of gcl) {
  1573. const data = {
  1574. xmj_id: xmj.id,
  1575. gcl_id: xmj.gcl_id,
  1576. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1577. };
  1578. datas.push(data);
  1579. }
  1580. if (isStageSelf) {
  1581. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1582. // 取所有的gclGatherData才行,然后获取下的值
  1583. const gclData = gclGatherData[index];
  1584. for (const [index, ms] of materialStageData.entries()) {
  1585. if (ms.id !== ms_id) {
  1586. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1587. if (gclOther) {
  1588. const leafXmjs = gclOther.leafXmjs.filter(item => {
  1589. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1590. });
  1591. for (const xmj of leafXmjs) {
  1592. const data = {
  1593. xmj_id: xmj.id,
  1594. gcl_id: xmj.gcl_id,
  1595. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1596. };
  1597. if (_.indexOf(datas, data) === -1) {
  1598. datas.push(data);
  1599. }
  1600. }
  1601. }
  1602. }
  1603. }
  1604. }
  1605. console.log(datas, materialSelect.mb_id);
  1606. postData(window.location.pathname + '/save', {type: 'dels', postData: { xmjs: datas, mb_id: materialSelect.mb_id }, ms_id: $('#myTab').find('.active').data('msid') || null}, function (result) {
  1607. materialListData = result.materialListData;
  1608. gclList = result.gclList;
  1609. calculateJiaCha(gclGatherData);
  1610. // const index = gclGatherData.indexOf(ledgerSelect);
  1611. loadLeafXmjData(index);
  1612. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1613. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1614. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1615. loadMaterialData(index);
  1616. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1617. });
  1618. // postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  1619. // const index = materialList.indexOf(select);
  1620. // materialList.splice(index, 1);
  1621. // sheet.deleteRows(index, 1);
  1622. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1623. // const sel = sheet.getSelections();
  1624. // sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1625. // const materialListIndex = materialListData.indexOf(select);
  1626. // materialListData.splice(materialListIndex, 1);
  1627. // const [iGclRow, iRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  1628. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1629. // calculateJiaCha(gclGatherData, iGclRow);
  1630. // SpreadJsObj.reLoadRowData(lsheet, iRow);
  1631. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1632. // });
  1633. },
  1634. deletePress: function (sheet) {
  1635. return;
  1636. },
  1637. editStarting: function (e, info) {
  1638. const col = info.sheet.zh_setting.cols[info.col];
  1639. const select = SpreadJsObj.getSelectObject(info.sheet);
  1640. if (col.field === 'quantity') {
  1641. if (select.expr && select.expr !== '') {
  1642. info.sheet.getCell(info.row, info.col).text(select.expr);
  1643. }
  1644. }
  1645. },
  1646. editEnded: function (e, info) {
  1647. if (info.sheet.zh_setting) {
  1648. const select = SpreadJsObj.getSelectObject(info.sheet);
  1649. const col = info.sheet.zh_setting.cols[info.col];
  1650. // 未改变值则不提交
  1651. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1652. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1653. // let orgValue = select[col.field];
  1654. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1655. let orgValue;
  1656. if (col.field === 'quantity') {
  1657. orgValue = validText && validText !== ''
  1658. ? _.toNumber(validText) ? select.quantity : select.expr
  1659. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1660. } else {
  1661. orgValue = select[col.field];
  1662. }
  1663. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1664. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1665. return;
  1666. }
  1667. const exprQuantity = {
  1668. expr: '',
  1669. quantity: 0,
  1670. };
  1671. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1672. if (!valid) {
  1673. toastr.error(msg);
  1674. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1675. return;
  1676. }
  1677. if (isNaN(exprQuantity.quantity)) {
  1678. toastr.error('不能输入其它非数字类型字符');
  1679. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1680. return;
  1681. }
  1682. const num = parseFloat(exprQuantity.quantity);
  1683. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1684. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1685. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1686. // return;
  1687. toastr.warning('已保留6位小数');
  1688. exprQuantity.quantity = ZhCalc.round(num, 6);
  1689. }
  1690. // 更新至服务器
  1691. const ledgerSheet = ledgerSpread.getActiveSheet();
  1692. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1693. const index = gclGatherData.indexOf(ledgerSelect);
  1694. const gcl = gclGatherData[index].leafXmjs;
  1695. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1696. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1697. // const xmjIndex = gcl.indexOf(xmjSelect);
  1698. const datas = [];
  1699. for (const xmj of gcl) {
  1700. const data = {
  1701. xmj_id: xmj.id,
  1702. gcl_id: xmj.gcl_id,
  1703. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1704. };
  1705. datas.push(data);
  1706. }
  1707. if (isStageSelf) {
  1708. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1709. // 取所有的gclGatherData才行,然后获取下的值
  1710. const gclData = gclGatherData[index];
  1711. for (const [index, ms] of materialStageData.entries()) {
  1712. if (ms.id !== ms_id) {
  1713. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1714. if (gclOther) {
  1715. const leafXmjs = gclOther.leafXmjs.filter(item => {
  1716. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1717. });
  1718. for (const xmj of leafXmjs) {
  1719. const data = {
  1720. xmj_id: xmj.id,
  1721. gcl_id: xmj.gcl_id,
  1722. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1723. };
  1724. if (_.indexOf(datas, data) === -1) {
  1725. datas.push(data);
  1726. }
  1727. }
  1728. }
  1729. }
  1730. }
  1731. }
  1732. console.log(exprQuantity, datas, select.mb_id);
  1733. postData(window.location.pathname + '/save', { type:'updates', updateData: { xmjs: datas, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id }, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1734. materialListData = result.materialListData;
  1735. gclList = result.gclList;
  1736. calculateJiaCha(gclGatherData);
  1737. // const index = gclGatherData.indexOf(ledgerSelect);
  1738. loadLeafXmjData(index);
  1739. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1740. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1741. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1742. loadMaterialData(index);
  1743. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1744. materialSpread.getActiveSheet().setSelection(info.row + 1, info.col, 1, 1);
  1745. }, function () {
  1746. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1747. });
  1748. // postData(window.location.pathname + '/save', { type:'update', updateData: { id:select.id, quantity: validText, mb_id: select.mb_id } }, function (result) {
  1749. // const materialListIndex = materialListData.indexOf(select);
  1750. // const index = materialList.indexOf(select);
  1751. // select[col.field] = validText;
  1752. // materialListData.splice(materialListIndex, 1, select);
  1753. // materialList.indexOf(index, 1, select);
  1754. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1755. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1756. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1757. // calculateJiaCha(gclGatherData, iGclRow)
  1758. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1759. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1760. // }, function () {
  1761. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1762. // });
  1763. }
  1764. },
  1765. clipboardPasted(e, info) {
  1766. const hint = {
  1767. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1768. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1769. numberCan: {type: 'warning', msg: '已保留6位小数'},
  1770. };
  1771. const range = info.cellRange;
  1772. const sortData = info.sheet.zh_data || [];
  1773. if (range.row + range.rowCount > sortData.length) {
  1774. toastMessageUniq(hint.cellError);
  1775. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1776. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1777. return;
  1778. }
  1779. if (sortData.length > 0 && range.col + range.colCount > 5) {
  1780. toastMessageUniq(hint.cellError);
  1781. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1782. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1783. return;
  1784. }
  1785. const data = [];
  1786. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1787. let bPaste = true;
  1788. const curRow = range.row + iRow;
  1789. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  1790. const hintRow = range.rowCount > 1 ? curRow : '';
  1791. let sameCol = 0;
  1792. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1793. const curCol = range.col + iCol;
  1794. const colSetting = info.sheet.zh_setting.cols[curCol];
  1795. if (!colSetting) continue;
  1796. // let validText = info.sheet.getText(curRow, curCol);
  1797. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1798. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1799. const orgValue = sortData[curRow][colSetting.field];
  1800. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1801. sameCol++;
  1802. if (range.colCount === sameCol) {
  1803. bPaste = false;
  1804. }
  1805. continue;
  1806. }
  1807. const exprQuantity = {
  1808. expr: '',
  1809. quantity: 0,
  1810. };
  1811. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1812. if (!valid) {
  1813. toastMessageUniq(getPasteHint(msg, hintRow));
  1814. bPaste = false;
  1815. continue;
  1816. }
  1817. if (isNaN(exprQuantity.quantity)) {
  1818. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1819. bPaste = false;
  1820. continue;
  1821. }
  1822. const num = parseFloat(exprQuantity.quantity);
  1823. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1824. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1825. // bPaste = false;
  1826. // continue;
  1827. exprQuantity.quantity = ZhCalc.round(num, 6);
  1828. }
  1829. // materialData[colSetting.field] = validText;
  1830. materialData.expr = exprQuantity.expr;
  1831. materialData.quantity = exprQuantity.quantity;
  1832. }
  1833. if (bPaste) {
  1834. data.push(materialData);
  1835. // rowData.push(curRow);
  1836. } else {
  1837. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1838. }
  1839. }
  1840. if (data.length === 0) {
  1841. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1842. return;
  1843. }
  1844. const ledgerSheet = ledgerSpread.getActiveSheet();
  1845. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1846. const index = gclGatherData.indexOf(ledgerSelect);
  1847. const gcl = gclGatherData[index].leafXmjs;
  1848. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1849. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1850. // const xmjIndex = gcl.indexOf(xmjSelect);
  1851. const datas = [];
  1852. for (const xmj of gcl) {
  1853. const data2 = {
  1854. xmj_id: xmj.id,
  1855. gcl_id: xmj.gcl_id,
  1856. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1857. };
  1858. datas.push(data2);
  1859. }
  1860. if (isStageSelf) {
  1861. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1862. // 取所有的gclGatherData才行,然后获取下的值
  1863. const gclData = gclGatherData[index];
  1864. for (const [index, ms] of materialStageData.entries()) {
  1865. if (ms.id !== ms_id) {
  1866. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1867. if (gclOther) {
  1868. const leafXmjs = gclOther.leafXmjs.filter(item => {
  1869. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1870. });
  1871. for (const xmj of leafXmjs) {
  1872. const data = {
  1873. xmj_id: xmj.id,
  1874. gcl_id: xmj.gcl_id,
  1875. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1876. };
  1877. if (_.indexOf(datas, data) === -1) {
  1878. datas.push(data);
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. console.log(data, datas);
  1886. // 更新至服务器
  1887. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data }, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1888. materialListData = result.materialListData;
  1889. gclList = result.gclList;
  1890. calculateJiaCha(gclGatherData);
  1891. // const index = gclGatherData.indexOf(ledgerSelect);
  1892. loadLeafXmjData(index);
  1893. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1894. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1895. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1896. loadMaterialData(index);
  1897. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1898. materialSpread.getActiveSheet().setSelection(info.cellRange.row, info.cellRange.col, info.cellRange.rowCount, info.cellRange.colCount);
  1899. }, function () {
  1900. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1901. });
  1902. // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1903. // materialListData = result;
  1904. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1905. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1906. // calculateJiaCha(gclGatherData, iGclRow);
  1907. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1908. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1909. // }, function () {
  1910. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1911. // });
  1912. },
  1913. _checkExprValid(expr) {
  1914. if (!expr) return [true, null];
  1915. const param = [];
  1916. let num = '', base = '';
  1917. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1918. if (/^[\d\.%]+/.test(expr[i])) {
  1919. if (base !== '') {
  1920. param.push({type: 'base', value: base});
  1921. base = '';
  1922. }
  1923. num = num + expr[i];
  1924. } else if (expr[i] === '(') {
  1925. if (num !== '') {
  1926. param.push({type: 'num', value: num});
  1927. num = '';
  1928. }
  1929. if (base !== '') {
  1930. param.push({type: 'base', value: base});
  1931. base = '';
  1932. }
  1933. param.push({type: 'left', value: '('});
  1934. } else if (expr[i] === ')') {
  1935. if (num !== '') {
  1936. param.push({type: 'num', value: num});
  1937. num = '';
  1938. }
  1939. if (base !== '') {
  1940. param.push({type: 'base', value: base});
  1941. base = '';
  1942. }
  1943. param.push({type: 'right', value: ')'});
  1944. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1945. if (num !== '') {
  1946. param.push({type: 'num', value: num});
  1947. num = '';
  1948. }
  1949. if (base !== '') {
  1950. param.push({type: 'base', value: base});
  1951. base = '';
  1952. }
  1953. param.push({type: 'calc', value: expr[i]});
  1954. } else {
  1955. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1956. }
  1957. }
  1958. if (num !== '') {
  1959. param.push({type: 'num', value: num});
  1960. num = '';
  1961. }
  1962. if (base !== '') {
  1963. param.push({type: 'base', value: base});
  1964. base = '';
  1965. }
  1966. if (param.length === 0) return true;
  1967. if (param.length > 1) {
  1968. if (param[0].value === '-' && param[1].type === 'num') {
  1969. param[1].value = '-' + param[1].value;
  1970. param.shift();
  1971. }
  1972. }
  1973. const iLen = param.length;
  1974. let iLeftCount = 0, iRightCount = 0;
  1975. for (const [i, p] of param.entries()) {
  1976. if (p.type === 'calc') {
  1977. if (i === 0 || i === iLen - 1)
  1978. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1979. }
  1980. if (p.type === 'num') {
  1981. num = p.value.replace('%', '');
  1982. if (p.value.length - num.length > 1)
  1983. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1984. num = _.toNumber(num);
  1985. if (num === undefined || num === null || _.isNaN(num))
  1986. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1987. if (i > 0) {
  1988. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1989. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1990. } else if (param[i - 1].value === '/' && num === 0) {
  1991. return [false, '输入的表达式非法:请勿除0'];
  1992. }
  1993. }
  1994. }
  1995. if (p.type === 'base') {
  1996. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1997. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1998. }
  1999. if (p.type === 'left') {
  2000. iLeftCount += 1;
  2001. if (i !== 0 && param[i-1].type !== 'calc')
  2002. return [false, '输入的表达式非法:(前应有运算符'];
  2003. }
  2004. if (p.type === 'right') {
  2005. iRightCount += 1;
  2006. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  2007. return [false, '输入的表达式非法:)后应有运算符'];
  2008. if (iRightCount > iLeftCount)
  2009. return [false, '输入的表达式非法:")"前无对应的"("'];
  2010. }
  2011. }
  2012. if (iLeftCount > iRightCount)
  2013. return [false, '输入的表达式非法:"("后无对应的")"'];
  2014. return [true, ''];
  2015. },
  2016. _checkExpr: function (text, data) {
  2017. if (text) {
  2018. const num = _.toNumber(text);
  2019. if (num) {
  2020. data.quantity = num;
  2021. data.expr = '';
  2022. } else {
  2023. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  2024. const [valid, msg] = this._checkExprValid(expr);
  2025. if (!valid) return [valid, msg];
  2026. data.expr = expr;
  2027. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace(new RegExp('%', 'gm'), '/100'));
  2028. // const ce = new CalcEvalMin();
  2029. // data.quantity = ce.eval(expr);
  2030. // console.log(data.quantity);
  2031. }
  2032. } else {
  2033. data.quantity = 0;
  2034. data.expr = '';
  2035. }
  2036. return [true, ''];
  2037. },
  2038. };
  2039. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  2040. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  2041. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  2042. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  2043. // material-spread右键功能
  2044. if (openMaterialSelf) {
  2045. const materialSelfSpreadObj = {
  2046. del: function () {
  2047. const sheet = materialSelfSpread.getActiveSheet();
  2048. const select = SpreadJsObj.getSelectObject(sheet);
  2049. console.log(select);
  2050. postData(window.location.pathname + '/save', {
  2051. type: 'del',
  2052. id: select.id,
  2053. mb_id: select.mb_id,
  2054. ms_id: $('#myTab').find('.active').data('msid') || null
  2055. }, function (result) {
  2056. const index = materialListSelf.indexOf(select);
  2057. materialListSelf.splice(index, 1);
  2058. sheet.deleteRows(index, 1);
  2059. SpreadJsObj.reLoadSheetData(materialSelfSpread.getActiveSheet());
  2060. const sel = sheet.getSelections();
  2061. sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  2062. const materialListIndex = materialListData.indexOf(select);
  2063. materialListData.splice(materialListIndex, 1);
  2064. const [iGclRow, iRow, nRow, lsheet, lselect, color] = leafXmjSpreadObj.getSelect();
  2065. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  2066. calculateJiaCha(gclGatherData, iGclRow);
  2067. SpreadJsObj.reLoadRowData(lsheet, nRow);
  2068. lsheet.getRange(nRow, -1, 1, -1).backColor(color);
  2069. leafXmjSpreadObj.refreshQtyColor(lselect, nRow);
  2070. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  2071. });
  2072. },
  2073. deletePress: function (sheet) {
  2074. return;
  2075. },
  2076. editStarting: function (e, info) {
  2077. const col = info.sheet.zh_setting.cols[info.col];
  2078. const select = SpreadJsObj.getSelectObject(info.sheet);
  2079. if (col.field === 'quantity') {
  2080. if (select.expr && select.expr !== '') {
  2081. info.sheet.getCell(info.row, info.col).text(select.expr);
  2082. }
  2083. }
  2084. },
  2085. editEnded: function (e, info) {
  2086. if (info.sheet.zh_setting) {
  2087. const select = SpreadJsObj.getSelectObject(info.sheet);
  2088. const col = info.sheet.zh_setting.cols[info.col];
  2089. // 未改变值则不提交
  2090. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  2091. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  2092. // let orgValue = select[col.field];
  2093. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  2094. let orgValue;
  2095. if (col.field === 'quantity') {
  2096. orgValue = validText && validText !== ''
  2097. ? _.toNumber(validText) ? select.quantity : select.expr
  2098. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  2099. } else {
  2100. orgValue = select[col.field];
  2101. }
  2102. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  2103. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2104. return;
  2105. }
  2106. const exprQuantity = {
  2107. expr: '',
  2108. quantity: 0,
  2109. };
  2110. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  2111. if (!valid) {
  2112. toastr.error(msg);
  2113. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2114. return;
  2115. }
  2116. if (isNaN(exprQuantity.quantity)) {
  2117. toastr.error('不能输入其它非数字类型字符');
  2118. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2119. return;
  2120. }
  2121. const num = parseFloat(exprQuantity.quantity);
  2122. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  2123. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  2124. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2125. // return;
  2126. toastr.warning('已保留6位小数');
  2127. exprQuantity.quantity = ZhCalc.round(num, 6);
  2128. }
  2129. // 更新至服务器
  2130. console.log(exprQuantity, select.mb_id);
  2131. postData(window.location.pathname + '/save', {
  2132. type: 'update',
  2133. updateData: {
  2134. id: select.id,
  2135. expr: exprQuantity.expr,
  2136. quantity: exprQuantity.quantity,
  2137. mb_id: select.mb_id
  2138. },
  2139. ms_id: $('#myTab').find('.active').data('msid') || null
  2140. }, function (result) {
  2141. const materialListIndex = materialListData.indexOf(select);
  2142. const index = materialList.indexOf(select);
  2143. select.quantity = exprQuantity.quantity;
  2144. select.expr = exprQuantity.expr;
  2145. materialListData.splice(materialListIndex, 1, select);
  2146. materialList.indexOf(index, 1, select);
  2147. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2148. const [iGclRow, iRow, nRow, sheet, lselect, color] = leafXmjSpreadObj.getSelect();
  2149. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  2150. calculateJiaCha(gclGatherData, iGclRow);
  2151. SpreadJsObj.reLoadRowData(sheet, nRow);
  2152. console.log(lselect, color);
  2153. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  2154. leafXmjSpreadObj.refreshQtyColor(lselect, nRow);
  2155. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  2156. }, function () {
  2157. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2158. });
  2159. }
  2160. },
  2161. clipboardPasted(e, info) {
  2162. const hint = {
  2163. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  2164. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  2165. numberCan: {type: 'warning', msg: '已保留6位小数'},
  2166. };
  2167. const range = info.cellRange;
  2168. const sortData = info.sheet.zh_data || [];
  2169. if (range.row + range.rowCount > sortData.length) {
  2170. toastMessageUniq(hint.cellError);
  2171. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  2172. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  2173. return;
  2174. }
  2175. if (sortData.length > 0 && range.col + range.colCount > 5) {
  2176. toastMessageUniq(hint.cellError);
  2177. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  2178. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  2179. return;
  2180. }
  2181. const data = [];
  2182. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  2183. let bPaste = true;
  2184. const curRow = range.row + iRow;
  2185. const materialData = {id: sortData[curRow].id, mb_id: sortData[curRow].mb_id};
  2186. const hintRow = range.rowCount > 1 ? curRow : '';
  2187. let sameCol = 0;
  2188. for (let iCol = 0; iCol < range.colCount; iCol++) {
  2189. const curCol = range.col + iCol;
  2190. const colSetting = info.sheet.zh_setting.cols[curCol];
  2191. if (!colSetting) continue;
  2192. // let validText = info.sheet.getText(curRow, curCol);
  2193. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  2194. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  2195. const orgValue = sortData[curRow][colSetting.field];
  2196. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  2197. sameCol++;
  2198. if (range.colCount === sameCol) {
  2199. bPaste = false;
  2200. }
  2201. continue;
  2202. }
  2203. const exprQuantity = {
  2204. expr: '',
  2205. quantity: 0,
  2206. };
  2207. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  2208. if (!valid) {
  2209. toastMessageUniq(getPasteHint(msg, hintRow));
  2210. bPaste = false;
  2211. continue;
  2212. }
  2213. if (isNaN(exprQuantity.quantity)) {
  2214. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  2215. bPaste = false;
  2216. continue;
  2217. }
  2218. const num = parseFloat(exprQuantity.quantity);
  2219. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  2220. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  2221. // bPaste = false;
  2222. // continue;
  2223. exprQuantity.quantity = ZhCalc.round(num, 6);
  2224. }
  2225. // materialData[colSetting.field] = validText;
  2226. materialData.expr = exprQuantity.expr;
  2227. materialData.quantity = exprQuantity.quantity;
  2228. }
  2229. if (bPaste) {
  2230. data.push(materialData);
  2231. // rowData.push(curRow);
  2232. } else {
  2233. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  2234. }
  2235. }
  2236. if (data.length === 0) {
  2237. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2238. return;
  2239. }
  2240. console.log(data);
  2241. postData(window.location.pathname + '/save', {
  2242. type: 'paste',
  2243. updateData: data,
  2244. ms_id: $('#myTab').find('.active').data('msid') || null
  2245. }, function (result) {
  2246. materialListData = result;
  2247. const [iGclRow, iRow, nRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  2248. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  2249. calculateJiaCha(gclGatherData, iGclRow);
  2250. SpreadJsObj.reLoadRowData(sheet, nRow);
  2251. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  2252. loadXmjMaterialData(iGclRow, nRow);
  2253. }, function () {
  2254. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2255. });
  2256. },
  2257. };
  2258. materialSelfSpread.bind(spreadNS.Events.EditStarting, materialSelfSpreadObj.editStarting);
  2259. materialSelfSpread.bind(spreadNS.Events.EditEnded, materialSelfSpreadObj.editEnded);
  2260. materialSelfSpread.bind(spreadNS.Events.ClipboardPasted, materialSelfSpreadObj.clipboardPasted);
  2261. SpreadJsObj.addDeleteBind(materialSelfSpread, materialSelfSpreadObj.deletePress);
  2262. if (!editForAudit) {
  2263. $.contextMenu({
  2264. selector: '#material-self-spread',
  2265. build: function ($trigger, e) {
  2266. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSelfSpread);
  2267. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2268. },
  2269. items: {
  2270. 'create': {
  2271. name: '添加工料',
  2272. icon: 'fa-sign-in',
  2273. callback: function (key, opt) {
  2274. // 获取已选清单
  2275. changeMaterialTable('self');
  2276. $('#add_type').val('self');
  2277. $('#addgl').modal('show');
  2278. },
  2279. disabled: function (key, opt) {
  2280. const sheet = leafXmjSpread.getActiveSheet();
  2281. const select = SpreadJsObj.getSelectObject(sheet);
  2282. // const notx = findNotJoinLeafXmj(select);
  2283. if (!select) {
  2284. return true;
  2285. }
  2286. // if (!readOnly && notx === undefined) {
  2287. // return false;
  2288. // } else {
  2289. // return true;
  2290. // }
  2291. return readOnly;
  2292. },
  2293. },
  2294. 'delete': {
  2295. name: '删除工料',
  2296. icon: 'fa-remove',
  2297. callback: function (key, opt) {
  2298. materialSelfSpreadObj.del(materialSelfSpread.getActiveSheet());
  2299. },
  2300. disabled: function (key, opt) {
  2301. const sheet = materialSelfSpread.getActiveSheet();
  2302. const select = SpreadJsObj.getSelectObject(sheet);
  2303. if (!select) {
  2304. return true;
  2305. }
  2306. if (!readOnly && select && materialSelfBase.isEdit(select, 'del')) {
  2307. return false;
  2308. } else {
  2309. return true;
  2310. }
  2311. }
  2312. },
  2313. }
  2314. });
  2315. }
  2316. }
  2317. if (!openMaterialChecklist && !editForAudit) {
  2318. $.contextMenu({
  2319. selector: '#material-spread',
  2320. build: function ($trigger, e) {
  2321. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  2322. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2323. },
  2324. items: {
  2325. 'create': {
  2326. name: '添加工料',
  2327. icon: 'fa-sign-in',
  2328. callback: function (key, opt) {
  2329. // 获取已选清单
  2330. changeMaterialTable();
  2331. $('#add_type').val('all');
  2332. $('#addgl').modal('show');
  2333. },
  2334. disabled: function (key, opt) {
  2335. const sheet = leafXmjSpread.getActiveSheet();
  2336. const select = SpreadJsObj.getSelectObject(sheet);
  2337. // const notx = findNotJoinLeafXmj(select);
  2338. if (!select) {
  2339. return true;
  2340. }
  2341. // if (!readOnly && notx === undefined) {
  2342. // return false;
  2343. // } else {
  2344. // return true;
  2345. // }
  2346. return readOnly;
  2347. }
  2348. },
  2349. 'delete': {
  2350. name: '删除工料',
  2351. icon: 'fa-remove',
  2352. callback: function (key, opt) {
  2353. materialSpreadObj.del(materialSpread.getActiveSheet());
  2354. },
  2355. disabled: function (key, opt) {
  2356. const sheet = materialSpread.getActiveSheet();
  2357. const select = SpreadJsObj.getSelectObject(sheet);
  2358. if (!select) {
  2359. return true;
  2360. }
  2361. if (!readOnly && select && materialBase.isEdit(select, 'del')) {
  2362. return false;
  2363. } else {
  2364. return true;
  2365. }
  2366. }
  2367. },
  2368. }
  2369. });
  2370. }
  2371. }
  2372. // 应用调差工料至其他清单明细
  2373. $('#user_all_material').click(function () {
  2374. const ledgerSheet = ledgerSpread.getActiveSheet();
  2375. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  2376. if (ledgerSelect.leafXmjs.length < 2) {
  2377. toastr.warning('没有需要应用调差工料的其它清单明细');
  2378. return false;
  2379. }
  2380. const xmjSheet = leafXmjSpread.getActiveSheet();
  2381. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  2382. console.log(ledgerSelect.leafXmjs);
  2383. // 判断需要应用调差工料的清单明细
  2384. const needAddList = [];
  2385. for (const xmj of ledgerSelect.leafXmjs) {
  2386. const notx = findNotJoinLeafXmj(xmj);
  2387. if (notx === undefined && xmjSelect !== xmj && xmj.gather_qty && xmj.jiacha === null && xmjSelect.jiacha !== null) {
  2388. needAddList.push(xmj);
  2389. }
  2390. }
  2391. // if (needAddList.length === 0) {
  2392. // toastr.warning('没有需要应用调差工料的其它清单明细');
  2393. // return false;
  2394. // }
  2395. console.log(needAddList, materialList);
  2396. // 更新至服务器
  2397. postData(window.location.pathname + '/save', { type:'useOther', postData: { addXmj: needAddList, materialBills: materialList } }, function (result) {
  2398. materialListData = result.materialListData;
  2399. gclList = result.gclList;
  2400. toastr.success('已成功应用');
  2401. calculateJiaCha(gclGatherData);
  2402. const index = gclGatherData.indexOf(ledgerSelect);
  2403. loadLeafXmjData(index);
  2404. // const xmjSheet = leafXmjSpread.getActiveSheet();
  2405. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  2406. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  2407. loadMaterialData(index);
  2408. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  2409. });
  2410. });
  2411. // 切换清单行,读取所属项目节数据
  2412. ledgerSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  2413. if (info.oldSelections !== undefined) {
  2414. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  2415. if (iNewRow !== iOldRow) {
  2416. loadLeafXmjData(iNewRow);
  2417. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  2418. loadMaterialData(iNewRow);
  2419. loadXmjMaterialData(iNewRow, 0);
  2420. checkNotJoinMaterialData();
  2421. }
  2422. }
  2423. });
  2424. // 切换项目节数据清单明细行,读取单独的清单工料数据
  2425. leafXmjSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  2426. if (info.oldSelections !== undefined) {
  2427. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  2428. if (iNewRow !== iOldRow) {
  2429. const sheet = ledgerSpread.getActiveSheet();
  2430. const select = SpreadJsObj.getSelectObject(sheet);
  2431. const index = gclGatherData.indexOf(select);
  2432. loadXmjMaterialData(index, iNewRow);
  2433. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  2434. }
  2435. }
  2436. });
  2437. // 显示有调差工料清单
  2438. $('#show_material_gcl').click(function () {
  2439. if ($(this).is(':checked')) {
  2440. const hadMaterialGclGatherData = [];
  2441. const hadGclIdList = [];
  2442. for (const ml of materialListData) {
  2443. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  2444. hadGclIdList.push(ml.gcl_id);
  2445. }
  2446. }
  2447. for (const gcl of gclGatherData) {
  2448. for (const index in gcl.leafXmjs) {
  2449. const gcl_id = gcl.leafXmjs[index].gcl_id;
  2450. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  2451. hadMaterialGclGatherData.push(gcl);
  2452. break;
  2453. }
  2454. }
  2455. }
  2456. gclGatherData = hadMaterialGclGatherData;
  2457. } else {
  2458. if (isStageSelf) {
  2459. const ms_id = parseInt($('#myTab').find('.active').data('msid'));
  2460. updateBillsData(ms_id);
  2461. const i = _.findIndex(materialStageData, { id: ms_id });
  2462. gclGatherData = gclGatherListData[i];
  2463. } else {
  2464. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
  2465. gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
  2466. gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  2467. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  2468. });
  2469. }
  2470. if (openMaterialChecklist) {
  2471. // 取交集
  2472. gclGatherData = _.filter(gclGatherData, function (item) {
  2473. return _.find(materialChecklistData, { b_code: item.b_code, name: item.name, unit: item.unit, unit_price: item.unit_price });
  2474. });
  2475. }
  2476. }
  2477. calculateJiaCha(gclGatherData);
  2478. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  2479. loadLeafXmjData(0);
  2480. loadMaterialData(0);
  2481. loadXmjMaterialData(0, 0);
  2482. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  2483. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  2484. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  2485. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  2486. checkNotJoinMaterialData();
  2487. });
  2488. $.subMenu({
  2489. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2490. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2491. key: 'menu.1.0.0',
  2492. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2493. callback: function (info) {
  2494. if (info.mini) {
  2495. $('.panel-title').addClass('fluid');
  2496. $('#sub-menu').removeClass('panel-sidebar');
  2497. } else {
  2498. $('.panel-title').removeClass('fluid');
  2499. $('#sub-menu').addClass('panel-sidebar');
  2500. }
  2501. autoFlashHeight();
  2502. ledgerSpread.refresh();
  2503. leafXmjSpread.refresh();
  2504. materialSpread.refresh();
  2505. materialSelfSpread.refresh();
  2506. }
  2507. });
  2508. $(window).resize(function () {
  2509. ledgerSpread.refresh();
  2510. leafXmjSpread.refresh();
  2511. materialSpread.refresh();
  2512. materialSelfSpread.refresh();
  2513. });
  2514. $.divResizer({
  2515. select: '#right-spr',
  2516. callback: function () {
  2517. ledgerSpread.refresh();
  2518. // leafXmjSpread.refresh();
  2519. materialSpread.refresh();
  2520. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  2521. setLocalCache('material_list_' + materialID, width);
  2522. }
  2523. });
  2524. $.divResizer({
  2525. select: '#right-spr2',
  2526. callback: function () {
  2527. leafXmjSpread.refresh();
  2528. materialSelfSpread.refresh();
  2529. // const width = (($('#right-view2').width()/$('#right-view2').parent('div').width())*100).toFixed();
  2530. // setLocalCache('material_list3_' + materialID, width);
  2531. }
  2532. });
  2533. $.divResizer({
  2534. select: '#main-resize',
  2535. callback: function () {
  2536. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2537. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  2538. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2539. $(".sp-wrap").height(bcontent-30);
  2540. materialSpread.refresh();
  2541. ledgerSpread.refresh();
  2542. leafXmjSpread.refresh();
  2543. materialSelfSpread.refresh();
  2544. const height = $('.bcontent-wrap').height();
  2545. setLocalCache('material_list2_' + materialID, height);
  2546. }
  2547. });
  2548. // 展开收起月信息价并浏览器记住本期展开收起
  2549. $('a', '.right-nav').bind('click', function () {
  2550. //const main = $('#main-view'), tool = $('#tools-view');
  2551. const tab = $(this), tabPanel = $(tab.attr('content'));
  2552. if (!tab.hasClass('active')) {
  2553. $('a', '.side-menu').removeClass('active');
  2554. $('.tab-content .tab-select-show').removeClass('active');
  2555. tab.addClass('active');
  2556. tabPanel.addClass('active');
  2557. showSideTools(tab.hasClass('active'));
  2558. if (tab.attr('content') === '#material-tab') {
  2559. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  2560. setLocalCache('material_list_' + materialID, width);
  2561. }
  2562. } else {
  2563. removeLocalCache('material_list_' + materialID);
  2564. tab.removeClass('active');
  2565. tabPanel.removeClass('active');
  2566. showSideTools(tab.hasClass('active'));
  2567. }
  2568. ledgerSpread.refresh();
  2569. // leafXmjSpread.refresh();
  2570. materialSpread.refresh();
  2571. });
  2572. // 根据浏览器记录展开收起
  2573. if (getLocalCache('material_list_' + materialID)) {
  2574. const tab = $('.right-nav a[content="#material-tab"]'), tabPanel = $(tab.attr('content'));
  2575. $('a', '.side-menu').removeClass('active');
  2576. $('.tab-content .tab-select-show').removeClass('active');
  2577. tab.addClass('active');
  2578. tabPanel.addClass('active');
  2579. $('#right-view').css('width', getLocalCache('material_list_' + materialID) + '%');
  2580. showSideTools(tab.hasClass('active'));
  2581. ledgerSpread.refresh();
  2582. // leafXmjSpread.refresh();
  2583. materialSpread.refresh();
  2584. }
  2585. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  2586. if (getLocalCache('material_list2_' + materialID)) {
  2587. $('.bcontent-wrap').height(getLocalCache('material_list2_' + materialID));
  2588. const cHeader = getObjHeight($(".c-header"));
  2589. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2590. $(".sp-wrap").height(bcontent-30);
  2591. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  2592. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2593. materialSpread.refresh();
  2594. ledgerSpread.refresh();
  2595. leafXmjSpread.refresh();
  2596. materialSelfSpread.refresh();
  2597. } else {
  2598. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2599. ledgerSpread.refresh();
  2600. }
  2601. function getObjHeight(select) {
  2602. return select.length > 0 ? select.height() : 0;
  2603. }
  2604. const showSelfSideTools = function (show) {
  2605. const left = $('#left-view2'), right = $('#right-view2'), parent = left.parent();
  2606. if (show) {
  2607. right.show();
  2608. autoFlashHeight();
  2609. /**
  2610. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  2611. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  2612. * 故需要通过最终的parent.width再计算一次left.width
  2613. *
  2614. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  2615. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  2616. *
  2617. */
  2618. //left.css('width', parent.width() - right.outerWidth());
  2619. //left.css('width', parent.width() - right.outerWidth());
  2620. const percent = 100 - right.outerWidth() /parent.width() * 100;
  2621. left.css('width', percent + '%');
  2622. } else {
  2623. // left.css('width', parent.width());
  2624. left.css('width', '100%');
  2625. right.hide();
  2626. }
  2627. };
  2628. });