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;
  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. const leafXmjColor = findNotJoinLeafXmj(leafXmjSelect) ? '#d6d8db' : '';
  629. return [index, iRow, nRow, leafXmjSheet, leafXmjSelect, leafXmjColor];
  630. },
  631. checkJoinMaterial: function (type) {
  632. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  633. const color = type === 'join' ? '' : '#d6d8db';
  634. const data = {
  635. type: type,
  636. select: type === 'join' ? findNotJoinLeafXmj(select) : select,
  637. };
  638. // 添加到
  639. postData(window.location.pathname + '/save', data, function (result) {
  640. if (type === 'join') {
  641. const index = findNotJoinLeafXmj(select, 'index');
  642. notJoinList.splice(index, 1);
  643. } else {
  644. notJoinList.push(result);
  645. }
  646. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  647. calculateJiaCha(gclGatherData, iGclRow);
  648. SpreadJsObj.reLoadRowData(sheet, nRow);
  649. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  650. loadMaterialData(iGclRow);
  651. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  652. });
  653. },
  654. checkSelfMaterial: function (type) {
  655. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  656. // const color = type === 'self' ? '' : '#d6d8db';
  657. const data = {
  658. type: type,
  659. select: type === 'noself' ? findSelfLeafXmj(select) : select,
  660. };
  661. // 添加到
  662. postData(window.location.pathname + '/save', data, function (result) {
  663. if (type === 'noself') {
  664. const index = findSelfLeafXmj(select, 'index');
  665. selfList.splice(index, 1);
  666. } else {
  667. selfList.push(result);
  668. }
  669. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  670. calculateJiaCha(gclGatherData, iGclRow);
  671. SpreadJsObj.reLoadRowData(sheet, nRow);
  672. // sheet.getRange(nRow, -1, 1, -1).backColor(color);
  673. loadXmjMaterialData(iGclRow, nRow);
  674. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  675. });
  676. },
  677. }
  678. // leafXmj右键功能
  679. $.contextMenu({
  680. selector: '#leaf-xmj-spread',
  681. build: function ($trigger, e) {
  682. const target = SpreadJsObj.safeRightClickSelection($trigger, e, leafXmjSpread);
  683. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  684. },
  685. items: {
  686. 'stop': {
  687. name: '不参与调差',
  688. icon: 'fa-remove',
  689. callback: function (key, opt) {
  690. leafXmjSpreadObj.checkJoinMaterial('notjoin');
  691. },
  692. visible: function (key, opt) {
  693. const sheet = leafXmjSpread.getActiveSheet();
  694. const select = SpreadJsObj.getSelectObject(sheet);
  695. const sel = sheet.getSelections()[0];
  696. if (!select || sel.rowCount !== 1) {
  697. return false;
  698. }
  699. const notx = findNotJoinLeafXmj(select);
  700. if (!readOnly && select && notx === undefined) {
  701. return true;
  702. } else {
  703. return false;
  704. }
  705. }
  706. },
  707. 'start': {
  708. name: '参与调差',
  709. icon: 'fa-sign-in',
  710. callback: function (key, opt) {
  711. leafXmjSpreadObj.checkJoinMaterial('join');
  712. },
  713. visible: function (key, opt) {
  714. const sheet = leafXmjSpread.getActiveSheet();
  715. const select = SpreadJsObj.getSelectObject(sheet);
  716. const sel = sheet.getSelections()[0];
  717. if (!select || sel.rowCount !== 1) {
  718. return false;
  719. }
  720. const notx = findNotJoinLeafXmj(select);
  721. if (!readOnly && select && notx === undefined) {
  722. return false;
  723. } else {
  724. return true;
  725. }
  726. },
  727. },
  728. 'self': {
  729. name: '单独添加工料',
  730. icon: 'fa-sign-in',
  731. callback: function (key, opt) {
  732. leafXmjSpreadObj.checkSelfMaterial('self');
  733. },
  734. visible: function (key, opt) {
  735. const sheet = leafXmjSpread.getActiveSheet();
  736. const select = SpreadJsObj.getSelectObject(sheet);
  737. const sel = sheet.getSelections()[0];
  738. if (!select || sel.rowCount !== 1) {
  739. return false;
  740. }
  741. const notx = findSelfLeafXmj(select);
  742. if (!readOnly && select && notx === undefined) {
  743. return true;
  744. } else {
  745. return false;
  746. }
  747. }
  748. },
  749. 'noself': {
  750. name: '取消单独添加工料',
  751. icon: 'fa-remove',
  752. callback: function (key, opt) {
  753. leafXmjSpreadObj.checkSelfMaterial('noself');
  754. },
  755. visible: function (key, opt) {
  756. const sheet = leafXmjSpread.getActiveSheet();
  757. const select = SpreadJsObj.getSelectObject(sheet);
  758. const sel = sheet.getSelections()[0];
  759. if (!select || sel.rowCount !== 1) {
  760. return false;
  761. }
  762. const notx = findSelfLeafXmj(select);
  763. if (!readOnly && select && notx === undefined) {
  764. return false;
  765. } else {
  766. return true;
  767. }
  768. },
  769. },
  770. }
  771. });
  772. // material-spread右键功能
  773. const materialSpreadObj = {
  774. del: function () {
  775. const materialSheet = materialSpread.getActiveSheet();
  776. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  777. const sheet = ledgerSpread.getActiveSheet();
  778. const select = SpreadJsObj.getSelectObject(sheet);
  779. const index = gclGatherData.indexOf(select);
  780. // const leafXmjSheet = leafXmjSpread.getActiveSheet();
  781. // const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  782. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  783. // const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  784. const datas = [];
  785. for (const xmj of gcl) {
  786. const data = {
  787. xmj_id: xmj.id,
  788. gcl_id: xmj.gcl_id,
  789. mx_id: xmj.mx_id ? xmj.mx_id : '',
  790. };
  791. datas.push(data);
  792. }
  793. console.log(datas, materialSelect.mb_id);
  794. postData(window.location.pathname + '/save', {type: 'dels', postData: { xmjs: datas, mb_id: materialSelect.mb_id }}, function (result) {
  795. materialListData = result.materialListData;
  796. gclList = result.gclList;
  797. calculateJiaCha(gclGatherData);
  798. // const index = gclGatherData.indexOf(ledgerSelect);
  799. loadLeafXmjData(index);
  800. // const xmjSheet = leafXmjSpread.getActiveSheet();
  801. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  802. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  803. loadMaterialData(index);
  804. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  805. });
  806. // postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  807. // const index = materialList.indexOf(select);
  808. // materialList.splice(index, 1);
  809. // sheet.deleteRows(index, 1);
  810. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  811. // const sel = sheet.getSelections();
  812. // sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  813. // const materialListIndex = materialListData.indexOf(select);
  814. // materialListData.splice(materialListIndex, 1);
  815. // const [iGclRow, iRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  816. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  817. // calculateJiaCha(gclGatherData, iGclRow);
  818. // SpreadJsObj.reLoadRowData(lsheet, iRow);
  819. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  820. // });
  821. },
  822. deletePress: function (sheet) {
  823. return;
  824. },
  825. editStarting: function (e, info) {
  826. const col = info.sheet.zh_setting.cols[info.col];
  827. const select = SpreadJsObj.getSelectObject(info.sheet);
  828. if (col.field === 'quantity') {
  829. if (select.expr && select.expr !== '') {
  830. info.sheet.getCell(info.row, info.col).text(select.expr);
  831. }
  832. }
  833. },
  834. editEnded: function (e, info) {
  835. if (info.sheet.zh_setting) {
  836. const select = SpreadJsObj.getSelectObject(info.sheet);
  837. const col = info.sheet.zh_setting.cols[info.col];
  838. // 未改变值则不提交
  839. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  840. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  841. // let orgValue = select[col.field];
  842. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  843. let orgValue;
  844. if (col.field === 'quantity') {
  845. orgValue = validText && validText !== ''
  846. ? _.toNumber(validText) ? select.quantity : select.expr
  847. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  848. } else {
  849. orgValue = select[col.field];
  850. }
  851. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  852. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  853. return;
  854. }
  855. const exprQuantity = {
  856. expr: '',
  857. quantity: 0,
  858. };
  859. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  860. if (!valid) {
  861. toastr.error(msg);
  862. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  863. return;
  864. }
  865. if (isNaN(exprQuantity.quantity)) {
  866. toastr.error('不能输入其它非数字类型字符');
  867. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  868. return;
  869. }
  870. const num = parseFloat(exprQuantity.quantity);
  871. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  872. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  873. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  874. // return;
  875. toastr.warning('已保留6位小数');
  876. exprQuantity.quantity = ZhCalc.round(num, 6);
  877. }
  878. // 更新至服务器
  879. const ledgerSheet = ledgerSpread.getActiveSheet();
  880. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  881. const index = gclGatherData.indexOf(ledgerSelect);
  882. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  883. // const xmjSheet = leafXmjSpread.getActiveSheet();
  884. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  885. // const xmjIndex = gcl.indexOf(xmjSelect);
  886. const datas = [];
  887. for (const xmj of gcl) {
  888. const data = {
  889. xmj_id: xmj.id,
  890. gcl_id: xmj.gcl_id,
  891. mx_id: xmj.mx_id ? xmj.mx_id : '',
  892. };
  893. datas.push(data);
  894. }
  895. console.log(exprQuantity, datas, select.mb_id);
  896. postData(window.location.pathname + '/save', { type:'updates', updateData: { xmjs: datas, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id } }, function (result) {
  897. materialListData = result.materialListData;
  898. gclList = result.gclList;
  899. calculateJiaCha(gclGatherData);
  900. // const index = gclGatherData.indexOf(ledgerSelect);
  901. loadLeafXmjData(index);
  902. // const xmjSheet = leafXmjSpread.getActiveSheet();
  903. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  904. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  905. loadMaterialData(index);
  906. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  907. materialSpread.getActiveSheet().setSelection(info.row + 1, info.col, 1, 1);
  908. }, function () {
  909. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  910. });
  911. // postData(window.location.pathname + '/save', { type:'update', updateData: { id:select.id, quantity: validText, mb_id: select.mb_id } }, function (result) {
  912. // const materialListIndex = materialListData.indexOf(select);
  913. // const index = materialList.indexOf(select);
  914. // select[col.field] = validText;
  915. // materialListData.splice(materialListIndex, 1, select);
  916. // materialList.indexOf(index, 1, select);
  917. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  918. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  919. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  920. // calculateJiaCha(gclGatherData, iGclRow)
  921. // SpreadJsObj.reLoadRowData(sheet, iRow);
  922. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  923. // }, function () {
  924. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  925. // });
  926. }
  927. },
  928. clipboardPasted(e, info) {
  929. const hint = {
  930. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  931. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  932. numberCan: {type: 'warning', msg: '已保留6位小数'},
  933. };
  934. const range = info.cellRange;
  935. const sortData = info.sheet.zh_data || [];
  936. if (range.row + range.rowCount > sortData.length) {
  937. toastMessageUniq(hint.cellError);
  938. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  939. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  940. return;
  941. }
  942. if (sortData.length > 0 && range.col + range.colCount > 5) {
  943. toastMessageUniq(hint.cellError);
  944. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  945. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  946. return;
  947. }
  948. const data = [];
  949. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  950. let bPaste = true;
  951. const curRow = range.row + iRow;
  952. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  953. const hintRow = range.rowCount > 1 ? curRow : '';
  954. let sameCol = 0;
  955. for (let iCol = 0; iCol < range.colCount; iCol++) {
  956. const curCol = range.col + iCol;
  957. const colSetting = info.sheet.zh_setting.cols[curCol];
  958. if (!colSetting) continue;
  959. // let validText = info.sheet.getText(curRow, curCol);
  960. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  961. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  962. const orgValue = sortData[curRow][colSetting.field];
  963. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  964. sameCol++;
  965. if (range.colCount === sameCol) {
  966. bPaste = false;
  967. }
  968. continue;
  969. }
  970. const exprQuantity = {
  971. expr: '',
  972. quantity: 0,
  973. };
  974. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  975. if (!valid) {
  976. toastMessageUniq(getPasteHint(msg, hintRow));
  977. bPaste = false;
  978. continue;
  979. }
  980. if (isNaN(exprQuantity.quantity)) {
  981. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  982. bPaste = false;
  983. continue;
  984. }
  985. const num = parseFloat(exprQuantity.quantity);
  986. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  987. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  988. // bPaste = false;
  989. // continue;
  990. exprQuantity.quantity = ZhCalc.round(num, 6);
  991. }
  992. // materialData[colSetting.field] = validText;
  993. materialData.expr = exprQuantity.expr;
  994. materialData.quantity = exprQuantity.quantity;
  995. }
  996. if (bPaste) {
  997. data.push(materialData);
  998. // rowData.push(curRow);
  999. } else {
  1000. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1001. }
  1002. }
  1003. if (data.length === 0) {
  1004. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1005. return;
  1006. }
  1007. const ledgerSheet = ledgerSpread.getActiveSheet();
  1008. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1009. const index = gclGatherData.indexOf(ledgerSelect);
  1010. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1011. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1012. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1013. // const xmjIndex = gcl.indexOf(xmjSelect);
  1014. const datas = [];
  1015. for (const xmj of gcl) {
  1016. const data2 = {
  1017. xmj_id: xmj.id,
  1018. gcl_id: xmj.gcl_id,
  1019. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1020. };
  1021. datas.push(data2);
  1022. }
  1023. console.log(data, datas);
  1024. // 更新至服务器
  1025. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data } }, function (result) {
  1026. materialListData = result.materialListData;
  1027. gclList = result.gclList;
  1028. calculateJiaCha(gclGatherData);
  1029. // const index = gclGatherData.indexOf(ledgerSelect);
  1030. loadLeafXmjData(index);
  1031. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1032. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1033. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1034. loadMaterialData(index);
  1035. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1036. materialSpread.getActiveSheet().setSelection(info.cellRange.row, info.cellRange.col, info.cellRange.rowCount, info.cellRange.colCount);
  1037. }, function () {
  1038. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1039. });
  1040. // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1041. // materialListData = result;
  1042. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1043. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1044. // calculateJiaCha(gclGatherData, iGclRow);
  1045. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1046. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1047. // }, function () {
  1048. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1049. // });
  1050. },
  1051. _checkExprValid(expr) {
  1052. if (!expr) return [true, null];
  1053. const param = [];
  1054. let num = '', base = '';
  1055. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1056. if (/^[\d\.%]+/.test(expr[i])) {
  1057. if (base !== '') {
  1058. param.push({type: 'base', value: base});
  1059. base = '';
  1060. }
  1061. num = num + expr[i];
  1062. } else if (expr[i] === '(') {
  1063. if (num !== '') {
  1064. param.push({type: 'num', value: num});
  1065. num = '';
  1066. }
  1067. if (base !== '') {
  1068. param.push({type: 'base', value: base});
  1069. base = '';
  1070. }
  1071. param.push({type: 'left', value: '('});
  1072. } else if (expr[i] === ')') {
  1073. if (num !== '') {
  1074. param.push({type: 'num', value: num});
  1075. num = '';
  1076. }
  1077. if (base !== '') {
  1078. param.push({type: 'base', value: base});
  1079. base = '';
  1080. }
  1081. param.push({type: 'right', value: ')'});
  1082. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1083. if (num !== '') {
  1084. param.push({type: 'num', value: num});
  1085. num = '';
  1086. }
  1087. if (base !== '') {
  1088. param.push({type: 'base', value: base});
  1089. base = '';
  1090. }
  1091. param.push({type: 'calc', value: expr[i]});
  1092. } else {
  1093. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1094. }
  1095. }
  1096. if (num !== '') {
  1097. param.push({type: 'num', value: num});
  1098. num = '';
  1099. }
  1100. if (base !== '') {
  1101. param.push({type: 'base', value: base});
  1102. base = '';
  1103. }
  1104. if (param.length === 0) return true;
  1105. if (param.length > 1) {
  1106. if (param[0].value === '-') {
  1107. param[1].value = '-' + param[1];
  1108. }
  1109. param.unshift();
  1110. }
  1111. const iLen = param.length;
  1112. let iLeftCount = 0, iRightCount = 0;
  1113. for (const [i, p] of param.entries()) {
  1114. if (p.type === 'calc') {
  1115. if (i === 0 || i === iLen - 1)
  1116. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1117. }
  1118. if (p.type === 'num') {
  1119. num = p.value.replace('%', '');
  1120. if (p.value.length - num.length > 1)
  1121. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1122. num = _.toNumber(num);
  1123. if (num === undefined || num === null || _.isNaN(num))
  1124. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1125. if (i > 0) {
  1126. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1127. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1128. } else if (param[i - 1].value === '/' && num === 0) {
  1129. return [false, '输入的表达式非法:请勿除0'];
  1130. }
  1131. }
  1132. }
  1133. if (p.type === 'base') {
  1134. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1135. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1136. }
  1137. if (p.type === 'left') {
  1138. iLeftCount += 1;
  1139. if (i !== 0 && param[i-1].type !== 'calc')
  1140. return [false, '输入的表达式非法:(前应有运算符'];
  1141. }
  1142. if (p.type === 'right') {
  1143. iRightCount += 1;
  1144. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1145. return [false, '输入的表达式非法:)后应有运算符'];
  1146. if (iRightCount > iLeftCount)
  1147. return [false, '输入的表达式非法:")"前无对应的"("'];
  1148. }
  1149. }
  1150. if (iLeftCount > iRightCount)
  1151. return [false, '输入的表达式非法:"("后无对应的")"'];
  1152. return [true, ''];
  1153. },
  1154. _checkExpr: function (text, data) {
  1155. if (text) {
  1156. const num = _.toNumber(text);
  1157. if (num) {
  1158. data.quantity = num;
  1159. data.expr = '';
  1160. } else {
  1161. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  1162. const [valid, msg] = this._checkExprValid(expr);
  1163. if (!valid) return [valid, msg];
  1164. data.expr = expr;
  1165. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr);
  1166. // const ce = new CalcEvalMin();
  1167. // data.quantity = ce.eval(expr);
  1168. // console.log(data.quantity);
  1169. }
  1170. } else {
  1171. data.quantity = 0;
  1172. data.expr = '';
  1173. }
  1174. return [true, ''];
  1175. },
  1176. };
  1177. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  1178. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  1179. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  1180. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  1181. // material-spread右键功能
  1182. const materialSelfSpreadObj = {
  1183. del: function () {
  1184. const sheet = materialSelfSpread.getActiveSheet();
  1185. const select = SpreadJsObj.getSelectObject(sheet);
  1186. console.log(select);
  1187. postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  1188. const index = materialListSelf.indexOf(select);
  1189. materialListSelf.splice(index, 1);
  1190. sheet.deleteRows(index, 1);
  1191. SpreadJsObj.reLoadSheetData(materialSelfSpread.getActiveSheet());
  1192. const sel = sheet.getSelections();
  1193. sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1194. const materialListIndex = materialListData.indexOf(select);
  1195. materialListData.splice(materialListIndex, 1);
  1196. const [iGclRow, iRow, nRow, lsheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1197. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1198. calculateJiaCha(gclGatherData, iGclRow);
  1199. SpreadJsObj.reLoadRowData(lsheet, nRow);
  1200. lsheet.getRange(nRow, -1, 1, -1).backColor(color);
  1201. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1202. });
  1203. },
  1204. deletePress: function (sheet) {
  1205. return;
  1206. },
  1207. editStarting: function (e, info) {
  1208. const col = info.sheet.zh_setting.cols[info.col];
  1209. const select = SpreadJsObj.getSelectObject(info.sheet);
  1210. if (col.field === 'quantity') {
  1211. if (select.expr && select.expr !== '') {
  1212. info.sheet.getCell(info.row, info.col).text(select.expr);
  1213. }
  1214. }
  1215. },
  1216. editEnded: function (e, info) {
  1217. if (info.sheet.zh_setting) {
  1218. const select = SpreadJsObj.getSelectObject(info.sheet);
  1219. const col = info.sheet.zh_setting.cols[info.col];
  1220. // 未改变值则不提交
  1221. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1222. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1223. // let orgValue = select[col.field];
  1224. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1225. let orgValue;
  1226. if (col.field === 'quantity') {
  1227. orgValue = validText && validText !== ''
  1228. ? _.toNumber(validText) ? select.quantity : select.expr
  1229. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1230. } else {
  1231. orgValue = select[col.field];
  1232. }
  1233. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1234. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1235. return;
  1236. }
  1237. const exprQuantity = {
  1238. expr: '',
  1239. quantity: 0,
  1240. };
  1241. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1242. if (!valid) {
  1243. toastr.error(msg);
  1244. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1245. return;
  1246. }
  1247. if (isNaN(exprQuantity.quantity)) {
  1248. toastr.error('不能输入其它非数字类型字符');
  1249. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1250. return;
  1251. }
  1252. const num = parseFloat(exprQuantity.quantity);
  1253. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1254. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1255. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1256. // return;
  1257. toastr.warning('已保留6位小数');
  1258. exprQuantity.quantity = ZhCalc.round(num, 6);
  1259. }
  1260. // 更新至服务器
  1261. console.log(exprQuantity, select.mb_id);
  1262. postData(window.location.pathname + '/save', { type:'update', updateData: { id: select.id, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id } }, function (result) {
  1263. const materialListIndex = materialListData.indexOf(select);
  1264. const index = materialList.indexOf(select);
  1265. select.quantity = exprQuantity.quantity;
  1266. select.expr = exprQuantity.expr;
  1267. materialListData.splice(materialListIndex, 1, select);
  1268. materialList.indexOf(index, 1, select);
  1269. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1270. const [iGclRow, iRow, nRow, sheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1271. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1272. calculateJiaCha(gclGatherData, iGclRow);
  1273. SpreadJsObj.reLoadRowData(sheet, nRow);
  1274. console.log(lselect, color);
  1275. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  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. });