material_list.js 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  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 getMpSpreadByMBData(id) {
  23. const info = materialBillsData.find(function (item) {
  24. return item.id === parseInt(id);
  25. });
  26. return info ? info.m_spread : 0;
  27. }
  28. function getMaterialListByLeafXmj(gcl_id, xmj_id, mx_id = null) {
  29. const list = [];
  30. for (const ml of materialListData) {
  31. if (gcl_id === ml.gcl_id && xmj_id === ml.xmj_id && (mx_id === null || mx_id === ml.mx_id)) {
  32. list.push(ml);
  33. }
  34. }
  35. return list;
  36. }
  37. function calcOneBQJC(xmj) {
  38. let jiacha = 0;
  39. const notx = findNotJoinLeafXmj(xmj);
  40. if (notx === undefined) {
  41. const list = xmj.mx_id !== undefined ? getMaterialListByLeafXmj(xmj.gcl_id, xmj.id, xmj.mx_id) : getMaterialListByLeafXmj(xmj.gcl_id, xmj.id);
  42. for (const l of list) {
  43. jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.gather_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
  44. }
  45. }
  46. return ZhCalc.round(jiacha, materialDecimal.tp);
  47. }
  48. function getPasteHint (str, row = '') {
  49. let returnObj = str;
  50. if (row) {
  51. returnObj.msg = '清单第' + (row+1) + '行' + (str.msg ? str.msg : str);
  52. }
  53. return returnObj;
  54. }
  55. // 重新计算列表的价差
  56. function calculateJiaCha(data, index) {
  57. // 计算单条的
  58. if (index) {
  59. const gcld = data[index]
  60. let total_jiacha = 0;
  61. for (const [index, xmj] of gcld.leafXmjs.entries()) {
  62. const jiacha = calcOneBQJC(xmj);
  63. gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
  64. total_jiacha += jiacha;
  65. }
  66. gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
  67. } else {
  68. for(const gcld of data) {
  69. let total_jiacha = 0;
  70. for (const [index, xmj] of gcld.leafXmjs.entries()) {
  71. const jiacha = calcOneBQJC(xmj);
  72. gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
  73. total_jiacha += jiacha;
  74. }
  75. gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
  76. }
  77. }
  78. }
  79. const is_numeric = (value) => {
  80. if (typeof(value) === 'object') {
  81. return false;
  82. } else {
  83. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  84. }
  85. };
  86. $(document).ready(() => {
  87. function TipCellType()
  88. {
  89. }
  90. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.ColumnHeader();
  91. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  92. return { x: x, y: y, row: context.row, col: context.col, cellRect: cellRect, sheetArea: context.sheetArea, sheet: context.sheet };
  93. };
  94. TipCellType.prototype.processMouseEnter = function (hitInfo){
  95. if (!this._toolTipElement) {
  96. var div = document.createElement("div");
  97. $(div).css("position", "absolute")
  98. .css("border", "1px #C0C0C0 solid")
  99. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  100. .css("font", "9pt Arial")
  101. .css("background", "#fff")
  102. // .css("color", "#fff")
  103. .css("z-index", "1000")
  104. .css("padding", 5);
  105. this._toolTipElement = div;
  106. }
  107. $(this._toolTipElement).text("单位数量:每一单位清单下所需工料消耗量。")
  108. .css("top", hitInfo.y + 15)
  109. .css("left", hitInfo.x - 15);
  110. $(this._toolTipElement).hide();
  111. // document.body.insertBefore(this._toolTipElement, null);
  112. $('#material-spread-div').append(this._toolTipElement, null);
  113. $(this._toolTipElement).show("fast");
  114. };
  115. TipCellType.prototype.processMouseLeave = function (hitInfo) {
  116. if (this._toolTipElement) {
  117. // document.body.removeChild(this._toolTipElement);
  118. // $('#material-spread-div').removeChild(this._toolTipElement);
  119. this._toolTipElement.remove();
  120. this._toolTipElement = null;
  121. }
  122. };
  123. autoFlashHeight();
  124. // 清单table
  125. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  126. const ledgerSpreadSetting = {
  127. cols: [
  128. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 90, formatter: '@'},
  129. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 220, formatter: '@'},
  130. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 80, formatter: '@'},
  131. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 110, type: 'Number'},
  132. {title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'},
  133. {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'},
  134. {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 110, type: 'Number'},
  135. {title: '本期完成金额', colSpan: '1', rowSpan: '2', field: 'gather_tp', hAlign: 2, width: 110, type: 'Number'},
  136. {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'total_jiacha', hAlign:3, width: 110, type: 'Number'}
  137. ],
  138. emptyRows: 0,
  139. headRows: 2,
  140. headRowHeight: [25, 25],
  141. defaultRowHeight: 21,
  142. headerFont: '12px 微软雅黑',
  143. font: '12px 微软雅黑',
  144. readOnly: true,
  145. };
  146. // let gclGatherData = gclGatherModel.gatherGclData()
  147. // 获取项目节数据
  148. function loadLeafXmjData(iGclRow) {
  149. const gcl = gclGatherData[iGclRow];
  150. if (gcl) {
  151. for (const [index, xmj] of gcl.leafXmjs.entries()) {
  152. const jiacha = calcOneBQJC(xmj);
  153. gcl.leafXmjs[index].jiacha = jiacha !== 0 ? ZhCalc.round(jiacha, materialDecimal.tp) : null;
  154. }
  155. const leafXmjs = gcl.leafXmjs.filter(item => {
  156. return item.qc_qty || item.contract_qty
  157. });
  158. console.log(leafXmjs);
  159. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, leafXmjs);
  160. // 对清单调差工料table的单位数量进行改变
  161. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + gcl.unit + '数量 �';
  162. // SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  163. } else {
  164. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  165. }
  166. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  167. }
  168. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  169. // 项目明细table
  170. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  171. const leafXmjSpreadSetting = {
  172. cols: [
  173. {title: '项目节|编号', colSpan: '2|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  174. {title: '|项目节名称', colSpan: '|1', rowSpan: '|1', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  175. {title: '计量单元|计量单元', colSpan: '2|1', rowSpan: '1|1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  176. {title: '|复核数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 0, width: 80, type: 'Number'},
  177. {title: '部位信息|单位工程', colSpan: '3|1', rowSpan: '1|1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  178. {title: '|分部工程', colSpan: '|1', rowSpan: '|1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  179. {title: '|分项工程', colSpan: '|1', rowSpan: '|1', field: 'fxgc', hAlign: 0, width: 180, formatter: '@'},
  180. {title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  181. {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 80, type: 'Number'},
  182. {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  183. {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'jiacha', hAlign: 2, width: 80, type: 'Number'},
  184. ],
  185. emptyRows: 0,
  186. headRows: 2,
  187. headRowHeight: [25, 25],
  188. defaultRowHeight: 21,
  189. headerFont: '12px 微软雅黑',
  190. font: '12px 微软雅黑',
  191. readOnly: true,
  192. };
  193. // 加载清单数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  194. postData(window.location.pathname + '/load', {}, async function (result) {
  195. ledger = result.ledger;
  196. curLedgerData = result.curLedgerData;
  197. pos = result.pos;
  198. curPosData = result.curPosData;
  199. materialListData = result.materialListData;
  200. const gclList = result.gclList;
  201. notJoinList = result.materialNotJoinListData;
  202. materialChecklistData = result.materialChecklistData;
  203. // 解析清单汇总数据
  204. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  205. gclGatherModel.loadPosData(pos, curPosData);
  206. gclGatherData = gclGatherModel.gatherGclData();
  207. console.log(gclGatherData);
  208. if (openMaterialChecklist) {
  209. const hadBillsidList = _.uniq(_.map(gclList, 'gcl_id'));
  210. console.log(hadBillsidList);
  211. // 判断是否有修订影响到本次数据,并有几率修改清单设置页的值
  212. const pushData = [];
  213. const updateData = [];
  214. for (const hb of hadBillsidList) {
  215. const gcl = _.find(gclGatherData, function (item) {
  216. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, { gcl_id : hb }) !== -1;
  217. });
  218. if (gcl) {
  219. const mc = _.find(materialChecklistData, { b_code: gcl.b_code, name: gcl.name, unit: gcl.unit, unit_price: gcl.unit_price });
  220. // const newOrder = _.indexOf(gclGatherData, gcl);
  221. // console.log(newOrder);
  222. if (!mc && _.findIndex(pushData, { b_code: gcl.b_code, name: gcl.name, unit: gcl.unit, unit_price: gcl.unit_price }) === -1) {
  223. 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 });
  224. }
  225. }
  226. }
  227. const removeData = [];
  228. for (const mc of materialChecklistData) {
  229. const gcl = _.find(gclGatherData, { b_code: mc.b_code, name: mc.name, unit: mc.unit, unit_price: mc.unit_price });
  230. // 判断是否已不存在工料清单,台账修改过后删除之
  231. if (!gcl) {
  232. removeData.push(mc.id);
  233. } else {
  234. // 更新had_bills值
  235. const updateObj = { id: mc.id };
  236. if (mc.had_bills === 1) {
  237. if (_.indexOf(hadBillsidList, gcl.leafXmjs ? gcl.leafXmjs[0].gcl_id : null) === -1) {
  238. updateObj.mid = materialID;
  239. updateObj.had_bills = 0;
  240. // updateData.push({ id: mc.id, mid: materialID, had_bills: 0 });
  241. }
  242. }
  243. // 更新工程量及台账金额
  244. if (mc.quantity !== (gcl.quantity ? gcl.quantity : null)) {
  245. updateObj.quantity = gcl.quantity ? gcl.quantity : null;
  246. updateObj.total_price = gcl.total_price ? gcl.total_price : null;
  247. }
  248. if(!_.isEqual(updateObj,{ id: mc.id })) updateData.push(updateObj);
  249. }
  250. }
  251. console.log(pushData, removeData, updateData);
  252. if (pushData.length > 0 || removeData.length > 0 || updateData.length > 0) {
  253. // materialChecklistData = await postDataAsync('/tender/'+ tenderID +'/measure/material/'+ stage_order +'/checklist/save', { type: 'resetChecklist', pushData, removeData, updateData })
  254. }
  255. gclGatherData = gclGatherData.filter(item => {
  256. return item.qc_qty || item.contract_qty
  257. });
  258. // 取交集
  259. gclGatherData = _.filter(gclGatherData, function (item) {
  260. return _.find(materialChecklistData, { b_code: item.b_code, name: item.name, unit: item.unit, unit_price: item.unit_price });
  261. });
  262. } else {
  263. gclGatherData = gclGatherData.filter(item => {
  264. return item.qc_qty || item.contract_qty
  265. });
  266. }
  267. calculateJiaCha(gclGatherData);
  268. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  269. // 加载清单数据
  270. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  271. loadLeafXmjData(0);
  272. loadMaterialData(0, 0);
  273. const sheet = materialSpread.getActiveSheet();
  274. sheet.suspendPaint();
  275. sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  276. sheet.resumePaint();
  277. checkNotJoinMaterialData();
  278. });
  279. // const leafXmjCol = {
  280. // getValue: {
  281. // jiacha: function (data) {
  282. // let sum = 0;
  283. // const sheet = leafXmjSpread.getActiveSheet();
  284. // const select = SpreadJsObj.getSelectObject(sheet);
  285. // const notx = findNotJoinLeafXmj(select);
  286. // if (notx === undefined) {
  287. // for(const ml of materialList) {
  288. // sum = ZhCalc.round(ZhCalc.add(sum, ZhCalc.mul(ZhCalc.mul(data.gather_qty, ml.quantity), getMpSpreadByMBData(ml.mb_id))), 2);
  289. // }
  290. // }
  291. // return sum !== 0 ? sum : null;
  292. // }
  293. // }
  294. // };
  295. // SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  296. // 调差清单工料table
  297. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  298. const materialSpreadSetting = {
  299. cols: [
  300. {title: '清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  301. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  302. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  303. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  304. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  305. ],
  306. emptyRows: 0,
  307. headRows: 2,
  308. headRowHeight: [25, 25],
  309. defaultRowHeight: 21,
  310. headerFont: '12px 微软雅黑',
  311. font: '12px 微软雅黑',
  312. };
  313. const materialBase = {
  314. isEdit: function (data) {
  315. // 是否本期添加的工料
  316. return data.order === stage_order && !openMaterialChecklist;
  317. }
  318. };
  319. const materialCol = {
  320. readOnly: {
  321. isEdit: function (data) {
  322. // const sheet = leafXmjSpread.getActiveSheet();
  323. // const select = SpreadJsObj.getSelectObject(sheet);
  324. // const notx = findNotJoinLeafXmj(select);
  325. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  326. return !(!readOnly && materialBase.isEdit(data));
  327. },
  328. },
  329. };
  330. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  331. // 获取项目节数据
  332. let materialList = [];
  333. function loadMaterialData(iGclRow, iLXmjRow) {
  334. const gcl = gclGatherData[iGclRow];
  335. const leafXmjs = gcl && gcl.leafXmjs ? gcl.leafXmjs.filter(item => {
  336. return item.qc_qty || item.contract_qty
  337. }) : null;
  338. console.log(gcl, leafXmjs);
  339. if (leafXmjs) {
  340. const xmj = leafXmjs[iLXmjRow];
  341. console.log(xmj, iLXmjRow);
  342. materialList = [];
  343. for (const m of materialListData) {
  344. 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)) {
  345. materialList.push(m);
  346. }
  347. }
  348. console.log(xmj, materialList);
  349. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialList);
  350. } else {
  351. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  352. }
  353. // SpreadJsObj.reLoadSheetData(leafXmjSpread.getActiveSheet());
  354. }
  355. // SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), )
  356. // loadLeafXmjData(0);
  357. // loadMaterialData(0, 0);
  358. // const sheet = materialSpread.getActiveSheet();
  359. // sheet.suspendPaint();
  360. // sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  361. // sheet.resumePaint();
  362. // 不参与调差数据值变灰
  363. function checkNotJoinMaterialData() {
  364. const sheet = ledgerSpread.getActiveSheet();
  365. const select = SpreadJsObj.getSelectObject(sheet);
  366. const index = gclGatherData.indexOf(select);
  367. if (index !== -1) {
  368. const xmj = gclGatherData[index].leafXmjs.filter(item => {
  369. return item.qc_qty || item.contract_qty
  370. });
  371. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  372. for (const [iRow,x] of xmj.entries()) {
  373. const notx = findNotJoinLeafXmj(x);
  374. const color = notx === undefined ? '' : '#d6d8db';
  375. leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
  376. }
  377. }
  378. }
  379. // checkNotJoinMaterialData();
  380. // 对添加工料表格赋值
  381. function changeMaterialTable() {
  382. $('#materialBills tr').removeClass('table-secondary');
  383. $('#materialBills').find('input').removeAttr('disabled');
  384. $('#materialBills').find('input').prop('checked', false);
  385. for (const [index, ml] of materialList.entries()) {
  386. const mbIndex = materialBillsData.findIndex(function (item) {
  387. return item.id === ml.mb_id;
  388. });
  389. if (mbIndex !== -1) {
  390. $('#materialBills tr').eq(mbIndex).addClass('table-secondary');
  391. $('#materialBills').find('input').eq(mbIndex).attr('disabled', true);
  392. $('#materialBills').find('input').eq(mbIndex).prop('checked', true);
  393. }
  394. }
  395. }
  396. // 添加调差工料
  397. $('#add_material_bill').click(function () {
  398. // 获取已选工料
  399. $('#materialBills').find('input:disabled').prop('checked', false);
  400. const selectList = $('#materialBills').find('input:checked');
  401. if (selectList.length === 0) {
  402. toastr.warning('请选择调差工料');
  403. $('#materialBills').find('input:disabled').prop('checked', true);
  404. return false;
  405. }
  406. const mb_id = [];
  407. for (let s = 0; s < selectList.length; s++) {
  408. mb_id.push($('#materialBills').find('input:checked').eq(s).val());
  409. }
  410. // 获取当前项目节或部位明细id
  411. const sheet = ledgerSpread.getActiveSheet();
  412. const select = SpreadJsObj.getSelectObject(sheet);
  413. const index = gclGatherData.indexOf(select);
  414. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  415. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  416. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  417. const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  418. // const xmj = gcl[leafXmjIndex];
  419. // const data = {
  420. // xmj_id: xmj.id,
  421. // gcl_id: xmj.gcl_id,
  422. // mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  423. // mb_id: mb_id,
  424. // gather_qty: xmj.gather_qty,
  425. // };
  426. const datas = [];
  427. for (const xmj of gcl) {
  428. const notx = findNotJoinLeafXmj(xmj);
  429. const data = {
  430. xmj_id: xmj.id,
  431. gcl_id: xmj.gcl_id,
  432. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  433. gather_qty: xmj.gather_qty,
  434. is_join: notx === undefined ? 1 : 0,
  435. };
  436. datas.push(data);
  437. }
  438. // 上传到数据库
  439. console.log(datas, gcl);
  440. postData(window.location.pathname + '/save', {type: 'adds', postData: {xmjs: datas, mbIds: mb_id}}, function (result) {
  441. materialListData = result;
  442. // toastr.success('已成功应用');
  443. calculateJiaCha(gclGatherData);
  444. // const index = gclGatherData.indexOf(ledgerSelect);
  445. loadLeafXmjData(index);
  446. // const xmjSheet = leafXmjSpread.getActiveSheet();
  447. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  448. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  449. loadMaterialData(index, leafXmjIndex);
  450. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  451. $('#addgl').modal('hide');
  452. });
  453. // postData(window.location.pathname + '/save', {type: 'add', postData: data}, function (result) {
  454. // // 添加到materialList里
  455. // materialListData = result;
  456. // loadMaterialData(index, leafXmjIndex);
  457. // $('#addgl').modal('hide');
  458. // });
  459. $('#materialBills').find('input:disabled').prop('checked', true);
  460. });
  461. if (!readOnly) {
  462. const leafXmjSpreadObj = {
  463. getSelect : function () {
  464. const sheet = ledgerSpread.getActiveSheet();
  465. const select = SpreadJsObj.getSelectObject(sheet);
  466. const index = gclGatherData.indexOf(select);
  467. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  468. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  469. const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
  470. const leafXmjs = gclGatherData[index].leafXmjs.filter(item => {
  471. return item.qc_qty || item.contract_qty
  472. });
  473. const nRow = leafXmjs.indexOf(leafXmjSelect);
  474. return [index, iRow, nRow, leafXmjSheet, leafXmjSelect];
  475. },
  476. checkJoinMaterial: function (type) {
  477. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  478. const color = type === 'join' ? '' : '#d6d8db';
  479. const data = {
  480. type: type,
  481. select: type === 'join' ? findNotJoinLeafXmj(select) : select,
  482. };
  483. console.log(iGclRow, iRow, nRow, select);
  484. console.log(materialList);
  485. // 添加到
  486. postData(window.location.pathname + '/save', data, function (result) {
  487. if (type === 'join') {
  488. const index = findNotJoinLeafXmj(select, 'index');
  489. notJoinList.splice(index, 1);
  490. } else {
  491. notJoinList.push(result);
  492. }
  493. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  494. calculateJiaCha(gclGatherData, iGclRow);
  495. SpreadJsObj.reLoadRowData(sheet, nRow);
  496. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  497. loadMaterialData(iGclRow, 0);
  498. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  499. });
  500. },
  501. }
  502. // leafXmj右键功能
  503. $.contextMenu({
  504. selector: '#leaf-xmj-spread',
  505. build: function ($trigger, e) {
  506. const target = SpreadJsObj.safeRightClickSelection($trigger, e, leafXmjSpread);
  507. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  508. },
  509. items: {
  510. 'stop': {
  511. name: '不参与调差',
  512. icon: 'fa-remove',
  513. callback: function (key, opt) {
  514. leafXmjSpreadObj.checkJoinMaterial('notjoin');
  515. },
  516. visible: function (key, opt) {
  517. const sheet = leafXmjSpread.getActiveSheet();
  518. const select = SpreadJsObj.getSelectObject(sheet);
  519. const sel = sheet.getSelections()[0];
  520. const notx = findNotJoinLeafXmj(select);
  521. if (!select || sel.rowCount !== 1) {
  522. return false;
  523. }
  524. if (!readOnly && select && notx === undefined) {
  525. return true;
  526. } else {
  527. return false;
  528. }
  529. }
  530. },
  531. 'start': {
  532. name: '参与调差',
  533. icon: 'fa-sign-in',
  534. callback: function (key, opt) {
  535. leafXmjSpreadObj.checkJoinMaterial('join');
  536. },
  537. visible: function (key, opt) {
  538. const sheet = leafXmjSpread.getActiveSheet();
  539. const select = SpreadJsObj.getSelectObject(sheet);
  540. const sel = sheet.getSelections()[0];
  541. const notx = findNotJoinLeafXmj(select);
  542. if (!select || sel.rowCount !== 1) {
  543. return false;
  544. }
  545. if (!readOnly && select && notx === undefined) {
  546. return false;
  547. } else {
  548. return true;
  549. }
  550. },
  551. }
  552. }
  553. });
  554. // material-spread右键功能
  555. const materialSpreadObj = {
  556. del: function () {
  557. const materialSheet = materialSpread.getActiveSheet();
  558. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  559. const sheet = ledgerSpread.getActiveSheet();
  560. const select = SpreadJsObj.getSelectObject(sheet);
  561. const index = gclGatherData.indexOf(select);
  562. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  563. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  564. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  565. const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  566. const datas = [];
  567. for (const xmj of gcl) {
  568. const data = {
  569. xmj_id: xmj.id,
  570. gcl_id: xmj.gcl_id,
  571. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  572. };
  573. datas.push(data);
  574. }
  575. console.log(datas, materialSelect.mb_id);
  576. postData(window.location.pathname + '/save', {type: 'dels', postData: { xmjs: datas, mb_id: materialSelect.mb_id }}, function (result) {
  577. materialListData = result;
  578. calculateJiaCha(gclGatherData);
  579. // const index = gclGatherData.indexOf(ledgerSelect);
  580. loadLeafXmjData(index);
  581. // const xmjSheet = leafXmjSpread.getActiveSheet();
  582. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  583. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  584. loadMaterialData(index, leafXmjIndex);
  585. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  586. });
  587. // postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  588. // const index = materialList.indexOf(select);
  589. // materialList.splice(index, 1);
  590. // sheet.deleteRows(index, 1);
  591. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  592. // const sel = sheet.getSelections();
  593. // sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  594. // const materialListIndex = materialListData.indexOf(select);
  595. // materialListData.splice(materialListIndex, 1);
  596. // const [iGclRow, iRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  597. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  598. // calculateJiaCha(gclGatherData, iGclRow);
  599. // SpreadJsObj.reLoadRowData(lsheet, iRow);
  600. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  601. // });
  602. },
  603. deletePress: function (sheet) {
  604. return;
  605. },
  606. editStarting: function (e, info) {
  607. const col = info.sheet.zh_setting.cols[info.col];
  608. const select = SpreadJsObj.getSelectObject(info.sheet);
  609. if (col.field === 'quantity') {
  610. if (select.expr && select.expr !== '') {
  611. info.sheet.getCell(info.row, info.col).text(select.expr);
  612. }
  613. }
  614. },
  615. editEnded: function (e, info) {
  616. if (info.sheet.zh_setting) {
  617. const select = SpreadJsObj.getSelectObject(info.sheet);
  618. const col = info.sheet.zh_setting.cols[info.col];
  619. // 未改变值则不提交
  620. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  621. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  622. // let orgValue = select[col.field];
  623. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  624. let orgValue;
  625. if (col.field === 'quantity') {
  626. orgValue = validText && validText !== ''
  627. ? _.toNumber(validText) ? select.quantity : select.expr
  628. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  629. } else {
  630. orgValue = select[col.field];
  631. }
  632. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  633. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  634. return;
  635. }
  636. const exprQuantity = {
  637. expr: '',
  638. quantity: 0,
  639. };
  640. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  641. if (!valid) {
  642. toastr.error(msg);
  643. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  644. return;
  645. }
  646. if (isNaN(exprQuantity.quantity)) {
  647. toastr.error('不能输入其它非数字类型字符');
  648. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  649. return;
  650. }
  651. const num = parseFloat(exprQuantity.quantity);
  652. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  653. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  654. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  655. // return;
  656. toastr.warning('已保留6位小数');
  657. exprQuantity.quantity = ZhCalc.round(num, 6);
  658. }
  659. // 更新至服务器
  660. const ledgerSheet = ledgerSpread.getActiveSheet();
  661. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  662. const index = gclGatherData.indexOf(ledgerSelect);
  663. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  664. const xmjSheet = leafXmjSpread.getActiveSheet();
  665. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  666. const xmjIndex = gcl.indexOf(xmjSelect);
  667. const datas = [];
  668. for (const xmj of gcl) {
  669. const data = {
  670. xmj_id: xmj.id,
  671. gcl_id: xmj.gcl_id,
  672. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  673. };
  674. datas.push(data);
  675. }
  676. console.log(exprQuantity, datas, select.mb_id);
  677. postData(window.location.pathname + '/save', { type:'updates', updateData: { xmjs: datas, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id } }, function (result) {
  678. materialListData = result;
  679. calculateJiaCha(gclGatherData);
  680. // const index = gclGatherData.indexOf(ledgerSelect);
  681. loadLeafXmjData(index);
  682. // const xmjSheet = leafXmjSpread.getActiveSheet();
  683. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  684. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  685. loadMaterialData(index, xmjIndex);
  686. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  687. materialSpread.getActiveSheet().setSelection(info.row + 1, info.col, 1, 1);
  688. }, function () {
  689. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  690. });
  691. // postData(window.location.pathname + '/save', { type:'update', updateData: { id:select.id, quantity: validText, mb_id: select.mb_id } }, function (result) {
  692. // const materialListIndex = materialListData.indexOf(select);
  693. // const index = materialList.indexOf(select);
  694. // select[col.field] = validText;
  695. // materialListData.splice(materialListIndex, 1, select);
  696. // materialList.indexOf(index, 1, select);
  697. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  698. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  699. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  700. // calculateJiaCha(gclGatherData, iGclRow)
  701. // SpreadJsObj.reLoadRowData(sheet, iRow);
  702. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  703. // }, function () {
  704. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  705. // });
  706. }
  707. },
  708. clipboardPasted(e, info) {
  709. const hint = {
  710. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  711. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  712. numberCan: {type: 'warning', msg: '已保留6位小数'},
  713. };
  714. const range = info.cellRange;
  715. const sortData = info.sheet.zh_data || [];
  716. if (range.row + range.rowCount > sortData.length) {
  717. toastMessageUniq(hint.cellError);
  718. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  719. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  720. return;
  721. }
  722. if (sortData.length > 0 && range.col + range.colCount > 5) {
  723. toastMessageUniq(hint.cellError);
  724. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  725. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  726. return;
  727. }
  728. const data = [];
  729. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  730. let bPaste = true;
  731. const curRow = range.row + iRow;
  732. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  733. const hintRow = range.rowCount > 1 ? curRow : '';
  734. let sameCol = 0;
  735. for (let iCol = 0; iCol < range.colCount; iCol++) {
  736. const curCol = range.col + iCol;
  737. const colSetting = info.sheet.zh_setting.cols[curCol];
  738. if (!colSetting) continue;
  739. // let validText = info.sheet.getText(curRow, curCol);
  740. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  741. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  742. const orgValue = sortData[curRow][colSetting.field];
  743. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  744. sameCol++;
  745. if (range.colCount === sameCol) {
  746. bPaste = false;
  747. }
  748. continue;
  749. }
  750. const exprQuantity = {
  751. expr: '',
  752. quantity: 0,
  753. };
  754. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  755. if (!valid) {
  756. toastMessageUniq(getPasteHint(msg, hintRow));
  757. bPaste = false;
  758. continue;
  759. }
  760. if (isNaN(exprQuantity.quantity)) {
  761. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  762. bPaste = false;
  763. continue;
  764. }
  765. const num = parseFloat(exprQuantity.quantity);
  766. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  767. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  768. // bPaste = false;
  769. // continue;
  770. exprQuantity.quantity = ZhCalc.round(num, 6);
  771. }
  772. // materialData[colSetting.field] = validText;
  773. materialData.expr = exprQuantity.expr;
  774. materialData.quantity = exprQuantity.quantity;
  775. }
  776. if (bPaste) {
  777. data.push(materialData);
  778. // rowData.push(curRow);
  779. } else {
  780. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  781. }
  782. }
  783. if (data.length === 0) {
  784. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  785. return;
  786. }
  787. const ledgerSheet = ledgerSpread.getActiveSheet();
  788. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  789. const index = gclGatherData.indexOf(ledgerSelect);
  790. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  791. const xmjSheet = leafXmjSpread.getActiveSheet();
  792. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  793. const xmjIndex = gcl.indexOf(xmjSelect);
  794. const datas = [];
  795. for (const xmj of gcl) {
  796. const data2 = {
  797. xmj_id: xmj.id,
  798. gcl_id: xmj.gcl_id,
  799. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  800. };
  801. datas.push(data2);
  802. }
  803. console.log(data, datas);
  804. // 更新至服务器
  805. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data } }, function (result) {
  806. materialListData = result;
  807. calculateJiaCha(gclGatherData);
  808. // const index = gclGatherData.indexOf(ledgerSelect);
  809. loadLeafXmjData(index);
  810. // const xmjSheet = leafXmjSpread.getActiveSheet();
  811. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  812. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  813. loadMaterialData(index, xmjIndex);
  814. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  815. materialSpread.getActiveSheet().setSelection(info.cellRange.row, info.cellRange.col, info.cellRange.rowCount, info.cellRange.colCount);
  816. }, function () {
  817. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  818. });
  819. // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  820. // materialListData = result;
  821. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  822. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  823. // calculateJiaCha(gclGatherData, iGclRow);
  824. // SpreadJsObj.reLoadRowData(sheet, iRow);
  825. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  826. // }, function () {
  827. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  828. // });
  829. },
  830. _checkExprValid(expr) {
  831. if (!expr) return [true, null];
  832. const param = [];
  833. let num = '', base = '';
  834. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  835. if (/^[\d\.%]+/.test(expr[i])) {
  836. if (base !== '') {
  837. param.push({type: 'base', value: base});
  838. base = '';
  839. }
  840. num = num + expr[i];
  841. } else if (expr[i] === '(') {
  842. if (num !== '') {
  843. param.push({type: 'num', value: num});
  844. num = '';
  845. }
  846. if (base !== '') {
  847. param.push({type: 'base', value: base});
  848. base = '';
  849. }
  850. param.push({type: 'left', value: '('});
  851. } else if (expr[i] === ')') {
  852. if (num !== '') {
  853. param.push({type: 'num', value: num});
  854. num = '';
  855. }
  856. if (base !== '') {
  857. param.push({type: 'base', value: base});
  858. base = '';
  859. }
  860. param.push({type: 'right', value: ')'});
  861. } else if (/^[\+\-*\/]/.test(expr[i])) {
  862. if (num !== '') {
  863. param.push({type: 'num', value: num});
  864. num = '';
  865. }
  866. if (base !== '') {
  867. param.push({type: 'base', value: base});
  868. base = '';
  869. }
  870. param.push({type: 'calc', value: expr[i]});
  871. } else {
  872. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  873. }
  874. }
  875. if (num !== '') {
  876. param.push({type: 'num', value: num});
  877. num = '';
  878. }
  879. if (base !== '') {
  880. param.push({type: 'base', value: base});
  881. base = '';
  882. }
  883. if (param.length === 0) return true;
  884. if (param.length > 1) {
  885. if (param[0].value === '-') {
  886. param[1].value = '-' + param[1];
  887. }
  888. param.unshift();
  889. }
  890. const iLen = param.length;
  891. let iLeftCount = 0, iRightCount = 0;
  892. for (const [i, p] of param.entries()) {
  893. if (p.type === 'calc') {
  894. if (i === 0 || i === iLen - 1)
  895. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  896. }
  897. if (p.type === 'num') {
  898. num = p.value.replace('%', '');
  899. if (p.value.length - num.length > 1)
  900. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  901. num = _.toNumber(num);
  902. if (num === undefined || num === null || _.isNaN(num))
  903. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  904. if (i > 0) {
  905. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  906. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  907. } else if (param[i - 1].value === '/' && num === 0) {
  908. return [false, '输入的表达式非法:请勿除0'];
  909. }
  910. }
  911. }
  912. if (p.type === 'base') {
  913. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  914. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  915. }
  916. if (p.type === 'left') {
  917. iLeftCount += 1;
  918. if (i !== 0 && param[i-1].type !== 'calc')
  919. return [false, '输入的表达式非法:(前应有运算符'];
  920. }
  921. if (p.type === 'right') {
  922. iRightCount += 1;
  923. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  924. return [false, '输入的表达式非法:)后应有运算符'];
  925. if (iRightCount > iLeftCount)
  926. return [false, '输入的表达式非法:")"前无对应的"("'];
  927. }
  928. }
  929. if (iLeftCount > iRightCount)
  930. return [false, '输入的表达式非法:"("后无对应的")"'];
  931. return [true, ''];
  932. },
  933. _checkExpr: function (text, data) {
  934. if (text) {
  935. const num = _.toNumber(text);
  936. if (num) {
  937. data.quantity = num;
  938. data.expr = '';
  939. } else {
  940. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  941. const [valid, msg] = this._checkExprValid(expr);
  942. if (!valid) return [valid, msg];
  943. data.expr = expr;
  944. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr);
  945. // const ce = new CalcEvalMin();
  946. // data.quantity = ce.eval(expr);
  947. // console.log(data.quantity);
  948. }
  949. } else {
  950. data.quantity = 0;
  951. data.expr = '';
  952. }
  953. return [true, ''];
  954. },
  955. };
  956. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  957. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  958. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  959. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  960. if (!openMaterialChecklist) {
  961. $.contextMenu({
  962. selector: '#material-spread',
  963. build: function ($trigger, e) {
  964. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  965. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  966. },
  967. items: {
  968. 'create': {
  969. name: '添加工料',
  970. icon: 'fa-sign-in',
  971. callback: function (key, opt) {
  972. // 获取已选清单
  973. changeMaterialTable();
  974. $('#addgl').modal('show');
  975. },
  976. disabled: function (key, opt) {
  977. const sheet = leafXmjSpread.getActiveSheet();
  978. const select = SpreadJsObj.getSelectObject(sheet);
  979. // const notx = findNotJoinLeafXmj(select);
  980. if (!select) {
  981. return true;
  982. }
  983. // if (!readOnly && notx === undefined) {
  984. // return false;
  985. // } else {
  986. // return true;
  987. // }
  988. return readOnly;
  989. }
  990. },
  991. 'delete': {
  992. name: '删除工料',
  993. icon: 'fa-remove',
  994. callback: function (key, opt) {
  995. materialSpreadObj.del(materialSpread.getActiveSheet());
  996. },
  997. disabled: function (key, opt) {
  998. const sheet = materialSpread.getActiveSheet();
  999. const select = SpreadJsObj.getSelectObject(sheet);
  1000. if (!select) {
  1001. return true;
  1002. }
  1003. if (!readOnly && select && materialBase.isEdit(select)) {
  1004. return false;
  1005. } else {
  1006. return true;
  1007. }
  1008. }
  1009. },
  1010. }
  1011. });
  1012. }
  1013. }
  1014. // 应用调差工料至其他清单明细
  1015. $('#user_all_material').click(function () {
  1016. const ledgerSheet = ledgerSpread.getActiveSheet();
  1017. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1018. if (ledgerSelect.leafXmjs.length < 2) {
  1019. toastr.warning('没有需要应用调差工料的其它清单明细');
  1020. return false;
  1021. }
  1022. const xmjSheet = leafXmjSpread.getActiveSheet();
  1023. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1024. console.log(ledgerSelect.leafXmjs);
  1025. // 判断需要应用调差工料的清单明细
  1026. const needAddList = [];
  1027. for (const xmj of ledgerSelect.leafXmjs) {
  1028. const notx = findNotJoinLeafXmj(xmj);
  1029. if (notx === undefined && xmjSelect !== xmj && xmj.gather_qty && xmj.jiacha === null && xmjSelect.jiacha !== null) {
  1030. needAddList.push(xmj);
  1031. }
  1032. }
  1033. // if (needAddList.length === 0) {
  1034. // toastr.warning('没有需要应用调差工料的其它清单明细');
  1035. // return false;
  1036. // }
  1037. console.log(needAddList, materialList);
  1038. // 更新至服务器
  1039. postData(window.location.pathname + '/save', { type:'useOther', postData: { addXmj: needAddList, materialBills: materialList } }, function (result) {
  1040. materialListData = result;
  1041. toastr.success('已成功应用');
  1042. calculateJiaCha(gclGatherData);
  1043. const index = gclGatherData.indexOf(ledgerSelect);
  1044. loadLeafXmjData(index);
  1045. const xmjSheet = leafXmjSpread.getActiveSheet();
  1046. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1047. const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1048. loadMaterialData(index, xmjIndex);
  1049. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1050. });
  1051. });
  1052. // 切换清单行,读取所属项目节数据
  1053. ledgerSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1054. if (info.oldSelections !== undefined) {
  1055. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1056. if (iNewRow !== iOldRow) {
  1057. loadLeafXmjData(iNewRow);
  1058. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1059. loadMaterialData(iNewRow, 0);
  1060. checkNotJoinMaterialData();
  1061. }
  1062. }
  1063. });
  1064. // 切换项目节数据清单明细行,读取已调用的清单工料数据
  1065. leafXmjSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1066. if (info.oldSelections !== undefined) {
  1067. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1068. if (iNewRow !== iOldRow) {
  1069. const sheet = ledgerSpread.getActiveSheet();
  1070. const select = SpreadJsObj.getSelectObject(sheet);
  1071. const index = gclGatherData.indexOf(select);
  1072. loadMaterialData(index, iNewRow);
  1073. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  1074. }
  1075. }
  1076. });
  1077. // 显示有调差工料清单
  1078. $('#show_material_gcl').click(function () {
  1079. if ($(this).is(':checked')) {
  1080. const hadMaterialGclGatherData = [];
  1081. const hadGclIdList = [];
  1082. for (const ml of materialListData) {
  1083. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  1084. hadGclIdList.push(ml.gcl_id);
  1085. }
  1086. }
  1087. for (const gcl of gclGatherData) {
  1088. for (const index in gcl.leafXmjs) {
  1089. const gcl_id = gcl.leafXmjs[index].gcl_id;
  1090. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  1091. hadMaterialGclGatherData.push(gcl);
  1092. break;
  1093. }
  1094. }
  1095. }
  1096. gclGatherData = hadMaterialGclGatherData;
  1097. } else {
  1098. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  1099. gclGatherModel.loadPosData(pos, curPosData);
  1100. gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  1101. return item.qc_qty || item.contract_qty
  1102. });
  1103. if (openMaterialChecklist) {
  1104. // 取交集
  1105. gclGatherData = _.filter(gclGatherData, function (item) {
  1106. return _.find(materialChecklistData, { b_code: item.b_code, name: item.name, unit: item.unit, unit_price: item.unit_price });
  1107. });
  1108. }
  1109. }
  1110. calculateJiaCha(gclGatherData);
  1111. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  1112. loadLeafXmjData(0);
  1113. loadMaterialData(0, 0);
  1114. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  1115. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1116. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  1117. checkNotJoinMaterialData();
  1118. });
  1119. $.subMenu({
  1120. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1121. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1122. key: 'menu.1.0.0',
  1123. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1124. callback: function (info) {
  1125. if (info.mini) {
  1126. $('.panel-title').addClass('fluid');
  1127. $('#sub-menu').removeClass('panel-sidebar');
  1128. } else {
  1129. $('.panel-title').removeClass('fluid');
  1130. $('#sub-menu').addClass('panel-sidebar');
  1131. }
  1132. autoFlashHeight();
  1133. ledgerSpread.refresh();
  1134. leafXmjSpread.refresh();
  1135. materialSpread.refresh();
  1136. }
  1137. });
  1138. $.divResizer({
  1139. select: '#right-spr',
  1140. callback: function () {
  1141. ledgerSpread.refresh();
  1142. // leafXmjSpread.refresh();
  1143. materialSpread.refresh();
  1144. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1145. setLocalCache('material_list_' + materialID, width);
  1146. }
  1147. });
  1148. $.divResizer({
  1149. select: '#main-resize',
  1150. callback: function () {
  1151. materialSpread.refresh();
  1152. ledgerSpread.refresh();
  1153. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1154. $(".sp-wrap").height(bcontent-30);
  1155. leafXmjSpread.refresh();
  1156. const height = $('.bcontent-wrap').height();
  1157. setLocalCache('material_list2_' + materialID, height);
  1158. }
  1159. });
  1160. // 展开收起月信息价并浏览器记住本期展开收起
  1161. $('a', '.right-nav').bind('click', function () {
  1162. //const main = $('#main-view'), tool = $('#tools-view');
  1163. const tab = $(this), tabPanel = $(tab.attr('content'));
  1164. if (!tab.hasClass('active')) {
  1165. $('a', '.side-menu').removeClass('active');
  1166. $('.tab-content .tab-select-show').removeClass('active');
  1167. tab.addClass('active');
  1168. tabPanel.addClass('active');
  1169. showSideTools(tab.hasClass('active'));
  1170. if (tab.attr('content') === '#material-tab') {
  1171. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1172. setLocalCache('material_list_' + materialID, width);
  1173. }
  1174. } else {
  1175. removeLocalCache('material_list_' + materialID);
  1176. tab.removeClass('active');
  1177. tabPanel.removeClass('active');
  1178. showSideTools(tab.hasClass('active'));
  1179. }
  1180. ledgerSpread.refresh();
  1181. // leafXmjSpread.refresh();
  1182. materialSpread.refresh();
  1183. });
  1184. // 根据浏览器记录展开收起
  1185. if (getLocalCache('material_list_' + materialID)) {
  1186. const tab = $('.right-nav a[content="#material-tab"]'), tabPanel = $(tab.attr('content'));
  1187. $('a', '.side-menu').removeClass('active');
  1188. $('.tab-content .tab-select-show').removeClass('active');
  1189. tab.addClass('active');
  1190. tabPanel.addClass('active');
  1191. $('#right-view').width(getLocalCache('material_list_' + materialID) + '%');
  1192. showSideTools(tab.hasClass('active'));
  1193. ledgerSpread.refresh();
  1194. // leafXmjSpread.refresh();
  1195. materialSpread.refresh();
  1196. }
  1197. if (getLocalCache('material_list2_' + materialID)) {
  1198. $('.bcontent-wrap').height(getLocalCache('material_list2_' + materialID));
  1199. const cHeader = getObjHeight($(".c-header"));
  1200. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1201. $(".sp-wrap").height(bcontent-30);
  1202. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  1203. materialSpread.refresh();
  1204. ledgerSpread.refresh();
  1205. leafXmjSpread.refresh();
  1206. }
  1207. function getObjHeight(select) {
  1208. return select.length > 0 ? select.height() : 0;
  1209. }
  1210. });