material_list.js 109 KB

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