material_list.js 88 KB

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