material_checklist.js 54 KB

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