material_list.js 105 KB

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