material_list.js 103 KB

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