material_list.js 127 KB

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