material_list.js 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018
  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') {
  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') {
  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 !(!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. if (!readOnly) {
  782. const leafXmjSpreadObj = {
  783. getSelect : function () {
  784. const sheet = ledgerSpread.getActiveSheet();
  785. const select = SpreadJsObj.getSelectObject(sheet);
  786. const index = gclGatherData.indexOf(select);
  787. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  788. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  789. const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
  790. const leafXmjs = gclGatherData[index].leafXmjs.filter(item => {
  791. return item.qc_qty || item.contract_qty
  792. });
  793. const nRow = leafXmjs.indexOf(leafXmjSelect);
  794. const leafXmjColor = findNotJoinLeafXmj(leafXmjSelect) ? '#d6d8db' : '';
  795. return [index, iRow, nRow, leafXmjSheet, leafXmjSelect, leafXmjColor];
  796. },
  797. checkJoinMaterial: function (type) {
  798. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  799. const color = type === 'join' ? '' : '#d6d8db';
  800. const data = {
  801. type: type,
  802. select: type === 'join' ? findNotJoinLeafXmj(select) : select,
  803. ms_id: $('#myTab').find('.active').data('msid') || null,
  804. };
  805. // 添加到
  806. postData(window.location.pathname + '/save', data, function (result) {
  807. if (type === 'join') {
  808. const index = findNotJoinLeafXmj(select, 'index');
  809. notJoinList.splice(index, 1);
  810. } else {
  811. notJoinList.push(result);
  812. }
  813. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  814. calculateJiaCha(gclGatherData, iGclRow);
  815. SpreadJsObj.reLoadRowData(sheet, nRow);
  816. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  817. loadMaterialData(iGclRow);
  818. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  819. });
  820. },
  821. checkSelfMaterial: function (type) {
  822. const [iGclRow, iRow, nRow, sheet, select, color] = leafXmjSpreadObj.getSelect();
  823. // const color = type === 'self' ? '' : '#d6d8db';
  824. const data = {
  825. type: type,
  826. select: type === 'noself' ? findSelfLeafXmj(select) : select,
  827. ms_id: $('#myTab').find('.active').data('msid') || null,
  828. };
  829. // 添加到
  830. postData(window.location.pathname + '/save', data, function (result) {
  831. if (type === 'noself') {
  832. const index = findSelfLeafXmj(select, 'index');
  833. selfList.splice(index, 1);
  834. materialListData = result;
  835. $('#cancel-self').modal('hide');
  836. } else {
  837. selfList.push(result);
  838. }
  839. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  840. calculateJiaCha(gclGatherData, iGclRow);
  841. SpreadJsObj.reLoadRowData(sheet, nRow);
  842. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  843. loadXmjMaterialData(iGclRow, nRow);
  844. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  845. });
  846. },
  847. }
  848. // leafXmj右键功能
  849. $.contextMenu({
  850. selector: '#leaf-xmj-spread',
  851. build: function ($trigger, e) {
  852. const target = SpreadJsObj.safeRightClickSelection($trigger, e, leafXmjSpread);
  853. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  854. },
  855. items: {
  856. 'stop': {
  857. name: '不参与调差',
  858. icon: 'fa-remove',
  859. callback: function (key, opt) {
  860. leafXmjSpreadObj.checkJoinMaterial('notjoin');
  861. },
  862. visible: function (key, opt) {
  863. const sheet = leafXmjSpread.getActiveSheet();
  864. const select = SpreadJsObj.getSelectObject(sheet);
  865. const sel = sheet.getSelections()[0];
  866. if (!select || sel.rowCount !== 1) {
  867. return false;
  868. }
  869. const notx = findNotJoinLeafXmj(select);
  870. if (!readOnly && select && notx === undefined) {
  871. return true;
  872. } else {
  873. return false;
  874. }
  875. }
  876. },
  877. 'start': {
  878. name: '参与调差',
  879. icon: 'fa-sign-in',
  880. callback: function (key, opt) {
  881. leafXmjSpreadObj.checkJoinMaterial('join');
  882. },
  883. visible: function (key, opt) {
  884. const sheet = leafXmjSpread.getActiveSheet();
  885. const select = SpreadJsObj.getSelectObject(sheet);
  886. const sel = sheet.getSelections()[0];
  887. if (!select || sel.rowCount !== 1) {
  888. return false;
  889. }
  890. const notx = findNotJoinLeafXmj(select);
  891. if (!readOnly && select && notx === undefined) {
  892. return false;
  893. } else {
  894. return true;
  895. }
  896. },
  897. },
  898. 'self': {
  899. name: '单独添加工料',
  900. icon: 'fa-sign-in',
  901. callback: function (key, opt) {
  902. leafXmjSpreadObj.checkSelfMaterial('self');
  903. },
  904. visible: function (key, opt) {
  905. const sheet = leafXmjSpread.getActiveSheet();
  906. const select = SpreadJsObj.getSelectObject(sheet);
  907. const sel = sheet.getSelections()[0];
  908. if (!select || sel.rowCount !== 1) {
  909. return false;
  910. }
  911. const notx = findSelfLeafXmj(select);
  912. if (!readOnly && select && notx === undefined) {
  913. return true;
  914. } else {
  915. return false;
  916. }
  917. }
  918. },
  919. 'noself': {
  920. name: '取消单独添加工料',
  921. icon: 'fa-remove',
  922. callback: function (key, opt) {
  923. $('#cancel-self').modal('show');
  924. // leafXmjSpreadObj.checkSelfMaterial('noself');
  925. },
  926. visible: function (key, opt) {
  927. const sheet = leafXmjSpread.getActiveSheet();
  928. const select = SpreadJsObj.getSelectObject(sheet);
  929. const sel = sheet.getSelections()[0];
  930. if (!select || sel.rowCount !== 1) {
  931. return false;
  932. }
  933. const notx = findSelfLeafXmj(select);
  934. if (!readOnly && select && notx === undefined) {
  935. return false;
  936. } else {
  937. return true;
  938. }
  939. },
  940. },
  941. }
  942. });
  943. $('#cancelSelfBtn').click(function () {
  944. leafXmjSpreadObj.checkSelfMaterial('noself');
  945. });
  946. // material-spread右键功能
  947. const materialSpreadObj = {
  948. del: function () {
  949. const materialSheet = materialSpread.getActiveSheet();
  950. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  951. const sheet = ledgerSpread.getActiveSheet();
  952. const select = SpreadJsObj.getSelectObject(sheet);
  953. const index = gclGatherData.indexOf(select);
  954. // const leafXmjSheet = leafXmjSpread.getActiveSheet();
  955. // const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  956. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  957. // const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  958. const datas = [];
  959. for (const xmj of gcl) {
  960. const data = {
  961. xmj_id: xmj.id,
  962. gcl_id: xmj.gcl_id,
  963. mx_id: xmj.mx_id ? xmj.mx_id : '',
  964. };
  965. datas.push(data);
  966. }
  967. if (isStageSelf) {
  968. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  969. // 取所有的gclGatherData才行,然后获取下的值
  970. const gclData = gclGatherData[index];
  971. for (const [index, ms] of materialStageData.entries()) {
  972. if (ms.id !== ms_id) {
  973. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  974. if (gclOther) {
  975. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  976. for (const xmj of leafXmjs) {
  977. const data = {
  978. xmj_id: xmj.id,
  979. gcl_id: xmj.gcl_id,
  980. mx_id: xmj.mx_id ? xmj.mx_id : '',
  981. };
  982. if (_.indexOf(datas, data) === -1) {
  983. datas.push(data);
  984. }
  985. }
  986. }
  987. }
  988. }
  989. }
  990. console.log(datas, materialSelect.mb_id);
  991. 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) {
  992. materialListData = result.materialListData;
  993. gclList = result.gclList;
  994. calculateJiaCha(gclGatherData);
  995. // const index = gclGatherData.indexOf(ledgerSelect);
  996. loadLeafXmjData(index);
  997. // const xmjSheet = leafXmjSpread.getActiveSheet();
  998. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  999. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1000. loadMaterialData(index);
  1001. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1002. });
  1003. // postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  1004. // const index = materialList.indexOf(select);
  1005. // materialList.splice(index, 1);
  1006. // sheet.deleteRows(index, 1);
  1007. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1008. // const sel = sheet.getSelections();
  1009. // sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1010. // const materialListIndex = materialListData.indexOf(select);
  1011. // materialListData.splice(materialListIndex, 1);
  1012. // const [iGclRow, iRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  1013. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1014. // calculateJiaCha(gclGatherData, iGclRow);
  1015. // SpreadJsObj.reLoadRowData(lsheet, iRow);
  1016. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1017. // });
  1018. },
  1019. deletePress: function (sheet) {
  1020. return;
  1021. },
  1022. editStarting: function (e, info) {
  1023. const col = info.sheet.zh_setting.cols[info.col];
  1024. const select = SpreadJsObj.getSelectObject(info.sheet);
  1025. if (col.field === 'quantity') {
  1026. if (select.expr && select.expr !== '') {
  1027. info.sheet.getCell(info.row, info.col).text(select.expr);
  1028. }
  1029. }
  1030. },
  1031. editEnded: function (e, info) {
  1032. if (info.sheet.zh_setting) {
  1033. const select = SpreadJsObj.getSelectObject(info.sheet);
  1034. const col = info.sheet.zh_setting.cols[info.col];
  1035. // 未改变值则不提交
  1036. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1037. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1038. // let orgValue = select[col.field];
  1039. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1040. let orgValue;
  1041. if (col.field === 'quantity') {
  1042. orgValue = validText && validText !== ''
  1043. ? _.toNumber(validText) ? select.quantity : select.expr
  1044. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1045. } else {
  1046. orgValue = select[col.field];
  1047. }
  1048. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1049. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1050. return;
  1051. }
  1052. const exprQuantity = {
  1053. expr: '',
  1054. quantity: 0,
  1055. };
  1056. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1057. if (!valid) {
  1058. toastr.error(msg);
  1059. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1060. return;
  1061. }
  1062. if (isNaN(exprQuantity.quantity)) {
  1063. toastr.error('不能输入其它非数字类型字符');
  1064. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1065. return;
  1066. }
  1067. const num = parseFloat(exprQuantity.quantity);
  1068. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1069. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1070. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1071. // return;
  1072. toastr.warning('已保留6位小数');
  1073. exprQuantity.quantity = ZhCalc.round(num, 6);
  1074. }
  1075. // 更新至服务器
  1076. const ledgerSheet = ledgerSpread.getActiveSheet();
  1077. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1078. const index = gclGatherData.indexOf(ledgerSelect);
  1079. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1080. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1081. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1082. // const xmjIndex = gcl.indexOf(xmjSelect);
  1083. const datas = [];
  1084. for (const xmj of gcl) {
  1085. const data = {
  1086. xmj_id: xmj.id,
  1087. gcl_id: xmj.gcl_id,
  1088. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1089. };
  1090. datas.push(data);
  1091. }
  1092. if (isStageSelf) {
  1093. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1094. // 取所有的gclGatherData才行,然后获取下的值
  1095. const gclData = gclGatherData[index];
  1096. for (const [index, ms] of materialStageData.entries()) {
  1097. if (ms.id !== ms_id) {
  1098. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1099. if (gclOther) {
  1100. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1101. for (const xmj of leafXmjs) {
  1102. const data = {
  1103. xmj_id: xmj.id,
  1104. gcl_id: xmj.gcl_id,
  1105. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1106. };
  1107. if (_.indexOf(datas, data) === -1) {
  1108. datas.push(data);
  1109. }
  1110. }
  1111. }
  1112. }
  1113. }
  1114. }
  1115. console.log(exprQuantity, datas, select.mb_id);
  1116. 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) {
  1117. materialListData = result.materialListData;
  1118. gclList = result.gclList;
  1119. calculateJiaCha(gclGatherData);
  1120. // const index = gclGatherData.indexOf(ledgerSelect);
  1121. loadLeafXmjData(index);
  1122. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1123. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1124. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1125. loadMaterialData(index);
  1126. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1127. materialSpread.getActiveSheet().setSelection(info.row + 1, info.col, 1, 1);
  1128. }, function () {
  1129. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1130. });
  1131. // postData(window.location.pathname + '/save', { type:'update', updateData: { id:select.id, quantity: validText, mb_id: select.mb_id } }, function (result) {
  1132. // const materialListIndex = materialListData.indexOf(select);
  1133. // const index = materialList.indexOf(select);
  1134. // select[col.field] = validText;
  1135. // materialListData.splice(materialListIndex, 1, select);
  1136. // materialList.indexOf(index, 1, select);
  1137. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1138. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1139. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1140. // calculateJiaCha(gclGatherData, iGclRow)
  1141. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1142. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1143. // }, function () {
  1144. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1145. // });
  1146. }
  1147. },
  1148. clipboardPasted(e, info) {
  1149. const hint = {
  1150. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1151. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1152. numberCan: {type: 'warning', msg: '已保留6位小数'},
  1153. };
  1154. const range = info.cellRange;
  1155. const sortData = info.sheet.zh_data || [];
  1156. if (range.row + range.rowCount > sortData.length) {
  1157. toastMessageUniq(hint.cellError);
  1158. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1159. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1160. return;
  1161. }
  1162. if (sortData.length > 0 && range.col + range.colCount > 5) {
  1163. toastMessageUniq(hint.cellError);
  1164. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1165. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1166. return;
  1167. }
  1168. const data = [];
  1169. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1170. let bPaste = true;
  1171. const curRow = range.row + iRow;
  1172. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  1173. const hintRow = range.rowCount > 1 ? curRow : '';
  1174. let sameCol = 0;
  1175. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1176. const curCol = range.col + iCol;
  1177. const colSetting = info.sheet.zh_setting.cols[curCol];
  1178. if (!colSetting) continue;
  1179. // let validText = info.sheet.getText(curRow, curCol);
  1180. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1181. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1182. const orgValue = sortData[curRow][colSetting.field];
  1183. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1184. sameCol++;
  1185. if (range.colCount === sameCol) {
  1186. bPaste = false;
  1187. }
  1188. continue;
  1189. }
  1190. const exprQuantity = {
  1191. expr: '',
  1192. quantity: 0,
  1193. };
  1194. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1195. if (!valid) {
  1196. toastMessageUniq(getPasteHint(msg, hintRow));
  1197. bPaste = false;
  1198. continue;
  1199. }
  1200. if (isNaN(exprQuantity.quantity)) {
  1201. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1202. bPaste = false;
  1203. continue;
  1204. }
  1205. const num = parseFloat(exprQuantity.quantity);
  1206. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1207. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1208. // bPaste = false;
  1209. // continue;
  1210. exprQuantity.quantity = ZhCalc.round(num, 6);
  1211. }
  1212. // materialData[colSetting.field] = validText;
  1213. materialData.expr = exprQuantity.expr;
  1214. materialData.quantity = exprQuantity.quantity;
  1215. }
  1216. if (bPaste) {
  1217. data.push(materialData);
  1218. // rowData.push(curRow);
  1219. } else {
  1220. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1221. }
  1222. }
  1223. if (data.length === 0) {
  1224. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1225. return;
  1226. }
  1227. const ledgerSheet = ledgerSpread.getActiveSheet();
  1228. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1229. const index = gclGatherData.indexOf(ledgerSelect);
  1230. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1231. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1232. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1233. // const xmjIndex = gcl.indexOf(xmjSelect);
  1234. const datas = [];
  1235. for (const xmj of gcl) {
  1236. const data2 = {
  1237. xmj_id: xmj.id,
  1238. gcl_id: xmj.gcl_id,
  1239. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1240. };
  1241. datas.push(data2);
  1242. }
  1243. if (isStageSelf) {
  1244. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1245. // 取所有的gclGatherData才行,然后获取下的值
  1246. const gclData = gclGatherData[index];
  1247. for (const [index, ms] of materialStageData.entries()) {
  1248. if (ms.id !== ms_id) {
  1249. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1250. console.log(gclOther);
  1251. if (gclOther) {
  1252. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1253. for (const xmj of leafXmjs) {
  1254. const data = {
  1255. xmj_id: xmj.id,
  1256. gcl_id: xmj.gcl_id,
  1257. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1258. };
  1259. if (_.indexOf(datas, data) === -1) {
  1260. datas.push(data);
  1261. }
  1262. }
  1263. }
  1264. }
  1265. }
  1266. }
  1267. console.log(data, datas);
  1268. // 更新至服务器
  1269. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data }, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1270. materialListData = result.materialListData;
  1271. gclList = result.gclList;
  1272. calculateJiaCha(gclGatherData);
  1273. // const index = gclGatherData.indexOf(ledgerSelect);
  1274. loadLeafXmjData(index);
  1275. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1276. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1277. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1278. loadMaterialData(index);
  1279. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1280. materialSpread.getActiveSheet().setSelection(info.cellRange.row, info.cellRange.col, info.cellRange.rowCount, info.cellRange.colCount);
  1281. }, function () {
  1282. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1283. });
  1284. // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1285. // materialListData = result;
  1286. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1287. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1288. // calculateJiaCha(gclGatherData, iGclRow);
  1289. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1290. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1291. // }, function () {
  1292. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1293. // });
  1294. },
  1295. _checkExprValid(expr) {
  1296. if (!expr) return [true, null];
  1297. const param = [];
  1298. let num = '', base = '';
  1299. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1300. if (/^[\d\.%]+/.test(expr[i])) {
  1301. if (base !== '') {
  1302. param.push({type: 'base', value: base});
  1303. base = '';
  1304. }
  1305. num = num + expr[i];
  1306. } else if (expr[i] === '(') {
  1307. if (num !== '') {
  1308. param.push({type: 'num', value: num});
  1309. num = '';
  1310. }
  1311. if (base !== '') {
  1312. param.push({type: 'base', value: base});
  1313. base = '';
  1314. }
  1315. param.push({type: 'left', value: '('});
  1316. } else if (expr[i] === ')') {
  1317. if (num !== '') {
  1318. param.push({type: 'num', value: num});
  1319. num = '';
  1320. }
  1321. if (base !== '') {
  1322. param.push({type: 'base', value: base});
  1323. base = '';
  1324. }
  1325. param.push({type: 'right', value: ')'});
  1326. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1327. if (num !== '') {
  1328. param.push({type: 'num', value: num});
  1329. num = '';
  1330. }
  1331. if (base !== '') {
  1332. param.push({type: 'base', value: base});
  1333. base = '';
  1334. }
  1335. param.push({type: 'calc', value: expr[i]});
  1336. } else {
  1337. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1338. }
  1339. }
  1340. if (num !== '') {
  1341. param.push({type: 'num', value: num});
  1342. num = '';
  1343. }
  1344. if (base !== '') {
  1345. param.push({type: 'base', value: base});
  1346. base = '';
  1347. }
  1348. if (param.length === 0) return true;
  1349. if (param.length > 1) {
  1350. if (param[0].value === '-') {
  1351. param[1].value = '-' + param[1];
  1352. }
  1353. param.unshift();
  1354. }
  1355. const iLen = param.length;
  1356. let iLeftCount = 0, iRightCount = 0;
  1357. for (const [i, p] of param.entries()) {
  1358. if (p.type === 'calc') {
  1359. if (i === 0 || i === iLen - 1)
  1360. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1361. }
  1362. if (p.type === 'num') {
  1363. num = p.value.replace('%', '');
  1364. if (p.value.length - num.length > 1)
  1365. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1366. num = _.toNumber(num);
  1367. if (num === undefined || num === null || _.isNaN(num))
  1368. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1369. if (i > 0) {
  1370. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1371. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1372. } else if (param[i - 1].value === '/' && num === 0) {
  1373. return [false, '输入的表达式非法:请勿除0'];
  1374. }
  1375. }
  1376. }
  1377. if (p.type === 'base') {
  1378. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1379. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1380. }
  1381. if (p.type === 'left') {
  1382. iLeftCount += 1;
  1383. if (i !== 0 && param[i-1].type !== 'calc')
  1384. return [false, '输入的表达式非法:(前应有运算符'];
  1385. }
  1386. if (p.type === 'right') {
  1387. iRightCount += 1;
  1388. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1389. return [false, '输入的表达式非法:)后应有运算符'];
  1390. if (iRightCount > iLeftCount)
  1391. return [false, '输入的表达式非法:")"前无对应的"("'];
  1392. }
  1393. }
  1394. if (iLeftCount > iRightCount)
  1395. return [false, '输入的表达式非法:"("后无对应的")"'];
  1396. return [true, ''];
  1397. },
  1398. _checkExpr: function (text, data) {
  1399. if (text) {
  1400. const num = _.toNumber(text);
  1401. if (num) {
  1402. data.quantity = num;
  1403. data.expr = '';
  1404. } else {
  1405. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  1406. const [valid, msg] = this._checkExprValid(expr);
  1407. if (!valid) return [valid, msg];
  1408. data.expr = expr;
  1409. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr);
  1410. // const ce = new CalcEvalMin();
  1411. // data.quantity = ce.eval(expr);
  1412. // console.log(data.quantity);
  1413. }
  1414. } else {
  1415. data.quantity = 0;
  1416. data.expr = '';
  1417. }
  1418. return [true, ''];
  1419. },
  1420. };
  1421. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  1422. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  1423. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  1424. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  1425. // material-spread右键功能
  1426. const materialSelfSpreadObj = {
  1427. del: function () {
  1428. const sheet = materialSelfSpread.getActiveSheet();
  1429. const select = SpreadJsObj.getSelectObject(sheet);
  1430. console.log(select);
  1431. postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id, ms_id: $('#myTab').find('.active').data('msid') || null}, function (result) {
  1432. const index = materialListSelf.indexOf(select);
  1433. materialListSelf.splice(index, 1);
  1434. sheet.deleteRows(index, 1);
  1435. SpreadJsObj.reLoadSheetData(materialSelfSpread.getActiveSheet());
  1436. const sel = sheet.getSelections();
  1437. sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1438. const materialListIndex = materialListData.indexOf(select);
  1439. materialListData.splice(materialListIndex, 1);
  1440. const [iGclRow, iRow, nRow, lsheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1441. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1442. calculateJiaCha(gclGatherData, iGclRow);
  1443. SpreadJsObj.reLoadRowData(lsheet, nRow);
  1444. lsheet.getRange(nRow, -1, 1, -1).backColor(color);
  1445. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1446. });
  1447. },
  1448. deletePress: function (sheet) {
  1449. return;
  1450. },
  1451. editStarting: function (e, info) {
  1452. const col = info.sheet.zh_setting.cols[info.col];
  1453. const select = SpreadJsObj.getSelectObject(info.sheet);
  1454. if (col.field === 'quantity') {
  1455. if (select.expr && select.expr !== '') {
  1456. info.sheet.getCell(info.row, info.col).text(select.expr);
  1457. }
  1458. }
  1459. },
  1460. editEnded: function (e, info) {
  1461. if (info.sheet.zh_setting) {
  1462. const select = SpreadJsObj.getSelectObject(info.sheet);
  1463. const col = info.sheet.zh_setting.cols[info.col];
  1464. // 未改变值则不提交
  1465. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1466. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1467. // let orgValue = select[col.field];
  1468. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1469. let orgValue;
  1470. if (col.field === 'quantity') {
  1471. orgValue = validText && validText !== ''
  1472. ? _.toNumber(validText) ? select.quantity : select.expr
  1473. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1474. } else {
  1475. orgValue = select[col.field];
  1476. }
  1477. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1478. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1479. return;
  1480. }
  1481. const exprQuantity = {
  1482. expr: '',
  1483. quantity: 0,
  1484. };
  1485. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1486. if (!valid) {
  1487. toastr.error(msg);
  1488. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1489. return;
  1490. }
  1491. if (isNaN(exprQuantity.quantity)) {
  1492. toastr.error('不能输入其它非数字类型字符');
  1493. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1494. return;
  1495. }
  1496. const num = parseFloat(exprQuantity.quantity);
  1497. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1498. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1499. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1500. // return;
  1501. toastr.warning('已保留6位小数');
  1502. exprQuantity.quantity = ZhCalc.round(num, 6);
  1503. }
  1504. // 更新至服务器
  1505. console.log(exprQuantity, select.mb_id);
  1506. postData(window.location.pathname + '/save', { type:'update', updateData: { id: select.id, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id }, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1507. const materialListIndex = materialListData.indexOf(select);
  1508. const index = materialList.indexOf(select);
  1509. select.quantity = exprQuantity.quantity;
  1510. select.expr = exprQuantity.expr;
  1511. materialListData.splice(materialListIndex, 1, select);
  1512. materialList.indexOf(index, 1, select);
  1513. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1514. const [iGclRow, iRow, nRow, sheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1515. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1516. calculateJiaCha(gclGatherData, iGclRow);
  1517. SpreadJsObj.reLoadRowData(sheet, nRow);
  1518. console.log(lselect, color);
  1519. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  1520. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1521. }, function () {
  1522. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1523. });
  1524. }
  1525. },
  1526. clipboardPasted(e, info) {
  1527. const hint = {
  1528. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1529. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1530. numberCan: {type: 'warning', msg: '已保留6位小数'},
  1531. };
  1532. const range = info.cellRange;
  1533. const sortData = info.sheet.zh_data || [];
  1534. if (range.row + range.rowCount > sortData.length) {
  1535. toastMessageUniq(hint.cellError);
  1536. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1537. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1538. return;
  1539. }
  1540. if (sortData.length > 0 && range.col + range.colCount > 5) {
  1541. toastMessageUniq(hint.cellError);
  1542. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1543. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1544. return;
  1545. }
  1546. const data = [];
  1547. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1548. let bPaste = true;
  1549. const curRow = range.row + iRow;
  1550. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  1551. const hintRow = range.rowCount > 1 ? curRow : '';
  1552. let sameCol = 0;
  1553. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1554. const curCol = range.col + iCol;
  1555. const colSetting = info.sheet.zh_setting.cols[curCol];
  1556. if (!colSetting) continue;
  1557. // let validText = info.sheet.getText(curRow, curCol);
  1558. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1559. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1560. const orgValue = sortData[curRow][colSetting.field];
  1561. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1562. sameCol++;
  1563. if (range.colCount === sameCol) {
  1564. bPaste = false;
  1565. }
  1566. continue;
  1567. }
  1568. const exprQuantity = {
  1569. expr: '',
  1570. quantity: 0,
  1571. };
  1572. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1573. if (!valid) {
  1574. toastMessageUniq(getPasteHint(msg, hintRow));
  1575. bPaste = false;
  1576. continue;
  1577. }
  1578. if (isNaN(exprQuantity.quantity)) {
  1579. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1580. bPaste = false;
  1581. continue;
  1582. }
  1583. const num = parseFloat(exprQuantity.quantity);
  1584. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1585. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1586. // bPaste = false;
  1587. // continue;
  1588. exprQuantity.quantity = ZhCalc.round(num, 6);
  1589. }
  1590. // materialData[colSetting.field] = validText;
  1591. materialData.expr = exprQuantity.expr;
  1592. materialData.quantity = exprQuantity.quantity;
  1593. }
  1594. if (bPaste) {
  1595. data.push(materialData);
  1596. // rowData.push(curRow);
  1597. } else {
  1598. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1599. }
  1600. }
  1601. if (data.length === 0) {
  1602. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1603. return;
  1604. }
  1605. console.log(data);
  1606. postData(window.location.pathname + '/save', { type:'paste', updateData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1607. materialListData = result;
  1608. const [iGclRow, iRow, nRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1609. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1610. calculateJiaCha(gclGatherData, iGclRow);
  1611. // SpreadJsObj.reLoadRowData(sheet, nRow);
  1612. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1613. loadXmjMaterialData(iGclRow, nRow);
  1614. }, function () {
  1615. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1616. });
  1617. },
  1618. };
  1619. materialSelfSpread.bind(spreadNS.Events.EditStarting, materialSelfSpreadObj.editStarting);
  1620. materialSelfSpread.bind(spreadNS.Events.EditEnded, materialSelfSpreadObj.editEnded);
  1621. materialSelfSpread.bind(spreadNS.Events.ClipboardPasted, materialSelfSpreadObj.clipboardPasted);
  1622. SpreadJsObj.addDeleteBind(materialSelfSpread, materialSelfSpreadObj.deletePress);
  1623. if (!openMaterialChecklist) {
  1624. $.contextMenu({
  1625. selector: '#material-spread',
  1626. build: function ($trigger, e) {
  1627. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  1628. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1629. },
  1630. items: {
  1631. 'create': {
  1632. name: '添加工料',
  1633. icon: 'fa-sign-in',
  1634. callback: function (key, opt) {
  1635. // 获取已选清单
  1636. changeMaterialTable();
  1637. $('#add_type').val('all');
  1638. $('#addgl').modal('show');
  1639. },
  1640. disabled: function (key, opt) {
  1641. const sheet = leafXmjSpread.getActiveSheet();
  1642. const select = SpreadJsObj.getSelectObject(sheet);
  1643. // const notx = findNotJoinLeafXmj(select);
  1644. if (!select) {
  1645. return true;
  1646. }
  1647. // if (!readOnly && notx === undefined) {
  1648. // return false;
  1649. // } else {
  1650. // return true;
  1651. // }
  1652. return readOnly;
  1653. }
  1654. },
  1655. 'delete': {
  1656. name: '删除工料',
  1657. icon: 'fa-remove',
  1658. callback: function (key, opt) {
  1659. materialSpreadObj.del(materialSpread.getActiveSheet());
  1660. },
  1661. disabled: function (key, opt) {
  1662. const sheet = materialSpread.getActiveSheet();
  1663. const select = SpreadJsObj.getSelectObject(sheet);
  1664. if (!select) {
  1665. return true;
  1666. }
  1667. if (!readOnly && select && materialBase.isEdit(select, 'del')) {
  1668. return false;
  1669. } else {
  1670. return true;
  1671. }
  1672. }
  1673. },
  1674. }
  1675. });
  1676. }
  1677. $.contextMenu({
  1678. selector: '#material-self-spread',
  1679. build: function ($trigger, e) {
  1680. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSelfSpread);
  1681. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1682. },
  1683. items: {
  1684. 'create': {
  1685. name: '添加工料',
  1686. icon: 'fa-sign-in',
  1687. callback: function (key, opt) {
  1688. // 获取已选清单
  1689. changeMaterialTable('self');
  1690. $('#add_type').val('self');
  1691. $('#addgl').modal('show');
  1692. },
  1693. disabled: function (key, opt) {
  1694. const sheet = leafXmjSpread.getActiveSheet();
  1695. const select = SpreadJsObj.getSelectObject(sheet);
  1696. // const notx = findNotJoinLeafXmj(select);
  1697. if (!select) {
  1698. return true;
  1699. }
  1700. // if (!readOnly && notx === undefined) {
  1701. // return false;
  1702. // } else {
  1703. // return true;
  1704. // }
  1705. return readOnly;
  1706. }
  1707. },
  1708. 'delete': {
  1709. name: '删除工料',
  1710. icon: 'fa-remove',
  1711. callback: function (key, opt) {
  1712. materialSelfSpreadObj.del(materialSelfSpread.getActiveSheet());
  1713. },
  1714. disabled: function (key, opt) {
  1715. const sheet = materialSelfSpread.getActiveSheet();
  1716. const select = SpreadJsObj.getSelectObject(sheet);
  1717. if (!select) {
  1718. return true;
  1719. }
  1720. if (!readOnly && select) {
  1721. return false;
  1722. } else {
  1723. return true;
  1724. }
  1725. }
  1726. },
  1727. }
  1728. });
  1729. }
  1730. // 应用调差工料至其他清单明细
  1731. $('#user_all_material').click(function () {
  1732. const ledgerSheet = ledgerSpread.getActiveSheet();
  1733. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1734. if (ledgerSelect.leafXmjs.length < 2) {
  1735. toastr.warning('没有需要应用调差工料的其它清单明细');
  1736. return false;
  1737. }
  1738. const xmjSheet = leafXmjSpread.getActiveSheet();
  1739. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1740. console.log(ledgerSelect.leafXmjs);
  1741. // 判断需要应用调差工料的清单明细
  1742. const needAddList = [];
  1743. for (const xmj of ledgerSelect.leafXmjs) {
  1744. const notx = findNotJoinLeafXmj(xmj);
  1745. if (notx === undefined && xmjSelect !== xmj && xmj.gather_qty && xmj.jiacha === null && xmjSelect.jiacha !== null) {
  1746. needAddList.push(xmj);
  1747. }
  1748. }
  1749. // if (needAddList.length === 0) {
  1750. // toastr.warning('没有需要应用调差工料的其它清单明细');
  1751. // return false;
  1752. // }
  1753. console.log(needAddList, materialList);
  1754. // 更新至服务器
  1755. postData(window.location.pathname + '/save', { type:'useOther', postData: { addXmj: needAddList, materialBills: materialList } }, function (result) {
  1756. materialListData = result.materialListData;
  1757. gclList = result.gclList;
  1758. toastr.success('已成功应用');
  1759. calculateJiaCha(gclGatherData);
  1760. const index = gclGatherData.indexOf(ledgerSelect);
  1761. loadLeafXmjData(index);
  1762. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1763. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1764. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1765. loadMaterialData(index);
  1766. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1767. });
  1768. });
  1769. // 切换清单行,读取所属项目节数据
  1770. ledgerSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1771. if (info.oldSelections !== undefined) {
  1772. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1773. if (iNewRow !== iOldRow) {
  1774. loadLeafXmjData(iNewRow);
  1775. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1776. loadMaterialData(iNewRow);
  1777. loadXmjMaterialData(iNewRow, 0);
  1778. checkNotJoinMaterialData();
  1779. }
  1780. }
  1781. });
  1782. // 切换项目节数据清单明细行,读取单独的清单工料数据
  1783. leafXmjSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1784. if (info.oldSelections !== undefined) {
  1785. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1786. if (iNewRow !== iOldRow) {
  1787. const sheet = ledgerSpread.getActiveSheet();
  1788. const select = SpreadJsObj.getSelectObject(sheet);
  1789. const index = gclGatherData.indexOf(select);
  1790. loadXmjMaterialData(index, iNewRow);
  1791. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  1792. }
  1793. }
  1794. });
  1795. // 显示有调差工料清单
  1796. $('#show_material_gcl').click(function () {
  1797. if ($(this).is(':checked')) {
  1798. const hadMaterialGclGatherData = [];
  1799. const hadGclIdList = [];
  1800. for (const ml of materialListData) {
  1801. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  1802. hadGclIdList.push(ml.gcl_id);
  1803. }
  1804. }
  1805. for (const gcl of gclGatherData) {
  1806. for (const index in gcl.leafXmjs) {
  1807. const gcl_id = gcl.leafXmjs[index].gcl_id;
  1808. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  1809. hadMaterialGclGatherData.push(gcl);
  1810. break;
  1811. }
  1812. }
  1813. }
  1814. gclGatherData = hadMaterialGclGatherData;
  1815. } else {
  1816. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  1817. gclGatherModel.loadPosData(pos, curPosData);
  1818. gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  1819. return item.qc_qty || item.contract_qty
  1820. });
  1821. if (openMaterialChecklist) {
  1822. // 取交集
  1823. gclGatherData = _.filter(gclGatherData, function (item) {
  1824. return _.find(materialChecklistData, { b_code: item.b_code, name: item.name, unit: item.unit, unit_price: item.unit_price });
  1825. });
  1826. }
  1827. }
  1828. calculateJiaCha(gclGatherData);
  1829. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  1830. loadLeafXmjData(0);
  1831. loadMaterialData(0);
  1832. loadXmjMaterialData(0, 0);
  1833. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  1834. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1835. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  1836. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  1837. checkNotJoinMaterialData();
  1838. });
  1839. $.subMenu({
  1840. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1841. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1842. key: 'menu.1.0.0',
  1843. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1844. callback: function (info) {
  1845. if (info.mini) {
  1846. $('.panel-title').addClass('fluid');
  1847. $('#sub-menu').removeClass('panel-sidebar');
  1848. } else {
  1849. $('.panel-title').removeClass('fluid');
  1850. $('#sub-menu').addClass('panel-sidebar');
  1851. }
  1852. autoFlashHeight();
  1853. ledgerSpread.refresh();
  1854. leafXmjSpread.refresh();
  1855. materialSpread.refresh();
  1856. materialSelfSpread.refresh();
  1857. }
  1858. });
  1859. $(window).resize(function () {
  1860. ledgerSpread.refresh();
  1861. leafXmjSpread.refresh();
  1862. materialSpread.refresh();
  1863. materialSelfSpread.refresh();
  1864. });
  1865. $.divResizer({
  1866. select: '#right-spr',
  1867. callback: function () {
  1868. ledgerSpread.refresh();
  1869. // leafXmjSpread.refresh();
  1870. materialSpread.refresh();
  1871. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1872. setLocalCache('material_list_' + materialID, width);
  1873. }
  1874. });
  1875. $.divResizer({
  1876. select: '#right-spr2',
  1877. callback: function () {
  1878. leafXmjSpread.refresh();
  1879. materialSelfSpread.refresh();
  1880. // const width = (($('#right-view2').width()/$('#right-view2').parent('div').width())*100).toFixed();
  1881. // setLocalCache('material_list3_' + materialID, width);
  1882. }
  1883. });
  1884. $.divResizer({
  1885. select: '#main-resize',
  1886. callback: function () {
  1887. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1888. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1889. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1890. $(".sp-wrap").height(bcontent-30);
  1891. materialSpread.refresh();
  1892. ledgerSpread.refresh();
  1893. leafXmjSpread.refresh();
  1894. materialSelfSpread.refresh();
  1895. const height = $('.bcontent-wrap').height();
  1896. setLocalCache('material_list2_' + materialID, height);
  1897. }
  1898. });
  1899. // 展开收起月信息价并浏览器记住本期展开收起
  1900. $('a', '.right-nav').bind('click', function () {
  1901. //const main = $('#main-view'), tool = $('#tools-view');
  1902. const tab = $(this), tabPanel = $(tab.attr('content'));
  1903. if (!tab.hasClass('active')) {
  1904. $('a', '.side-menu').removeClass('active');
  1905. $('.tab-content .tab-select-show').removeClass('active');
  1906. tab.addClass('active');
  1907. tabPanel.addClass('active');
  1908. showSideTools(tab.hasClass('active'));
  1909. if (tab.attr('content') === '#material-tab') {
  1910. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1911. setLocalCache('material_list_' + materialID, width);
  1912. }
  1913. } else {
  1914. removeLocalCache('material_list_' + materialID);
  1915. tab.removeClass('active');
  1916. tabPanel.removeClass('active');
  1917. showSideTools(tab.hasClass('active'));
  1918. }
  1919. ledgerSpread.refresh();
  1920. // leafXmjSpread.refresh();
  1921. materialSpread.refresh();
  1922. });
  1923. // 根据浏览器记录展开收起
  1924. if (getLocalCache('material_list_' + materialID)) {
  1925. const tab = $('.right-nav a[content="#material-tab"]'), tabPanel = $(tab.attr('content'));
  1926. $('a', '.side-menu').removeClass('active');
  1927. $('.tab-content .tab-select-show').removeClass('active');
  1928. tab.addClass('active');
  1929. tabPanel.addClass('active');
  1930. $('#right-view').css('width', getLocalCache('material_list_' + materialID) + '%');
  1931. showSideTools(tab.hasClass('active'));
  1932. ledgerSpread.refresh();
  1933. // leafXmjSpread.refresh();
  1934. materialSpread.refresh();
  1935. }
  1936. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1937. if (getLocalCache('material_list2_' + materialID)) {
  1938. $('.bcontent-wrap').height(getLocalCache('material_list2_' + materialID));
  1939. const cHeader = getObjHeight($(".c-header"));
  1940. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1941. $(".sp-wrap").height(bcontent-30);
  1942. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  1943. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1944. materialSpread.refresh();
  1945. ledgerSpread.refresh();
  1946. leafXmjSpread.refresh();
  1947. materialSelfSpread.refresh();
  1948. } else {
  1949. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1950. ledgerSpread.refresh();
  1951. }
  1952. function getObjHeight(select) {
  1953. return select.length > 0 ? select.height() : 0;
  1954. }
  1955. const showSelfSideTools = function (show) {
  1956. const left = $('#left-view2'), right = $('#right-view2'), parent = left.parent();
  1957. if (show) {
  1958. right.show();
  1959. autoFlashHeight();
  1960. /**
  1961. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1962. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1963. * 故需要通过最终的parent.width再计算一次left.width
  1964. *
  1965. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1966. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1967. *
  1968. */
  1969. //left.css('width', parent.width() - right.outerWidth());
  1970. //left.css('width', parent.width() - right.outerWidth());
  1971. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1972. left.css('width', percent + '%');
  1973. } else {
  1974. // left.css('width', parent.width());
  1975. left.css('width', '100%');
  1976. right.hide();
  1977. }
  1978. };
  1979. });