material_list.js 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  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, color] = 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. materialListData = result;
  667. $('#cancel-self').modal('hide');
  668. } else {
  669. selfList.push(result);
  670. }
  671. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  672. calculateJiaCha(gclGatherData, iGclRow);
  673. SpreadJsObj.reLoadRowData(sheet, nRow);
  674. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  675. loadXmjMaterialData(iGclRow, nRow);
  676. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  677. });
  678. },
  679. }
  680. // leafXmj右键功能
  681. $.contextMenu({
  682. selector: '#leaf-xmj-spread',
  683. build: function ($trigger, e) {
  684. const target = SpreadJsObj.safeRightClickSelection($trigger, e, leafXmjSpread);
  685. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  686. },
  687. items: {
  688. 'stop': {
  689. name: '不参与调差',
  690. icon: 'fa-remove',
  691. callback: function (key, opt) {
  692. leafXmjSpreadObj.checkJoinMaterial('notjoin');
  693. },
  694. visible: function (key, opt) {
  695. const sheet = leafXmjSpread.getActiveSheet();
  696. const select = SpreadJsObj.getSelectObject(sheet);
  697. const sel = sheet.getSelections()[0];
  698. if (!select || sel.rowCount !== 1) {
  699. return false;
  700. }
  701. const notx = findNotJoinLeafXmj(select);
  702. if (!readOnly && select && notx === undefined) {
  703. return true;
  704. } else {
  705. return false;
  706. }
  707. }
  708. },
  709. 'start': {
  710. name: '参与调差',
  711. icon: 'fa-sign-in',
  712. callback: function (key, opt) {
  713. leafXmjSpreadObj.checkJoinMaterial('join');
  714. },
  715. visible: function (key, opt) {
  716. const sheet = leafXmjSpread.getActiveSheet();
  717. const select = SpreadJsObj.getSelectObject(sheet);
  718. const sel = sheet.getSelections()[0];
  719. if (!select || sel.rowCount !== 1) {
  720. return false;
  721. }
  722. const notx = findNotJoinLeafXmj(select);
  723. if (!readOnly && select && notx === undefined) {
  724. return false;
  725. } else {
  726. return true;
  727. }
  728. },
  729. },
  730. 'self': {
  731. name: '单独添加工料',
  732. icon: 'fa-sign-in',
  733. callback: function (key, opt) {
  734. leafXmjSpreadObj.checkSelfMaterial('self');
  735. },
  736. visible: function (key, opt) {
  737. const sheet = leafXmjSpread.getActiveSheet();
  738. const select = SpreadJsObj.getSelectObject(sheet);
  739. const sel = sheet.getSelections()[0];
  740. if (!select || sel.rowCount !== 1) {
  741. return false;
  742. }
  743. const notx = findSelfLeafXmj(select);
  744. if (!readOnly && select && notx === undefined) {
  745. return true;
  746. } else {
  747. return false;
  748. }
  749. }
  750. },
  751. 'noself': {
  752. name: '取消单独添加工料',
  753. icon: 'fa-remove',
  754. callback: function (key, opt) {
  755. $('#cancel-self').modal('show');
  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. $('#cancelSelfBtn').click(function () {
  776. leafXmjSpreadObj.checkSelfMaterial('noself');
  777. });
  778. // material-spread右键功能
  779. const materialSpreadObj = {
  780. del: function () {
  781. const materialSheet = materialSpread.getActiveSheet();
  782. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  783. const sheet = ledgerSpread.getActiveSheet();
  784. const select = SpreadJsObj.getSelectObject(sheet);
  785. const index = gclGatherData.indexOf(select);
  786. // const leafXmjSheet = leafXmjSpread.getActiveSheet();
  787. // const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  788. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  789. // const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  790. const datas = [];
  791. for (const xmj of gcl) {
  792. const data = {
  793. xmj_id: xmj.id,
  794. gcl_id: xmj.gcl_id,
  795. mx_id: xmj.mx_id ? xmj.mx_id : '',
  796. };
  797. datas.push(data);
  798. }
  799. console.log(datas, materialSelect.mb_id);
  800. postData(window.location.pathname + '/save', {type: 'dels', postData: { xmjs: datas, mb_id: materialSelect.mb_id }}, function (result) {
  801. materialListData = result.materialListData;
  802. gclList = result.gclList;
  803. calculateJiaCha(gclGatherData);
  804. // const index = gclGatherData.indexOf(ledgerSelect);
  805. loadLeafXmjData(index);
  806. // const xmjSheet = leafXmjSpread.getActiveSheet();
  807. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  808. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  809. loadMaterialData(index);
  810. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  811. });
  812. // postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  813. // const index = materialList.indexOf(select);
  814. // materialList.splice(index, 1);
  815. // sheet.deleteRows(index, 1);
  816. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  817. // const sel = sheet.getSelections();
  818. // sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  819. // const materialListIndex = materialListData.indexOf(select);
  820. // materialListData.splice(materialListIndex, 1);
  821. // const [iGclRow, iRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  822. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  823. // calculateJiaCha(gclGatherData, iGclRow);
  824. // SpreadJsObj.reLoadRowData(lsheet, iRow);
  825. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  826. // });
  827. },
  828. deletePress: function (sheet) {
  829. return;
  830. },
  831. editStarting: function (e, info) {
  832. const col = info.sheet.zh_setting.cols[info.col];
  833. const select = SpreadJsObj.getSelectObject(info.sheet);
  834. if (col.field === 'quantity') {
  835. if (select.expr && select.expr !== '') {
  836. info.sheet.getCell(info.row, info.col).text(select.expr);
  837. }
  838. }
  839. },
  840. editEnded: function (e, info) {
  841. if (info.sheet.zh_setting) {
  842. const select = SpreadJsObj.getSelectObject(info.sheet);
  843. const col = info.sheet.zh_setting.cols[info.col];
  844. // 未改变值则不提交
  845. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  846. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  847. // let orgValue = select[col.field];
  848. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  849. let orgValue;
  850. if (col.field === 'quantity') {
  851. orgValue = validText && validText !== ''
  852. ? _.toNumber(validText) ? select.quantity : select.expr
  853. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  854. } else {
  855. orgValue = select[col.field];
  856. }
  857. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  858. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  859. return;
  860. }
  861. const exprQuantity = {
  862. expr: '',
  863. quantity: 0,
  864. };
  865. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  866. if (!valid) {
  867. toastr.error(msg);
  868. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  869. return;
  870. }
  871. if (isNaN(exprQuantity.quantity)) {
  872. toastr.error('不能输入其它非数字类型字符');
  873. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  874. return;
  875. }
  876. const num = parseFloat(exprQuantity.quantity);
  877. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  878. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  879. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  880. // return;
  881. toastr.warning('已保留6位小数');
  882. exprQuantity.quantity = ZhCalc.round(num, 6);
  883. }
  884. // 更新至服务器
  885. const ledgerSheet = ledgerSpread.getActiveSheet();
  886. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  887. const index = gclGatherData.indexOf(ledgerSelect);
  888. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  889. // const xmjSheet = leafXmjSpread.getActiveSheet();
  890. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  891. // const xmjIndex = gcl.indexOf(xmjSelect);
  892. const datas = [];
  893. for (const xmj of gcl) {
  894. const data = {
  895. xmj_id: xmj.id,
  896. gcl_id: xmj.gcl_id,
  897. mx_id: xmj.mx_id ? xmj.mx_id : '',
  898. };
  899. datas.push(data);
  900. }
  901. console.log(exprQuantity, datas, select.mb_id);
  902. postData(window.location.pathname + '/save', { type:'updates', updateData: { xmjs: datas, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id } }, function (result) {
  903. materialListData = result.materialListData;
  904. gclList = result.gclList;
  905. calculateJiaCha(gclGatherData);
  906. // const index = gclGatherData.indexOf(ledgerSelect);
  907. loadLeafXmjData(index);
  908. // const xmjSheet = leafXmjSpread.getActiveSheet();
  909. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  910. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  911. loadMaterialData(index);
  912. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  913. materialSpread.getActiveSheet().setSelection(info.row + 1, info.col, 1, 1);
  914. }, function () {
  915. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  916. });
  917. // postData(window.location.pathname + '/save', { type:'update', updateData: { id:select.id, quantity: validText, mb_id: select.mb_id } }, function (result) {
  918. // const materialListIndex = materialListData.indexOf(select);
  919. // const index = materialList.indexOf(select);
  920. // select[col.field] = validText;
  921. // materialListData.splice(materialListIndex, 1, select);
  922. // materialList.indexOf(index, 1, select);
  923. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  924. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  925. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  926. // calculateJiaCha(gclGatherData, iGclRow)
  927. // SpreadJsObj.reLoadRowData(sheet, iRow);
  928. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  929. // }, function () {
  930. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  931. // });
  932. }
  933. },
  934. clipboardPasted(e, info) {
  935. const hint = {
  936. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  937. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  938. numberCan: {type: 'warning', msg: '已保留6位小数'},
  939. };
  940. const range = info.cellRange;
  941. const sortData = info.sheet.zh_data || [];
  942. if (range.row + range.rowCount > sortData.length) {
  943. toastMessageUniq(hint.cellError);
  944. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  945. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  946. return;
  947. }
  948. if (sortData.length > 0 && range.col + range.colCount > 5) {
  949. toastMessageUniq(hint.cellError);
  950. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  951. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  952. return;
  953. }
  954. const data = [];
  955. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  956. let bPaste = true;
  957. const curRow = range.row + iRow;
  958. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  959. const hintRow = range.rowCount > 1 ? curRow : '';
  960. let sameCol = 0;
  961. for (let iCol = 0; iCol < range.colCount; iCol++) {
  962. const curCol = range.col + iCol;
  963. const colSetting = info.sheet.zh_setting.cols[curCol];
  964. if (!colSetting) continue;
  965. // let validText = info.sheet.getText(curRow, curCol);
  966. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  967. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  968. const orgValue = sortData[curRow][colSetting.field];
  969. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  970. sameCol++;
  971. if (range.colCount === sameCol) {
  972. bPaste = false;
  973. }
  974. continue;
  975. }
  976. const exprQuantity = {
  977. expr: '',
  978. quantity: 0,
  979. };
  980. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  981. if (!valid) {
  982. toastMessageUniq(getPasteHint(msg, hintRow));
  983. bPaste = false;
  984. continue;
  985. }
  986. if (isNaN(exprQuantity.quantity)) {
  987. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  988. bPaste = false;
  989. continue;
  990. }
  991. const num = parseFloat(exprQuantity.quantity);
  992. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  993. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  994. // bPaste = false;
  995. // continue;
  996. exprQuantity.quantity = ZhCalc.round(num, 6);
  997. }
  998. // materialData[colSetting.field] = validText;
  999. materialData.expr = exprQuantity.expr;
  1000. materialData.quantity = exprQuantity.quantity;
  1001. }
  1002. if (bPaste) {
  1003. data.push(materialData);
  1004. // rowData.push(curRow);
  1005. } else {
  1006. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1007. }
  1008. }
  1009. if (data.length === 0) {
  1010. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1011. return;
  1012. }
  1013. const ledgerSheet = ledgerSpread.getActiveSheet();
  1014. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1015. const index = gclGatherData.indexOf(ledgerSelect);
  1016. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1017. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1018. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1019. // const xmjIndex = gcl.indexOf(xmjSelect);
  1020. const datas = [];
  1021. for (const xmj of gcl) {
  1022. const data2 = {
  1023. xmj_id: xmj.id,
  1024. gcl_id: xmj.gcl_id,
  1025. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1026. };
  1027. datas.push(data2);
  1028. }
  1029. console.log(data, datas);
  1030. // 更新至服务器
  1031. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data } }, function (result) {
  1032. materialListData = result.materialListData;
  1033. gclList = result.gclList;
  1034. calculateJiaCha(gclGatherData);
  1035. // const index = gclGatherData.indexOf(ledgerSelect);
  1036. loadLeafXmjData(index);
  1037. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1038. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1039. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1040. loadMaterialData(index);
  1041. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1042. materialSpread.getActiveSheet().setSelection(info.cellRange.row, info.cellRange.col, info.cellRange.rowCount, info.cellRange.colCount);
  1043. }, function () {
  1044. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1045. });
  1046. // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1047. // materialListData = result;
  1048. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1049. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1050. // calculateJiaCha(gclGatherData, iGclRow);
  1051. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1052. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1053. // }, function () {
  1054. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1055. // });
  1056. },
  1057. _checkExprValid(expr) {
  1058. if (!expr) return [true, null];
  1059. const param = [];
  1060. let num = '', base = '';
  1061. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1062. if (/^[\d\.%]+/.test(expr[i])) {
  1063. if (base !== '') {
  1064. param.push({type: 'base', value: base});
  1065. base = '';
  1066. }
  1067. num = num + expr[i];
  1068. } else if (expr[i] === '(') {
  1069. if (num !== '') {
  1070. param.push({type: 'num', value: num});
  1071. num = '';
  1072. }
  1073. if (base !== '') {
  1074. param.push({type: 'base', value: base});
  1075. base = '';
  1076. }
  1077. param.push({type: 'left', value: '('});
  1078. } else if (expr[i] === ')') {
  1079. if (num !== '') {
  1080. param.push({type: 'num', value: num});
  1081. num = '';
  1082. }
  1083. if (base !== '') {
  1084. param.push({type: 'base', value: base});
  1085. base = '';
  1086. }
  1087. param.push({type: 'right', value: ')'});
  1088. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1089. if (num !== '') {
  1090. param.push({type: 'num', value: num});
  1091. num = '';
  1092. }
  1093. if (base !== '') {
  1094. param.push({type: 'base', value: base});
  1095. base = '';
  1096. }
  1097. param.push({type: 'calc', value: expr[i]});
  1098. } else {
  1099. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1100. }
  1101. }
  1102. if (num !== '') {
  1103. param.push({type: 'num', value: num});
  1104. num = '';
  1105. }
  1106. if (base !== '') {
  1107. param.push({type: 'base', value: base});
  1108. base = '';
  1109. }
  1110. if (param.length === 0) return true;
  1111. if (param.length > 1) {
  1112. if (param[0].value === '-') {
  1113. param[1].value = '-' + param[1];
  1114. }
  1115. param.unshift();
  1116. }
  1117. const iLen = param.length;
  1118. let iLeftCount = 0, iRightCount = 0;
  1119. for (const [i, p] of param.entries()) {
  1120. if (p.type === 'calc') {
  1121. if (i === 0 || i === iLen - 1)
  1122. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1123. }
  1124. if (p.type === 'num') {
  1125. num = p.value.replace('%', '');
  1126. if (p.value.length - num.length > 1)
  1127. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1128. num = _.toNumber(num);
  1129. if (num === undefined || num === null || _.isNaN(num))
  1130. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1131. if (i > 0) {
  1132. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1133. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1134. } else if (param[i - 1].value === '/' && num === 0) {
  1135. return [false, '输入的表达式非法:请勿除0'];
  1136. }
  1137. }
  1138. }
  1139. if (p.type === 'base') {
  1140. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1141. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1142. }
  1143. if (p.type === 'left') {
  1144. iLeftCount += 1;
  1145. if (i !== 0 && param[i-1].type !== 'calc')
  1146. return [false, '输入的表达式非法:(前应有运算符'];
  1147. }
  1148. if (p.type === 'right') {
  1149. iRightCount += 1;
  1150. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1151. return [false, '输入的表达式非法:)后应有运算符'];
  1152. if (iRightCount > iLeftCount)
  1153. return [false, '输入的表达式非法:")"前无对应的"("'];
  1154. }
  1155. }
  1156. if (iLeftCount > iRightCount)
  1157. return [false, '输入的表达式非法:"("后无对应的")"'];
  1158. return [true, ''];
  1159. },
  1160. _checkExpr: function (text, data) {
  1161. if (text) {
  1162. const num = _.toNumber(text);
  1163. if (num) {
  1164. data.quantity = num;
  1165. data.expr = '';
  1166. } else {
  1167. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  1168. const [valid, msg] = this._checkExprValid(expr);
  1169. if (!valid) return [valid, msg];
  1170. data.expr = expr;
  1171. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr);
  1172. // const ce = new CalcEvalMin();
  1173. // data.quantity = ce.eval(expr);
  1174. // console.log(data.quantity);
  1175. }
  1176. } else {
  1177. data.quantity = 0;
  1178. data.expr = '';
  1179. }
  1180. return [true, ''];
  1181. },
  1182. };
  1183. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  1184. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  1185. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  1186. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  1187. // material-spread右键功能
  1188. const materialSelfSpreadObj = {
  1189. del: function () {
  1190. const sheet = materialSelfSpread.getActiveSheet();
  1191. const select = SpreadJsObj.getSelectObject(sheet);
  1192. console.log(select);
  1193. postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  1194. const index = materialListSelf.indexOf(select);
  1195. materialListSelf.splice(index, 1);
  1196. sheet.deleteRows(index, 1);
  1197. SpreadJsObj.reLoadSheetData(materialSelfSpread.getActiveSheet());
  1198. const sel = sheet.getSelections();
  1199. sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1200. const materialListIndex = materialListData.indexOf(select);
  1201. materialListData.splice(materialListIndex, 1);
  1202. const [iGclRow, iRow, nRow, lsheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1203. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1204. calculateJiaCha(gclGatherData, iGclRow);
  1205. SpreadJsObj.reLoadRowData(lsheet, nRow);
  1206. lsheet.getRange(nRow, -1, 1, -1).backColor(color);
  1207. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1208. });
  1209. },
  1210. deletePress: function (sheet) {
  1211. return;
  1212. },
  1213. editStarting: function (e, info) {
  1214. const col = info.sheet.zh_setting.cols[info.col];
  1215. const select = SpreadJsObj.getSelectObject(info.sheet);
  1216. if (col.field === 'quantity') {
  1217. if (select.expr && select.expr !== '') {
  1218. info.sheet.getCell(info.row, info.col).text(select.expr);
  1219. }
  1220. }
  1221. },
  1222. editEnded: function (e, info) {
  1223. if (info.sheet.zh_setting) {
  1224. const select = SpreadJsObj.getSelectObject(info.sheet);
  1225. const col = info.sheet.zh_setting.cols[info.col];
  1226. // 未改变值则不提交
  1227. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1228. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1229. // let orgValue = select[col.field];
  1230. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1231. let orgValue;
  1232. if (col.field === 'quantity') {
  1233. orgValue = validText && validText !== ''
  1234. ? _.toNumber(validText) ? select.quantity : select.expr
  1235. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1236. } else {
  1237. orgValue = select[col.field];
  1238. }
  1239. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1240. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1241. return;
  1242. }
  1243. const exprQuantity = {
  1244. expr: '',
  1245. quantity: 0,
  1246. };
  1247. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1248. if (!valid) {
  1249. toastr.error(msg);
  1250. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1251. return;
  1252. }
  1253. if (isNaN(exprQuantity.quantity)) {
  1254. toastr.error('不能输入其它非数字类型字符');
  1255. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1256. return;
  1257. }
  1258. const num = parseFloat(exprQuantity.quantity);
  1259. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1260. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1261. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1262. // return;
  1263. toastr.warning('已保留6位小数');
  1264. exprQuantity.quantity = ZhCalc.round(num, 6);
  1265. }
  1266. // 更新至服务器
  1267. console.log(exprQuantity, select.mb_id);
  1268. postData(window.location.pathname + '/save', { type:'update', updateData: { id: select.id, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id } }, function (result) {
  1269. const materialListIndex = materialListData.indexOf(select);
  1270. const index = materialList.indexOf(select);
  1271. select.quantity = exprQuantity.quantity;
  1272. select.expr = exprQuantity.expr;
  1273. materialListData.splice(materialListIndex, 1, select);
  1274. materialList.indexOf(index, 1, select);
  1275. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1276. const [iGclRow, iRow, nRow, sheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1277. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1278. calculateJiaCha(gclGatherData, iGclRow);
  1279. SpreadJsObj.reLoadRowData(sheet, nRow);
  1280. console.log(lselect, color);
  1281. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  1282. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1283. }, function () {
  1284. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1285. });
  1286. }
  1287. },
  1288. clipboardPasted(e, info) {
  1289. const hint = {
  1290. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1291. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1292. numberCan: {type: 'warning', msg: '已保留6位小数'},
  1293. };
  1294. const range = info.cellRange;
  1295. const sortData = info.sheet.zh_data || [];
  1296. if (range.row + range.rowCount > sortData.length) {
  1297. toastMessageUniq(hint.cellError);
  1298. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1299. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1300. return;
  1301. }
  1302. if (sortData.length > 0 && range.col + range.colCount > 5) {
  1303. toastMessageUniq(hint.cellError);
  1304. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1305. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1306. return;
  1307. }
  1308. const data = [];
  1309. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1310. let bPaste = true;
  1311. const curRow = range.row + iRow;
  1312. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  1313. const hintRow = range.rowCount > 1 ? curRow : '';
  1314. let sameCol = 0;
  1315. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1316. const curCol = range.col + iCol;
  1317. const colSetting = info.sheet.zh_setting.cols[curCol];
  1318. if (!colSetting) continue;
  1319. // let validText = info.sheet.getText(curRow, curCol);
  1320. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1321. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1322. const orgValue = sortData[curRow][colSetting.field];
  1323. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1324. sameCol++;
  1325. if (range.colCount === sameCol) {
  1326. bPaste = false;
  1327. }
  1328. continue;
  1329. }
  1330. const exprQuantity = {
  1331. expr: '',
  1332. quantity: 0,
  1333. };
  1334. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1335. if (!valid) {
  1336. toastMessageUniq(getPasteHint(msg, hintRow));
  1337. bPaste = false;
  1338. continue;
  1339. }
  1340. if (isNaN(exprQuantity.quantity)) {
  1341. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1342. bPaste = false;
  1343. continue;
  1344. }
  1345. const num = parseFloat(exprQuantity.quantity);
  1346. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1347. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1348. // bPaste = false;
  1349. // continue;
  1350. exprQuantity.quantity = ZhCalc.round(num, 6);
  1351. }
  1352. // materialData[colSetting.field] = validText;
  1353. materialData.expr = exprQuantity.expr;
  1354. materialData.quantity = exprQuantity.quantity;
  1355. }
  1356. if (bPaste) {
  1357. data.push(materialData);
  1358. // rowData.push(curRow);
  1359. } else {
  1360. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1361. }
  1362. }
  1363. if (data.length === 0) {
  1364. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1365. return;
  1366. }
  1367. console.log(data);
  1368. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1369. materialListData = result;
  1370. const [iGclRow, iRow, nRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1371. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1372. calculateJiaCha(gclGatherData, iGclRow);
  1373. // SpreadJsObj.reLoadRowData(sheet, nRow);
  1374. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1375. loadXmjMaterialData(iGclRow, nRow);
  1376. }, function () {
  1377. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1378. });
  1379. },
  1380. };
  1381. materialSelfSpread.bind(spreadNS.Events.EditStarting, materialSelfSpreadObj.editStarting);
  1382. materialSelfSpread.bind(spreadNS.Events.EditEnded, materialSelfSpreadObj.editEnded);
  1383. materialSelfSpread.bind(spreadNS.Events.ClipboardPasted, materialSelfSpreadObj.clipboardPasted);
  1384. SpreadJsObj.addDeleteBind(materialSelfSpread, materialSelfSpreadObj.deletePress);
  1385. if (!openMaterialChecklist) {
  1386. $.contextMenu({
  1387. selector: '#material-spread',
  1388. build: function ($trigger, e) {
  1389. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  1390. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1391. },
  1392. items: {
  1393. 'create': {
  1394. name: '添加工料',
  1395. icon: 'fa-sign-in',
  1396. callback: function (key, opt) {
  1397. // 获取已选清单
  1398. changeMaterialTable();
  1399. $('#add_type').val('all');
  1400. $('#addgl').modal('show');
  1401. },
  1402. disabled: function (key, opt) {
  1403. const sheet = leafXmjSpread.getActiveSheet();
  1404. const select = SpreadJsObj.getSelectObject(sheet);
  1405. // const notx = findNotJoinLeafXmj(select);
  1406. if (!select) {
  1407. return true;
  1408. }
  1409. // if (!readOnly && notx === undefined) {
  1410. // return false;
  1411. // } else {
  1412. // return true;
  1413. // }
  1414. return readOnly;
  1415. }
  1416. },
  1417. 'delete': {
  1418. name: '删除工料',
  1419. icon: 'fa-remove',
  1420. callback: function (key, opt) {
  1421. materialSpreadObj.del(materialSpread.getActiveSheet());
  1422. },
  1423. disabled: function (key, opt) {
  1424. const sheet = materialSpread.getActiveSheet();
  1425. const select = SpreadJsObj.getSelectObject(sheet);
  1426. if (!select) {
  1427. return true;
  1428. }
  1429. if (!readOnly && select && materialBase.isEdit(select, 'del')) {
  1430. return false;
  1431. } else {
  1432. return true;
  1433. }
  1434. }
  1435. },
  1436. }
  1437. });
  1438. }
  1439. $.contextMenu({
  1440. selector: '#material-self-spread',
  1441. build: function ($trigger, e) {
  1442. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSelfSpread);
  1443. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1444. },
  1445. items: {
  1446. 'create': {
  1447. name: '添加工料',
  1448. icon: 'fa-sign-in',
  1449. callback: function (key, opt) {
  1450. // 获取已选清单
  1451. changeMaterialTable('self');
  1452. $('#add_type').val('self');
  1453. $('#addgl').modal('show');
  1454. },
  1455. disabled: function (key, opt) {
  1456. const sheet = leafXmjSpread.getActiveSheet();
  1457. const select = SpreadJsObj.getSelectObject(sheet);
  1458. // const notx = findNotJoinLeafXmj(select);
  1459. if (!select) {
  1460. return true;
  1461. }
  1462. // if (!readOnly && notx === undefined) {
  1463. // return false;
  1464. // } else {
  1465. // return true;
  1466. // }
  1467. return readOnly;
  1468. }
  1469. },
  1470. 'delete': {
  1471. name: '删除工料',
  1472. icon: 'fa-remove',
  1473. callback: function (key, opt) {
  1474. materialSelfSpreadObj.del(materialSelfSpread.getActiveSheet());
  1475. },
  1476. disabled: function (key, opt) {
  1477. const sheet = materialSelfSpread.getActiveSheet();
  1478. const select = SpreadJsObj.getSelectObject(sheet);
  1479. if (!select) {
  1480. return true;
  1481. }
  1482. if (!readOnly && select) {
  1483. return false;
  1484. } else {
  1485. return true;
  1486. }
  1487. }
  1488. },
  1489. }
  1490. });
  1491. }
  1492. // 应用调差工料至其他清单明细
  1493. $('#user_all_material').click(function () {
  1494. const ledgerSheet = ledgerSpread.getActiveSheet();
  1495. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1496. if (ledgerSelect.leafXmjs.length < 2) {
  1497. toastr.warning('没有需要应用调差工料的其它清单明细');
  1498. return false;
  1499. }
  1500. const xmjSheet = leafXmjSpread.getActiveSheet();
  1501. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1502. console.log(ledgerSelect.leafXmjs);
  1503. // 判断需要应用调差工料的清单明细
  1504. const needAddList = [];
  1505. for (const xmj of ledgerSelect.leafXmjs) {
  1506. const notx = findNotJoinLeafXmj(xmj);
  1507. if (notx === undefined && xmjSelect !== xmj && xmj.gather_qty && xmj.jiacha === null && xmjSelect.jiacha !== null) {
  1508. needAddList.push(xmj);
  1509. }
  1510. }
  1511. // if (needAddList.length === 0) {
  1512. // toastr.warning('没有需要应用调差工料的其它清单明细');
  1513. // return false;
  1514. // }
  1515. console.log(needAddList, materialList);
  1516. // 更新至服务器
  1517. postData(window.location.pathname + '/save', { type:'useOther', postData: { addXmj: needAddList, materialBills: materialList } }, function (result) {
  1518. materialListData = result.materialListData;
  1519. gclList = result.gclList;
  1520. toastr.success('已成功应用');
  1521. calculateJiaCha(gclGatherData);
  1522. const index = gclGatherData.indexOf(ledgerSelect);
  1523. loadLeafXmjData(index);
  1524. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1525. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1526. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1527. loadMaterialData(index);
  1528. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1529. });
  1530. });
  1531. // 切换清单行,读取所属项目节数据
  1532. ledgerSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1533. if (info.oldSelections !== undefined) {
  1534. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1535. if (iNewRow !== iOldRow) {
  1536. loadLeafXmjData(iNewRow);
  1537. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1538. loadMaterialData(iNewRow);
  1539. loadXmjMaterialData(iNewRow, 0);
  1540. checkNotJoinMaterialData();
  1541. }
  1542. }
  1543. });
  1544. // 切换项目节数据清单明细行,读取单独的清单工料数据
  1545. leafXmjSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1546. if (info.oldSelections !== undefined) {
  1547. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1548. if (iNewRow !== iOldRow) {
  1549. const sheet = ledgerSpread.getActiveSheet();
  1550. const select = SpreadJsObj.getSelectObject(sheet);
  1551. const index = gclGatherData.indexOf(select);
  1552. loadXmjMaterialData(index, iNewRow);
  1553. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  1554. }
  1555. }
  1556. });
  1557. // 显示有调差工料清单
  1558. $('#show_material_gcl').click(function () {
  1559. if ($(this).is(':checked')) {
  1560. const hadMaterialGclGatherData = [];
  1561. const hadGclIdList = [];
  1562. for (const ml of materialListData) {
  1563. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  1564. hadGclIdList.push(ml.gcl_id);
  1565. }
  1566. }
  1567. for (const gcl of gclGatherData) {
  1568. for (const index in gcl.leafXmjs) {
  1569. const gcl_id = gcl.leafXmjs[index].gcl_id;
  1570. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  1571. hadMaterialGclGatherData.push(gcl);
  1572. break;
  1573. }
  1574. }
  1575. }
  1576. gclGatherData = hadMaterialGclGatherData;
  1577. } else {
  1578. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  1579. gclGatherModel.loadPosData(pos, curPosData);
  1580. gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  1581. return item.qc_qty || item.contract_qty
  1582. });
  1583. if (openMaterialChecklist) {
  1584. // 取交集
  1585. gclGatherData = _.filter(gclGatherData, function (item) {
  1586. return _.find(materialChecklistData, { b_code: item.b_code, name: item.name, unit: item.unit, unit_price: item.unit_price });
  1587. });
  1588. }
  1589. }
  1590. calculateJiaCha(gclGatherData);
  1591. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  1592. loadLeafXmjData(0);
  1593. loadMaterialData(0);
  1594. loadXmjMaterialData(0, 0);
  1595. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  1596. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1597. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  1598. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  1599. checkNotJoinMaterialData();
  1600. });
  1601. $.subMenu({
  1602. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1603. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1604. key: 'menu.1.0.0',
  1605. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1606. callback: function (info) {
  1607. if (info.mini) {
  1608. $('.panel-title').addClass('fluid');
  1609. $('#sub-menu').removeClass('panel-sidebar');
  1610. } else {
  1611. $('.panel-title').removeClass('fluid');
  1612. $('#sub-menu').addClass('panel-sidebar');
  1613. }
  1614. autoFlashHeight();
  1615. ledgerSpread.refresh();
  1616. leafXmjSpread.refresh();
  1617. materialSpread.refresh();
  1618. materialSelfSpread.refresh();
  1619. }
  1620. });
  1621. $(window).resize(function () {
  1622. ledgerSpread.refresh();
  1623. leafXmjSpread.refresh();
  1624. materialSpread.refresh();
  1625. materialSelfSpread.refresh();
  1626. });
  1627. $.divResizer({
  1628. select: '#right-spr',
  1629. callback: function () {
  1630. ledgerSpread.refresh();
  1631. // leafXmjSpread.refresh();
  1632. materialSpread.refresh();
  1633. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1634. setLocalCache('material_list_' + materialID, width);
  1635. }
  1636. });
  1637. $.divResizer({
  1638. select: '#right-spr2',
  1639. callback: function () {
  1640. leafXmjSpread.refresh();
  1641. materialSelfSpread.refresh();
  1642. // const width = (($('#right-view2').width()/$('#right-view2').parent('div').width())*100).toFixed();
  1643. // setLocalCache('material_list3_' + materialID, width);
  1644. }
  1645. });
  1646. $.divResizer({
  1647. select: '#main-resize',
  1648. callback: function () {
  1649. materialSpread.refresh();
  1650. ledgerSpread.refresh();
  1651. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1652. $(".sp-wrap").height(bcontent-30);
  1653. leafXmjSpread.refresh();
  1654. materialSelfSpread.refresh();
  1655. const height = $('.bcontent-wrap').height();
  1656. setLocalCache('material_list2_' + materialID, height);
  1657. }
  1658. });
  1659. // 展开收起月信息价并浏览器记住本期展开收起
  1660. $('a', '.right-nav').bind('click', function () {
  1661. //const main = $('#main-view'), tool = $('#tools-view');
  1662. const tab = $(this), tabPanel = $(tab.attr('content'));
  1663. if (!tab.hasClass('active')) {
  1664. $('a', '.side-menu').removeClass('active');
  1665. $('.tab-content .tab-select-show').removeClass('active');
  1666. tab.addClass('active');
  1667. tabPanel.addClass('active');
  1668. showSideTools(tab.hasClass('active'));
  1669. if (tab.attr('content') === '#material-tab') {
  1670. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1671. setLocalCache('material_list_' + materialID, width);
  1672. }
  1673. } else {
  1674. removeLocalCache('material_list_' + materialID);
  1675. tab.removeClass('active');
  1676. tabPanel.removeClass('active');
  1677. showSideTools(tab.hasClass('active'));
  1678. }
  1679. ledgerSpread.refresh();
  1680. // leafXmjSpread.refresh();
  1681. materialSpread.refresh();
  1682. });
  1683. // 根据浏览器记录展开收起
  1684. if (getLocalCache('material_list_' + materialID)) {
  1685. const tab = $('.right-nav a[content="#material-tab"]'), tabPanel = $(tab.attr('content'));
  1686. $('a', '.side-menu').removeClass('active');
  1687. $('.tab-content .tab-select-show').removeClass('active');
  1688. tab.addClass('active');
  1689. tabPanel.addClass('active');
  1690. $('#right-view').css('width', getLocalCache('material_list_' + materialID) + '%');
  1691. showSideTools(tab.hasClass('active'));
  1692. ledgerSpread.refresh();
  1693. // leafXmjSpread.refresh();
  1694. materialSpread.refresh();
  1695. }
  1696. if (getLocalCache('material_list2_' + materialID)) {
  1697. $('.bcontent-wrap').height(getLocalCache('material_list2_' + materialID));
  1698. const cHeader = getObjHeight($(".c-header"));
  1699. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1700. $(".sp-wrap").height(bcontent-30);
  1701. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  1702. materialSpread.refresh();
  1703. ledgerSpread.refresh();
  1704. leafXmjSpread.refresh();
  1705. materialSelfSpread.refresh();
  1706. }
  1707. function getObjHeight(select) {
  1708. return select.length > 0 ? select.height() : 0;
  1709. }
  1710. const showSelfSideTools = function (show) {
  1711. const left = $('#left-view2'), right = $('#right-view2'), parent = left.parent();
  1712. if (show) {
  1713. right.show();
  1714. autoFlashHeight();
  1715. /**
  1716. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1717. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1718. * 故需要通过最终的parent.width再计算一次left.width
  1719. *
  1720. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1721. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1722. *
  1723. */
  1724. //left.css('width', parent.width() - right.outerWidth());
  1725. //left.css('width', parent.width() - right.outerWidth());
  1726. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1727. left.css('width', percent + '%');
  1728. } else {
  1729. // left.css('width', parent.width());
  1730. left.css('width', '100%');
  1731. right.hide();
  1732. }
  1733. };
  1734. });