material_checklist.js 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535
  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 findNotChangeLeafXmj(x, type = '') {
  23. if (type === 'index') {
  24. return notChangeList.findIndex(function (item) {
  25. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  26. });
  27. }
  28. return notChangeList.find(function (item) {
  29. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  30. });
  31. }
  32. function getPasteHint (str, row = '') {
  33. let returnObj = str;
  34. if (row) {
  35. returnObj.msg = '清单第' + (row+1) + '行' + (str.msg ? str.msg : str);
  36. }
  37. return returnObj;
  38. }
  39. function makeChecklistData(lists, checklists) {
  40. let html = '';
  41. if (lists.length > 0) {
  42. for(const [i,l] of lists.entries()) {
  43. const checklistInfo = _.find(checklists, { b_code: l.b_code, name: l.name, unit: l.unit, unit_price: l.unit_price });
  44. const isChecked = checklistInfo ? ' checked' : '';
  45. const isDisabled = checklistInfo && checklistInfo.had_bills === 1 ? ' disabled' : '';
  46. html += '<tr>\n' +
  47. ' <td><div class="text-center custom-control custom-checkbox mb-2">\n' +
  48. ' <input type="checkbox" id="lists_'+ i +'" value="'+ i +'" name="customCheckbox" class="custom-control-input"'+ isChecked + isDisabled +'>\n' +
  49. ' <label class="custom-control-label" for="lists_'+ i +'"></label>\n' +
  50. ' </div></td>\n' +
  51. ' <td class="text-center">'+ (i+1) +'</td>\n' +
  52. ' <td>'+ l.b_code +'</td>\n' +
  53. ' <td>'+ l.name +'</td>\n' +
  54. ' <td class="text-center">'+ (l.unit ? l.unit : '') +'</td>\n' +
  55. ' <td class="text-right">'+ (l.unit_price ? l.unit_price : '') +'</td>\n' +
  56. ' <td class="text-right">'+ (l.quantity ? l.quantity : '') +'</td>\n' +
  57. ' <td class="text-right">'+ (l.total_price ? l.total_price : '') +'</td>\n' +
  58. ' </tr>';
  59. }
  60. }
  61. $('#lists_data').html(html);
  62. }
  63. // 清单搜索隐藏清单table部分值
  64. function remakeChecklistData(lists, showListData = lists) {
  65. // 先加载台账数据
  66. if (lists.length > 0) {
  67. for (const [index,gcl] of lists.entries()) {
  68. const isShow = _.find(showListData, gcl);
  69. $('#lists_data tr').eq(index).css('display', (isShow ? 'table-row' : 'none'));
  70. }
  71. }
  72. }
  73. $(document).ready(() => {
  74. function TipCellType()
  75. {
  76. }
  77. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.ColumnHeader();
  78. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  79. return { x: x, y: y, row: context.row, col: context.col, cellRect: cellRect, sheetArea: context.sheetArea, sheet: context.sheet };
  80. };
  81. TipCellType.prototype.processMouseEnter = function (hitInfo){
  82. if (!this._toolTipElement) {
  83. var div = document.createElement("div");
  84. $(div).css("position", "absolute")
  85. .css("border", "1px #C0C0C0 solid")
  86. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  87. .css("font", "9pt Arial")
  88. .css("background", "#fff")
  89. // .css("color", "#fff")
  90. .css("z-index", "1000")
  91. .css("padding", 5);
  92. this._toolTipElement = div;
  93. }
  94. $(this._toolTipElement).text("单位数量:每一单位清单下所需工料消耗量。")
  95. .css("top", hitInfo.y + 15)
  96. .css("left", hitInfo.x - 15);
  97. $(this._toolTipElement).hide();
  98. // document.body.insertBefore(this._toolTipElement, null);
  99. $('#material-spread-div').append(this._toolTipElement, null);
  100. $(this._toolTipElement).show("fast");
  101. };
  102. TipCellType.prototype.processMouseLeave = function (hitInfo) {
  103. if (this._toolTipElement) {
  104. this._toolTipElement.remove();
  105. this._toolTipElement = null;
  106. }
  107. };
  108. autoFlashHeight();
  109. // 清单table
  110. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  111. const ledgerSpreadSetting = {
  112. cols: [
  113. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  114. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 220, formatter: '@'},
  115. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  116. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 70, type: 'Number'},
  117. {title: '工程量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 90, type: 'Number'},
  118. {title: '台账金额', colSpan: '1', rowSpan: '2', field: 'total_price', hAlign: 2, width: 110, type: 'Number'},
  119. ],
  120. emptyRows: 0,
  121. headRows: 1,
  122. headRowHeight: [25, 25],
  123. defaultRowHeight: 21,
  124. headerFont: '12px 微软雅黑',
  125. font: '12px 微软雅黑',
  126. readOnly: true,
  127. };
  128. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  129. // 加载清单数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  130. postData(window.location.pathname + '/load', { sid: isStageSelf ? materialStageData[0].sid : null }, function (result) {
  131. ledger = result.ledger;
  132. curLedgerData = result.curLedgerData;
  133. pos = result.pos;
  134. curPosData = result.curPosData;
  135. // materialListData = result.materialListData;
  136. notJoinList = result.materialNotJoinListData;
  137. notChangeList = result.materialNotChangeListData;
  138. materialChecklistData = result.materialChecklistData;
  139. gclList = result.gclList;
  140. if (isStageSelf) {
  141. // updateBillsData(ms_id);
  142. const newGclGatherListData = [];
  143. for (const [index, s] of result.ledgerListData.entries()) {
  144. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), s);
  145. gclGatherModel.loadPosData(_.cloneDeep(pos), result.posListData[index]);
  146. const oneGclGatherData = gclGatherModel.gatherGclData().filter(item => {
  147. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  148. });
  149. newGclGatherListData.push(oneGclGatherData);
  150. }
  151. gclGatherListData = newGclGatherListData;
  152. }
  153. // 解析清单汇总数据
  154. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  155. gclGatherModel.loadPosData(pos, curPosData);
  156. // gclGatherData = gclGatherModel.gatherGclData().filter(function (item) {
  157. // return item.unit_price || item.quantity;
  158. // });
  159. gclGatherData = gclGatherModel.gatherGclData();
  160. console.log(gclGatherData);
  161. const hadBillsidList = _.uniq(_.map(gclList, 'gcl_id'));
  162. console.log(hadBillsidList, materialChecklistData);
  163. // 对比清单设置和调差清单,还要和台账对比,显示已选清单列表 不同则更新到清单设置页中
  164. const pushData = [];
  165. const updateData = [];
  166. for (const hb of hadBillsidList) {
  167. const gcl = _.find(gclGatherData, function (item) {
  168. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, { gcl_id : hb }) !== -1;
  169. });
  170. if (gcl) {
  171. const mc = _.find(materialChecklistData, { b_code: gcl.b_code, name: gcl.name, unit: gcl.unit, unit_price: gcl.unit_price });
  172. // const newOrder = _.indexOf(gclGatherData, gcl);
  173. // console.log(newOrder);
  174. if (!mc && _.findIndex(pushData, { b_code: gcl.b_code, name: gcl.name, unit: gcl.unit, unit_price: gcl.unit_price }) === -1) {
  175. 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 });
  176. }
  177. }
  178. }
  179. const removeData = [];
  180. for (const mc of materialChecklistData) {
  181. const gcl = _.find(gclGatherData, { b_code: mc.b_code, name: mc.name, unit: mc.unit, unit_price: mc.unit_price });
  182. // 判断是否已不存在工料清单,台账修改过后删除之
  183. if (!gcl) {
  184. removeData.push(mc.id);
  185. } else {
  186. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  187. const jiaoji = _.intersection(gcl_ids, hadBillsidList);
  188. // const leafXmjs = gcl.leafXmjs ? gcl.leafXmjs.filter(item => item.gather_qty) : [];
  189. // 更新had_bills值
  190. const updateObj = { id: mc.id };
  191. if (mc.had_bills === 1) {
  192. if (jiaoji.length === 0) {
  193. updateObj.mid = materialID;
  194. updateObj.had_bills = 0;
  195. // updateData.push({ id: mc.id, mid: materialID, had_bills: 0 });
  196. }
  197. } else if (mc.had_bills === 0) {
  198. if (jiaoji.length !== 0) {
  199. updateObj.had_bills = 1;
  200. }
  201. }
  202. // 更新工程量及台账金额
  203. if (mc.quantity !== (gcl.quantity ? gcl.quantity : null)) {
  204. updateObj.quantity = gcl.quantity ? gcl.quantity : null;
  205. updateObj.total_price = gcl.total_price ? gcl.total_price : null;
  206. }
  207. if(!_.isEqual(updateObj,{ id: mc.id })) updateData.push(updateObj);
  208. }
  209. }
  210. console.log(pushData, removeData, updateData);
  211. setChecklistData(pushData, removeData, updateData, true);
  212. });
  213. function setChecklistData(pushData, removeData, updateData = [], sendmsg = false) {
  214. if (pushData.length > 0 || removeData.length > 0 || updateData.length > 0) {
  215. postData(window.location.pathname + '/save', { type: 'resetChecklist', pushData, removeData, updateData }, function (result2) {
  216. if (sendmsg && pushData.length > 0) {
  217. toastr.success('已同步历史调差清单数据至本页中');
  218. }
  219. if (sendmsg && removeData.length > 0) {
  220. toastr.warning('已删除部分与台账清单不匹配的清单数据');
  221. }
  222. materialChecklistData = result2;
  223. showSjsData();
  224. })
  225. } else {
  226. showSjsData();
  227. }
  228. }
  229. function showSjsData() {
  230. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialChecklistData);
  231. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  232. if (materialChecklistData.length > 0) {
  233. const index = _.findIndex(gclGatherData, { b_code: materialChecklistData[0].b_code, name: materialChecklistData[0].name, unit: materialChecklistData[0].unit, unit_price: materialChecklistData[0].unit_price });
  234. loadMaterialData(index, 0);
  235. } else {
  236. loadMaterialData(-1, 0);
  237. }
  238. const sheet = materialSpread.getActiveSheet();
  239. sheet.suspendPaint();
  240. sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  241. sheet.resumePaint();
  242. }
  243. // 调差清单工料table
  244. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  245. const materialSpreadSetting = {
  246. cols: [
  247. {title: '清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  248. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  249. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  250. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  251. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  252. ],
  253. emptyRows: 0,
  254. headRows: 2,
  255. headRowHeight: [25, 25],
  256. defaultRowHeight: 21,
  257. headerFont: '12px 微软雅黑',
  258. font: '12px 微软雅黑',
  259. };
  260. const materialBase = {
  261. isEdit: function (data) {
  262. // 是否本期添加的工料
  263. return data.order === stage_order;
  264. }
  265. };
  266. const materialCol = {
  267. readOnly: {
  268. isEdit: function (data) {
  269. // return !(!readOnly && materialBase.isEdit(data));
  270. return readOnly;
  271. },
  272. },
  273. };
  274. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  275. // 获取项目节数据
  276. let materialList = [];
  277. function loadMaterialData(iGclRow, iLXmjRow) {
  278. const gcl = gclGatherData[iGclRow];
  279. // const leafXmjs = gcl && gcl.leafXmjs ? gcl.leafXmjs.filter(item => {
  280. // return item.qc_qty || item.contract_qty
  281. // }) : null;
  282. if (gcl && gcl.leafXmjs) {
  283. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  284. // const xmj2 = gcl.leafXmjs[iLXmjRow];
  285. materialList = [];
  286. const newMaterialList = _.uniqBy(_.filter(gclList, function (m) {
  287. return _.indexOf(gcl_ids, m.gcl_id) !== -1;
  288. }), 'mb_id');
  289. for(const m of newMaterialList) {
  290. const bills = _.find(materialBillsData, { id: m.mb_id });
  291. if(bills) {
  292. m.code = bills.code;
  293. m.name = bills.name;
  294. m.unit = bills.unit;
  295. }
  296. }
  297. console.log(newMaterialList);
  298. materialList = newMaterialList;
  299. // const leafXmjs = gcl.leafXmjs.filter(item => {
  300. // return item.qc_qty || item.contract_qty
  301. // });
  302. // const xmj = leafXmjs[iLXmjRow];
  303. // materialList = _.filter(materialListData, function (m) {
  304. // 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);
  305. // });
  306. // 对清单调差工料table的单位数量进行改变
  307. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  308. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  309. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialList);
  310. } else {
  311. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '数量 �';
  312. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  313. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  314. }
  315. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  316. }
  317. // 对添加工料表格赋值
  318. function changeMaterialTable() {
  319. $('#materialBills tr').removeClass('table-secondary');
  320. $('#materialBills').find('input').removeAttr('disabled');
  321. $('#materialBills').find('input').prop('checked', false);
  322. for (const ml of materialList) {
  323. const mbIndex = _.findIndex(materialBillsData, {id : ml.mb_id });
  324. if (mbIndex !== -1) {
  325. $('#materialBills tr').eq(mbIndex).addClass('table-secondary');
  326. $('#materialBills').find('input').eq(mbIndex).attr('disabled', true);
  327. $('#materialBills').find('input').eq(mbIndex).prop('checked', true);
  328. }
  329. }
  330. }
  331. // 选中清单并添加
  332. $('#set_checklist_btn').click(function () {
  333. const select_checklist = $('#lists_data').find('input:checked:not(:disabled)');
  334. const pushData = [];
  335. for (const sc of select_checklist) {
  336. const order = parseInt($(sc).val());
  337. const checklistInfo = _.find(materialChecklistData, { b_code: gclGatherData[order].b_code, name: gclGatherData[order].name, unit: gclGatherData[order].unit, unit_price: gclGatherData[order].unit_price });
  338. if (!checklistInfo) {
  339. pushData.push({
  340. b_code: gclGatherData[order].b_code,
  341. name: gclGatherData[order].name,
  342. unit: gclGatherData[order].unit,
  343. unit_price: gclGatherData[order].unit_price,
  344. quantity: gclGatherData[order].quantity ? gclGatherData[order].quantity : null,
  345. total_price: gclGatherData[order].total_price ? gclGatherData[order].total_price : null,
  346. had_bills: 0,
  347. })
  348. }
  349. }
  350. const notSelect_checklist = $('#lists_data').find('input:not(:checked):not(:disabled)');
  351. const removeData = [];
  352. for (const nsc of notSelect_checklist) {
  353. const order = parseInt($(nsc).val());
  354. // const order = parseInt($(nsc).attr('data-index'));
  355. const checklistInfo = _.find(materialChecklistData, { b_code: gclGatherData[order].b_code, name: gclGatherData[order].name, unit: gclGatherData[order].unit, unit_price: gclGatherData[order].unit_price });
  356. if (checklistInfo) {
  357. removeData.push(checklistInfo.id);
  358. }
  359. }
  360. setChecklistData(pushData, removeData);
  361. $('#addtclist').modal('hide');
  362. });
  363. // 筛选无调差工料清单
  364. $('#notBills_checkList').click(function () {
  365. const isCheck = $(this).is(':checked');
  366. let newMaterialChecklistData = materialChecklistData;
  367. if (isCheck) {
  368. $('#bills0_checkList').prop('checked', false);
  369. newMaterialChecklistData = _.filter(materialChecklistData, { had_bills: 0 });
  370. }
  371. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialChecklistData);
  372. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  373. if (newMaterialChecklistData.length > 0) {
  374. const index = _.findIndex(gclGatherData, { b_code: newMaterialChecklistData[0].b_code, name: newMaterialChecklistData[0].name, unit: newMaterialChecklistData[0].unit, unit_price: newMaterialChecklistData[0].unit_price });
  375. loadMaterialData(index, 0);
  376. } else {
  377. loadMaterialData(-1, 0);
  378. }
  379. });
  380. // 筛选调差工料清单为0
  381. $('#bills0_checkList').click(function () {
  382. const isCheck = $(this).is(':checked');
  383. let newMaterialChecklistData = materialChecklistData;
  384. if (isCheck) {
  385. newMaterialChecklistData = [];
  386. $('#notBills_checkList').prop('checked', false);
  387. const materialList0 = _.uniq(_.map(_.filter(gclList, { quantity: 0 }), 'gcl_id'));
  388. if (materialList0.length > 0) {
  389. const hadMaterialChecklistData = _.filter(materialChecklistData, { had_bills: 1 });
  390. for (const h of hadMaterialChecklistData) {
  391. const gcl = _.find(gclGatherData, { b_code: h.b_code, name: h.name, unit: h.unit, unit_price: h.unit_price });
  392. if (gcl && gcl.leafXmjs.length > 0 && _.indexOf(materialList0, gcl.leafXmjs[0].gcl_id) !== -1) {
  393. newMaterialChecklistData.push(h);
  394. }
  395. }
  396. }
  397. }
  398. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialChecklistData);
  399. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  400. if (newMaterialChecklistData.length > 0) {
  401. const index = _.findIndex(gclGatherData, { b_code: newMaterialChecklistData[0].b_code, name: newMaterialChecklistData[0].name, unit: newMaterialChecklistData[0].unit, unit_price: newMaterialChecklistData[0].unit_price });
  402. loadMaterialData(index, 0);
  403. } else {
  404. loadMaterialData(-1, 0);
  405. }
  406. });
  407. // 添加调差工料
  408. $('#add_material_bill').click(function () {
  409. // 获取已选工料
  410. $('#materialBills').find('input:disabled').prop('checked', false);
  411. const selectList = $('#materialBills').find('input:checked');
  412. if (selectList.length === 0) {
  413. toastr.warning('请选择调差工料');
  414. $('#materialBills').find('input:disabled').prop('checked', true);
  415. return false;
  416. }
  417. const mb_id = [];
  418. for (let s = 0; s < selectList.length; s++) {
  419. mb_id.push($('#materialBills').find('input:checked').eq(s).val());
  420. }
  421. // 获取当前项目节或部位明细id
  422. const sheet = ledgerSpread.getActiveSheet();
  423. const select = SpreadJsObj.getSelectObject(sheet);
  424. const gclIndex = _.findIndex(gclGatherData, { b_code: select.b_code, name: select.name, unit: select.unit, unit_price: select.unit_price });
  425. const gcl = gclGatherData[gclIndex].leafXmjs;
  426. const ms_id = isStageSelf ? materialStageData[0].id : null;
  427. const index = materialChecklistData.indexOf(select);
  428. const datas = [];
  429. for (const xmj of gcl) {
  430. const notx = findNotJoinLeafXmj(xmj);
  431. const notx2 = findNotChangeLeafXmj(xmj);
  432. const data = {
  433. xmj_id: xmj.id,
  434. gcl_id: xmj.gcl_id,
  435. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  436. contract_qty: xmj.contract_qty,
  437. qc_qty: xmj.qc_qty,
  438. qc_minus_qty: xmj.qc_minus_qty,
  439. gather_qty: xmj.gather_qty,
  440. is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
  441. };
  442. if (ms_id) data.ms_id = ms_id;
  443. datas.push(data);
  444. }
  445. if (isStageSelf) {
  446. // 取所有的gclGatherData才行,然后获取下的值
  447. const gclData = gclGatherData[gclIndex];
  448. for (const [index, ms] of materialStageData.entries()) {
  449. if (ms.id !== ms_id) {
  450. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  451. if (gclOther) {
  452. const leafXmjs = gclOther.leafXmjs.filter(item => {
  453. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  454. });
  455. for (const xmj of leafXmjs) {
  456. const notx = findNotJoinLeafXmj(xmj);
  457. const notx2 = findNotChangeLeafXmj(xmj);
  458. const data = {
  459. xmj_id: xmj.id,
  460. gcl_id: xmj.gcl_id,
  461. mx_id: xmj.mx_id ? xmj.mx_id : '',
  462. contract_qty: xmj.contract_qty,
  463. qc_qty: xmj.qc_qty,
  464. qc_minus_qty: xmj.qc_minus_qty,
  465. gather_qty: xmj.gather_qty,
  466. is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
  467. ms_id: ms.id,
  468. };
  469. datas.push(data);
  470. }
  471. }
  472. }
  473. }
  474. }
  475. // 上传到数据库
  476. console.log(datas, gcl);
  477. postData(window.location.pathname + '/save', {type: 'adds', checklist: { id: select.id, had_bills: 1 }, postData: {xmjs: datas, mbIds: mb_id}}, function (result) {
  478. // materialListData = result;
  479. gclList = result;
  480. materialChecklistData[index].had_bills = 1;
  481. loadMaterialData(gclIndex, 0);
  482. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  483. $('#addgl').modal('hide');
  484. });
  485. $('#materialBills').find('input:disabled').prop('checked', true);
  486. });
  487. if (!readOnly) {
  488. // material-spread右键功能
  489. const materialSpreadObj = {
  490. del: function () {
  491. const materialSheet = materialSpread.getActiveSheet();
  492. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  493. const sheet = ledgerSpread.getActiveSheet();
  494. const select = SpreadJsObj.getSelectObject(sheet);
  495. const index = materialChecklistData.indexOf(select);
  496. const gclIndex = _.findIndex(gclGatherData, { b_code: select.b_code, name: select.name, unit: select.unit, unit_price: select.unit_price });
  497. const gcl = gclGatherData[gclIndex].leafXmjs;
  498. const datas = [];
  499. const ms_id = isStageSelf ? materialStageData[0].id : null;
  500. for (const xmj of gcl) {
  501. const data = {
  502. xmj_id: xmj.id,
  503. gcl_id: xmj.gcl_id,
  504. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  505. };
  506. if (ms_id) data.ms_id = ms_id;
  507. datas.push(data);
  508. }
  509. if (isStageSelf) {
  510. // 取所有的gclGatherData才行,然后获取下的值
  511. const gclData = gclGatherData[gclIndex];
  512. for (const [index, ms] of materialStageData.entries()) {
  513. if (ms.id !== ms_id) {
  514. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  515. if (gclOther) {
  516. const leafXmjs = gclOther.leafXmjs.filter(item => {
  517. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  518. });
  519. for (const xmj of leafXmjs) {
  520. const data = {
  521. xmj_id: xmj.id,
  522. gcl_id: xmj.gcl_id,
  523. mx_id: xmj.mx_id ? xmj.mx_id : '',
  524. };
  525. if (_.indexOf(datas, data) === -1) {
  526. datas.push(data);
  527. }
  528. }
  529. }
  530. }
  531. }
  532. }
  533. const xmj = gcl[0];
  534. const materialCount = _.size(_.filter(gclList, function (m) {
  535. return m.gcl_id === xmj.gcl_id;
  536. }));
  537. // const materialCount = _.size(_.filter(materialListData, function (m) {
  538. // 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);
  539. // }));
  540. let checklist = false;
  541. if (materialCount === 1) {
  542. checklist = {
  543. id: select.id,
  544. had_bills: 0,
  545. }
  546. }
  547. console.log(datas, materialSelect.mb_id, checklist);
  548. 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) {
  549. // materialListData = result;
  550. gclList = result;
  551. if (checklist) materialChecklistData[index].had_bills = checklist.had_bills;
  552. loadMaterialData(gclIndex, 0);
  553. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  554. });
  555. },
  556. deletePress: function (sheet) {
  557. return;
  558. },
  559. editStarting: function (e, info) {
  560. const col = info.sheet.zh_setting.cols[info.col];
  561. const select = SpreadJsObj.getSelectObject(info.sheet);
  562. if (col.field === 'quantity') {
  563. if (select.expr && select.expr !== '') {
  564. info.sheet.getCell(info.row, info.col).text(select.expr);
  565. }
  566. }
  567. },
  568. editEnded: function (e, info) {
  569. if (info.sheet.zh_setting) {
  570. const select = SpreadJsObj.getSelectObject(info.sheet);
  571. const col = info.sheet.zh_setting.cols[info.col];
  572. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  573. let orgValue;
  574. if (col.field === 'quantity') {
  575. orgValue = validText && validText !== ''
  576. ? _.toNumber(validText) ? select.quantity : select.expr
  577. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  578. } else {
  579. orgValue = select[col.field];
  580. }
  581. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  582. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  583. return;
  584. }
  585. const exprQuantity = {
  586. expr: '',
  587. quantity: 0,
  588. };
  589. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  590. if (!valid) {
  591. toastr.error(msg);
  592. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  593. return;
  594. }
  595. if (isNaN(exprQuantity.quantity)) {
  596. toastr.error('不能输入其它非数字类型字符');
  597. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  598. return;
  599. }
  600. const num = parseFloat(exprQuantity.quantity);
  601. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  602. toastr.warning('已保留6位小数');
  603. exprQuantity.quantity = ZhCalc.round(num, 6);
  604. }
  605. // 更新至服务器
  606. const ledgerSheet = ledgerSpread.getActiveSheet();
  607. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  608. const gclIndex = _.findIndex(gclGatherData, { b_code: ledgerSelect.b_code, name: ledgerSelect.name, unit: ledgerSelect.unit, unit_price: ledgerSelect.unit_price });
  609. const gcl = gclGatherData[gclIndex].leafXmjs;
  610. const datas = [];
  611. const ms_id = isStageSelf ? materialStageData[0].id : null;
  612. for (const xmj of gcl) {
  613. const data = {
  614. xmj_id: xmj.id,
  615. gcl_id: xmj.gcl_id,
  616. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  617. };
  618. if (ms_id) data.ms_id = ms_id;
  619. datas.push(data);
  620. }
  621. if (isStageSelf) {
  622. // 取所有的gclGatherData才行,然后获取下的值
  623. const gclData = gclGatherData[gclIndex];
  624. for (const [index, ms] of materialStageData.entries()) {
  625. if (ms.id !== ms_id) {
  626. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  627. if (gclOther) {
  628. const leafXmjs = gclOther.leafXmjs.filter(item => {
  629. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  630. });
  631. for (const xmj of leafXmjs) {
  632. const data = {
  633. xmj_id: xmj.id,
  634. gcl_id: xmj.gcl_id,
  635. mx_id: xmj.mx_id ? xmj.mx_id : '',
  636. };
  637. if (_.indexOf(datas, data) === -1) {
  638. datas.push(data);
  639. }
  640. }
  641. }
  642. }
  643. }
  644. }
  645. console.log(exprQuantity, datas, select.mb_id);
  646. 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) {
  647. // materialListData = result;
  648. gclList = result;
  649. loadMaterialData(gclIndex, 0);
  650. materialSpread.getActiveSheet().setSelection(info.row + 1, info.col, 1, 1);
  651. }, function () {
  652. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  653. });
  654. }
  655. },
  656. clipboardPasted(e, info) {
  657. const hint = {
  658. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  659. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  660. numberCan: {type: 'warning', msg: '已保留6位小数'},
  661. };
  662. const range = info.cellRange;
  663. const sortData = info.sheet.zh_data || [];
  664. if (range.row + range.rowCount > sortData.length) {
  665. toastMessageUniq(hint.cellError);
  666. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  667. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  668. return;
  669. }
  670. if (sortData.length > 0 && range.col + range.colCount > 5) {
  671. toastMessageUniq(hint.cellError);
  672. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  673. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  674. return;
  675. }
  676. const data = [];
  677. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  678. let bPaste = true;
  679. const curRow = range.row + iRow;
  680. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  681. const hintRow = range.rowCount > 1 ? curRow : '';
  682. let sameCol = 0;
  683. for (let iCol = 0; iCol < range.colCount; iCol++) {
  684. const curCol = range.col + iCol;
  685. const colSetting = info.sheet.zh_setting.cols[curCol];
  686. if (!colSetting) continue;
  687. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  688. const orgValue = sortData[curRow][colSetting.field];
  689. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  690. sameCol++;
  691. if (range.colCount === sameCol) {
  692. bPaste = false;
  693. }
  694. continue;
  695. }
  696. const exprQuantity = {
  697. expr: '',
  698. quantity: 0,
  699. };
  700. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  701. if (!valid) {
  702. toastMessageUniq(getPasteHint(msg, hintRow));
  703. bPaste = false;
  704. continue;
  705. }
  706. if (isNaN(exprQuantity.quantity)) {
  707. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  708. bPaste = false;
  709. continue;
  710. }
  711. const num = parseFloat(exprQuantity.quantity);
  712. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  713. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  714. exprQuantity.quantity = ZhCalc.round(num, 6);
  715. }
  716. materialData.expr = exprQuantity.expr;
  717. materialData.quantity = exprQuantity.quantity;
  718. }
  719. if (bPaste) {
  720. data.push(materialData);
  721. } else {
  722. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  723. }
  724. }
  725. if (data.length === 0) {
  726. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  727. return;
  728. }
  729. const ledgerSheet = ledgerSpread.getActiveSheet();
  730. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  731. const gclIndex = _.findIndex(gclGatherData, { b_code: ledgerSelect.b_code, name: ledgerSelect.name, unit: ledgerSelect.unit, unit_price: ledgerSelect.unit_price });
  732. const gcl = gclGatherData[gclIndex].leafXmjs;
  733. const datas = [];
  734. const ms_id = isStageSelf ? materialStageData[0].id : null;
  735. for (const xmj of gcl) {
  736. const data2 = {
  737. xmj_id: xmj.id,
  738. gcl_id: xmj.gcl_id,
  739. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  740. };
  741. if (ms_id) data2.ms_id = ms_id;
  742. datas.push(data2);
  743. }
  744. if (isStageSelf) {
  745. // 取所有的gclGatherData才行,然后获取下的值
  746. const gclData = gclGatherData[gclIndex];
  747. for (const [index, ms] of materialStageData.entries()) {
  748. if (ms.id !== ms_id) {
  749. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  750. if (gclOther) {
  751. const leafXmjs = gclOther.leafXmjs.filter(item => {
  752. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  753. });
  754. for (const xmj of leafXmjs) {
  755. const data = {
  756. xmj_id: xmj.id,
  757. gcl_id: xmj.gcl_id,
  758. mx_id: xmj.mx_id ? xmj.mx_id : '',
  759. };
  760. if (_.indexOf(datas, data) === -1) {
  761. datas.push(data);
  762. }
  763. }
  764. }
  765. }
  766. }
  767. }
  768. console.log(data, datas);
  769. // 更新至服务器
  770. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data }, ms_id: isStageSelf ? materialStageData[0].id : null }, function (result) {
  771. // materialListData = result;
  772. gclList = result;
  773. loadMaterialData(gclIndex, 0);
  774. materialSpread.getActiveSheet().setSelection(info.cellRange.row, info.cellRange.col, info.cellRange.rowCount, info.cellRange.colCount);
  775. }, function () {
  776. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  777. });
  778. },
  779. _checkExprValid(expr) {
  780. if (!expr) return [true, null];
  781. const param = [];
  782. let num = '', base = '';
  783. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  784. if (/^[\d\.%]+/.test(expr[i])) {
  785. if (base !== '') {
  786. param.push({type: 'base', value: base});
  787. base = '';
  788. }
  789. num = num + expr[i];
  790. } else if (expr[i] === '(') {
  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. param.push({type: 'left', value: '('});
  800. } else if (expr[i] === ')') {
  801. if (num !== '') {
  802. param.push({type: 'num', value: num});
  803. num = '';
  804. }
  805. if (base !== '') {
  806. param.push({type: 'base', value: base});
  807. base = '';
  808. }
  809. param.push({type: 'right', value: ')'});
  810. } else if (/^[\+\-*\/]/.test(expr[i])) {
  811. if (num !== '') {
  812. param.push({type: 'num', value: num});
  813. num = '';
  814. }
  815. if (base !== '') {
  816. param.push({type: 'base', value: base});
  817. base = '';
  818. }
  819. param.push({type: 'calc', value: expr[i]});
  820. } else {
  821. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  822. }
  823. }
  824. if (num !== '') {
  825. param.push({type: 'num', value: num});
  826. num = '';
  827. }
  828. if (base !== '') {
  829. param.push({type: 'base', value: base});
  830. base = '';
  831. }
  832. if (param.length === 0) return true;
  833. if (param.length > 1) {
  834. if (param[0].value === '-' && param[1].type === 'num') {
  835. param[1].value = '-' + param[1].value;
  836. param.shift();
  837. }
  838. }
  839. const iLen = param.length;
  840. let iLeftCount = 0, iRightCount = 0;
  841. for (const [i, p] of param.entries()) {
  842. if (p.type === 'calc') {
  843. if (i === 0 || i === iLen - 1)
  844. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  845. }
  846. if (p.type === 'num') {
  847. num = p.value.replace('%', '');
  848. if (p.value.length - num.length > 1)
  849. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  850. num = _.toNumber(num);
  851. if (num === undefined || num === null || _.isNaN(num))
  852. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  853. if (i > 0) {
  854. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  855. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  856. } else if (param[i - 1].value === '/' && num === 0) {
  857. return [false, '输入的表达式非法:请勿除0'];
  858. }
  859. }
  860. }
  861. if (p.type === 'base') {
  862. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  863. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  864. }
  865. if (p.type === 'left') {
  866. iLeftCount += 1;
  867. if (i !== 0 && param[i-1].type !== 'calc')
  868. return [false, '输入的表达式非法:(前应有运算符'];
  869. }
  870. if (p.type === 'right') {
  871. iRightCount += 1;
  872. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  873. return [false, '输入的表达式非法:)后应有运算符'];
  874. if (iRightCount > iLeftCount)
  875. return [false, '输入的表达式非法:")"前无对应的"("'];
  876. }
  877. }
  878. if (iLeftCount > iRightCount)
  879. return [false, '输入的表达式非法:"("后无对应的")"'];
  880. return [true, ''];
  881. },
  882. _checkExpr: function (text, data) {
  883. if (text) {
  884. const num = _.toNumber(text);
  885. if (num) {
  886. data.quantity = num;
  887. data.expr = '';
  888. } else {
  889. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  890. const [valid, msg] = this._checkExprValid(expr);
  891. if (!valid) return [valid, msg];
  892. data.expr = expr;
  893. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace(new RegExp('%', 'gm'), '/100'));
  894. }
  895. } else {
  896. data.quantity = 0;
  897. data.expr = '';
  898. }
  899. return [true, ''];
  900. },
  901. };
  902. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  903. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  904. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  905. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  906. $.contextMenu({
  907. selector: '#material-spread',
  908. build: function ($trigger, e) {
  909. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  910. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  911. },
  912. items: {
  913. 'create': {
  914. name: '添加工料',
  915. icon: 'fa-sign-in',
  916. callback: function (key, opt) {
  917. // 获取已选清单
  918. changeMaterialTable();
  919. $('#addgl').modal('show');
  920. },
  921. disabled: function (key, opt) {
  922. const sheet = ledgerSpread.getActiveSheet();
  923. const select = SpreadJsObj.getSelectObject(sheet);
  924. if (!select) {
  925. return true;
  926. }
  927. return readOnly;
  928. }
  929. },
  930. 'delete': {
  931. name: '删除工料',
  932. icon: 'fa-remove',
  933. callback: function (key, opt) {
  934. materialSpreadObj.del(materialSpread.getActiveSheet());
  935. },
  936. disabled: function (key, opt) {
  937. const sheet = materialSpread.getActiveSheet();
  938. const selection = sheet.getSelections();
  939. const sel = selection ? selection[0] : sheet.getSelections()[0];
  940. const select = SpreadJsObj.getSelectObject(sheet);
  941. if (!select) {
  942. return true;
  943. }
  944. if (!readOnly && sel.rowCount === 1 && select && materialBase.isEdit(select)) {
  945. return false;
  946. } else {
  947. return true;
  948. }
  949. }
  950. },
  951. }
  952. });
  953. }
  954. // 切换清单行,读取所属项目节数据
  955. ledgerSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  956. if (info.oldSelections !== undefined) {
  957. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  958. if (iNewRow !== iOldRow) {
  959. const sheet = ledgerSpread.getActiveSheet();
  960. const select = SpreadJsObj.getSelectObject(sheet);
  961. const index = _.findIndex(gclGatherData, { b_code: select.b_code, name: select.name, unit: select.unit, unit_price: select.unit_price });
  962. loadMaterialData(index, 0);
  963. }
  964. }
  965. });
  966. $('#open_addtclist').click(function () {
  967. $('#tclist_search').val('');
  968. $('#tclist_search').siblings('a').hide();
  969. makeChecklistData(gclGatherData, materialChecklistData);
  970. $('#addtclist').modal('show');
  971. });
  972. // 回车提交
  973. $('#tclist_search').on('keypress', function () {
  974. if(window.event.keyCode === 13) {
  975. $(this).blur();
  976. }
  977. });
  978. $('#tclist_search').on('blur', function () {
  979. const value = _.trim($(this).val());
  980. let showListData = gclGatherData;
  981. if (value !== '') {
  982. $(this).siblings('a').show();
  983. showListData = _.filter(gclGatherData, function (c) {
  984. return (c.b_code && c.b_code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  985. })
  986. } else {
  987. $(this).siblings('a').hide();
  988. }
  989. remakeChecklistData(gclGatherData, showListData);
  990. });
  991. $('.remove-btn').on('click', function () {
  992. $(this).hide();
  993. $(this).siblings('input').val('');
  994. remakeChecklistData(gclGatherData);
  995. });
  996. // 显示有调差工料清单
  997. // $('#show_material_gcl').click(function () {
  998. // if ($(this).is(':checked')) {
  999. // const hadMaterialGclGatherData = [];
  1000. // const hadGclIdList = [];
  1001. // for (const ml of materialListData) {
  1002. // if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  1003. // hadGclIdList.push(ml.gcl_id);
  1004. // }
  1005. // }
  1006. // for (const gcl of gclGatherData) {
  1007. // for (const index in gcl.leafXmjs) {
  1008. // const gcl_id = gcl.leafXmjs[index].gcl_id;
  1009. // if (hadGclIdList.indexOf(gcl_id) !== -1) {
  1010. // hadMaterialGclGatherData.push(gcl);
  1011. // break;
  1012. // }
  1013. // }
  1014. // }
  1015. // gclGatherData = hadMaterialGclGatherData;
  1016. // } else {
  1017. // gclGatherModel.loadLedgerData(ledger, curLedgerData);
  1018. // gclGatherModel.loadPosData(pos, curPosData);
  1019. // gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  1020. // return item.qc_qty || item.contract_qty
  1021. // });
  1022. // }
  1023. // SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  1024. // loadLeafXmjData(0);
  1025. // loadMaterialData(0, 0);
  1026. // SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  1027. // SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1028. // SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  1029. // });
  1030. $.subMenu({
  1031. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1032. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1033. key: 'menu.1.0.0',
  1034. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1035. callback: function (info) {
  1036. if (info.mini) {
  1037. $('.panel-title').addClass('fluid');
  1038. $('#sub-menu').removeClass('panel-sidebar');
  1039. } else {
  1040. $('.panel-title').removeClass('fluid');
  1041. $('#sub-menu').addClass('panel-sidebar');
  1042. }
  1043. autoFlashHeight();
  1044. ledgerSpread.refresh();
  1045. materialSpread.refresh();
  1046. }
  1047. });
  1048. $.divResizer({
  1049. select: '#right-spr',
  1050. callback: function () {
  1051. ledgerSpread.refresh();
  1052. materialSpread.refresh();
  1053. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1054. setLocalCache('material_checklist_' + materialID, width);
  1055. }
  1056. });
  1057. // 展开收起工料并浏览器记住本期展开收起
  1058. $('a', '.right-nav').bind('click', function () {
  1059. const tab = $(this), tabPanel = $(tab.attr('content'));
  1060. if (!tab.hasClass('active')) {
  1061. $('a', '.side-menu').removeClass('active');
  1062. $('.tab-content .tab-select-show').removeClass('active');
  1063. tab.addClass('active');
  1064. tabPanel.addClass('active');
  1065. showSideTools(tab.hasClass('active'));
  1066. if (tab.attr('content') === '#material-tab') {
  1067. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1068. setLocalCache('material_checklist_' + materialID, width);
  1069. }
  1070. } else {
  1071. removeLocalCache('material_checklist_' + materialID);
  1072. tab.removeClass('active');
  1073. tabPanel.removeClass('active');
  1074. showSideTools(tab.hasClass('active'));
  1075. }
  1076. ledgerSpread.refresh();
  1077. materialSpread.refresh();
  1078. });
  1079. // 根据浏览器记录展开收起
  1080. if (getLocalCache('material_checklist_' + materialID)) {
  1081. const tab = $('.right-nav a[content="#material-tab"]'), tabPanel = $(tab.attr('content'));
  1082. $('a', '.side-menu').removeClass('active');
  1083. $('.tab-content .tab-select-show').removeClass('active');
  1084. tab.addClass('active');
  1085. tabPanel.addClass('active');
  1086. $('#right-view').width(getLocalCache('material_checklist_' + materialID) + '%');
  1087. showSideTools(tab.hasClass('active'));
  1088. ledgerSpread.refresh();
  1089. materialSpread.refresh();
  1090. }
  1091. // 导入功能
  1092. // 上传图片
  1093. let importFile = null;
  1094. $('#upload-list').click(function () {
  1095. if (materialBillsData.length === 0) {
  1096. toastr.error('请添加工料再导入。');
  1097. return
  1098. }
  1099. $("#import").modal('show');
  1100. // $(this).siblings('input').trigger('click');
  1101. });
  1102. $('#upload-list-file').change(function () {
  1103. const file = this.files[0];
  1104. importFile = file;
  1105. });
  1106. $('#import_btn').click(function() {
  1107. if (!importFile) {
  1108. toastr.error('请选择json或excel文件再确定');
  1109. return;
  1110. }
  1111. $('#import').modal('hide');
  1112. const ext = importFile.name.toLowerCase().split('.').splice(-1)[0];
  1113. const imgStr = /(xls|xlsx|json|XLS|XLSX|JSON)$/;
  1114. if (!imgStr.test(ext)) {
  1115. toastr.error('请导入正确格式的json或excel文件。');
  1116. return
  1117. }
  1118. const fileReader = new FileReader();
  1119. fileReader.onload = async function(ev) {
  1120. try{
  1121. const data = ev.target.result;
  1122. let tree = [];
  1123. const ignoreUnitPrice = $('#ignore').is(':checked');
  1124. resetExport();
  1125. $('#okedit').modal('show');
  1126. setProgress($('#export-progress'), 30);
  1127. if (/(xls|xlsx|XLS|XLSX)$/.test(ext)) {
  1128. const workbook = XLSX.read(data, {type: 'binary'}); // 以二进制流方式读取得到整份excel表格对象
  1129. const jsonData = transExcel(XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], { defval: null }));
  1130. if (!(jsonData[0] && jsonData[0].b_code !== undefined && jsonData[0].b_code !== null &&
  1131. jsonData[0].gljcode !== undefined && jsonData[0].name !== undefined && jsonData[0].name !== undefined &&
  1132. jsonData[0].unit !== undefined && jsonData[0].unit_price !== undefined)) {
  1133. throw 'excel必须按指定格式内容上传';
  1134. }
  1135. tree = _.filter(jsonData, function (item) {
  1136. return item.b_code !== null;
  1137. });
  1138. let lastIndex = 0;// 防止导入相同的清单导致导入的含量数量增多
  1139. for (const [i,t] of tree.entries()) {
  1140. const jIndex1 = _.findIndex(jsonData, { b_code: t.b_code, name: t.name, unit: t.unit, unit_price: t.unit_price }, lastIndex);
  1141. lastIndex = jIndex1;
  1142. if (i + 1 < tree.length) {
  1143. const jIndex2 = _.findIndex(jsonData, { b_code: tree[i+1].b_code, name: tree[i+1].name, unit: tree[i+1].unit, unit_price: tree[i+1].unit_price }, lastIndex);
  1144. t.children = jsonData.slice(jIndex1 + 1, jIndex2);
  1145. lastIndex = jIndex2;
  1146. } else {
  1147. t.children = jsonData.slice(jIndex1 + 1);
  1148. }
  1149. }
  1150. } else {
  1151. const ascii = jschardet.detect(data.substring(0, 10000));
  1152. iconv.skipDecodeWarning = true
  1153. tree = JSON.parse(iconv.decode(data, ascii.encoding));// 需要转码,否则前端处理中文会出现乱码
  1154. if (!(tree[0] && tree[0].b_code !== undefined && tree[0].b_code !== null &&
  1155. tree[0].gljcode !== undefined && tree[0].name !== undefined && tree[0].name !== undefined &&
  1156. tree[0].unit !== undefined && tree[0].unit_price !== undefined)) {
  1157. throw 'json必须按指定格式内容上传';
  1158. }
  1159. }
  1160. stopProgress($('#export-progress'));
  1161. $('#bill-detail').show();
  1162. setProgress($('#bill-progress'), 30);
  1163. // 导入先生成materialCheckList,再生成materialBillsData,最后生成materialListData
  1164. console.log(tree, gclGatherData, materialChecklistData, materialBillsData);
  1165. const pushChecklist = [];
  1166. const pushBillsData = [];
  1167. const needPushTree = [];
  1168. // 分析materialCheckList和tree,找出相同的清单并插入对应不存在的工料
  1169. for (const t of tree) {
  1170. if(t.children.length === 0) continue;
  1171. const findObject = {
  1172. b_code: t.b_code ? t.b_code.toString() : t.b_code,
  1173. name: t.name ? t.name.toString() : t.name,
  1174. unit: t.unit ? t.unit.toString() : t.unit,
  1175. };
  1176. if (!ignoreUnitPrice) findObject.unit_price = t.unit_price ? parseFloat(t.unit_price) : null;
  1177. const order = _.findIndex(gclGatherData, findObject);
  1178. const mlOrder = _.findIndex(materialChecklistData, findObject);
  1179. const haveQuantity = _.find(t.children, function (item) { return item.quantity && item.quantity !== 0 }) ? 1 : 0;
  1180. if (mlOrder === -1 && order !== -1 && haveQuantity && _.findIndex(pushChecklist, findObject) === -1) {
  1181. pushChecklist.push({
  1182. b_code: gclGatherData[order].b_code,
  1183. name: gclGatherData[order].name,
  1184. unit: gclGatherData[order].unit,
  1185. unit_price: gclGatherData[order].unit_price,
  1186. quantity: gclGatherData[order].quantity ? gclGatherData[order].quantity : null,
  1187. total_price: gclGatherData[order].total_price ? gclGatherData[order].total_price : null,
  1188. had_bills: 0,
  1189. });
  1190. } else if (mlOrder === -1 && order === -1) {
  1191. continue;
  1192. } else if (!haveQuantity) {
  1193. continue;
  1194. }
  1195. needPushTree.push(t);
  1196. // for (const c of t.children) {
  1197. // const mbOrder = _.findIndex(materialBillsData, { code: c.gljcode, name: c.name, unit: c.unit });
  1198. // if (c.b_code !== null && mbOrder === -1 && _.findIndex(pushBillsData, { code: c.gljcode, name: c.name, unit: c.unit }) === -1) {
  1199. // pushBillsData.push({
  1200. // code: c.gljcode,
  1201. // name: c.name,
  1202. // unit: c.unit,
  1203. // spec: c.specs,
  1204. // })
  1205. // }
  1206. // }
  1207. }
  1208. if (needPushTree.length === 0) {
  1209. throw '不存在需要导入的工料清单含量';
  1210. }
  1211. // 先上传需要生成的清单及工料
  1212. if (pushChecklist.length > 0 || pushBillsData.length > 0) {
  1213. postData(window.location.pathname + '/save', { type:'exportCB', addChecklist: pushChecklist, addBillsList: pushBillsData }, async function (result) {
  1214. // materialListData = result;
  1215. materialChecklistData = result.materialChecklistData;
  1216. materialBillsData = result.materialBillsData;
  1217. materialStageBillsData = result.materialStageBillsData;
  1218. stopProgress($('#bill-progress'));
  1219. await pushListData(needPushTree);
  1220. }, function () {
  1221. stop = true;
  1222. clearInterval(interval);
  1223. setTimeout(function () {
  1224. $('#okedit').modal('hide');
  1225. }, 1000);
  1226. });
  1227. } else {
  1228. stopProgress($('#bill-progress'));
  1229. await pushListData(needPushTree);
  1230. }
  1231. } catch (error) {
  1232. console.log(error);
  1233. toastr.error(error);
  1234. stop = true;
  1235. clearInterval(interval);
  1236. setTimeout(function () {
  1237. $('#okedit').modal('hide');
  1238. $('#import').modal('show');
  1239. }, 1000);
  1240. return
  1241. }
  1242. // 分析jsondata,得出每个清单间工料数量,生成新的树结构数组
  1243. // let persons = []; // 存储获取到的数据
  1244. // // 表格的表格范围,可用于判断表头是否数量是否正确
  1245. // let fromTo = '';
  1246. // // 遍历每张表读取
  1247. // for (const sheet in workbook.Sheets) {
  1248. // if (workbook.Sheets.hasOwnProperty(sheet)) {
  1249. // fromTo = workbook.Sheets[sheet]['!ref'];
  1250. // console.log(fromTo);
  1251. // persons = persons.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
  1252. // // break; // 如果只取第一张表,就取消注释这行
  1253. // }
  1254. // }
  1255. // console.log(persons);
  1256. };
  1257. // 以二进制方式打开文件
  1258. fileReader.readAsBinaryString(importFile);
  1259. $('#upload-list-file').val('');
  1260. importFile = null;
  1261. });
  1262. function sleep(millisecond) {
  1263. return new Promise(resolve => {
  1264. setTimeout(() => {
  1265. resolve()
  1266. }, millisecond)
  1267. })
  1268. }
  1269. let value = 0;
  1270. let interval;
  1271. let stop = false;
  1272. function setProgress(_this, time = 50) {
  1273. interval = setInterval(function () {
  1274. if (value < 100) {
  1275. value = parseInt(value) + 1;
  1276. _this.css("width", value + "%").text(value + "%");
  1277. } else if (value === 100) {
  1278. value = parseInt(value) + 1;
  1279. value = 30;
  1280. }
  1281. }, time);
  1282. }
  1283. function resetExport() {
  1284. resetProgress($('#export-progress'));
  1285. $('#bill-detail').hide();
  1286. resetProgress($('#bill-progress'));
  1287. $('#list-detail').hide();
  1288. resetProgress($('#list-progress'));
  1289. }
  1290. function resetProgress(_this) {
  1291. _this.removeClass('bg-success');
  1292. _this.css("width", "0%").text("0%").attr('aria-valuenow', '0');
  1293. }
  1294. function stopProgress(_this) {
  1295. if (interval) {
  1296. _this.addClass('bg-success');
  1297. _this.css("width", "100%").text("100%");
  1298. value = 0;
  1299. stop = true;
  1300. clearInterval(interval);
  1301. interval = 0;
  1302. }
  1303. }
  1304. async function pushListData(tree = []) {
  1305. if (tree.length > 0) {
  1306. const ignoreUnitPrice = $('#ignore').is(':checked');
  1307. for (const [i,t] of tree.entries()) {
  1308. $('#list-detail').find('b').text(t.b_code);
  1309. resetProgress($('#list-progress'));
  1310. if (!interval) {
  1311. $('#list-detail').show();
  1312. setProgress($('#list-progress'), 30);
  1313. }
  1314. const mbList = [];
  1315. for (const mb of t.children) {
  1316. if (mb.quantity) {
  1317. const mbInfo = _.find(materialBillsData, { code: mb.gljcode+'', name: mb.name+'', unit: mb.unit+'' });
  1318. if (mbInfo) {
  1319. const num = parseFloat(mb.quantity);
  1320. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1321. // toastr.warning('已保留6位小数');
  1322. mb.quantity = ZhCalc.round(num, 6);
  1323. }
  1324. mbList.push({ id: mbInfo.id, quantity: mb.quantity });
  1325. }
  1326. }
  1327. }
  1328. if (mbList.length === 0 && i+1 === tree.length) {
  1329. stopProgress($('#list-progress'));
  1330. toastr.success('导入成功');
  1331. setTimeout(function () { $('#okedit').modal('hide') }, 2000);
  1332. showSjsData();
  1333. return;
  1334. }
  1335. if (mbList.length === 0) {
  1336. continue;
  1337. }
  1338. const findObject = { b_code: t.b_code ? t.b_code.toString() : t.b_code,
  1339. name: t.name ? t.name.toString() : t.name,
  1340. unit: t.unit ? t.unit.toString() : t.unit,
  1341. };
  1342. if (!ignoreUnitPrice) findObject.unit_price = t.unit_price ? parseFloat(t.unit_price) : null;
  1343. const gclIndex = _.findIndex(gclGatherData, findObject);
  1344. const gcl = gclGatherData[gclIndex].leafXmjs;
  1345. const ms_id = isStageSelf ? materialStageData[0].id : null;
  1346. // const index = materialChecklistData.indexOf(select);
  1347. const datas = [];
  1348. for (const xmj of gcl) {
  1349. const notx = findNotJoinLeafXmj(xmj);
  1350. const notx2 = findNotChangeLeafXmj(xmj);
  1351. const data = {
  1352. xmj_id: xmj.id,
  1353. gcl_id: xmj.gcl_id,
  1354. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  1355. contract_qty: xmj.contract_qty,
  1356. qc_qty: xmj.qc_qty,
  1357. qc_minus_qty: xmj.qc_minus_qty,
  1358. gather_qty: xmj.gather_qty,
  1359. is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
  1360. };
  1361. if (ms_id) data.ms_id = ms_id;
  1362. datas.push(data);
  1363. }
  1364. if (isStageSelf) {
  1365. // 取所有的gclGatherData才行,然后获取下的值
  1366. const gclData = gclGatherData[gclIndex];
  1367. for (const [index, ms] of materialStageData.entries()) {
  1368. if (ms.id !== ms_id) {
  1369. const gclFindObject = { b_code: gclData.b_code ? gclData.b_code.toString() : gclData.b_code,
  1370. name: gclData.name ? gclData.name.toString() : gclData.name, unit: gclData.unit ? gclData.unit.toString() : gclData.unit };
  1371. if (!ignoreUnitPrice) gclFindObject.unit_price = gclData.unit_price;
  1372. const gclOther = _.find(gclGatherListData[index], gclFindObject);
  1373. if (gclOther) {
  1374. const leafXmjs = gclOther.leafXmjs.filter(item => {
  1375. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1376. });
  1377. for (const xmj of leafXmjs) {
  1378. const notx = findNotJoinLeafXmj(xmj);
  1379. const notx2 = findNotChangeLeafXmj(xmj);
  1380. const data = {
  1381. xmj_id: xmj.id,
  1382. gcl_id: xmj.gcl_id,
  1383. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1384. contract_qty: xmj.contract_qty,
  1385. qc_qty: xmj.qc_qty,
  1386. qc_minus_qty: xmj.qc_minus_qty,
  1387. gather_qty: xmj.gather_qty,
  1388. is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
  1389. ms_id: ms.id,
  1390. };
  1391. datas.push(data);
  1392. }
  1393. }
  1394. }
  1395. }
  1396. }
  1397. // 上传到数据库
  1398. const select = _.find(materialChecklistData, findObject);
  1399. console.log(select, datas, mbList);
  1400. if (select) {
  1401. const result = await postDataAsync(window.location.pathname + '/save', {type: 'adds', checklist: { id: select.id, had_bills: 1 }, postData: {xmjs: datas, mbIds: mbList, export: true}});
  1402. // materialListData = result;
  1403. select.had_bills = 1;
  1404. gclList = result;
  1405. stopProgress($('#list-progress'));
  1406. if (i+1 === tree.length) {
  1407. toastr.success('导入成功');
  1408. setTimeout(function () { $('#okedit').modal('hide') }, 2000);
  1409. showSjsData();
  1410. }
  1411. // }, function () {
  1412. // stop = true;
  1413. // clearInterval(interval);
  1414. // setTimeout(function () { $('#okedit').modal('hide') }, 1000);
  1415. // });
  1416. } else {
  1417. stopProgress($('#list-progress'));
  1418. }
  1419. }
  1420. }
  1421. }
  1422. function transExcel(results) {
  1423. const mapInfo = {
  1424. '清单编号': 'b_code',
  1425. '工料编号': 'gljcode',
  1426. '名称': 'name',
  1427. '单位': 'unit',
  1428. '规格': 'specs',
  1429. '单价': 'unit_price',
  1430. '单位耗量': 'quantity',
  1431. };
  1432. return results.map(zhObj => {
  1433. const enObj = {}
  1434. const zhKeys = Object.keys(zhObj);
  1435. zhKeys.forEach(zhKey => {
  1436. const enKey = mapInfo[zhKey];
  1437. enObj[enKey] = zhObj[zhKey] && _.isString(zhObj[zhKey]) ? _.trim(zhObj[zhKey]) : zhObj[zhKey];
  1438. });
  1439. return enObj
  1440. })
  1441. }
  1442. $('#exportExcel').click(function () {
  1443. const data = [];
  1444. const setting = {
  1445. cols: [
  1446. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  1447. {title: '工料编号', colSpan: '1', rowSpan: '2', field: 'gljcode', hAlign: 0, width: 80, formatter: '@'},
  1448. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 220, formatter: '@'},
  1449. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, type: 'Number'},
  1450. {title: '规格', colSpan: '1', rowSpan: '2', field: 'specs', hAlign: 0, width: 100, formatter: '@'},
  1451. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 90, formatter: '@'},
  1452. {title: '单位耗量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 90, formatter: '@'},
  1453. ],
  1454. headRows: 2,
  1455. headRowHeight: [25, 25],
  1456. defaultRowHeight: 21,
  1457. headerFont: 'bold 10px 微软雅黑',
  1458. font: '10px 微软雅黑'
  1459. };
  1460. if (!materialChecklistData || materialChecklistData.length === 0) return;
  1461. for (const ml of materialChecklistData) {
  1462. data.push({
  1463. b_code: ml.b_code, name: ml.name, unit: ml.unit,
  1464. unit_price: ml.unit_price,
  1465. });
  1466. const index = _.findIndex(gclGatherData, { b_code: ml.b_code, name: ml.name, unit: ml.unit, unit_price: ml.unit_price });
  1467. if (index === -1) continue;
  1468. const gcl = gclGatherData[index];
  1469. if (gcl && gcl.leafXmjs) {
  1470. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  1471. const newMaterialList = _.uniqBy(_.filter(gclList, function (m) {
  1472. return _.indexOf(gcl_ids, m.gcl_id) !== -1;
  1473. }), 'mb_id');
  1474. for(const m of newMaterialList) {
  1475. const bills = _.find(materialBillsData, { id: m.mb_id });
  1476. if(bills) {
  1477. m.code = bills.code;
  1478. m.name = bills.name;
  1479. m.unit = bills.unit;
  1480. }
  1481. }
  1482. if (newMaterialList.length > 0) {
  1483. for (const nm of newMaterialList) {
  1484. data.push({
  1485. gljcode: nm.code, name: nm.name, unit: nm.unit,
  1486. quantity: nm.quantity,
  1487. });
  1488. }
  1489. }
  1490. }
  1491. }
  1492. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, $('.sidebar-title').attr('data-original-title') + "-清单材料单位消耗量.xlsx");
  1493. });
  1494. });