material_list.js 88 KB

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