material_list.js 127 KB

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