material_list.js 126 KB

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