material_list.js 126 KB

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