material_list.js 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757
  1. 'use strict';
  2. /**
  3. * 材料调差 - 调差清单
  4. *
  5. * @author EllisRan
  6. * @date 2019/10/25
  7. * @version
  8. */
  9. function getStageId() {
  10. return window.location.pathname.split('/')[5];
  11. }
  12. function findNotJoinLeafXmj(x, type = '') {
  13. if (type === 'index') {
  14. return notJoinList.findIndex(function (item) {
  15. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  16. });
  17. }
  18. return notJoinList.find(function (item) {
  19. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  20. });
  21. }
  22. function findSelfLeafXmj(x, type = '') {
  23. if (type === 'index') {
  24. return selfList.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 selfList.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 getMpSpreadByMBData(id) {
  33. const info = materialBillsData.find(function (item) {
  34. return item.id === parseInt(id);
  35. });
  36. return info ? info.m_spread : 0;
  37. }
  38. function getMaterialListByLeafXmj(gcl_id, xmj_id, mx_id = '') {
  39. const list = [];
  40. for (const ml of materialListData) {
  41. if (gcl_id === ml.gcl_id && xmj_id === ml.xmj_id && (mx_id === '' || mx_id === ml.mx_id)) {
  42. list.push(ml);
  43. }
  44. }
  45. return list;
  46. }
  47. function calcOneBQJC(xmj) {
  48. let jiacha = 0;
  49. const notx = findNotJoinLeafXmj(xmj);
  50. if (notx === undefined) {
  51. const list = xmj.mx_id !== undefined ? getMaterialListByLeafXmj(xmj.gcl_id, xmj.id, xmj.mx_id) : getMaterialListByLeafXmj(xmj.gcl_id, xmj.id);
  52. for (const l of list) {
  53. jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.gather_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
  54. }
  55. }
  56. return ZhCalc.round(jiacha, materialDecimal.tp);
  57. }
  58. function getPasteHint (str, row = '') {
  59. let returnObj = str;
  60. if (row) {
  61. returnObj.msg = '清单第' + (row+1) + '行' + (str.msg ? str.msg : str);
  62. }
  63. return returnObj;
  64. }
  65. // 重新计算列表的价差
  66. function calculateJiaCha(data, index) {
  67. // 计算单条的
  68. if (index) {
  69. const gcld = data[index]
  70. let total_jiacha = 0;
  71. for (const [index, xmj] of gcld.leafXmjs.entries()) {
  72. const jiacha = calcOneBQJC(xmj);
  73. gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
  74. total_jiacha += jiacha;
  75. }
  76. gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
  77. } else {
  78. for(const gcld of data) {
  79. let total_jiacha = 0;
  80. for (const [index, xmj] of gcld.leafXmjs.entries()) {
  81. const jiacha = calcOneBQJC(xmj);
  82. gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
  83. total_jiacha += jiacha;
  84. }
  85. gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
  86. }
  87. }
  88. }
  89. const is_numeric = (value) => {
  90. if (typeof(value) === 'object') {
  91. return false;
  92. } else {
  93. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  94. }
  95. };
  96. $(document).ready(() => {
  97. function TipCellType()
  98. {
  99. }
  100. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.ColumnHeader();
  101. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  102. return { x: x, y: y, row: context.row, col: context.col, cellRect: cellRect, sheetArea: context.sheetArea, sheet: context.sheet };
  103. };
  104. TipCellType.prototype.processMouseEnter = function (hitInfo){
  105. if (!this._toolTipElement) {
  106. var div = document.createElement("div");
  107. $(div).css("position", "absolute")
  108. .css("border", "1px #C0C0C0 solid")
  109. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  110. .css("font", "9pt Arial")
  111. .css("background", "#fff")
  112. // .css("color", "#fff")
  113. .css("z-index", "1000")
  114. .css("padding", 5);
  115. this._toolTipElement = div;
  116. }
  117. $(this._toolTipElement).text("单位数量:每一单位清单下所需工料消耗量。")
  118. .css("top", hitInfo.y + 15)
  119. .css("left", hitInfo.x - 15);
  120. $(this._toolTipElement).hide();
  121. // document.body.insertBefore(this._toolTipElement, null);
  122. if (hitInfo.sheet.yn === 4) { // 用于区分上下两个工料关联表
  123. $('#material-self-spread-div').append(this._toolTipElement, null);
  124. } else {
  125. $('#material-spread-div').append(this._toolTipElement, null);
  126. }
  127. $(this._toolTipElement).show("fast");
  128. };
  129. TipCellType.prototype.processMouseLeave = function (hitInfo) {
  130. if (this._toolTipElement) {
  131. // document.body.removeChild(this._toolTipElement);
  132. // $('#material-spread-div').removeChild(this._toolTipElement);
  133. this._toolTipElement.remove();
  134. this._toolTipElement = null;
  135. }
  136. };
  137. autoFlashHeight();
  138. // 清单table
  139. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  140. const ledgerSpreadSetting = {
  141. cols: [
  142. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 90, formatter: '@'},
  143. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 220, formatter: '@'},
  144. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 80, formatter: '@'},
  145. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 110, type: 'Number'},
  146. {title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'},
  147. {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'},
  148. {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 110, type: 'Number'},
  149. {title: '本期完成金额', colSpan: '1', rowSpan: '2', field: 'gather_tp', hAlign: 2, width: 110, type: 'Number'},
  150. {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'total_jiacha', hAlign:3, width: 110, type: 'Number'}
  151. ],
  152. emptyRows: 0,
  153. headRows: 2,
  154. headRowHeight: [25, 25],
  155. defaultRowHeight: 21,
  156. headerFont: '12px 微软雅黑',
  157. font: '12px 微软雅黑',
  158. readOnly: true,
  159. };
  160. // let gclGatherData = gclGatherModel.gatherGclData()
  161. // 获取项目节数据
  162. function loadLeafXmjData(iGclRow) {
  163. const gcl = gclGatherData[iGclRow];
  164. if (gcl) {
  165. for (const [index, xmj] of gcl.leafXmjs.entries()) {
  166. const jiacha = calcOneBQJC(xmj);
  167. gcl.leafXmjs[index].jiacha = jiacha !== 0 ? ZhCalc.round(jiacha, materialDecimal.tp) : null;
  168. }
  169. const leafXmjs = gcl.leafXmjs.filter(item => {
  170. return item.qc_qty || item.contract_qty
  171. });
  172. console.log(leafXmjs);
  173. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, leafXmjs);
  174. // 对清单调差工料table的单位数量进行改变
  175. // materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  176. // SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  177. } else {
  178. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  179. }
  180. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  181. }
  182. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  183. // 项目明细table
  184. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  185. const leafXmjSpreadSetting = {
  186. cols: [
  187. {title: '项目节|编号', colSpan: '2|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  188. {title: '|项目节名称', colSpan: '|1', rowSpan: '|1', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  189. {title: '计量单元|计量单元', colSpan: '2|1', rowSpan: '1|1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  190. {title: '|复核数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 0, width: 80, type: 'Number'},
  191. {title: '部位信息|单位工程', colSpan: '3|1', rowSpan: '1|1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  192. {title: '|分部工程', colSpan: '|1', rowSpan: '|1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  193. {title: '|分项工程', colSpan: '|1', rowSpan: '|1', field: 'fxgc', hAlign: 0, width: 180, formatter: '@'},
  194. {title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  195. {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 80, type: 'Number'},
  196. {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  197. {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'jiacha', hAlign: 2, width: 80, type: 'Number'},
  198. ],
  199. emptyRows: 0,
  200. headRows: 2,
  201. headRowHeight: [25, 25],
  202. defaultRowHeight: 21,
  203. headerFont: '12px 微软雅黑',
  204. font: '12px 微软雅黑',
  205. readOnly: true,
  206. rowHeader:[
  207. {
  208. rowHeaderType: 'circle',
  209. setting: {
  210. size: 5,
  211. indent: 16,
  212. getColor: function (index, data) {
  213. if (!data) return;
  214. if (_.findIndex(selfList, { gcl_id: data.gcl_id, xmj_id: data.id, mx_id: (data.mx_id ? data.mx_id : '') }) !== -1) {
  215. return '#dc3545';
  216. }
  217. }
  218. },
  219. },
  220. ],
  221. };
  222. // 加载清单数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  223. postData(window.location.pathname + '/load', {}, async function (result) {
  224. ledger = result.ledger;
  225. curLedgerData = result.curLedgerData;
  226. pos = result.pos;
  227. curPosData = result.curPosData;
  228. materialListData = result.materialListData;
  229. gclList = result.gclList;
  230. notJoinList = result.materialNotJoinListData;
  231. selfList = result.materialSelfListData;
  232. materialChecklistData = result.materialChecklistData;
  233. // 解析清单汇总数据
  234. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  235. gclGatherModel.loadPosData(pos, curPosData);
  236. gclGatherData = gclGatherModel.gatherGclData();
  237. console.log(gclGatherData);
  238. if (openMaterialChecklist) {
  239. const hadBillsidList = _.uniq(_.map(gclList, 'gcl_id'));
  240. console.log(hadBillsidList);
  241. // 判断是否有修订影响到本次数据,并有几率修改清单设置页的值
  242. const pushData = [];
  243. const updateData = [];
  244. for (const hb of hadBillsidList) {
  245. const gcl = _.find(gclGatherData, function (item) {
  246. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, { gcl_id : hb }) !== -1;
  247. });
  248. if (gcl) {
  249. const mc = _.find(materialChecklistData, { b_code: gcl.b_code, name: gcl.name, unit: gcl.unit, unit_price: gcl.unit_price });
  250. // const newOrder = _.indexOf(gclGatherData, gcl);
  251. // console.log(newOrder);
  252. if (!mc && _.findIndex(pushData, { b_code: gcl.b_code, name: gcl.name, unit: gcl.unit, unit_price: gcl.unit_price }) === -1) {
  253. 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 });
  254. }
  255. }
  256. }
  257. const removeData = [];
  258. for (const mc of materialChecklistData) {
  259. const gcl = _.find(gclGatherData, { b_code: mc.b_code, name: mc.name, unit: mc.unit, unit_price: mc.unit_price });
  260. // 判断是否已不存在工料清单,台账修改过后删除之
  261. if (!gcl) {
  262. removeData.push(mc.id);
  263. } else {
  264. // 更新had_bills值
  265. const updateObj = { id: mc.id };
  266. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  267. const jiaoji = _.intersection(gcl_ids, hadBillsidList);
  268. if (mc.had_bills === 1) {
  269. if (jiaoji.length === 0) {
  270. updateObj.mid = materialID;
  271. updateObj.had_bills = 0;
  272. // updateData.push({ id: mc.id, mid: materialID, had_bills: 0 });
  273. }
  274. } else if (mc.had_bills === 0) {
  275. if (jiaoji.length !== 0) {
  276. updateObj.had_bills = 1;
  277. }
  278. }
  279. // 更新工程量及台账金额
  280. if (mc.quantity !== (gcl.quantity ? gcl.quantity : null)) {
  281. updateObj.quantity = gcl.quantity ? gcl.quantity : null;
  282. updateObj.total_price = gcl.total_price ? gcl.total_price : null;
  283. }
  284. if(!_.isEqual(updateObj,{ id: mc.id })) updateData.push(updateObj);
  285. }
  286. }
  287. console.log(pushData, removeData, updateData);
  288. if (pushData.length > 0 || removeData.length > 0 || updateData.length > 0) {
  289. // materialChecklistData = await postDataAsync('/tender/'+ tenderID +'/measure/material/'+ stage_order +'/checklist/save', { type: 'resetChecklist', pushData, removeData, updateData })
  290. }
  291. gclGatherData = gclGatherData.filter(item => {
  292. return item.qc_qty || item.contract_qty
  293. });
  294. // 取交集
  295. const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
  296. gclGatherData = _.filter(gclGatherData, function (item) {
  297. if(_.find(materialChecklistData, { b_code: item.b_code, name: item.name, unit: item.unit, unit_price: item.unit_price })) {
  298. return true;
  299. } else {
  300. const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
  301. const jiaoji = _.intersection(gcl_ids, selfListGcl);
  302. if (jiaoji.length > 0) {
  303. return true;
  304. }
  305. }
  306. });
  307. } else {
  308. gclGatherData = gclGatherData.filter(item => {
  309. return item.qc_qty || item.contract_qty
  310. });
  311. }
  312. calculateJiaCha(gclGatherData);
  313. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  314. // 加载清单数据
  315. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  316. loadLeafXmjData(0);
  317. loadMaterialData(0);
  318. loadXmjMaterialData(0, 0);
  319. const sheet = materialSpread.getActiveSheet();
  320. sheet.suspendPaint();
  321. sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  322. sheet.resumePaint();
  323. const selfSheet = materialSelfSpread.getActiveSheet();
  324. selfSheet.suspendPaint();
  325. selfSheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  326. selfSheet.resumePaint();
  327. checkNotJoinMaterialData();
  328. });
  329. // const leafXmjCol = {
  330. // getValue: {
  331. // jiacha: function (data) {
  332. // let sum = 0;
  333. // const sheet = leafXmjSpread.getActiveSheet();
  334. // const select = SpreadJsObj.getSelectObject(sheet);
  335. // const notx = findNotJoinLeafXmj(select);
  336. // if (notx === undefined) {
  337. // for(const ml of materialList) {
  338. // sum = ZhCalc.round(ZhCalc.add(sum, ZhCalc.mul(ZhCalc.mul(data.gather_qty, ml.quantity), getMpSpreadByMBData(ml.mb_id))), 2);
  339. // }
  340. // }
  341. // return sum !== 0 ? sum : null;
  342. // }
  343. // }
  344. // };
  345. // SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  346. // 调差清单工料table
  347. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  348. const materialSpreadSetting = {
  349. cols: [
  350. {title: '清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  351. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  352. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  353. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  354. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  355. ],
  356. emptyRows: 0,
  357. headRows: 2,
  358. headRowHeight: [25, 25],
  359. defaultRowHeight: 21,
  360. headerFont: '12px 微软雅黑',
  361. font: '12px 微软雅黑',
  362. };
  363. const materialBase = {
  364. isEdit: function (data, type = 'normal') {
  365. // 是否本期添加的工料
  366. // return data.order === stage_order && !openMaterialChecklist;
  367. let flag = true;
  368. if (type === 'del') {
  369. flag = data.order === stage_order;
  370. }
  371. return flag && !openMaterialChecklist;
  372. }
  373. };
  374. const materialCol = {
  375. readOnly: {
  376. isEdit: function (data) {
  377. // const sheet = leafXmjSpread.getActiveSheet();
  378. // const select = SpreadJsObj.getSelectObject(sheet);
  379. // const notx = findNotJoinLeafXmj(select);
  380. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  381. return !(!readOnly && materialBase.isEdit(data));
  382. },
  383. },
  384. };
  385. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  386. // 获取项目节数据
  387. let materialList = [];
  388. function loadMaterialData(iGclRow) {
  389. const gcl = gclGatherData[iGclRow];
  390. if (gcl && gcl.leafXmjs) {
  391. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  392. materialList = [];
  393. const newMaterialList = _.uniqBy(_.filter(gclList, function (m) {
  394. return _.indexOf(gcl_ids, m.gcl_id) !== -1;
  395. }), 'mb_id');
  396. for(const m of newMaterialList) {
  397. const bills = _.find(materialBillsData, { id: m.mb_id });
  398. if(bills) {
  399. m.code = bills.code;
  400. m.name = bills.name;
  401. m.unit = bills.unit;
  402. }
  403. }
  404. console.log(newMaterialList);
  405. materialList = newMaterialList;
  406. // 对清单调差工料table的单位数量进行改变
  407. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  408. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  409. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialList);
  410. } else {
  411. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '数量 �';
  412. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  413. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  414. }
  415. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  416. }
  417. // 调差清单工料table
  418. const materialSelfSpread = SpreadJsObj.createNewSpread($('#material-self-spread')[0]);
  419. const materialSelfSpreadSetting = {
  420. cols: [
  421. {title: '明细清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  422. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  423. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  424. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  425. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  426. ],
  427. emptyRows: 0,
  428. headRows: 2,
  429. headRowHeight: [25, 25],
  430. defaultRowHeight: 21,
  431. headerFont: '12px 微软雅黑',
  432. font: '12px 微软雅黑',
  433. };
  434. const materialSelfBase = {
  435. isEdit: function (data, type = 'normal') {
  436. // 是否本期添加的工料
  437. // return data.order === stage_order && !openMaterialChecklist;
  438. let flag = true;
  439. if (type === 'del') {
  440. flag = data.order === stage_order;
  441. }
  442. return flag;
  443. }
  444. };
  445. const materialSelfCol = {
  446. readOnly: {
  447. isEdit: function (data) {
  448. // const sheet = leafXmjSpread.getActiveSheet();
  449. // const select = SpreadJsObj.getSelectObject(sheet);
  450. // const notx = findNotJoinLeafXmj(select);
  451. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  452. return !(!readOnly && materialSelfBase.isEdit(data));
  453. },
  454. },
  455. };
  456. SpreadJsObj.initSpreadSettingEvents(materialSelfSpreadSetting, materialSelfCol);
  457. let materialListSelf = [];
  458. function loadXmjMaterialData(iGclRow, iLXmjRow) {
  459. // 存在单独设置的才展示,不然隐藏
  460. const gcl = gclGatherData[iGclRow];
  461. const leafXmjs = gcl && gcl.leafXmjs ? gcl.leafXmjs.filter(item => {
  462. return item.qc_qty || item.contract_qty
  463. }) : null;
  464. if (leafXmjs) {
  465. const xmj = leafXmjs[iLXmjRow];
  466. console.log(xmj, iLXmjRow);
  467. materialListSelf = [];
  468. if (_.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: (xmj.mx_id ? xmj.mx_id : '') }) != -1) {
  469. for (const m of materialListData) {
  470. if (m.gcl_id === xmj.gcl_id && m.xmj_id === xmj.id && ((xmj.mx_id !==undefined && m.mx_id === xmj.mx_id) || xmj.mx_id === undefined)) {
  471. materialListSelf.push(m);
  472. }
  473. }
  474. $('#material-self-spread-div').addClass('active');
  475. showSelfSideTools(true);
  476. } else {
  477. $('#material-self-spread-div').removeClass('active');
  478. showSelfSideTools(false);
  479. }
  480. // 对清单调差工料table的单位数量进行改变
  481. materialSelfSpreadSetting.cols[materialSelfSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  482. SpreadJsObj.initSheet(materialSelfSpread.getActiveSheet(), materialSelfSpreadSetting);
  483. SpreadJsObj.loadSheetData(materialSelfSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialListSelf);
  484. } else {
  485. $('#material-self-spread-div').removeClass('active');
  486. showSelfSideTools(false);
  487. materialSpreadSetting.cols[materialSelfSpreadSetting.cols.length - 2].title = '数量 �';
  488. SpreadJsObj.initSheet(materialSelfSpread.getActiveSheet(), materialSelfSpreadSetting);
  489. SpreadJsObj.loadSheetData(materialSelfSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  490. }
  491. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  492. leafXmjSpread.refresh();
  493. materialSelfSpread.refresh();
  494. }
  495. // SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), )
  496. // loadLeafXmjData(0);
  497. // loadMaterialData(0, 0);
  498. // const sheet = materialSpread.getActiveSheet();
  499. // sheet.suspendPaint();
  500. // sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  501. // sheet.resumePaint();
  502. // 不参与调差数据值变灰
  503. function checkNotJoinMaterialData() {
  504. const sheet = ledgerSpread.getActiveSheet();
  505. const select = SpreadJsObj.getSelectObject(sheet);
  506. const index = gclGatherData.indexOf(select);
  507. if (index !== -1) {
  508. const xmj = gclGatherData[index].leafXmjs.filter(item => {
  509. return item.qc_qty || item.contract_qty
  510. });
  511. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  512. for (const [iRow,x] of xmj.entries()) {
  513. const notx = findNotJoinLeafXmj(x);
  514. const color = notx === undefined ? '' : '#d6d8db';
  515. leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
  516. }
  517. }
  518. }
  519. // checkNotJoinMaterialData();
  520. // 对添加工料表格赋值
  521. function changeMaterialTable(from = 'all') {
  522. $('#materialBills tr').removeClass('table-secondary');
  523. $('#materialBills').find('input').removeAttr('disabled');
  524. $('#materialBills').find('input').prop('checked', false);
  525. const searchList = from === 'self' ? materialListSelf : materialList;
  526. console.log(searchList);
  527. for (const [index, ml] of searchList.entries()) {
  528. const mbIndex = materialBillsData.findIndex(function (item) {
  529. return item.id === ml.mb_id;
  530. });
  531. if (mbIndex !== -1) {
  532. $('#materialBills tr').eq(mbIndex).addClass('table-secondary');
  533. $('#materialBills').find('input').eq(mbIndex).attr('disabled', true);
  534. $('#materialBills').find('input').eq(mbIndex).prop('checked', true);
  535. }
  536. }
  537. }
  538. // 添加调差工料
  539. $('#add_material_bill').click(function () {
  540. // 获取已选工料
  541. $('#materialBills').find('input:disabled').prop('checked', false);
  542. const selectList = $('#materialBills').find('input:checked');
  543. if (selectList.length === 0) {
  544. toastr.warning('请选择调差工料');
  545. $('#materialBills').find('input:disabled').prop('checked', true);
  546. return false;
  547. }
  548. const mb_id = [];
  549. for (let s = 0; s < selectList.length; s++) {
  550. mb_id.push($('#materialBills').find('input:checked').eq(s).val());
  551. }
  552. const type = $('#add_type').val();
  553. if (type === 'all') {
  554. // 获取当前项目节或部位明细id
  555. const sheet = ledgerSpread.getActiveSheet();
  556. const select = SpreadJsObj.getSelectObject(sheet);
  557. const index = gclGatherData.indexOf(select);
  558. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  559. const datas = [];
  560. for (const xmj of gcl) {
  561. const notx = findNotJoinLeafXmj(xmj);
  562. const data = {
  563. xmj_id: xmj.id,
  564. gcl_id: xmj.gcl_id,
  565. mx_id: xmj.mx_id ? xmj.mx_id : '',
  566. gather_qty: xmj.gather_qty,
  567. is_join: notx === undefined ? 1 : 0,
  568. };
  569. datas.push(data);
  570. }
  571. console.log(datas, gcl, mb_id);
  572. postData(window.location.pathname + '/save', {type: 'adds', postData: {xmjs: datas, mbIds: mb_id}}, function (result) {
  573. materialListData = result.materialListData;
  574. gclList = result.gclList;
  575. // toastr.success('已成功应用');
  576. calculateJiaCha(gclGatherData);
  577. // const index = gclGatherData.indexOf(ledgerSelect);
  578. loadLeafXmjData(index);
  579. // const xmjSheet = leafXmjSpread.getActiveSheet();
  580. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  581. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  582. loadMaterialData(index);
  583. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  584. $('#addgl').modal('hide');
  585. });
  586. } else if (type === 'self') {
  587. // 获取当前项目节或部位明细id
  588. const sheet = ledgerSpread.getActiveSheet();
  589. const select = SpreadJsObj.getSelectObject(sheet);
  590. const index = gclGatherData.indexOf(select);
  591. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  592. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  593. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  594. const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  595. const xmj = gcl[leafXmjIndex];
  596. const notx = findNotJoinLeafXmj(xmj);
  597. const data = {
  598. xmj_id: xmj.id,
  599. gcl_id: xmj.gcl_id,
  600. mx_id: xmj.mx_id ? xmj.mx_id : '',
  601. mb_id: mb_id,
  602. gather_qty: xmj.gather_qty,
  603. is_join: notx === undefined ? 1 : 0,
  604. };
  605. console.log(data);
  606. postData(window.location.pathname + '/save', {type: 'add', postData: data}, function (result) {
  607. // 添加到materialList里
  608. materialListData = result;
  609. loadXmjMaterialData(index, leafXmjIndex);
  610. $('#addgl').modal('hide');
  611. });
  612. }
  613. $('#materialBills').find('input:disabled').prop('checked', true);
  614. });
  615. if (!readOnly) {
  616. const leafXmjSpreadObj = {
  617. getSelect : function () {
  618. const sheet = ledgerSpread.getActiveSheet();
  619. const select = SpreadJsObj.getSelectObject(sheet);
  620. const index = gclGatherData.indexOf(select);
  621. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  622. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  623. const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
  624. const leafXmjs = gclGatherData[index].leafXmjs.filter(item => {
  625. return item.qc_qty || item.contract_qty
  626. });
  627. const nRow = leafXmjs.indexOf(leafXmjSelect);
  628. return [index, iRow, nRow, leafXmjSheet, leafXmjSelect];
  629. },
  630. checkJoinMaterial: function (type) {
  631. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  632. const color = type === 'join' ? '' : '#d6d8db';
  633. const data = {
  634. type: type,
  635. select: type === 'join' ? findNotJoinLeafXmj(select) : select,
  636. };
  637. // 添加到
  638. postData(window.location.pathname + '/save', data, function (result) {
  639. if (type === 'join') {
  640. const index = findNotJoinLeafXmj(select, 'index');
  641. notJoinList.splice(index, 1);
  642. } else {
  643. notJoinList.push(result);
  644. }
  645. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  646. calculateJiaCha(gclGatherData, iGclRow);
  647. SpreadJsObj.reLoadRowData(sheet, nRow);
  648. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  649. loadMaterialData(iGclRow);
  650. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  651. });
  652. },
  653. checkSelfMaterial: function (type) {
  654. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  655. // const color = type === 'self' ? '' : '#d6d8db';
  656. const data = {
  657. type: type,
  658. select: type === 'noself' ? findSelfLeafXmj(select) : select,
  659. };
  660. // 添加到
  661. postData(window.location.pathname + '/save', data, function (result) {
  662. if (type === 'noself') {
  663. const index = findSelfLeafXmj(select, 'index');
  664. selfList.splice(index, 1);
  665. } else {
  666. selfList.push(result);
  667. }
  668. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  669. calculateJiaCha(gclGatherData, iGclRow);
  670. SpreadJsObj.reLoadRowData(sheet, nRow);
  671. // sheet.getRange(nRow, -1, 1, -1).backColor(color);
  672. loadXmjMaterialData(iGclRow, nRow);
  673. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  674. });
  675. },
  676. }
  677. // leafXmj右键功能
  678. $.contextMenu({
  679. selector: '#leaf-xmj-spread',
  680. build: function ($trigger, e) {
  681. const target = SpreadJsObj.safeRightClickSelection($trigger, e, leafXmjSpread);
  682. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  683. },
  684. items: {
  685. 'stop': {
  686. name: '不参与调差',
  687. icon: 'fa-remove',
  688. callback: function (key, opt) {
  689. leafXmjSpreadObj.checkJoinMaterial('notjoin');
  690. },
  691. visible: function (key, opt) {
  692. const sheet = leafXmjSpread.getActiveSheet();
  693. const select = SpreadJsObj.getSelectObject(sheet);
  694. const sel = sheet.getSelections()[0];
  695. if (!select || sel.rowCount !== 1) {
  696. return false;
  697. }
  698. const notx = findNotJoinLeafXmj(select);
  699. if (!readOnly && select && notx === undefined) {
  700. return true;
  701. } else {
  702. return false;
  703. }
  704. }
  705. },
  706. 'start': {
  707. name: '参与调差',
  708. icon: 'fa-sign-in',
  709. callback: function (key, opt) {
  710. leafXmjSpreadObj.checkJoinMaterial('join');
  711. },
  712. visible: function (key, opt) {
  713. const sheet = leafXmjSpread.getActiveSheet();
  714. const select = SpreadJsObj.getSelectObject(sheet);
  715. const sel = sheet.getSelections()[0];
  716. if (!select || sel.rowCount !== 1) {
  717. return false;
  718. }
  719. const notx = findNotJoinLeafXmj(select);
  720. if (!readOnly && select && notx === undefined) {
  721. return false;
  722. } else {
  723. return true;
  724. }
  725. },
  726. },
  727. 'self': {
  728. name: '单独添加工料',
  729. icon: 'fa-sign-in',
  730. callback: function (key, opt) {
  731. leafXmjSpreadObj.checkSelfMaterial('self');
  732. },
  733. visible: function (key, opt) {
  734. const sheet = leafXmjSpread.getActiveSheet();
  735. const select = SpreadJsObj.getSelectObject(sheet);
  736. const sel = sheet.getSelections()[0];
  737. if (!select || sel.rowCount !== 1) {
  738. return false;
  739. }
  740. const notx = findSelfLeafXmj(select);
  741. if (!readOnly && select && notx === undefined) {
  742. return true;
  743. } else {
  744. return false;
  745. }
  746. }
  747. },
  748. 'noself': {
  749. name: '取消单独添加工料',
  750. icon: 'fa-remove',
  751. callback: function (key, opt) {
  752. leafXmjSpreadObj.checkSelfMaterial('noself');
  753. },
  754. visible: function (key, opt) {
  755. const sheet = leafXmjSpread.getActiveSheet();
  756. const select = SpreadJsObj.getSelectObject(sheet);
  757. const sel = sheet.getSelections()[0];
  758. if (!select || sel.rowCount !== 1) {
  759. return false;
  760. }
  761. const notx = findSelfLeafXmj(select);
  762. if (!readOnly && select && notx === undefined) {
  763. return false;
  764. } else {
  765. return true;
  766. }
  767. },
  768. },
  769. }
  770. });
  771. // material-spread右键功能
  772. const materialSpreadObj = {
  773. del: function () {
  774. const materialSheet = materialSpread.getActiveSheet();
  775. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  776. const sheet = ledgerSpread.getActiveSheet();
  777. const select = SpreadJsObj.getSelectObject(sheet);
  778. const index = gclGatherData.indexOf(select);
  779. // const leafXmjSheet = leafXmjSpread.getActiveSheet();
  780. // const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  781. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  782. // const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  783. const datas = [];
  784. for (const xmj of gcl) {
  785. const data = {
  786. xmj_id: xmj.id,
  787. gcl_id: xmj.gcl_id,
  788. mx_id: xmj.mx_id ? xmj.mx_id : '',
  789. };
  790. datas.push(data);
  791. }
  792. console.log(datas, materialSelect.mb_id);
  793. postData(window.location.pathname + '/save', {type: 'dels', postData: { xmjs: datas, mb_id: materialSelect.mb_id }}, function (result) {
  794. materialListData = result.materialListData;
  795. gclList = result.gclList;
  796. calculateJiaCha(gclGatherData);
  797. // const index = gclGatherData.indexOf(ledgerSelect);
  798. loadLeafXmjData(index);
  799. // const xmjSheet = leafXmjSpread.getActiveSheet();
  800. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  801. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  802. loadMaterialData(index);
  803. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  804. });
  805. // postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  806. // const index = materialList.indexOf(select);
  807. // materialList.splice(index, 1);
  808. // sheet.deleteRows(index, 1);
  809. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  810. // const sel = sheet.getSelections();
  811. // sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  812. // const materialListIndex = materialListData.indexOf(select);
  813. // materialListData.splice(materialListIndex, 1);
  814. // const [iGclRow, iRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  815. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  816. // calculateJiaCha(gclGatherData, iGclRow);
  817. // SpreadJsObj.reLoadRowData(lsheet, iRow);
  818. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  819. // });
  820. },
  821. deletePress: function (sheet) {
  822. return;
  823. },
  824. editStarting: function (e, info) {
  825. const col = info.sheet.zh_setting.cols[info.col];
  826. const select = SpreadJsObj.getSelectObject(info.sheet);
  827. if (col.field === 'quantity') {
  828. if (select.expr && select.expr !== '') {
  829. info.sheet.getCell(info.row, info.col).text(select.expr);
  830. }
  831. }
  832. },
  833. editEnded: function (e, info) {
  834. if (info.sheet.zh_setting) {
  835. const select = SpreadJsObj.getSelectObject(info.sheet);
  836. const col = info.sheet.zh_setting.cols[info.col];
  837. // 未改变值则不提交
  838. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  839. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  840. // let orgValue = select[col.field];
  841. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  842. let orgValue;
  843. if (col.field === 'quantity') {
  844. orgValue = validText && validText !== ''
  845. ? _.toNumber(validText) ? select.quantity : select.expr
  846. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  847. } else {
  848. orgValue = select[col.field];
  849. }
  850. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  851. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  852. return;
  853. }
  854. const exprQuantity = {
  855. expr: '',
  856. quantity: 0,
  857. };
  858. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  859. if (!valid) {
  860. toastr.error(msg);
  861. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  862. return;
  863. }
  864. if (isNaN(exprQuantity.quantity)) {
  865. toastr.error('不能输入其它非数字类型字符');
  866. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  867. return;
  868. }
  869. const num = parseFloat(exprQuantity.quantity);
  870. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  871. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  872. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  873. // return;
  874. toastr.warning('已保留6位小数');
  875. exprQuantity.quantity = ZhCalc.round(num, 6);
  876. }
  877. // 更新至服务器
  878. const ledgerSheet = ledgerSpread.getActiveSheet();
  879. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  880. const index = gclGatherData.indexOf(ledgerSelect);
  881. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  882. // const xmjSheet = leafXmjSpread.getActiveSheet();
  883. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  884. // const xmjIndex = gcl.indexOf(xmjSelect);
  885. const datas = [];
  886. for (const xmj of gcl) {
  887. const data = {
  888. xmj_id: xmj.id,
  889. gcl_id: xmj.gcl_id,
  890. mx_id: xmj.mx_id ? xmj.mx_id : '',
  891. };
  892. datas.push(data);
  893. }
  894. console.log(exprQuantity, datas, select.mb_id);
  895. postData(window.location.pathname + '/save', { type:'updates', updateData: { xmjs: datas, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id } }, function (result) {
  896. materialListData = result.materialListData;
  897. gclList = result.gclList;
  898. calculateJiaCha(gclGatherData);
  899. // const index = gclGatherData.indexOf(ledgerSelect);
  900. loadLeafXmjData(index);
  901. // const xmjSheet = leafXmjSpread.getActiveSheet();
  902. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  903. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  904. loadMaterialData(index);
  905. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  906. materialSpread.getActiveSheet().setSelection(info.row + 1, info.col, 1, 1);
  907. }, function () {
  908. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  909. });
  910. // postData(window.location.pathname + '/save', { type:'update', updateData: { id:select.id, quantity: validText, mb_id: select.mb_id } }, function (result) {
  911. // const materialListIndex = materialListData.indexOf(select);
  912. // const index = materialList.indexOf(select);
  913. // select[col.field] = validText;
  914. // materialListData.splice(materialListIndex, 1, select);
  915. // materialList.indexOf(index, 1, select);
  916. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  917. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  918. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  919. // calculateJiaCha(gclGatherData, iGclRow)
  920. // SpreadJsObj.reLoadRowData(sheet, iRow);
  921. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  922. // }, function () {
  923. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  924. // });
  925. }
  926. },
  927. clipboardPasted(e, info) {
  928. const hint = {
  929. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  930. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  931. numberCan: {type: 'warning', msg: '已保留6位小数'},
  932. };
  933. const range = info.cellRange;
  934. const sortData = info.sheet.zh_data || [];
  935. if (range.row + range.rowCount > sortData.length) {
  936. toastMessageUniq(hint.cellError);
  937. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  938. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  939. return;
  940. }
  941. if (sortData.length > 0 && range.col + range.colCount > 5) {
  942. toastMessageUniq(hint.cellError);
  943. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  944. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  945. return;
  946. }
  947. const data = [];
  948. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  949. let bPaste = true;
  950. const curRow = range.row + iRow;
  951. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  952. const hintRow = range.rowCount > 1 ? curRow : '';
  953. let sameCol = 0;
  954. for (let iCol = 0; iCol < range.colCount; iCol++) {
  955. const curCol = range.col + iCol;
  956. const colSetting = info.sheet.zh_setting.cols[curCol];
  957. if (!colSetting) continue;
  958. // let validText = info.sheet.getText(curRow, curCol);
  959. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  960. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  961. const orgValue = sortData[curRow][colSetting.field];
  962. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  963. sameCol++;
  964. if (range.colCount === sameCol) {
  965. bPaste = false;
  966. }
  967. continue;
  968. }
  969. const exprQuantity = {
  970. expr: '',
  971. quantity: 0,
  972. };
  973. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  974. if (!valid) {
  975. toastMessageUniq(getPasteHint(msg, hintRow));
  976. bPaste = false;
  977. continue;
  978. }
  979. if (isNaN(exprQuantity.quantity)) {
  980. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  981. bPaste = false;
  982. continue;
  983. }
  984. const num = parseFloat(exprQuantity.quantity);
  985. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  986. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  987. // bPaste = false;
  988. // continue;
  989. exprQuantity.quantity = ZhCalc.round(num, 6);
  990. }
  991. // materialData[colSetting.field] = validText;
  992. materialData.expr = exprQuantity.expr;
  993. materialData.quantity = exprQuantity.quantity;
  994. }
  995. if (bPaste) {
  996. data.push(materialData);
  997. // rowData.push(curRow);
  998. } else {
  999. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1000. }
  1001. }
  1002. if (data.length === 0) {
  1003. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1004. return;
  1005. }
  1006. const ledgerSheet = ledgerSpread.getActiveSheet();
  1007. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1008. const index = gclGatherData.indexOf(ledgerSelect);
  1009. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1010. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1011. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1012. // const xmjIndex = gcl.indexOf(xmjSelect);
  1013. const datas = [];
  1014. for (const xmj of gcl) {
  1015. const data2 = {
  1016. xmj_id: xmj.id,
  1017. gcl_id: xmj.gcl_id,
  1018. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1019. };
  1020. datas.push(data2);
  1021. }
  1022. console.log(data, datas);
  1023. // 更新至服务器
  1024. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data } }, function (result) {
  1025. materialListData = result.materialListData;
  1026. gclList = result.gclList;
  1027. calculateJiaCha(gclGatherData);
  1028. // const index = gclGatherData.indexOf(ledgerSelect);
  1029. loadLeafXmjData(index);
  1030. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1031. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1032. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1033. loadMaterialData(index);
  1034. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1035. materialSpread.getActiveSheet().setSelection(info.cellRange.row, info.cellRange.col, info.cellRange.rowCount, info.cellRange.colCount);
  1036. }, function () {
  1037. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1038. });
  1039. // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1040. // materialListData = result;
  1041. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1042. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1043. // calculateJiaCha(gclGatherData, iGclRow);
  1044. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1045. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1046. // }, function () {
  1047. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1048. // });
  1049. },
  1050. _checkExprValid(expr) {
  1051. if (!expr) return [true, null];
  1052. const param = [];
  1053. let num = '', base = '';
  1054. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1055. if (/^[\d\.%]+/.test(expr[i])) {
  1056. if (base !== '') {
  1057. param.push({type: 'base', value: base});
  1058. base = '';
  1059. }
  1060. num = num + expr[i];
  1061. } else if (expr[i] === '(') {
  1062. if (num !== '') {
  1063. param.push({type: 'num', value: num});
  1064. num = '';
  1065. }
  1066. if (base !== '') {
  1067. param.push({type: 'base', value: base});
  1068. base = '';
  1069. }
  1070. param.push({type: 'left', value: '('});
  1071. } else if (expr[i] === ')') {
  1072. if (num !== '') {
  1073. param.push({type: 'num', value: num});
  1074. num = '';
  1075. }
  1076. if (base !== '') {
  1077. param.push({type: 'base', value: base});
  1078. base = '';
  1079. }
  1080. param.push({type: 'right', value: ')'});
  1081. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1082. if (num !== '') {
  1083. param.push({type: 'num', value: num});
  1084. num = '';
  1085. }
  1086. if (base !== '') {
  1087. param.push({type: 'base', value: base});
  1088. base = '';
  1089. }
  1090. param.push({type: 'calc', value: expr[i]});
  1091. } else {
  1092. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1093. }
  1094. }
  1095. if (num !== '') {
  1096. param.push({type: 'num', value: num});
  1097. num = '';
  1098. }
  1099. if (base !== '') {
  1100. param.push({type: 'base', value: base});
  1101. base = '';
  1102. }
  1103. if (param.length === 0) return true;
  1104. if (param.length > 1) {
  1105. if (param[0].value === '-') {
  1106. param[1].value = '-' + param[1];
  1107. }
  1108. param.unshift();
  1109. }
  1110. const iLen = param.length;
  1111. let iLeftCount = 0, iRightCount = 0;
  1112. for (const [i, p] of param.entries()) {
  1113. if (p.type === 'calc') {
  1114. if (i === 0 || i === iLen - 1)
  1115. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1116. }
  1117. if (p.type === 'num') {
  1118. num = p.value.replace('%', '');
  1119. if (p.value.length - num.length > 1)
  1120. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1121. num = _.toNumber(num);
  1122. if (num === undefined || num === null || _.isNaN(num))
  1123. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1124. if (i > 0) {
  1125. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1126. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1127. } else if (param[i - 1].value === '/' && num === 0) {
  1128. return [false, '输入的表达式非法:请勿除0'];
  1129. }
  1130. }
  1131. }
  1132. if (p.type === 'base') {
  1133. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1134. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1135. }
  1136. if (p.type === 'left') {
  1137. iLeftCount += 1;
  1138. if (i !== 0 && param[i-1].type !== 'calc')
  1139. return [false, '输入的表达式非法:(前应有运算符'];
  1140. }
  1141. if (p.type === 'right') {
  1142. iRightCount += 1;
  1143. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1144. return [false, '输入的表达式非法:)后应有运算符'];
  1145. if (iRightCount > iLeftCount)
  1146. return [false, '输入的表达式非法:")"前无对应的"("'];
  1147. }
  1148. }
  1149. if (iLeftCount > iRightCount)
  1150. return [false, '输入的表达式非法:"("后无对应的")"'];
  1151. return [true, ''];
  1152. },
  1153. _checkExpr: function (text, data) {
  1154. if (text) {
  1155. const num = _.toNumber(text);
  1156. if (num) {
  1157. data.quantity = num;
  1158. data.expr = '';
  1159. } else {
  1160. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  1161. const [valid, msg] = this._checkExprValid(expr);
  1162. if (!valid) return [valid, msg];
  1163. data.expr = expr;
  1164. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr);
  1165. // const ce = new CalcEvalMin();
  1166. // data.quantity = ce.eval(expr);
  1167. // console.log(data.quantity);
  1168. }
  1169. } else {
  1170. data.quantity = 0;
  1171. data.expr = '';
  1172. }
  1173. return [true, ''];
  1174. },
  1175. };
  1176. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  1177. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  1178. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  1179. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  1180. // material-spread右键功能
  1181. const materialSelfSpreadObj = {
  1182. del: function () {
  1183. const sheet = materialSelfSpread.getActiveSheet();
  1184. const select = SpreadJsObj.getSelectObject(sheet);
  1185. console.log(select);
  1186. postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  1187. const index = materialListSelf.indexOf(select);
  1188. materialListSelf.splice(index, 1);
  1189. sheet.deleteRows(index, 1);
  1190. SpreadJsObj.reLoadSheetData(materialSelfSpread.getActiveSheet());
  1191. const sel = sheet.getSelections();
  1192. sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1193. const materialListIndex = materialListData.indexOf(select);
  1194. materialListData.splice(materialListIndex, 1);
  1195. const [iGclRow, iRow, nRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  1196. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1197. calculateJiaCha(gclGatherData, iGclRow);
  1198. SpreadJsObj.reLoadRowData(lsheet, nRow);
  1199. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1200. });
  1201. },
  1202. deletePress: function (sheet) {
  1203. return;
  1204. },
  1205. editStarting: function (e, info) {
  1206. const col = info.sheet.zh_setting.cols[info.col];
  1207. const select = SpreadJsObj.getSelectObject(info.sheet);
  1208. if (col.field === 'quantity') {
  1209. if (select.expr && select.expr !== '') {
  1210. info.sheet.getCell(info.row, info.col).text(select.expr);
  1211. }
  1212. }
  1213. },
  1214. editEnded: function (e, info) {
  1215. if (info.sheet.zh_setting) {
  1216. const select = SpreadJsObj.getSelectObject(info.sheet);
  1217. const col = info.sheet.zh_setting.cols[info.col];
  1218. // 未改变值则不提交
  1219. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1220. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1221. // let orgValue = select[col.field];
  1222. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1223. let orgValue;
  1224. if (col.field === 'quantity') {
  1225. orgValue = validText && validText !== ''
  1226. ? _.toNumber(validText) ? select.quantity : select.expr
  1227. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1228. } else {
  1229. orgValue = select[col.field];
  1230. }
  1231. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1232. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1233. return;
  1234. }
  1235. const exprQuantity = {
  1236. expr: '',
  1237. quantity: 0,
  1238. };
  1239. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1240. if (!valid) {
  1241. toastr.error(msg);
  1242. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1243. return;
  1244. }
  1245. if (isNaN(exprQuantity.quantity)) {
  1246. toastr.error('不能输入其它非数字类型字符');
  1247. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1248. return;
  1249. }
  1250. const num = parseFloat(exprQuantity.quantity);
  1251. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1252. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1253. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1254. // return;
  1255. toastr.warning('已保留6位小数');
  1256. exprQuantity.quantity = ZhCalc.round(num, 6);
  1257. }
  1258. // 更新至服务器
  1259. console.log(exprQuantity, select.mb_id);
  1260. postData(window.location.pathname + '/save', { type:'update', updateData: { id: select.id, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id } }, function (result) {
  1261. const materialListIndex = materialListData.indexOf(select);
  1262. const index = materialList.indexOf(select);
  1263. select.quantity = exprQuantity.quantity;
  1264. select.expr = exprQuantity.expr;
  1265. materialListData.splice(materialListIndex, 1, select);
  1266. materialList.indexOf(index, 1, select);
  1267. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1268. const [iGclRow, iRow, nRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1269. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1270. calculateJiaCha(gclGatherData, iGclRow);
  1271. SpreadJsObj.reLoadRowData(sheet, nRow);
  1272. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1273. }, function () {
  1274. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1275. });
  1276. }
  1277. },
  1278. clipboardPasted(e, info) {
  1279. const hint = {
  1280. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1281. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1282. numberCan: {type: 'warning', msg: '已保留6位小数'},
  1283. };
  1284. const range = info.cellRange;
  1285. const sortData = info.sheet.zh_data || [];
  1286. if (range.row + range.rowCount > sortData.length) {
  1287. toastMessageUniq(hint.cellError);
  1288. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1289. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1290. return;
  1291. }
  1292. if (sortData.length > 0 && range.col + range.colCount > 5) {
  1293. toastMessageUniq(hint.cellError);
  1294. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1295. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1296. return;
  1297. }
  1298. const data = [];
  1299. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1300. let bPaste = true;
  1301. const curRow = range.row + iRow;
  1302. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  1303. const hintRow = range.rowCount > 1 ? curRow : '';
  1304. let sameCol = 0;
  1305. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1306. const curCol = range.col + iCol;
  1307. const colSetting = info.sheet.zh_setting.cols[curCol];
  1308. if (!colSetting) continue;
  1309. // let validText = info.sheet.getText(curRow, curCol);
  1310. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1311. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1312. const orgValue = sortData[curRow][colSetting.field];
  1313. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1314. sameCol++;
  1315. if (range.colCount === sameCol) {
  1316. bPaste = false;
  1317. }
  1318. continue;
  1319. }
  1320. const exprQuantity = {
  1321. expr: '',
  1322. quantity: 0,
  1323. };
  1324. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1325. if (!valid) {
  1326. toastMessageUniq(getPasteHint(msg, hintRow));
  1327. bPaste = false;
  1328. continue;
  1329. }
  1330. if (isNaN(exprQuantity.quantity)) {
  1331. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1332. bPaste = false;
  1333. continue;
  1334. }
  1335. const num = parseFloat(exprQuantity.quantity);
  1336. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1337. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1338. // bPaste = false;
  1339. // continue;
  1340. exprQuantity.quantity = ZhCalc.round(num, 6);
  1341. }
  1342. // materialData[colSetting.field] = validText;
  1343. materialData.expr = exprQuantity.expr;
  1344. materialData.quantity = exprQuantity.quantity;
  1345. }
  1346. if (bPaste) {
  1347. data.push(materialData);
  1348. // rowData.push(curRow);
  1349. } else {
  1350. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1351. }
  1352. }
  1353. if (data.length === 0) {
  1354. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1355. return;
  1356. }
  1357. console.log(data);
  1358. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1359. materialListData = result;
  1360. const [iGclRow, iRow, nRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1361. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1362. calculateJiaCha(gclGatherData, iGclRow);
  1363. // SpreadJsObj.reLoadRowData(sheet, nRow);
  1364. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1365. loadXmjMaterialData(iGclRow, nRow);
  1366. }, function () {
  1367. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1368. });
  1369. },
  1370. };
  1371. materialSelfSpread.bind(spreadNS.Events.EditStarting, materialSelfSpreadObj.editStarting);
  1372. materialSelfSpread.bind(spreadNS.Events.EditEnded, materialSelfSpreadObj.editEnded);
  1373. materialSelfSpread.bind(spreadNS.Events.ClipboardPasted, materialSelfSpreadObj.clipboardPasted);
  1374. SpreadJsObj.addDeleteBind(materialSelfSpread, materialSelfSpreadObj.deletePress);
  1375. if (!openMaterialChecklist) {
  1376. $.contextMenu({
  1377. selector: '#material-spread',
  1378. build: function ($trigger, e) {
  1379. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  1380. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1381. },
  1382. items: {
  1383. 'create': {
  1384. name: '添加工料',
  1385. icon: 'fa-sign-in',
  1386. callback: function (key, opt) {
  1387. // 获取已选清单
  1388. changeMaterialTable();
  1389. $('#add_type').val('all');
  1390. $('#addgl').modal('show');
  1391. },
  1392. disabled: function (key, opt) {
  1393. const sheet = leafXmjSpread.getActiveSheet();
  1394. const select = SpreadJsObj.getSelectObject(sheet);
  1395. // const notx = findNotJoinLeafXmj(select);
  1396. if (!select) {
  1397. return true;
  1398. }
  1399. // if (!readOnly && notx === undefined) {
  1400. // return false;
  1401. // } else {
  1402. // return true;
  1403. // }
  1404. return readOnly;
  1405. }
  1406. },
  1407. 'delete': {
  1408. name: '删除工料',
  1409. icon: 'fa-remove',
  1410. callback: function (key, opt) {
  1411. materialSpreadObj.del(materialSpread.getActiveSheet());
  1412. },
  1413. disabled: function (key, opt) {
  1414. const sheet = materialSpread.getActiveSheet();
  1415. const select = SpreadJsObj.getSelectObject(sheet);
  1416. if (!select) {
  1417. return true;
  1418. }
  1419. if (!readOnly && select && materialBase.isEdit(select, 'del')) {
  1420. return false;
  1421. } else {
  1422. return true;
  1423. }
  1424. }
  1425. },
  1426. }
  1427. });
  1428. }
  1429. $.contextMenu({
  1430. selector: '#material-self-spread',
  1431. build: function ($trigger, e) {
  1432. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSelfSpread);
  1433. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1434. },
  1435. items: {
  1436. 'create': {
  1437. name: '添加工料',
  1438. icon: 'fa-sign-in',
  1439. callback: function (key, opt) {
  1440. // 获取已选清单
  1441. changeMaterialTable('self');
  1442. $('#add_type').val('self');
  1443. $('#addgl').modal('show');
  1444. },
  1445. disabled: function (key, opt) {
  1446. const sheet = leafXmjSpread.getActiveSheet();
  1447. const select = SpreadJsObj.getSelectObject(sheet);
  1448. // const notx = findNotJoinLeafXmj(select);
  1449. if (!select) {
  1450. return true;
  1451. }
  1452. // if (!readOnly && notx === undefined) {
  1453. // return false;
  1454. // } else {
  1455. // return true;
  1456. // }
  1457. return readOnly;
  1458. }
  1459. },
  1460. 'delete': {
  1461. name: '删除工料',
  1462. icon: 'fa-remove',
  1463. callback: function (key, opt) {
  1464. materialSelfSpreadObj.del(materialSelfSpread.getActiveSheet());
  1465. },
  1466. disabled: function (key, opt) {
  1467. const sheet = materialSelfSpread.getActiveSheet();
  1468. const select = SpreadJsObj.getSelectObject(sheet);
  1469. if (!select) {
  1470. return true;
  1471. }
  1472. if (!readOnly && select && materialSelfBase.isEdit(select, 'del')) {
  1473. return false;
  1474. } else {
  1475. return true;
  1476. }
  1477. }
  1478. },
  1479. }
  1480. });
  1481. }
  1482. // 应用调差工料至其他清单明细
  1483. $('#user_all_material').click(function () {
  1484. const ledgerSheet = ledgerSpread.getActiveSheet();
  1485. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1486. if (ledgerSelect.leafXmjs.length < 2) {
  1487. toastr.warning('没有需要应用调差工料的其它清单明细');
  1488. return false;
  1489. }
  1490. const xmjSheet = leafXmjSpread.getActiveSheet();
  1491. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1492. console.log(ledgerSelect.leafXmjs);
  1493. // 判断需要应用调差工料的清单明细
  1494. const needAddList = [];
  1495. for (const xmj of ledgerSelect.leafXmjs) {
  1496. const notx = findNotJoinLeafXmj(xmj);
  1497. if (notx === undefined && xmjSelect !== xmj && xmj.gather_qty && xmj.jiacha === null && xmjSelect.jiacha !== null) {
  1498. needAddList.push(xmj);
  1499. }
  1500. }
  1501. // if (needAddList.length === 0) {
  1502. // toastr.warning('没有需要应用调差工料的其它清单明细');
  1503. // return false;
  1504. // }
  1505. console.log(needAddList, materialList);
  1506. // 更新至服务器
  1507. postData(window.location.pathname + '/save', { type:'useOther', postData: { addXmj: needAddList, materialBills: materialList } }, function (result) {
  1508. materialListData = result.materialListData;
  1509. gclList = result.gclList;
  1510. toastr.success('已成功应用');
  1511. calculateJiaCha(gclGatherData);
  1512. const index = gclGatherData.indexOf(ledgerSelect);
  1513. loadLeafXmjData(index);
  1514. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1515. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1516. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1517. loadMaterialData(index);
  1518. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1519. });
  1520. });
  1521. // 切换清单行,读取所属项目节数据
  1522. ledgerSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1523. if (info.oldSelections !== undefined) {
  1524. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1525. if (iNewRow !== iOldRow) {
  1526. loadLeafXmjData(iNewRow);
  1527. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1528. loadMaterialData(iNewRow);
  1529. loadXmjMaterialData(iNewRow, 0);
  1530. checkNotJoinMaterialData();
  1531. }
  1532. }
  1533. });
  1534. // 切换项目节数据清单明细行,读取单独的清单工料数据
  1535. leafXmjSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1536. if (info.oldSelections !== undefined) {
  1537. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1538. if (iNewRow !== iOldRow) {
  1539. const sheet = ledgerSpread.getActiveSheet();
  1540. const select = SpreadJsObj.getSelectObject(sheet);
  1541. const index = gclGatherData.indexOf(select);
  1542. loadXmjMaterialData(index, iNewRow);
  1543. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  1544. }
  1545. }
  1546. });
  1547. // 显示有调差工料清单
  1548. $('#show_material_gcl').click(function () {
  1549. if ($(this).is(':checked')) {
  1550. const hadMaterialGclGatherData = [];
  1551. const hadGclIdList = [];
  1552. for (const ml of materialListData) {
  1553. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  1554. hadGclIdList.push(ml.gcl_id);
  1555. }
  1556. }
  1557. for (const gcl of gclGatherData) {
  1558. for (const index in gcl.leafXmjs) {
  1559. const gcl_id = gcl.leafXmjs[index].gcl_id;
  1560. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  1561. hadMaterialGclGatherData.push(gcl);
  1562. break;
  1563. }
  1564. }
  1565. }
  1566. gclGatherData = hadMaterialGclGatherData;
  1567. } else {
  1568. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  1569. gclGatherModel.loadPosData(pos, curPosData);
  1570. gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  1571. return item.qc_qty || item.contract_qty
  1572. });
  1573. if (openMaterialChecklist) {
  1574. // 取交集
  1575. gclGatherData = _.filter(gclGatherData, function (item) {
  1576. return _.find(materialChecklistData, { b_code: item.b_code, name: item.name, unit: item.unit, unit_price: item.unit_price });
  1577. });
  1578. }
  1579. }
  1580. calculateJiaCha(gclGatherData);
  1581. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  1582. loadLeafXmjData(0);
  1583. loadMaterialData(0);
  1584. loadXmjMaterialData(0, 0);
  1585. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  1586. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1587. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  1588. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  1589. checkNotJoinMaterialData();
  1590. });
  1591. $.subMenu({
  1592. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1593. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1594. key: 'menu.1.0.0',
  1595. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1596. callback: function (info) {
  1597. if (info.mini) {
  1598. $('.panel-title').addClass('fluid');
  1599. $('#sub-menu').removeClass('panel-sidebar');
  1600. } else {
  1601. $('.panel-title').removeClass('fluid');
  1602. $('#sub-menu').addClass('panel-sidebar');
  1603. }
  1604. autoFlashHeight();
  1605. ledgerSpread.refresh();
  1606. leafXmjSpread.refresh();
  1607. materialSpread.refresh();
  1608. materialSelfSpread.refresh();
  1609. }
  1610. });
  1611. $(window).resize(function () {
  1612. ledgerSpread.refresh();
  1613. leafXmjSpread.refresh();
  1614. materialSpread.refresh();
  1615. materialSelfSpread.refresh();
  1616. });
  1617. $.divResizer({
  1618. select: '#right-spr',
  1619. callback: function () {
  1620. ledgerSpread.refresh();
  1621. // leafXmjSpread.refresh();
  1622. materialSpread.refresh();
  1623. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1624. setLocalCache('material_list_' + materialID, width);
  1625. }
  1626. });
  1627. $.divResizer({
  1628. select: '#right-spr2',
  1629. callback: function () {
  1630. leafXmjSpread.refresh();
  1631. materialSelfSpread.refresh();
  1632. // const width = (($('#right-view2').width()/$('#right-view2').parent('div').width())*100).toFixed();
  1633. // setLocalCache('material_list3_' + materialID, width);
  1634. }
  1635. });
  1636. $.divResizer({
  1637. select: '#main-resize',
  1638. callback: function () {
  1639. materialSpread.refresh();
  1640. ledgerSpread.refresh();
  1641. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1642. $(".sp-wrap").height(bcontent-30);
  1643. leafXmjSpread.refresh();
  1644. materialSelfSpread.refresh();
  1645. const height = $('.bcontent-wrap').height();
  1646. setLocalCache('material_list2_' + materialID, height);
  1647. }
  1648. });
  1649. // 展开收起月信息价并浏览器记住本期展开收起
  1650. $('a', '.right-nav').bind('click', function () {
  1651. //const main = $('#main-view'), tool = $('#tools-view');
  1652. const tab = $(this), tabPanel = $(tab.attr('content'));
  1653. if (!tab.hasClass('active')) {
  1654. $('a', '.side-menu').removeClass('active');
  1655. $('.tab-content .tab-select-show').removeClass('active');
  1656. tab.addClass('active');
  1657. tabPanel.addClass('active');
  1658. showSideTools(tab.hasClass('active'));
  1659. if (tab.attr('content') === '#material-tab') {
  1660. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1661. setLocalCache('material_list_' + materialID, width);
  1662. }
  1663. } else {
  1664. removeLocalCache('material_list_' + materialID);
  1665. tab.removeClass('active');
  1666. tabPanel.removeClass('active');
  1667. showSideTools(tab.hasClass('active'));
  1668. }
  1669. ledgerSpread.refresh();
  1670. // leafXmjSpread.refresh();
  1671. materialSpread.refresh();
  1672. });
  1673. // 根据浏览器记录展开收起
  1674. if (getLocalCache('material_list_' + materialID)) {
  1675. const tab = $('.right-nav a[content="#material-tab"]'), tabPanel = $(tab.attr('content'));
  1676. $('a', '.side-menu').removeClass('active');
  1677. $('.tab-content .tab-select-show').removeClass('active');
  1678. tab.addClass('active');
  1679. tabPanel.addClass('active');
  1680. $('#right-view').css('width', getLocalCache('material_list_' + materialID) + '%');
  1681. showSideTools(tab.hasClass('active'));
  1682. ledgerSpread.refresh();
  1683. // leafXmjSpread.refresh();
  1684. materialSpread.refresh();
  1685. }
  1686. if (getLocalCache('material_list2_' + materialID)) {
  1687. $('.bcontent-wrap').height(getLocalCache('material_list2_' + materialID));
  1688. const cHeader = getObjHeight($(".c-header"));
  1689. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1690. $(".sp-wrap").height(bcontent-30);
  1691. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  1692. materialSpread.refresh();
  1693. ledgerSpread.refresh();
  1694. leafXmjSpread.refresh();
  1695. materialSelfSpread.refresh();
  1696. }
  1697. function getObjHeight(select) {
  1698. return select.length > 0 ? select.height() : 0;
  1699. }
  1700. const showSelfSideTools = function (show) {
  1701. const left = $('#left-view2'), right = $('#right-view2'), parent = left.parent();
  1702. if (show) {
  1703. right.show();
  1704. autoFlashHeight();
  1705. /**
  1706. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1707. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1708. * 故需要通过最终的parent.width再计算一次left.width
  1709. *
  1710. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1711. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1712. *
  1713. */
  1714. //left.css('width', parent.width() - right.outerWidth());
  1715. //left.css('width', parent.width() - right.outerWidth());
  1716. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1717. left.css('width', percent + '%');
  1718. } else {
  1719. // left.css('width', parent.width());
  1720. left.css('width', '100%');
  1721. right.hide();
  1722. }
  1723. };
  1724. });