material_list.js 124 KB

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