material_list.js 104 KB

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