material_list.js 144 KB

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