material_list.js 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068
  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. ledgerSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  444. }
  445. }
  446. function updateBillsData(ms_id) {
  447. const msbList = _.filter(materialStageBillsData, { ms_id });
  448. for (const mb of materialBillsData) {
  449. mb.ms_id = ms_id;
  450. const msbInfo = _.find(msbList, { mb_id: mb.id });
  451. for (const nu of needUpdateArray) {
  452. mb[nu] = msbInfo[nu];
  453. }
  454. }
  455. }
  456. setListsData(isStageSelf ? materialStageData[0].sid : null, isStageSelf ? materialStageData[0].id : null);
  457. // 期切换
  458. $('#myTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  459. e.preventDefault();
  460. const ms_id = $('#myTab').find('.active').data('msid');
  461. const msInfo = _.find(materialStageData, { id: ms_id });
  462. showWaitingView();
  463. setTimeout(function () {
  464. setListsData(msInfo.sid, ms_id);
  465. closeWaitingView();
  466. }, 500);
  467. });
  468. // const leafXmjCol = {
  469. // getValue: {
  470. // jiacha: function (data) {
  471. // let sum = 0;
  472. // const sheet = leafXmjSpread.getActiveSheet();
  473. // const select = SpreadJsObj.getSelectObject(sheet);
  474. // const notx = findNotJoinLeafXmj(select);
  475. // if (notx === undefined) {
  476. // for(const ml of materialList) {
  477. // sum = ZhCalc.round(ZhCalc.add(sum, ZhCalc.mul(ZhCalc.mul(data.gather_qty, ml.quantity), getMpSpreadByMBData(ml.mb_id))), 2);
  478. // }
  479. // }
  480. // return sum !== 0 ? sum : null;
  481. // }
  482. // }
  483. // };
  484. // SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  485. // 调差清单工料table
  486. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  487. const materialSpreadSetting = {
  488. cols: [
  489. {title: '清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  490. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  491. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  492. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  493. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  494. ],
  495. emptyRows: 0,
  496. headRows: 2,
  497. headRowHeight: [25, 25],
  498. defaultRowHeight: 21,
  499. headerFont: '12px 微软雅黑',
  500. font: '12px 微软雅黑',
  501. };
  502. const materialBase = {
  503. isEdit: function (data, type = 'normal') {
  504. // 是否本期添加的工料
  505. // return data.order === stage_order && !openMaterialChecklist;
  506. let flag = true;
  507. if (type === 'del' || !editListPermission) {
  508. flag = data.order === stage_order;
  509. }
  510. return flag && !openMaterialChecklist;
  511. }
  512. };
  513. const materialCol = {
  514. readOnly: {
  515. isEdit: function (data) {
  516. // const sheet = leafXmjSpread.getActiveSheet();
  517. // const select = SpreadJsObj.getSelectObject(sheet);
  518. // const notx = findNotJoinLeafXmj(select);
  519. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  520. return !(!readOnly && materialBase.isEdit(data));
  521. },
  522. },
  523. };
  524. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  525. // 获取项目节数据
  526. let materialList = [];
  527. function loadMaterialData(iGclRow) {
  528. const gcl = gclGatherData[iGclRow];
  529. if (gcl && gcl.leafXmjs) {
  530. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  531. materialList = [];
  532. const newMaterialList = _.uniqBy(_.filter(gclList, function (m) {
  533. return _.indexOf(gcl_ids, m.gcl_id) !== -1;
  534. }), 'mb_id');
  535. for(const m of newMaterialList) {
  536. const bills = _.find(materialBillsData, { id: m.mb_id });
  537. if(bills) {
  538. m.code = bills.code;
  539. m.name = bills.name;
  540. m.unit = bills.unit;
  541. }
  542. }
  543. console.log(newMaterialList);
  544. materialList = newMaterialList;
  545. // 对清单调差工料table的单位数量进行改变
  546. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  547. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  548. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialList);
  549. } else {
  550. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '数量 �';
  551. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  552. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  553. }
  554. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  555. }
  556. // 调差清单工料table
  557. const materialSelfSpread = SpreadJsObj.createNewSpread($('#material-self-spread')[0]);
  558. const materialSelfSpreadSetting = {
  559. cols: [
  560. {title: '明细清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  561. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  562. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  563. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  564. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  565. ],
  566. emptyRows: 0,
  567. headRows: 2,
  568. headRowHeight: [25, 25],
  569. defaultRowHeight: 21,
  570. headerFont: '12px 微软雅黑',
  571. font: '12px 微软雅黑',
  572. };
  573. const materialSelfBase = {
  574. isEdit: function (data, type = 'normal') {
  575. // 是否本期添加的工料
  576. // return data.order === stage_order && !openMaterialChecklist;
  577. let flag = true;
  578. if (type === 'del') {
  579. flag = data.order === stage_order;
  580. }
  581. return flag;
  582. }
  583. };
  584. const materialSelfCol = {
  585. readOnly: {
  586. isEdit: function (data) {
  587. // const sheet = leafXmjSpread.getActiveSheet();
  588. // const select = SpreadJsObj.getSelectObject(sheet);
  589. // const notx = findNotJoinLeafXmj(select);
  590. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  591. return openMaterialSelf && !(!readOnly && materialSelfBase.isEdit(data));
  592. },
  593. },
  594. };
  595. SpreadJsObj.initSpreadSettingEvents(materialSelfSpreadSetting, materialSelfCol);
  596. let materialListSelf = [];
  597. function loadXmjMaterialData(iGclRow, iLXmjRow) {
  598. // 存在单独设置的才展示,不然隐藏
  599. const gcl = gclGatherData[iGclRow];
  600. const leafXmjs = gcl && gcl.leafXmjs ? gcl.leafXmjs.filter(item => {
  601. return item.qc_qty || item.contract_qty
  602. }) : null;
  603. if (leafXmjs) {
  604. const xmj = leafXmjs[iLXmjRow];
  605. console.log(xmj, iLXmjRow);
  606. materialListSelf = [];
  607. if (_.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: (xmj.mx_id ? xmj.mx_id : '') }) != -1) {
  608. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  609. for (const m of materialListData) {
  610. 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)) {
  611. materialListSelf.push(m);
  612. }
  613. }
  614. $('#material-self-spread-div').addClass('active');
  615. showSelfSideTools(true);
  616. } else {
  617. $('#material-self-spread-div').removeClass('active');
  618. showSelfSideTools(false);
  619. }
  620. // 对清单调差工料table的单位数量进行改变
  621. materialSelfSpreadSetting.cols[materialSelfSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  622. SpreadJsObj.initSheet(materialSelfSpread.getActiveSheet(), materialSelfSpreadSetting);
  623. SpreadJsObj.loadSheetData(materialSelfSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialListSelf);
  624. } else {
  625. $('#material-self-spread-div').removeClass('active');
  626. showSelfSideTools(false);
  627. materialSpreadSetting.cols[materialSelfSpreadSetting.cols.length - 2].title = '数量 �';
  628. SpreadJsObj.initSheet(materialSelfSpread.getActiveSheet(), materialSelfSpreadSetting);
  629. SpreadJsObj.loadSheetData(materialSelfSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  630. }
  631. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  632. leafXmjSpread.refresh();
  633. materialSelfSpread.refresh();
  634. }
  635. // SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), )
  636. // loadLeafXmjData(0);
  637. // loadMaterialData(0, 0);
  638. // const sheet = materialSpread.getActiveSheet();
  639. // sheet.suspendPaint();
  640. // sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  641. // sheet.resumePaint();
  642. // 不参与调差数据值变灰
  643. function checkNotJoinMaterialData() {
  644. const sheet = ledgerSpread.getActiveSheet();
  645. const select = SpreadJsObj.getSelectObject(sheet);
  646. const index = gclGatherData.indexOf(select);
  647. if (index !== -1) {
  648. const xmj = gclGatherData[index].leafXmjs.filter(item => {
  649. return item.qc_qty || item.contract_qty
  650. });
  651. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  652. for (const [iRow,x] of xmj.entries()) {
  653. const notx = findNotJoinLeafXmj(x);
  654. const color = notx === undefined ? '' : '#d6d8db';
  655. leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
  656. }
  657. }
  658. }
  659. // checkNotJoinMaterialData();
  660. // 对添加工料表格赋值
  661. function changeMaterialTable(from = 'all') {
  662. $('#materialBills tr').removeClass('table-secondary');
  663. $('#materialBills').find('input').removeAttr('disabled');
  664. $('#materialBills').find('input').prop('checked', false);
  665. const searchList = from === 'self' ? materialListSelf : materialList;
  666. console.log(searchList);
  667. for (const [index, ml] of searchList.entries()) {
  668. const mbIndex = materialBillsData.findIndex(function (item) {
  669. return item.id === ml.mb_id;
  670. });
  671. if (mbIndex !== -1) {
  672. $('#materialBills tr').eq(mbIndex).addClass('table-secondary');
  673. $('#materialBills').find('input').eq(mbIndex).attr('disabled', true);
  674. $('#materialBills').find('input').eq(mbIndex).prop('checked', true);
  675. }
  676. }
  677. }
  678. // 添加调差工料
  679. $('#add_material_bill').click(function () {
  680. // 获取已选工料
  681. $('#materialBills').find('input:disabled').prop('checked', false);
  682. const selectList = $('#materialBills').find('input:checked');
  683. if (selectList.length === 0) {
  684. toastr.warning('请选择调差工料');
  685. $('#materialBills').find('input:disabled').prop('checked', true);
  686. return false;
  687. }
  688. const mb_id = [];
  689. for (let s = 0; s < selectList.length; s++) {
  690. mb_id.push($('#materialBills').find('input:checked').eq(s).val());
  691. }
  692. const type = $('#add_type').val();
  693. if (type === 'all') {
  694. // 获取当前项目节或部位明细id
  695. const sheet = ledgerSpread.getActiveSheet();
  696. const select = SpreadJsObj.getSelectObject(sheet);
  697. const index = gclGatherData.indexOf(select);
  698. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  699. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  700. const datas = [];
  701. for (const xmj of gcl) {
  702. const notx = findNotJoinLeafXmj(xmj);
  703. const data = {
  704. xmj_id: xmj.id,
  705. gcl_id: xmj.gcl_id,
  706. mx_id: xmj.mx_id ? xmj.mx_id : '',
  707. gather_qty: xmj.gather_qty,
  708. is_join: notx === undefined ? 1 : 0,
  709. };
  710. if (ms_id) data.ms_id = ms_id;
  711. datas.push(data);
  712. }
  713. if (isStageSelf) {
  714. // 取所有的gclGatherData才行,然后获取下的值
  715. const gclData = gclGatherData[index];
  716. for (const [index, ms] of materialStageData.entries()) {
  717. if (ms.id !== ms_id) {
  718. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  719. if (gclOther) {
  720. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  721. for (const xmj of leafXmjs) {
  722. const notx = findNotJoinLeafXmj(xmj);
  723. const data = {
  724. xmj_id: xmj.id,
  725. gcl_id: xmj.gcl_id,
  726. mx_id: xmj.mx_id ? xmj.mx_id : '',
  727. gather_qty: xmj.gather_qty,
  728. is_join: notx === undefined ? 1 : 0,
  729. ms_id: ms.id,
  730. };
  731. datas.push(data);
  732. }
  733. }
  734. }
  735. }
  736. }
  737. console.log(datas, gcl, mb_id);
  738. postData(window.location.pathname + '/save', {type: 'adds', postData: {xmjs: datas, mbIds: mb_id} }, function (result) {
  739. materialListData = result.materialListData;
  740. gclList = result.gclList;
  741. // toastr.success('已成功应用');
  742. calculateJiaCha(gclGatherData);
  743. // const index = gclGatherData.indexOf(ledgerSelect);
  744. loadLeafXmjData(index);
  745. // const xmjSheet = leafXmjSpread.getActiveSheet();
  746. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  747. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  748. loadMaterialData(index);
  749. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  750. $('#addgl').modal('hide');
  751. });
  752. } else if (type === 'self') {
  753. // 获取当前项目节或部位明细id
  754. const sheet = ledgerSpread.getActiveSheet();
  755. const select = SpreadJsObj.getSelectObject(sheet);
  756. const index = gclGatherData.indexOf(select);
  757. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  758. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  759. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  760. const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  761. const xmj = gcl[leafXmjIndex];
  762. const notx = findNotJoinLeafXmj(xmj);
  763. const data = {
  764. xmj_id: xmj.id,
  765. gcl_id: xmj.gcl_id,
  766. mx_id: xmj.mx_id ? xmj.mx_id : '',
  767. mb_id: mb_id,
  768. gather_qty: xmj.gather_qty,
  769. is_join: notx === undefined ? 1 : 0,
  770. };
  771. console.log(data);
  772. postData(window.location.pathname + '/save', {type: 'add', postData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  773. // 添加到materialList里
  774. materialListData = result;
  775. loadXmjMaterialData(index, leafXmjIndex);
  776. $('#addgl').modal('hide');
  777. });
  778. }
  779. $('#materialBills').find('input:disabled').prop('checked', true);
  780. });
  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. if (type === 'noself') {
  829. if (isStageSelf) {
  830. // 取所有的gclGatherData才行,然后获取下的值
  831. const gclData = gclGatherData[index];
  832. for (const [index, ms] of materialStageData.entries()) {
  833. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  834. let gather_qty = null;
  835. if (gclOther) {
  836. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  837. const oneXmj = _.find(leafXmjs, function (item) {
  838. return item.gcl_id === select.gcl_id && item.id === select.id && (select.mx_id === undefined || item.mx_id === select.mx_id);
  839. });
  840. if (oneXmj) gather_qty = oneXmj.gather_qty;
  841. }
  842. data.select.gather_qty[ms.id] = gather_qty;
  843. }
  844. } else {
  845. data.select.gather_qty = select.gather_qty ? select.gather_qty : null;
  846. }
  847. }
  848. // 添加到
  849. postData(window.location.pathname + '/save', data, function (result) {
  850. if (type === 'noself') {
  851. const index = findSelfLeafXmj(select, 'index');
  852. selfList.splice(index, 1);
  853. materialListData = result;
  854. $('#cancel-self').modal('hide');
  855. } else {
  856. selfList.push(result);
  857. }
  858. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  859. calculateJiaCha(gclGatherData, iGclRow);
  860. SpreadJsObj.reLoadRowData(sheet, nRow);
  861. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  862. loadXmjMaterialData(iGclRow, nRow);
  863. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  864. });
  865. },
  866. }
  867. if (!readOnly) {
  868. // leafXmj右键功能
  869. if (!editForAudit) {
  870. $.contextMenu({
  871. selector: '#leaf-xmj-spread',
  872. build: function ($trigger, e) {
  873. const target = SpreadJsObj.safeRightClickSelection($trigger, e, leafXmjSpread);
  874. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  875. },
  876. items: {
  877. 'stop': {
  878. name: '不参与调差',
  879. icon: 'fa-remove',
  880. callback: function (key, opt) {
  881. leafXmjSpreadObj.checkJoinMaterial('notjoin');
  882. },
  883. visible: function (key, opt) {
  884. const sheet = leafXmjSpread.getActiveSheet();
  885. const select = SpreadJsObj.getSelectObject(sheet);
  886. const sel = sheet.getSelections()[0];
  887. if (!select || sel.rowCount !== 1) {
  888. return false;
  889. }
  890. const notx = findNotJoinLeafXmj(select);
  891. if (!readOnly && select && notx === undefined) {
  892. return true;
  893. } else {
  894. return false;
  895. }
  896. }
  897. },
  898. 'start': {
  899. name: '参与调差',
  900. icon: 'fa-sign-in',
  901. callback: function (key, opt) {
  902. leafXmjSpreadObj.checkJoinMaterial('join');
  903. },
  904. visible: function (key, opt) {
  905. const sheet = leafXmjSpread.getActiveSheet();
  906. const select = SpreadJsObj.getSelectObject(sheet);
  907. const sel = sheet.getSelections()[0];
  908. if (!select || sel.rowCount !== 1) {
  909. return false;
  910. }
  911. const notx = findNotJoinLeafXmj(select);
  912. if (!readOnly && select && notx === undefined) {
  913. return false;
  914. } else {
  915. return true;
  916. }
  917. },
  918. },
  919. 'self': {
  920. name: '单独添加工料',
  921. icon: 'fa-sign-in',
  922. callback: function (key, opt) {
  923. leafXmjSpreadObj.checkSelfMaterial('self');
  924. },
  925. visible: function (key, opt) {
  926. if (!openMaterialSelf) {
  927. return false;
  928. }
  929. const sheet = leafXmjSpread.getActiveSheet();
  930. const select = SpreadJsObj.getSelectObject(sheet);
  931. const sel = sheet.getSelections()[0];
  932. if (!select || sel.rowCount !== 1) {
  933. return false;
  934. }
  935. const notx = findSelfLeafXmj(select);
  936. if (!readOnly && select && notx === undefined) {
  937. return true;
  938. } else {
  939. return false;
  940. }
  941. }
  942. },
  943. 'noself': {
  944. name: '取消单独添加工料',
  945. icon: 'fa-remove',
  946. callback: function (key, opt) {
  947. $('#cancel-self').modal('show');
  948. // leafXmjSpreadObj.checkSelfMaterial('noself');
  949. },
  950. visible: function (key, opt) {
  951. if (!openMaterialSelf) {
  952. return false;
  953. }
  954. const sheet = leafXmjSpread.getActiveSheet();
  955. const select = SpreadJsObj.getSelectObject(sheet);
  956. const sel = sheet.getSelections()[0];
  957. if (!select || sel.rowCount !== 1) {
  958. return false;
  959. }
  960. const notx = findSelfLeafXmj(select);
  961. if (!readOnly && select && notx === undefined) {
  962. return false;
  963. } else {
  964. return true;
  965. }
  966. },
  967. },
  968. }
  969. });
  970. $('#cancelSelfBtn').click(function () {
  971. leafXmjSpreadObj.checkSelfMaterial('noself');
  972. });
  973. }
  974. // material-spread右键功能
  975. const materialSpreadObj = {
  976. del: function () {
  977. const materialSheet = materialSpread.getActiveSheet();
  978. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  979. const sheet = ledgerSpread.getActiveSheet();
  980. const select = SpreadJsObj.getSelectObject(sheet);
  981. const index = gclGatherData.indexOf(select);
  982. // const leafXmjSheet = leafXmjSpread.getActiveSheet();
  983. // const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  984. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  985. // const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  986. const datas = [];
  987. for (const xmj of gcl) {
  988. const data = {
  989. xmj_id: xmj.id,
  990. gcl_id: xmj.gcl_id,
  991. mx_id: xmj.mx_id ? xmj.mx_id : '',
  992. };
  993. datas.push(data);
  994. }
  995. if (isStageSelf) {
  996. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  997. // 取所有的gclGatherData才行,然后获取下的值
  998. const gclData = gclGatherData[index];
  999. for (const [index, ms] of materialStageData.entries()) {
  1000. if (ms.id !== ms_id) {
  1001. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1002. if (gclOther) {
  1003. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1004. for (const xmj of leafXmjs) {
  1005. const data = {
  1006. xmj_id: xmj.id,
  1007. gcl_id: xmj.gcl_id,
  1008. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1009. };
  1010. if (_.indexOf(datas, data) === -1) {
  1011. datas.push(data);
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. }
  1018. console.log(datas, materialSelect.mb_id);
  1019. 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) {
  1020. materialListData = result.materialListData;
  1021. gclList = result.gclList;
  1022. calculateJiaCha(gclGatherData);
  1023. // const index = gclGatherData.indexOf(ledgerSelect);
  1024. loadLeafXmjData(index);
  1025. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1026. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1027. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1028. loadMaterialData(index);
  1029. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1030. });
  1031. // postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  1032. // const index = materialList.indexOf(select);
  1033. // materialList.splice(index, 1);
  1034. // sheet.deleteRows(index, 1);
  1035. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1036. // const sel = sheet.getSelections();
  1037. // sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1038. // const materialListIndex = materialListData.indexOf(select);
  1039. // materialListData.splice(materialListIndex, 1);
  1040. // const [iGclRow, iRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  1041. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1042. // calculateJiaCha(gclGatherData, iGclRow);
  1043. // SpreadJsObj.reLoadRowData(lsheet, iRow);
  1044. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1045. // });
  1046. },
  1047. deletePress: function (sheet) {
  1048. return;
  1049. },
  1050. editStarting: function (e, info) {
  1051. const col = info.sheet.zh_setting.cols[info.col];
  1052. const select = SpreadJsObj.getSelectObject(info.sheet);
  1053. if (col.field === 'quantity') {
  1054. if (select.expr && select.expr !== '') {
  1055. info.sheet.getCell(info.row, info.col).text(select.expr);
  1056. }
  1057. }
  1058. },
  1059. editEnded: function (e, info) {
  1060. if (info.sheet.zh_setting) {
  1061. const select = SpreadJsObj.getSelectObject(info.sheet);
  1062. const col = info.sheet.zh_setting.cols[info.col];
  1063. // 未改变值则不提交
  1064. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1065. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1066. // let orgValue = select[col.field];
  1067. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1068. let orgValue;
  1069. if (col.field === 'quantity') {
  1070. orgValue = validText && validText !== ''
  1071. ? _.toNumber(validText) ? select.quantity : select.expr
  1072. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1073. } else {
  1074. orgValue = select[col.field];
  1075. }
  1076. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1077. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1078. return;
  1079. }
  1080. const exprQuantity = {
  1081. expr: '',
  1082. quantity: 0,
  1083. };
  1084. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1085. if (!valid) {
  1086. toastr.error(msg);
  1087. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1088. return;
  1089. }
  1090. if (isNaN(exprQuantity.quantity)) {
  1091. toastr.error('不能输入其它非数字类型字符');
  1092. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1093. return;
  1094. }
  1095. const num = parseFloat(exprQuantity.quantity);
  1096. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1097. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1098. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1099. // return;
  1100. toastr.warning('已保留6位小数');
  1101. exprQuantity.quantity = ZhCalc.round(num, 6);
  1102. }
  1103. // 更新至服务器
  1104. const ledgerSheet = ledgerSpread.getActiveSheet();
  1105. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1106. const index = gclGatherData.indexOf(ledgerSelect);
  1107. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1108. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1109. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1110. // const xmjIndex = gcl.indexOf(xmjSelect);
  1111. const datas = [];
  1112. for (const xmj of gcl) {
  1113. const data = {
  1114. xmj_id: xmj.id,
  1115. gcl_id: xmj.gcl_id,
  1116. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1117. };
  1118. datas.push(data);
  1119. }
  1120. if (isStageSelf) {
  1121. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1122. // 取所有的gclGatherData才行,然后获取下的值
  1123. const gclData = gclGatherData[index];
  1124. for (const [index, ms] of materialStageData.entries()) {
  1125. if (ms.id !== ms_id) {
  1126. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1127. if (gclOther) {
  1128. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1129. for (const xmj of leafXmjs) {
  1130. const data = {
  1131. xmj_id: xmj.id,
  1132. gcl_id: xmj.gcl_id,
  1133. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1134. };
  1135. if (_.indexOf(datas, data) === -1) {
  1136. datas.push(data);
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. }
  1143. console.log(exprQuantity, datas, select.mb_id);
  1144. 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) {
  1145. materialListData = result.materialListData;
  1146. gclList = result.gclList;
  1147. calculateJiaCha(gclGatherData);
  1148. // const index = gclGatherData.indexOf(ledgerSelect);
  1149. loadLeafXmjData(index);
  1150. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1151. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1152. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1153. loadMaterialData(index);
  1154. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1155. materialSpread.getActiveSheet().setSelection(info.row + 1, info.col, 1, 1);
  1156. }, function () {
  1157. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1158. });
  1159. // postData(window.location.pathname + '/save', { type:'update', updateData: { id:select.id, quantity: validText, mb_id: select.mb_id } }, function (result) {
  1160. // const materialListIndex = materialListData.indexOf(select);
  1161. // const index = materialList.indexOf(select);
  1162. // select[col.field] = validText;
  1163. // materialListData.splice(materialListIndex, 1, select);
  1164. // materialList.indexOf(index, 1, select);
  1165. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1166. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1167. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1168. // calculateJiaCha(gclGatherData, iGclRow)
  1169. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1170. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1171. // }, function () {
  1172. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1173. // });
  1174. }
  1175. },
  1176. clipboardPasted(e, info) {
  1177. const hint = {
  1178. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1179. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1180. numberCan: {type: 'warning', msg: '已保留6位小数'},
  1181. };
  1182. const range = info.cellRange;
  1183. const sortData = info.sheet.zh_data || [];
  1184. if (range.row + range.rowCount > sortData.length) {
  1185. toastMessageUniq(hint.cellError);
  1186. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1187. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1188. return;
  1189. }
  1190. if (sortData.length > 0 && range.col + range.colCount > 5) {
  1191. toastMessageUniq(hint.cellError);
  1192. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1193. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1194. return;
  1195. }
  1196. const data = [];
  1197. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1198. let bPaste = true;
  1199. const curRow = range.row + iRow;
  1200. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  1201. const hintRow = range.rowCount > 1 ? curRow : '';
  1202. let sameCol = 0;
  1203. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1204. const curCol = range.col + iCol;
  1205. const colSetting = info.sheet.zh_setting.cols[curCol];
  1206. if (!colSetting) continue;
  1207. // let validText = info.sheet.getText(curRow, curCol);
  1208. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1209. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1210. const orgValue = sortData[curRow][colSetting.field];
  1211. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1212. sameCol++;
  1213. if (range.colCount === sameCol) {
  1214. bPaste = false;
  1215. }
  1216. continue;
  1217. }
  1218. const exprQuantity = {
  1219. expr: '',
  1220. quantity: 0,
  1221. };
  1222. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1223. if (!valid) {
  1224. toastMessageUniq(getPasteHint(msg, hintRow));
  1225. bPaste = false;
  1226. continue;
  1227. }
  1228. if (isNaN(exprQuantity.quantity)) {
  1229. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1230. bPaste = false;
  1231. continue;
  1232. }
  1233. const num = parseFloat(exprQuantity.quantity);
  1234. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1235. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1236. // bPaste = false;
  1237. // continue;
  1238. exprQuantity.quantity = ZhCalc.round(num, 6);
  1239. }
  1240. // materialData[colSetting.field] = validText;
  1241. materialData.expr = exprQuantity.expr;
  1242. materialData.quantity = exprQuantity.quantity;
  1243. }
  1244. if (bPaste) {
  1245. data.push(materialData);
  1246. // rowData.push(curRow);
  1247. } else {
  1248. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1249. }
  1250. }
  1251. if (data.length === 0) {
  1252. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1253. return;
  1254. }
  1255. const ledgerSheet = ledgerSpread.getActiveSheet();
  1256. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1257. const index = gclGatherData.indexOf(ledgerSelect);
  1258. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1259. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1260. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1261. // const xmjIndex = gcl.indexOf(xmjSelect);
  1262. const datas = [];
  1263. for (const xmj of gcl) {
  1264. const data2 = {
  1265. xmj_id: xmj.id,
  1266. gcl_id: xmj.gcl_id,
  1267. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1268. };
  1269. datas.push(data2);
  1270. }
  1271. if (isStageSelf) {
  1272. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1273. // 取所有的gclGatherData才行,然后获取下的值
  1274. const gclData = gclGatherData[index];
  1275. for (const [index, ms] of materialStageData.entries()) {
  1276. if (ms.id !== ms_id) {
  1277. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1278. console.log(gclOther);
  1279. if (gclOther) {
  1280. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1281. for (const xmj of leafXmjs) {
  1282. const data = {
  1283. xmj_id: xmj.id,
  1284. gcl_id: xmj.gcl_id,
  1285. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1286. };
  1287. if (_.indexOf(datas, data) === -1) {
  1288. datas.push(data);
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. console.log(data, datas);
  1296. // 更新至服务器
  1297. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data }, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1298. materialListData = result.materialListData;
  1299. gclList = result.gclList;
  1300. calculateJiaCha(gclGatherData);
  1301. // const index = gclGatherData.indexOf(ledgerSelect);
  1302. loadLeafXmjData(index);
  1303. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1304. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1305. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1306. loadMaterialData(index);
  1307. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1308. materialSpread.getActiveSheet().setSelection(info.cellRange.row, info.cellRange.col, info.cellRange.rowCount, info.cellRange.colCount);
  1309. }, function () {
  1310. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1311. });
  1312. // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1313. // materialListData = result;
  1314. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1315. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1316. // calculateJiaCha(gclGatherData, iGclRow);
  1317. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1318. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1319. // }, function () {
  1320. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1321. // });
  1322. },
  1323. _checkExprValid(expr) {
  1324. if (!expr) return [true, null];
  1325. const param = [];
  1326. let num = '', base = '';
  1327. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1328. if (/^[\d\.%]+/.test(expr[i])) {
  1329. if (base !== '') {
  1330. param.push({type: 'base', value: base});
  1331. base = '';
  1332. }
  1333. num = num + expr[i];
  1334. } else if (expr[i] === '(') {
  1335. if (num !== '') {
  1336. param.push({type: 'num', value: num});
  1337. num = '';
  1338. }
  1339. if (base !== '') {
  1340. param.push({type: 'base', value: base});
  1341. base = '';
  1342. }
  1343. param.push({type: 'left', value: '('});
  1344. } else if (expr[i] === ')') {
  1345. if (num !== '') {
  1346. param.push({type: 'num', value: num});
  1347. num = '';
  1348. }
  1349. if (base !== '') {
  1350. param.push({type: 'base', value: base});
  1351. base = '';
  1352. }
  1353. param.push({type: 'right', value: ')'});
  1354. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1355. if (num !== '') {
  1356. param.push({type: 'num', value: num});
  1357. num = '';
  1358. }
  1359. if (base !== '') {
  1360. param.push({type: 'base', value: base});
  1361. base = '';
  1362. }
  1363. param.push({type: 'calc', value: expr[i]});
  1364. } else {
  1365. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1366. }
  1367. }
  1368. if (num !== '') {
  1369. param.push({type: 'num', value: num});
  1370. num = '';
  1371. }
  1372. if (base !== '') {
  1373. param.push({type: 'base', value: base});
  1374. base = '';
  1375. }
  1376. if (param.length === 0) return true;
  1377. if (param.length > 1) {
  1378. if (param[0].value === '-') {
  1379. param[1].value = '-' + param[1];
  1380. }
  1381. param.unshift();
  1382. }
  1383. const iLen = param.length;
  1384. let iLeftCount = 0, iRightCount = 0;
  1385. for (const [i, p] of param.entries()) {
  1386. if (p.type === 'calc') {
  1387. if (i === 0 || i === iLen - 1)
  1388. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1389. }
  1390. if (p.type === 'num') {
  1391. num = p.value.replace('%', '');
  1392. if (p.value.length - num.length > 1)
  1393. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1394. num = _.toNumber(num);
  1395. if (num === undefined || num === null || _.isNaN(num))
  1396. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1397. if (i > 0) {
  1398. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1399. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1400. } else if (param[i - 1].value === '/' && num === 0) {
  1401. return [false, '输入的表达式非法:请勿除0'];
  1402. }
  1403. }
  1404. }
  1405. if (p.type === 'base') {
  1406. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1407. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1408. }
  1409. if (p.type === 'left') {
  1410. iLeftCount += 1;
  1411. if (i !== 0 && param[i-1].type !== 'calc')
  1412. return [false, '输入的表达式非法:(前应有运算符'];
  1413. }
  1414. if (p.type === 'right') {
  1415. iRightCount += 1;
  1416. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1417. return [false, '输入的表达式非法:)后应有运算符'];
  1418. if (iRightCount > iLeftCount)
  1419. return [false, '输入的表达式非法:")"前无对应的"("'];
  1420. }
  1421. }
  1422. if (iLeftCount > iRightCount)
  1423. return [false, '输入的表达式非法:"("后无对应的")"'];
  1424. return [true, ''];
  1425. },
  1426. _checkExpr: function (text, data) {
  1427. if (text) {
  1428. const num = _.toNumber(text);
  1429. if (num) {
  1430. data.quantity = num;
  1431. data.expr = '';
  1432. } else {
  1433. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  1434. const [valid, msg] = this._checkExprValid(expr);
  1435. if (!valid) return [valid, msg];
  1436. data.expr = expr;
  1437. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr);
  1438. // const ce = new CalcEvalMin();
  1439. // data.quantity = ce.eval(expr);
  1440. // console.log(data.quantity);
  1441. }
  1442. } else {
  1443. data.quantity = 0;
  1444. data.expr = '';
  1445. }
  1446. return [true, ''];
  1447. },
  1448. };
  1449. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  1450. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  1451. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  1452. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  1453. // material-spread右键功能
  1454. if (openMaterialSelf) {
  1455. const materialSelfSpreadObj = {
  1456. del: function () {
  1457. const sheet = materialSelfSpread.getActiveSheet();
  1458. const select = SpreadJsObj.getSelectObject(sheet);
  1459. console.log(select);
  1460. postData(window.location.pathname + '/save', {
  1461. type: 'del',
  1462. id: select.id,
  1463. mb_id: select.mb_id,
  1464. ms_id: $('#myTab').find('.active').data('msid') || null
  1465. }, function (result) {
  1466. const index = materialListSelf.indexOf(select);
  1467. materialListSelf.splice(index, 1);
  1468. sheet.deleteRows(index, 1);
  1469. SpreadJsObj.reLoadSheetData(materialSelfSpread.getActiveSheet());
  1470. const sel = sheet.getSelections();
  1471. sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1472. const materialListIndex = materialListData.indexOf(select);
  1473. materialListData.splice(materialListIndex, 1);
  1474. const [iGclRow, iRow, nRow, lsheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1475. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1476. calculateJiaCha(gclGatherData, iGclRow);
  1477. SpreadJsObj.reLoadRowData(lsheet, nRow);
  1478. lsheet.getRange(nRow, -1, 1, -1).backColor(color);
  1479. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1480. });
  1481. },
  1482. deletePress: function (sheet) {
  1483. return;
  1484. },
  1485. editStarting: function (e, info) {
  1486. const col = info.sheet.zh_setting.cols[info.col];
  1487. const select = SpreadJsObj.getSelectObject(info.sheet);
  1488. if (col.field === 'quantity') {
  1489. if (select.expr && select.expr !== '') {
  1490. info.sheet.getCell(info.row, info.col).text(select.expr);
  1491. }
  1492. }
  1493. },
  1494. editEnded: function (e, info) {
  1495. if (info.sheet.zh_setting) {
  1496. const select = SpreadJsObj.getSelectObject(info.sheet);
  1497. const col = info.sheet.zh_setting.cols[info.col];
  1498. // 未改变值则不提交
  1499. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1500. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1501. // let orgValue = select[col.field];
  1502. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1503. let orgValue;
  1504. if (col.field === 'quantity') {
  1505. orgValue = validText && validText !== ''
  1506. ? _.toNumber(validText) ? select.quantity : select.expr
  1507. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1508. } else {
  1509. orgValue = select[col.field];
  1510. }
  1511. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1512. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1513. return;
  1514. }
  1515. const exprQuantity = {
  1516. expr: '',
  1517. quantity: 0,
  1518. };
  1519. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1520. if (!valid) {
  1521. toastr.error(msg);
  1522. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1523. return;
  1524. }
  1525. if (isNaN(exprQuantity.quantity)) {
  1526. toastr.error('不能输入其它非数字类型字符');
  1527. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1528. return;
  1529. }
  1530. const num = parseFloat(exprQuantity.quantity);
  1531. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1532. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1533. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1534. // return;
  1535. toastr.warning('已保留6位小数');
  1536. exprQuantity.quantity = ZhCalc.round(num, 6);
  1537. }
  1538. // 更新至服务器
  1539. console.log(exprQuantity, select.mb_id);
  1540. postData(window.location.pathname + '/save', {
  1541. type: 'update',
  1542. updateData: {
  1543. id: select.id,
  1544. expr: exprQuantity.expr,
  1545. quantity: exprQuantity.quantity,
  1546. mb_id: select.mb_id
  1547. },
  1548. ms_id: $('#myTab').find('.active').data('msid') || null
  1549. }, function (result) {
  1550. const materialListIndex = materialListData.indexOf(select);
  1551. const index = materialList.indexOf(select);
  1552. select.quantity = exprQuantity.quantity;
  1553. select.expr = exprQuantity.expr;
  1554. materialListData.splice(materialListIndex, 1, select);
  1555. materialList.indexOf(index, 1, select);
  1556. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1557. const [iGclRow, iRow, nRow, sheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1558. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1559. calculateJiaCha(gclGatherData, iGclRow);
  1560. SpreadJsObj.reLoadRowData(sheet, nRow);
  1561. console.log(lselect, color);
  1562. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  1563. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1564. }, function () {
  1565. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1566. });
  1567. }
  1568. },
  1569. clipboardPasted(e, info) {
  1570. const hint = {
  1571. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1572. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1573. numberCan: {type: 'warning', msg: '已保留6位小数'},
  1574. };
  1575. const range = info.cellRange;
  1576. const sortData = info.sheet.zh_data || [];
  1577. if (range.row + range.rowCount > sortData.length) {
  1578. toastMessageUniq(hint.cellError);
  1579. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1580. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1581. return;
  1582. }
  1583. if (sortData.length > 0 && range.col + range.colCount > 5) {
  1584. toastMessageUniq(hint.cellError);
  1585. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1586. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1587. return;
  1588. }
  1589. const data = [];
  1590. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1591. let bPaste = true;
  1592. const curRow = range.row + iRow;
  1593. const materialData = {id: sortData[curRow].id, mb_id: sortData[curRow].mb_id};
  1594. const hintRow = range.rowCount > 1 ? curRow : '';
  1595. let sameCol = 0;
  1596. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1597. const curCol = range.col + iCol;
  1598. const colSetting = info.sheet.zh_setting.cols[curCol];
  1599. if (!colSetting) continue;
  1600. // let validText = info.sheet.getText(curRow, curCol);
  1601. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1602. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1603. const orgValue = sortData[curRow][colSetting.field];
  1604. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1605. sameCol++;
  1606. if (range.colCount === sameCol) {
  1607. bPaste = false;
  1608. }
  1609. continue;
  1610. }
  1611. const exprQuantity = {
  1612. expr: '',
  1613. quantity: 0,
  1614. };
  1615. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1616. if (!valid) {
  1617. toastMessageUniq(getPasteHint(msg, hintRow));
  1618. bPaste = false;
  1619. continue;
  1620. }
  1621. if (isNaN(exprQuantity.quantity)) {
  1622. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1623. bPaste = false;
  1624. continue;
  1625. }
  1626. const num = parseFloat(exprQuantity.quantity);
  1627. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1628. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1629. // bPaste = false;
  1630. // continue;
  1631. exprQuantity.quantity = ZhCalc.round(num, 6);
  1632. }
  1633. // materialData[colSetting.field] = validText;
  1634. materialData.expr = exprQuantity.expr;
  1635. materialData.quantity = exprQuantity.quantity;
  1636. }
  1637. if (bPaste) {
  1638. data.push(materialData);
  1639. // rowData.push(curRow);
  1640. } else {
  1641. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1642. }
  1643. }
  1644. if (data.length === 0) {
  1645. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1646. return;
  1647. }
  1648. console.log(data);
  1649. postData(window.location.pathname + '/save', {
  1650. type: 'paste',
  1651. updateData: data,
  1652. ms_id: $('#myTab').find('.active').data('msid') || null
  1653. }, function (result) {
  1654. materialListData = result;
  1655. const [iGclRow, iRow, nRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1656. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1657. calculateJiaCha(gclGatherData, iGclRow);
  1658. SpreadJsObj.reLoadRowData(sheet, nRow);
  1659. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1660. loadXmjMaterialData(iGclRow, nRow);
  1661. }, function () {
  1662. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1663. });
  1664. },
  1665. };
  1666. materialSelfSpread.bind(spreadNS.Events.EditStarting, materialSelfSpreadObj.editStarting);
  1667. materialSelfSpread.bind(spreadNS.Events.EditEnded, materialSelfSpreadObj.editEnded);
  1668. materialSelfSpread.bind(spreadNS.Events.ClipboardPasted, materialSelfSpreadObj.clipboardPasted);
  1669. SpreadJsObj.addDeleteBind(materialSelfSpread, materialSelfSpreadObj.deletePress);
  1670. }
  1671. if (!openMaterialChecklist && !editForAudit) {
  1672. $.contextMenu({
  1673. selector: '#material-spread',
  1674. build: function ($trigger, e) {
  1675. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  1676. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1677. },
  1678. items: {
  1679. 'create': {
  1680. name: '添加工料',
  1681. icon: 'fa-sign-in',
  1682. callback: function (key, opt) {
  1683. // 获取已选清单
  1684. changeMaterialTable();
  1685. $('#add_type').val('all');
  1686. $('#addgl').modal('show');
  1687. },
  1688. disabled: function (key, opt) {
  1689. const sheet = leafXmjSpread.getActiveSheet();
  1690. const select = SpreadJsObj.getSelectObject(sheet);
  1691. // const notx = findNotJoinLeafXmj(select);
  1692. if (!select) {
  1693. return true;
  1694. }
  1695. // if (!readOnly && notx === undefined) {
  1696. // return false;
  1697. // } else {
  1698. // return true;
  1699. // }
  1700. return readOnly;
  1701. }
  1702. },
  1703. 'delete': {
  1704. name: '删除工料',
  1705. icon: 'fa-remove',
  1706. callback: function (key, opt) {
  1707. materialSpreadObj.del(materialSpread.getActiveSheet());
  1708. },
  1709. disabled: function (key, opt) {
  1710. const sheet = materialSpread.getActiveSheet();
  1711. const select = SpreadJsObj.getSelectObject(sheet);
  1712. if (!select) {
  1713. return true;
  1714. }
  1715. if (!readOnly && select && materialBase.isEdit(select, 'del')) {
  1716. return false;
  1717. } else {
  1718. return true;
  1719. }
  1720. }
  1721. },
  1722. }
  1723. });
  1724. }
  1725. if (openMaterialSelf && !editForAudit) {
  1726. $.contextMenu({
  1727. selector: '#material-self-spread',
  1728. build: function ($trigger, e) {
  1729. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSelfSpread);
  1730. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1731. },
  1732. items: {
  1733. 'create': {
  1734. name: '添加工料',
  1735. icon: 'fa-sign-in',
  1736. callback: function (key, opt) {
  1737. // 获取已选清单
  1738. changeMaterialTable('self');
  1739. $('#add_type').val('self');
  1740. $('#addgl').modal('show');
  1741. },
  1742. disabled: function (key, opt) {
  1743. const sheet = leafXmjSpread.getActiveSheet();
  1744. const select = SpreadJsObj.getSelectObject(sheet);
  1745. // const notx = findNotJoinLeafXmj(select);
  1746. if (!select) {
  1747. return true;
  1748. }
  1749. // if (!readOnly && notx === undefined) {
  1750. // return false;
  1751. // } else {
  1752. // return true;
  1753. // }
  1754. return readOnly;
  1755. },
  1756. },
  1757. 'delete': {
  1758. name: '删除工料',
  1759. icon: 'fa-remove',
  1760. callback: function (key, opt) {
  1761. materialSelfSpreadObj.del(materialSelfSpread.getActiveSheet());
  1762. },
  1763. disabled: function (key, opt) {
  1764. const sheet = materialSelfSpread.getActiveSheet();
  1765. const select = SpreadJsObj.getSelectObject(sheet);
  1766. if (!select) {
  1767. return true;
  1768. }
  1769. if (!readOnly && select) {
  1770. return false;
  1771. } else {
  1772. return true;
  1773. }
  1774. }
  1775. },
  1776. }
  1777. });
  1778. }
  1779. }
  1780. // 应用调差工料至其他清单明细
  1781. $('#user_all_material').click(function () {
  1782. const ledgerSheet = ledgerSpread.getActiveSheet();
  1783. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1784. if (ledgerSelect.leafXmjs.length < 2) {
  1785. toastr.warning('没有需要应用调差工料的其它清单明细');
  1786. return false;
  1787. }
  1788. const xmjSheet = leafXmjSpread.getActiveSheet();
  1789. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1790. console.log(ledgerSelect.leafXmjs);
  1791. // 判断需要应用调差工料的清单明细
  1792. const needAddList = [];
  1793. for (const xmj of ledgerSelect.leafXmjs) {
  1794. const notx = findNotJoinLeafXmj(xmj);
  1795. if (notx === undefined && xmjSelect !== xmj && xmj.gather_qty && xmj.jiacha === null && xmjSelect.jiacha !== null) {
  1796. needAddList.push(xmj);
  1797. }
  1798. }
  1799. // if (needAddList.length === 0) {
  1800. // toastr.warning('没有需要应用调差工料的其它清单明细');
  1801. // return false;
  1802. // }
  1803. console.log(needAddList, materialList);
  1804. // 更新至服务器
  1805. postData(window.location.pathname + '/save', { type:'useOther', postData: { addXmj: needAddList, materialBills: materialList } }, function (result) {
  1806. materialListData = result.materialListData;
  1807. gclList = result.gclList;
  1808. toastr.success('已成功应用');
  1809. calculateJiaCha(gclGatherData);
  1810. const index = gclGatherData.indexOf(ledgerSelect);
  1811. loadLeafXmjData(index);
  1812. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1813. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1814. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1815. loadMaterialData(index);
  1816. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1817. });
  1818. });
  1819. // 切换清单行,读取所属项目节数据
  1820. ledgerSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1821. if (info.oldSelections !== undefined) {
  1822. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1823. if (iNewRow !== iOldRow) {
  1824. loadLeafXmjData(iNewRow);
  1825. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1826. loadMaterialData(iNewRow);
  1827. loadXmjMaterialData(iNewRow, 0);
  1828. checkNotJoinMaterialData();
  1829. }
  1830. }
  1831. });
  1832. // 切换项目节数据清单明细行,读取单独的清单工料数据
  1833. leafXmjSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1834. if (info.oldSelections !== undefined) {
  1835. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1836. if (iNewRow !== iOldRow) {
  1837. const sheet = ledgerSpread.getActiveSheet();
  1838. const select = SpreadJsObj.getSelectObject(sheet);
  1839. const index = gclGatherData.indexOf(select);
  1840. loadXmjMaterialData(index, iNewRow);
  1841. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  1842. }
  1843. }
  1844. });
  1845. // 显示有调差工料清单
  1846. $('#show_material_gcl').click(function () {
  1847. if ($(this).is(':checked')) {
  1848. const hadMaterialGclGatherData = [];
  1849. const hadGclIdList = [];
  1850. for (const ml of materialListData) {
  1851. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  1852. hadGclIdList.push(ml.gcl_id);
  1853. }
  1854. }
  1855. for (const gcl of gclGatherData) {
  1856. for (const index in gcl.leafXmjs) {
  1857. const gcl_id = gcl.leafXmjs[index].gcl_id;
  1858. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  1859. hadMaterialGclGatherData.push(gcl);
  1860. break;
  1861. }
  1862. }
  1863. }
  1864. gclGatherData = hadMaterialGclGatherData;
  1865. } else {
  1866. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  1867. gclGatherModel.loadPosData(pos, curPosData);
  1868. gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  1869. return item.qc_qty || item.contract_qty
  1870. });
  1871. if (openMaterialChecklist) {
  1872. // 取交集
  1873. gclGatherData = _.filter(gclGatherData, function (item) {
  1874. return _.find(materialChecklistData, { b_code: item.b_code, name: item.name, unit: item.unit, unit_price: item.unit_price });
  1875. });
  1876. }
  1877. }
  1878. calculateJiaCha(gclGatherData);
  1879. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  1880. loadLeafXmjData(0);
  1881. loadMaterialData(0);
  1882. loadXmjMaterialData(0, 0);
  1883. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  1884. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1885. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  1886. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  1887. checkNotJoinMaterialData();
  1888. });
  1889. $.subMenu({
  1890. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1891. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1892. key: 'menu.1.0.0',
  1893. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1894. callback: function (info) {
  1895. if (info.mini) {
  1896. $('.panel-title').addClass('fluid');
  1897. $('#sub-menu').removeClass('panel-sidebar');
  1898. } else {
  1899. $('.panel-title').removeClass('fluid');
  1900. $('#sub-menu').addClass('panel-sidebar');
  1901. }
  1902. autoFlashHeight();
  1903. ledgerSpread.refresh();
  1904. leafXmjSpread.refresh();
  1905. materialSpread.refresh();
  1906. materialSelfSpread.refresh();
  1907. }
  1908. });
  1909. $(window).resize(function () {
  1910. ledgerSpread.refresh();
  1911. leafXmjSpread.refresh();
  1912. materialSpread.refresh();
  1913. materialSelfSpread.refresh();
  1914. });
  1915. $.divResizer({
  1916. select: '#right-spr',
  1917. callback: function () {
  1918. ledgerSpread.refresh();
  1919. // leafXmjSpread.refresh();
  1920. materialSpread.refresh();
  1921. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1922. setLocalCache('material_list_' + materialID, width);
  1923. }
  1924. });
  1925. $.divResizer({
  1926. select: '#right-spr2',
  1927. callback: function () {
  1928. leafXmjSpread.refresh();
  1929. materialSelfSpread.refresh();
  1930. // const width = (($('#right-view2').width()/$('#right-view2').parent('div').width())*100).toFixed();
  1931. // setLocalCache('material_list3_' + materialID, width);
  1932. }
  1933. });
  1934. $.divResizer({
  1935. select: '#main-resize',
  1936. callback: function () {
  1937. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1938. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1939. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1940. $(".sp-wrap").height(bcontent-30);
  1941. materialSpread.refresh();
  1942. ledgerSpread.refresh();
  1943. leafXmjSpread.refresh();
  1944. materialSelfSpread.refresh();
  1945. const height = $('.bcontent-wrap').height();
  1946. setLocalCache('material_list2_' + materialID, height);
  1947. }
  1948. });
  1949. // 展开收起月信息价并浏览器记住本期展开收起
  1950. $('a', '.right-nav').bind('click', function () {
  1951. //const main = $('#main-view'), tool = $('#tools-view');
  1952. const tab = $(this), tabPanel = $(tab.attr('content'));
  1953. if (!tab.hasClass('active')) {
  1954. $('a', '.side-menu').removeClass('active');
  1955. $('.tab-content .tab-select-show').removeClass('active');
  1956. tab.addClass('active');
  1957. tabPanel.addClass('active');
  1958. showSideTools(tab.hasClass('active'));
  1959. if (tab.attr('content') === '#material-tab') {
  1960. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1961. setLocalCache('material_list_' + materialID, width);
  1962. }
  1963. } else {
  1964. removeLocalCache('material_list_' + materialID);
  1965. tab.removeClass('active');
  1966. tabPanel.removeClass('active');
  1967. showSideTools(tab.hasClass('active'));
  1968. }
  1969. ledgerSpread.refresh();
  1970. // leafXmjSpread.refresh();
  1971. materialSpread.refresh();
  1972. });
  1973. // 根据浏览器记录展开收起
  1974. if (getLocalCache('material_list_' + materialID)) {
  1975. const tab = $('.right-nav a[content="#material-tab"]'), tabPanel = $(tab.attr('content'));
  1976. $('a', '.side-menu').removeClass('active');
  1977. $('.tab-content .tab-select-show').removeClass('active');
  1978. tab.addClass('active');
  1979. tabPanel.addClass('active');
  1980. $('#right-view').css('width', getLocalCache('material_list_' + materialID) + '%');
  1981. showSideTools(tab.hasClass('active'));
  1982. ledgerSpread.refresh();
  1983. // leafXmjSpread.refresh();
  1984. materialSpread.refresh();
  1985. }
  1986. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1987. if (getLocalCache('material_list2_' + materialID)) {
  1988. $('.bcontent-wrap').height(getLocalCache('material_list2_' + materialID));
  1989. const cHeader = getObjHeight($(".c-header"));
  1990. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1991. $(".sp-wrap").height(bcontent-30);
  1992. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  1993. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1994. materialSpread.refresh();
  1995. ledgerSpread.refresh();
  1996. leafXmjSpread.refresh();
  1997. materialSelfSpread.refresh();
  1998. } else {
  1999. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2000. ledgerSpread.refresh();
  2001. }
  2002. function getObjHeight(select) {
  2003. return select.length > 0 ? select.height() : 0;
  2004. }
  2005. const showSelfSideTools = function (show) {
  2006. const left = $('#left-view2'), right = $('#right-view2'), parent = left.parent();
  2007. if (show) {
  2008. right.show();
  2009. autoFlashHeight();
  2010. /**
  2011. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  2012. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  2013. * 故需要通过最终的parent.width再计算一次left.width
  2014. *
  2015. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  2016. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  2017. *
  2018. */
  2019. //left.css('width', parent.width() - right.outerWidth());
  2020. //left.css('width', parent.width() - right.outerWidth());
  2021. const percent = 100 - right.outerWidth() /parent.width() * 100;
  2022. left.css('width', percent + '%');
  2023. } else {
  2024. // left.css('width', parent.width());
  2025. left.css('width', '100%');
  2026. right.hide();
  2027. }
  2028. };
  2029. });