material_list.js 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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, 2);
  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, 2)
  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, 2)
  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. // 解析清单汇总数据
  147. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  148. gclGatherModel.loadPosData(pos, curPosData);
  149. let gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  150. return item.qc_qty || item.contract_qty
  151. });
  152. calculateJiaCha(gclGatherData);
  153. // let gclGatherData = gclGatherModel.gatherGclData()
  154. // 获取项目节数据
  155. function loadLeafXmjData(iGclRow) {
  156. const gcl = gclGatherData[iGclRow];
  157. if (gcl) {
  158. for (const [index, xmj] of gcl.leafXmjs.entries()) {
  159. const jiacha = calcOneBQJC(xmj);
  160. gcl.leafXmjs[index].jiacha = jiacha !== 0 ? ZhCalc.round(jiacha, 2) : null;
  161. }
  162. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gcl.leafXmjs);
  163. // 对清单调差工料table的单位数量进行改变
  164. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + gcl.unit + '数量 �';
  165. // SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  166. } else {
  167. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  168. }
  169. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  170. }
  171. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  172. // 项目明细table
  173. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  174. const leafXmjSpreadSetting = {
  175. cols: [
  176. {title: '项目节|编号', colSpan: '2|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  177. {title: '|项目节名称', colSpan: '|1', rowSpan: '|1', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  178. {title: '计量单元|计量单元', colSpan: '2|1', rowSpan: '1|1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  179. {title: '|复核数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 0, width: 80, type: 'Number'},
  180. {title: '部位信息|单位工程', colSpan: '3|1', rowSpan: '1|1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  181. {title: '|分部工程', colSpan: '|1', rowSpan: '|1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  182. {title: '|分项工程', colSpan: '|1', rowSpan: '|1', field: 'fxgc', hAlign: 0, width: 180, formatter: '@'},
  183. {title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  184. {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 80, type: 'Number'},
  185. {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  186. {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'jiacha', hAlign: 2, width: 80, type: 'Number'},
  187. ],
  188. emptyRows: 0,
  189. headRows: 2,
  190. headRowHeight: [25, 25],
  191. defaultRowHeight: 21,
  192. headerFont: '12px 微软雅黑',
  193. font: '12px 微软雅黑',
  194. readOnly: true,
  195. };
  196. // const leafXmjCol = {
  197. // getValue: {
  198. // jiacha: function (data) {
  199. // let sum = 0;
  200. // const sheet = leafXmjSpread.getActiveSheet();
  201. // const select = SpreadJsObj.getSelectObject(sheet);
  202. // const notx = findNotJoinLeafXmj(select);
  203. // if (notx === undefined) {
  204. // for(const ml of materialList) {
  205. // sum = ZhCalc.round(ZhCalc.add(sum, ZhCalc.mul(ZhCalc.mul(data.gather_qty, ml.quantity), getMpSpreadByMBData(ml.mb_id))), 2);
  206. // }
  207. // }
  208. // return sum !== 0 ? sum : null;
  209. // }
  210. // }
  211. // };
  212. // SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  213. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  214. // 加载清单数据
  215. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  216. // 调差清单工料table
  217. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  218. const materialSpreadSetting = {
  219. cols: [
  220. {title: '清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  221. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  222. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  223. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  224. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  225. ],
  226. emptyRows: 0,
  227. headRows: 2,
  228. headRowHeight: [25, 25],
  229. defaultRowHeight: 21,
  230. headerFont: '12px 微软雅黑',
  231. font: '12px 微软雅黑',
  232. };
  233. const materialBase = {
  234. isEdit: function (data) {
  235. // 是否本期添加的工料
  236. return data.order === stage_order;
  237. }
  238. };
  239. const materialCol = {
  240. readOnly: {
  241. isEdit: function (data) {
  242. // const sheet = leafXmjSpread.getActiveSheet();
  243. // const select = SpreadJsObj.getSelectObject(sheet);
  244. // const notx = findNotJoinLeafXmj(select);
  245. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  246. return !(!readOnly && materialBase.isEdit(data));
  247. },
  248. },
  249. };
  250. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  251. // 获取项目节数据
  252. let materialList = [];
  253. function loadMaterialData(iGclRow, iLXmjRow) {
  254. const gcl = gclGatherData[iGclRow];
  255. if (gcl && gcl.leafXmjs[iLXmjRow]) {
  256. const xmj = gcl.leafXmjs[iLXmjRow];
  257. materialList = [];
  258. for (const m of materialListData) {
  259. 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)) {
  260. materialList.push(m);
  261. }
  262. }
  263. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialList);
  264. } else {
  265. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  266. }
  267. SpreadJsObj.reLoadSheetData(leafXmjSpread.getActiveSheet());
  268. }
  269. // SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), )
  270. loadLeafXmjData(0);
  271. loadMaterialData(0, 0);
  272. const sheet = materialSpread.getActiveSheet();
  273. sheet.suspendPaint();
  274. sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  275. sheet.resumePaint();
  276. // 不参与调差数据值变灰
  277. function checkNotJoinMaterialData() {
  278. const sheet = ledgerSpread.getActiveSheet();
  279. const select = SpreadJsObj.getSelectObject(sheet);
  280. const index = gclGatherData.indexOf(select);
  281. if (index !== -1) {
  282. const xmj = gclGatherData[index].leafXmjs;
  283. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  284. for (const [iRow,x] of xmj.entries()) {
  285. const notx = findNotJoinLeafXmj(x);
  286. const color = notx === undefined ? '' : '#d6d8db';
  287. leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
  288. }
  289. }
  290. }
  291. checkNotJoinMaterialData();
  292. // 对添加工料表格赋值
  293. function changeMaterialTable() {
  294. $('#materialBills tr').removeClass('table-secondary');
  295. $('#materialBills').find('input').removeAttr('disabled');
  296. $('#materialBills').find('input').prop('checked', false);
  297. for (const [index, ml] of materialList.entries()) {
  298. const mbIndex = materialBillsData.findIndex(function (item) {
  299. return item.id === ml.mb_id;
  300. });
  301. if (mbIndex !== -1) {
  302. $('#materialBills tr').eq(mbIndex).addClass('table-secondary');
  303. $('#materialBills').find('input').eq(mbIndex).attr('disabled', true);
  304. $('#materialBills').find('input').eq(mbIndex).prop('checked', true);
  305. }
  306. }
  307. }
  308. // 添加调差工料
  309. $('#add_material_bill').click(function () {
  310. // 获取已选工料
  311. $('#materialBills').find('input:disabled').prop('checked', false);
  312. const selectList = $('#materialBills').find('input:checked');
  313. if (selectList.length === 0) {
  314. toastr.warning('请选择调差工料');
  315. $('#materialBills').find('input:disabled').prop('checked', true);
  316. return false;
  317. }
  318. const mb_id = [];
  319. for (let s = 0; s < selectList.length; s++) {
  320. mb_id.push($('#materialBills').find('input:checked').eq(s).val());
  321. }
  322. // 获取当前项目节或部位明细id
  323. const sheet = ledgerSpread.getActiveSheet();
  324. const select = SpreadJsObj.getSelectObject(sheet);
  325. const index = gclGatherData.indexOf(select);
  326. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  327. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  328. const gcl = gclGatherData[index].leafXmjs;
  329. // const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  330. // const xmj = gcl[leafXmjIndex];
  331. // const data = {
  332. // xmj_id: xmj.id,
  333. // gcl_id: xmj.gcl_id,
  334. // mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  335. // mb_id: mb_id,
  336. // gather_qty: xmj.gather_qty,
  337. // };
  338. const datas = [];
  339. for (const xmj of gcl) {
  340. const notx = findNotJoinLeafXmj(xmj);
  341. const data = {
  342. xmj_id: xmj.id,
  343. gcl_id: xmj.gcl_id,
  344. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  345. gather_qty: xmj.gather_qty,
  346. is_join: notx === undefined ? 1 : 0,
  347. };
  348. datas.push(data);
  349. }
  350. // 上传到数据库
  351. console.log(datas, gcl);
  352. postData(window.location.pathname + '/save', {type: 'adds', postData: {xmjs: datas, mbIds: mb_id}}, function (result) {
  353. materialListData = result;
  354. // toastr.success('已成功应用');
  355. calculateJiaCha(gclGatherData);
  356. // const index = gclGatherData.indexOf(ledgerSelect);
  357. loadLeafXmjData(index);
  358. const xmjSheet = leafXmjSpread.getActiveSheet();
  359. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  360. const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  361. loadMaterialData(index, xmjIndex);
  362. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  363. $('#addgl').modal('hide');
  364. });
  365. // postData(window.location.pathname + '/save', {type: 'add', postData: data}, function (result) {
  366. // // 添加到materialList里
  367. // materialListData = result;
  368. // loadMaterialData(index, leafXmjIndex);
  369. // $('#addgl').modal('hide');
  370. // });
  371. $('#materialBills').find('input:disabled').prop('checked', true);
  372. });
  373. if (!readOnly) {
  374. const leafXmjSpreadObj = {
  375. getSelect : function () {
  376. const sheet = ledgerSpread.getActiveSheet();
  377. const select = SpreadJsObj.getSelectObject(sheet);
  378. const index = gclGatherData.indexOf(select);
  379. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  380. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  381. const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
  382. return [index, iRow, leafXmjSheet, leafXmjSelect];
  383. },
  384. checkJoinMaterial: function (type) {
  385. const [iGclRow, iRow, sheet, select] = leafXmjSpreadObj.getSelect();
  386. const color = type === 'join' ? '' : '#d6d8db';
  387. const data = {
  388. type: type,
  389. select: type === 'join' ? findNotJoinLeafXmj(select) : select,
  390. }
  391. // 添加到
  392. postData(window.location.pathname + '/save', data, function (result) {
  393. if (type === 'join') {
  394. const index = findNotJoinLeafXmj(select, 'index');
  395. notJoinList.splice(index, 1);
  396. } else {
  397. notJoinList.push(result);
  398. }
  399. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  400. calculateJiaCha(gclGatherData, iGclRow)
  401. SpreadJsObj.reLoadRowData(sheet, iRow);
  402. sheet.getRange(iRow, -1, 1, -1).backColor(color);
  403. loadMaterialData(iGclRow, iRow);
  404. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  405. });
  406. },
  407. }
  408. // leafXmj右键功能
  409. $.contextMenu({
  410. selector: '#leaf-xmj-spread',
  411. build: function ($trigger, e) {
  412. const target = SpreadJsObj.safeRightClickSelection($trigger, e, leafXmjSpread);
  413. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  414. },
  415. items: {
  416. 'stop': {
  417. name: '不参与调差',
  418. icon: 'fa-remove',
  419. callback: function (key, opt) {
  420. leafXmjSpreadObj.checkJoinMaterial('notjoin');
  421. },
  422. visible: function (key, opt) {
  423. const sheet = leafXmjSpread.getActiveSheet();
  424. const select = SpreadJsObj.getSelectObject(sheet);
  425. const sel = sheet.getSelections()[0];
  426. const notx = findNotJoinLeafXmj(select);
  427. if (!select || sel.rowCount !== 1) {
  428. return false;
  429. }
  430. if (!readOnly && select && notx === undefined) {
  431. return true;
  432. } else {
  433. return false;
  434. }
  435. }
  436. },
  437. 'start': {
  438. name: '参与调差',
  439. icon: 'fa-sign-in',
  440. callback: function (key, opt) {
  441. leafXmjSpreadObj.checkJoinMaterial('join');
  442. },
  443. visible: function (key, opt) {
  444. const sheet = leafXmjSpread.getActiveSheet();
  445. const select = SpreadJsObj.getSelectObject(sheet);
  446. const sel = sheet.getSelections()[0];
  447. const notx = findNotJoinLeafXmj(select);
  448. if (!select || sel.rowCount !== 1) {
  449. return false;
  450. }
  451. if (!readOnly && select && notx === undefined) {
  452. return false;
  453. } else {
  454. return true;
  455. }
  456. },
  457. }
  458. }
  459. });
  460. // material-spread右键功能
  461. const materialSpreadObj = {
  462. del: function () {
  463. const materialSheet = materialSpread.getActiveSheet();
  464. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  465. const sheet = ledgerSpread.getActiveSheet();
  466. const select = SpreadJsObj.getSelectObject(sheet);
  467. const index = gclGatherData.indexOf(select);
  468. const gcl = gclGatherData[index].leafXmjs;
  469. const datas = [];
  470. for (const xmj of gcl) {
  471. const data = {
  472. xmj_id: xmj.id,
  473. gcl_id: xmj.gcl_id,
  474. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  475. };
  476. datas.push(data);
  477. }
  478. console.log(datas, materialSelect.mb_id);
  479. postData(window.location.pathname + '/save', {type: 'dels', postData: { xmjs: datas, mb_id: materialSelect.mb_id }}, function (result) {
  480. materialListData = result;
  481. calculateJiaCha(gclGatherData);
  482. // const index = gclGatherData.indexOf(ledgerSelect);
  483. loadLeafXmjData(index);
  484. const xmjSheet = leafXmjSpread.getActiveSheet();
  485. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  486. const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  487. loadMaterialData(index, xmjIndex);
  488. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  489. });
  490. // postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  491. // const index = materialList.indexOf(select);
  492. // materialList.splice(index, 1);
  493. // sheet.deleteRows(index, 1);
  494. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  495. // const sel = sheet.getSelections();
  496. // sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  497. // const materialListIndex = materialListData.indexOf(select);
  498. // materialListData.splice(materialListIndex, 1);
  499. // const [iGclRow, iRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  500. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  501. // calculateJiaCha(gclGatherData, iGclRow);
  502. // SpreadJsObj.reLoadRowData(lsheet, iRow);
  503. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  504. // });
  505. },
  506. deletePress: function (sheet) {
  507. return;
  508. },
  509. editStarting: function (e, info) {
  510. const col = info.sheet.zh_setting.cols[info.col];
  511. const select = SpreadJsObj.getSelectObject(info.sheet);
  512. if (col.field === 'quantity') {
  513. if (select.expr && select.expr !== '') {
  514. info.sheet.getCell(info.row, info.col).text(select.expr);
  515. }
  516. }
  517. },
  518. editEnded: function (e, info) {
  519. if (info.sheet.zh_setting) {
  520. const select = SpreadJsObj.getSelectObject(info.sheet);
  521. const col = info.sheet.zh_setting.cols[info.col];
  522. // 未改变值则不提交
  523. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  524. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  525. // let orgValue = select[col.field];
  526. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  527. let orgValue;
  528. if (col.field === 'quantity') {
  529. orgValue = validText && validText !== ''
  530. ? _.toNumber(validText) ? select.quantity : select.expr
  531. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  532. } else {
  533. orgValue = select[col.field];
  534. }
  535. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  536. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  537. return;
  538. }
  539. const exprQuantity = {
  540. expr: '',
  541. quantity: 0,
  542. };
  543. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  544. if (!valid) {
  545. toastr.error(msg);
  546. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  547. return;
  548. }
  549. if (isNaN(exprQuantity.quantity)) {
  550. toastr.error('不能输入其它非数字类型字符');
  551. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  552. return;
  553. }
  554. const num = parseFloat(exprQuantity.quantity);
  555. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  556. toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  557. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  558. return;
  559. }
  560. // 更新至服务器
  561. const ledgerSheet = ledgerSpread.getActiveSheet();
  562. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  563. const index = gclGatherData.indexOf(ledgerSelect);
  564. const gcl = gclGatherData[index].leafXmjs;
  565. const datas = [];
  566. for (const xmj of gcl) {
  567. const data = {
  568. xmj_id: xmj.id,
  569. gcl_id: xmj.gcl_id,
  570. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  571. };
  572. datas.push(data);
  573. }
  574. console.log(exprQuantity, datas, select.mb_id);
  575. postData(window.location.pathname + '/save', { type:'updates', updateData: { xmjs: datas, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id } }, function (result) {
  576. materialListData = result;
  577. calculateJiaCha(gclGatherData);
  578. // const index = gclGatherData.indexOf(ledgerSelect);
  579. loadLeafXmjData(index);
  580. const xmjSheet = leafXmjSpread.getActiveSheet();
  581. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  582. const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  583. loadMaterialData(index, xmjIndex);
  584. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  585. }, function () {
  586. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  587. });
  588. // postData(window.location.pathname + '/save', { type:'update', updateData: { id:select.id, quantity: validText, mb_id: select.mb_id } }, function (result) {
  589. // const materialListIndex = materialListData.indexOf(select);
  590. // const index = materialList.indexOf(select);
  591. // select[col.field] = validText;
  592. // materialListData.splice(materialListIndex, 1, select);
  593. // materialList.indexOf(index, 1, select);
  594. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  595. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  596. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  597. // calculateJiaCha(gclGatherData, iGclRow)
  598. // SpreadJsObj.reLoadRowData(sheet, iRow);
  599. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  600. // }, function () {
  601. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  602. // });
  603. }
  604. },
  605. clipboardPasted(e, info) {
  606. const hint = {
  607. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  608. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  609. numberCan: {type: 'error', msg: '请粘贴大于0并且小于6位小数的浮点数'},
  610. };
  611. const range = info.cellRange;
  612. const sortData = info.sheet.zh_data || [];
  613. if (range.row + range.rowCount > sortData.length) {
  614. toastMessageUniq(hint.cellError);
  615. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  616. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  617. return;
  618. }
  619. if (sortData.length > 0 && range.col + range.colCount > 5) {
  620. toastMessageUniq(hint.cellError);
  621. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  622. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  623. return;
  624. }
  625. const data = [];
  626. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  627. let bPaste = true;
  628. const curRow = range.row + iRow;
  629. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  630. const hintRow = range.rowCount > 1 ? curRow : '';
  631. let sameCol = 0;
  632. for (let iCol = 0; iCol < range.colCount; iCol++) {
  633. const curCol = range.col + iCol;
  634. const colSetting = info.sheet.zh_setting.cols[curCol];
  635. if (!colSetting) continue;
  636. // let validText = info.sheet.getText(curRow, curCol);
  637. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  638. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  639. const orgValue = sortData[curRow][colSetting.field];
  640. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  641. sameCol++;
  642. if (range.colCount === sameCol) {
  643. bPaste = false;
  644. }
  645. continue;
  646. }
  647. const exprQuantity = {
  648. expr: '',
  649. quantity: 0,
  650. };
  651. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  652. if (!valid) {
  653. toastMessageUniq(getPasteHint(msg, hintRow));
  654. bPaste = false;
  655. continue;
  656. }
  657. if (isNaN(exprQuantity.quantity)) {
  658. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  659. bPaste = false;
  660. continue;
  661. }
  662. const num = parseFloat(exprQuantity.quantity);
  663. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  664. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  665. bPaste = false;
  666. continue;
  667. }
  668. // materialData[colSetting.field] = validText;
  669. materialData.expr = exprQuantity.expr;
  670. materialData.quantity = exprQuantity.quantity;
  671. }
  672. if (bPaste) {
  673. data.push(materialData);
  674. // rowData.push(curRow);
  675. } else {
  676. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  677. }
  678. }
  679. if (data.length === 0) {
  680. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  681. return;
  682. }
  683. const ledgerSheet = ledgerSpread.getActiveSheet();
  684. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  685. const index = gclGatherData.indexOf(ledgerSelect);
  686. const gcl = gclGatherData[index].leafXmjs;
  687. const datas = [];
  688. for (const xmj of gcl) {
  689. const data2 = {
  690. xmj_id: xmj.id,
  691. gcl_id: xmj.gcl_id,
  692. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  693. };
  694. datas.push(data2);
  695. }
  696. console.log(data, datas);
  697. // 更新至服务器
  698. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data } }, function (result) {
  699. materialListData = result;
  700. calculateJiaCha(gclGatherData);
  701. // const index = gclGatherData.indexOf(ledgerSelect);
  702. loadLeafXmjData(index);
  703. const xmjSheet = leafXmjSpread.getActiveSheet();
  704. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  705. const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  706. loadMaterialData(index, xmjIndex);
  707. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  708. }, function () {
  709. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  710. });
  711. // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  712. // materialListData = result;
  713. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  714. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  715. // calculateJiaCha(gclGatherData, iGclRow);
  716. // SpreadJsObj.reLoadRowData(sheet, iRow);
  717. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  718. // }, function () {
  719. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  720. // });
  721. },
  722. _checkExprValid(expr) {
  723. if (!expr) return [true, null];
  724. const param = [];
  725. let num = '', base = '';
  726. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  727. if (/^[\d\.%]+/.test(expr[i])) {
  728. if (base !== '') {
  729. param.push({type: 'base', value: base});
  730. base = '';
  731. }
  732. num = num + expr[i];
  733. } else if (expr[i] === '(') {
  734. if (num !== '') {
  735. param.push({type: 'num', value: num});
  736. num = '';
  737. }
  738. if (base !== '') {
  739. param.push({type: 'base', value: base});
  740. base = '';
  741. }
  742. param.push({type: 'left', value: '('});
  743. } else if (expr[i] === ')') {
  744. if (num !== '') {
  745. param.push({type: 'num', value: num});
  746. num = '';
  747. }
  748. if (base !== '') {
  749. param.push({type: 'base', value: base});
  750. base = '';
  751. }
  752. param.push({type: 'right', value: ')'});
  753. } else if (/^[\+\-*\/]/.test(expr[i])) {
  754. if (num !== '') {
  755. param.push({type: 'num', value: num});
  756. num = '';
  757. }
  758. if (base !== '') {
  759. param.push({type: 'base', value: base});
  760. base = '';
  761. }
  762. param.push({type: 'calc', value: expr[i]});
  763. } else {
  764. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  765. }
  766. }
  767. if (num !== '') {
  768. param.push({type: 'num', value: num});
  769. num = '';
  770. }
  771. if (base !== '') {
  772. param.push({type: 'base', value: base});
  773. base = '';
  774. }
  775. if (param.length === 0) return true;
  776. if (param.length > 1) {
  777. if (param[0].value === '-') {
  778. param[1].value = '-' + param[1];
  779. }
  780. param.unshift();
  781. }
  782. const iLen = param.length;
  783. let iLeftCount = 0, iRightCount = 0;
  784. for (const [i, p] of param.entries()) {
  785. if (p.type === 'calc') {
  786. if (i === 0 || i === iLen - 1)
  787. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  788. }
  789. if (p.type === 'num') {
  790. num = p.value.replace('%', '');
  791. if (p.value.length - num.length > 1)
  792. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  793. num = _.toNumber(num);
  794. if (num === undefined || num === null || _.isNaN(num))
  795. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  796. if (i > 0) {
  797. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  798. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  799. } else if (param[i - 1].value === '/' && num === 0) {
  800. return [false, '输入的表达式非法:请勿除0'];
  801. }
  802. }
  803. }
  804. if (p.type === 'base') {
  805. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  806. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  807. }
  808. if (p.type === 'left') {
  809. iLeftCount += 1;
  810. if (i !== 0 && param[i-1].type !== 'calc')
  811. return [false, '输入的表达式非法:(前应有运算符'];
  812. }
  813. if (p.type === 'right') {
  814. iRightCount += 1;
  815. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  816. return [false, '输入的表达式非法:)后应有运算符'];
  817. if (iRightCount > iLeftCount)
  818. return [false, '输入的表达式非法:")"前无对应的"("'];
  819. }
  820. }
  821. if (iLeftCount > iRightCount)
  822. return [false, '输入的表达式非法:"("后无对应的")"'];
  823. return [true, ''];
  824. },
  825. _checkExpr: function (text, data) {
  826. if (text) {
  827. const num = _.toNumber(text);
  828. if (num) {
  829. data.quantity = num;
  830. data.expr = '';
  831. } else {
  832. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  833. const [valid, msg] = this._checkExprValid(expr);
  834. if (!valid) return [valid, msg];
  835. data.expr = expr;
  836. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr);
  837. // const ce = new CalcEvalMin();
  838. // data.quantity = ce.eval(expr);
  839. // console.log(data.quantity);
  840. }
  841. } else {
  842. data.quantity = 0;
  843. data.expr = '';
  844. }
  845. return [true, ''];
  846. },
  847. };
  848. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  849. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  850. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  851. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  852. // 应用调差工料至其他清单明细
  853. $('#user_all_material').click(function () {
  854. const ledgerSheet = ledgerSpread.getActiveSheet();
  855. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  856. if (ledgerSelect.leafXmjs.length < 2) {
  857. toastr.warning('没有需要应用调差工料的其它清单明细');
  858. return false;
  859. }
  860. const xmjSheet = leafXmjSpread.getActiveSheet();
  861. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  862. // 判断需要应用调差工料的清单明细
  863. const needAddList = [];
  864. for (const xmj of ledgerSelect.leafXmjs) {
  865. const notx = findNotJoinLeafXmj(xmj);
  866. if (notx === undefined && xmjSelect !== xmj) {
  867. needAddList.push(xmj);
  868. }
  869. }
  870. if (needAddList.length === 0) {
  871. toastr.warning('没有需要应用调差工料的其它清单明细');
  872. return false;
  873. }
  874. console.log(needAddList, materialList);
  875. // 更新至服务器
  876. // postData(window.location.pathname + '/save', { type:'useOther', postData: { addXmj: needAddList, materialBills: materialList } }, function (result) {
  877. // materialListData = result;
  878. // toastr.success('已成功应用');
  879. // calculateJiaCha(gclGatherData);
  880. // const index = gclGatherData.indexOf(ledgerSelect);
  881. // loadLeafXmjData(index);
  882. // const xmjSheet = leafXmjSpread.getActiveSheet();
  883. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  884. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  885. // loadMaterialData(index, xmjIndex);
  886. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  887. // });
  888. });
  889. $.contextMenu({
  890. selector: '#material-spread',
  891. build: function ($trigger, e) {
  892. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  893. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  894. },
  895. items: {
  896. 'create': {
  897. name: '添加工料',
  898. icon: 'fa-sign-in',
  899. callback: function (key, opt) {
  900. // 获取已选清单
  901. changeMaterialTable();
  902. $('#addgl').modal('show');
  903. },
  904. disabled: function (key, opt) {
  905. const sheet = leafXmjSpread.getActiveSheet();
  906. const select = SpreadJsObj.getSelectObject(sheet);
  907. // const notx = findNotJoinLeafXmj(select);
  908. if (!select) {
  909. return true;
  910. }
  911. // if (!readOnly && notx === undefined) {
  912. // return false;
  913. // } else {
  914. // return true;
  915. // }
  916. return readOnly;
  917. }
  918. },
  919. 'delete': {
  920. name: '删除工料',
  921. icon: 'fa-remove',
  922. callback: function (key, opt) {
  923. materialSpreadObj.del(materialSpread.getActiveSheet());
  924. },
  925. disabled: function (key, opt) {
  926. const sheet = materialSpread.getActiveSheet();
  927. const select = SpreadJsObj.getSelectObject(sheet);
  928. if (!select) {
  929. return true;
  930. }
  931. if (!readOnly && select && materialBase.isEdit(select)) {
  932. return false;
  933. } else {
  934. return true;
  935. }
  936. }
  937. },
  938. }
  939. });
  940. }
  941. // 切换清单行,读取所属项目节数据
  942. ledgerSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  943. if (info.oldSelections !== undefined) {
  944. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  945. if (iNewRow !== iOldRow) {
  946. loadLeafXmjData(iNewRow);
  947. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  948. loadMaterialData(iNewRow, 0);
  949. checkNotJoinMaterialData();
  950. }
  951. }
  952. });
  953. // 切换项目节数据清单明细行,读取已调用的清单工料数据
  954. leafXmjSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  955. if (info.oldSelections !== undefined) {
  956. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  957. if (iNewRow !== iOldRow) {
  958. const sheet = ledgerSpread.getActiveSheet();
  959. const select = SpreadJsObj.getSelectObject(sheet);
  960. const index = gclGatherData.indexOf(select);
  961. loadMaterialData(index, iNewRow);
  962. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  963. }
  964. }
  965. });
  966. // 显示有调差工料清单
  967. $('#show_material_gcl').click(function () {
  968. if ($(this).is(':checked')) {
  969. const hadMaterialGclGatherData = [];
  970. const hadGclIdList = [];
  971. for (const ml of materialListData) {
  972. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  973. hadGclIdList.push(ml.gcl_id);
  974. }
  975. }
  976. for (const gcl of gclGatherData) {
  977. for (const index in gcl.leafXmjs) {
  978. const gcl_id = gcl.leafXmjs[index].gcl_id;
  979. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  980. hadMaterialGclGatherData.push(gcl);
  981. break;
  982. }
  983. }
  984. }
  985. gclGatherData = hadMaterialGclGatherData;
  986. } else {
  987. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  988. gclGatherModel.loadPosData(pos, curPosData);
  989. gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  990. return item.qc_qty || item.contract_qty
  991. });
  992. }
  993. calculateJiaCha(gclGatherData);
  994. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  995. loadLeafXmjData(0);
  996. loadMaterialData(0, 0);
  997. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  998. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  999. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  1000. checkNotJoinMaterialData();
  1001. });
  1002. $.subMenu({
  1003. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1004. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1005. key: 'menu.1.0.0',
  1006. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1007. callback: function (info) {
  1008. if (info.mini) {
  1009. $('.panel-title').addClass('fluid');
  1010. $('#sub-menu').removeClass('panel-sidebar');
  1011. } else {
  1012. $('.panel-title').removeClass('fluid');
  1013. $('#sub-menu').addClass('panel-sidebar');
  1014. }
  1015. autoFlashHeight();
  1016. ledgerSpread.refresh();
  1017. leafXmjSpread.refresh();
  1018. materialSpread.refresh();
  1019. }
  1020. });
  1021. $.divResizer({
  1022. select: '#right-spr',
  1023. callback: function () {
  1024. ledgerSpread.refresh();
  1025. // leafXmjSpread.refresh();
  1026. materialSpread.refresh();
  1027. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1028. setLocalCache('material_list_' + materialID, width);
  1029. }
  1030. });
  1031. // 展开收起月信息价并浏览器记住本期展开收起
  1032. $('a', '.right-nav').bind('click', function () {
  1033. //const main = $('#main-view'), tool = $('#tools-view');
  1034. const tab = $(this), tabPanel = $(tab.attr('content'));
  1035. if (!tab.hasClass('active')) {
  1036. $('a', '.side-menu').removeClass('active');
  1037. $('.tab-content .tab-select-show').removeClass('active');
  1038. tab.addClass('active');
  1039. tabPanel.addClass('active');
  1040. showSideTools(tab.hasClass('active'));
  1041. if (tab.attr('content') === '#material-tab') {
  1042. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1043. setLocalCache('material_list_' + materialID, width);
  1044. }
  1045. } else {
  1046. removeLocalCache('material_list_' + materialID);
  1047. tab.removeClass('active');
  1048. tabPanel.removeClass('active');
  1049. showSideTools(tab.hasClass('active'));
  1050. }
  1051. ledgerSpread.refresh();
  1052. // leafXmjSpread.refresh();
  1053. materialSpread.refresh();
  1054. });
  1055. // 根据浏览器记录展开收起
  1056. if (getLocalCache('material_list_' + materialID)) {
  1057. const tab = $('.right-nav a[content="#material-tab"]'), tabPanel = $(tab.attr('content'));
  1058. $('a', '.side-menu').removeClass('active');
  1059. $('.tab-content .tab-select-show').removeClass('active');
  1060. tab.addClass('active');
  1061. tabPanel.addClass('active');
  1062. $('#right-view').width(getLocalCache('material_list_' + materialID) + '%');
  1063. showSideTools(tab.hasClass('active'));
  1064. ledgerSpread.refresh();
  1065. // leafXmjSpread.refresh();
  1066. materialSpread.refresh();
  1067. }
  1068. });