material_list.js 102 KB

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