material_checklist.js 77 KB

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