material_list.js 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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 getMpSpreadByMBData(id) {
  23. const info = materialBillsData.find(function (item) {
  24. return item.id === parseInt(id);
  25. });
  26. console.log(info);
  27. return info ? info.m_spread : 0;
  28. }
  29. function getMaterialListByLeafXmj(gcl_id, xmj_id, mx_id = null) {
  30. const list = [];
  31. for (const ml of materialListData) {
  32. if (gcl_id === ml.gcl_id && xmj_id === ml.xmj_id && (mx_id === null || mx_id === ml.mx_id)) {
  33. list.push(ml);
  34. }
  35. }
  36. return list;
  37. }
  38. function calcOneBQJC(xmj) {
  39. let jiacha = 0;
  40. const notx = findNotJoinLeafXmj(xmj);
  41. if (notx === undefined) {
  42. const list = xmj.mx_id !== undefined ? getMaterialListByLeafXmj(xmj.gcl_id, xmj.id, xmj.mx_id) : getMaterialListByLeafXmj(xmj.gcl_id, xmj.id);
  43. for (const l of list) {
  44. jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.gather_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
  45. }
  46. }
  47. return ZhCalc.round(jiacha, 2);
  48. }
  49. function getPasteHint (str, row = '') {
  50. let returnObj = str;
  51. if (row) {
  52. returnObj.msg = '清单第' + (row+1) + '行' + (str.msg ? str.msg : str);
  53. }
  54. return returnObj;
  55. }
  56. // 重新计算列表的价差
  57. function calculateJiaCha(data, index) {
  58. // 计算单条的
  59. if (index) {
  60. const gcld = data[index]
  61. let total_jiacha = 0;
  62. for (const [index, xmj] of gcld.leafXmjs.entries()) {
  63. const jiacha = calcOneBQJC(xmj);
  64. gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
  65. total_jiacha += jiacha;
  66. }
  67. gcld.total_jiacha = ZhCalc.round(total_jiacha, 2)
  68. } else {
  69. for(const gcld of data) {
  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, 2)
  77. }
  78. }
  79. }
  80. const is_numeric = (value) => {
  81. if (typeof(value) === 'object') {
  82. return false;
  83. } else {
  84. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  85. }
  86. };
  87. $(document).ready(() => {
  88. function TipCellType()
  89. {
  90. }
  91. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.ColumnHeader();
  92. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  93. return { x: x, y: y, row: context.row, col: context.col, cellRect: cellRect, sheetArea: context.sheetArea, sheet: context.sheet };
  94. };
  95. TipCellType.prototype.processMouseEnter = function (hitInfo){
  96. if (!this._toolTipElement) {
  97. var div = document.createElement("div");
  98. $(div).css("position", "absolute")
  99. .css("border", "1px #C0C0C0 solid")
  100. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  101. .css("font", "9pt Arial")
  102. .css("background", "#fff")
  103. // .css("color", "#fff")
  104. .css("z-index", "1000")
  105. .css("padding", 5);
  106. this._toolTipElement = div;
  107. }
  108. $(this._toolTipElement).text("单位数量:每一单位清单下所需工料消耗量。")
  109. .css("top", hitInfo.y + 15)
  110. .css("left", hitInfo.x - 15);
  111. $(this._toolTipElement).hide();
  112. // document.body.insertBefore(this._toolTipElement, null);
  113. $('#material-spread-div').append(this._toolTipElement, null);
  114. $(this._toolTipElement).show("fast");
  115. };
  116. TipCellType.prototype.processMouseLeave = function (hitInfo) {
  117. if (this._toolTipElement) {
  118. // document.body.removeChild(this._toolTipElement);
  119. // $('#material-spread-div').removeChild(this._toolTipElement);
  120. this._toolTipElement.remove();
  121. this._toolTipElement = null;
  122. }
  123. };
  124. autoFlashHeight();
  125. // 清单table
  126. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  127. const ledgerSpreadSetting = {
  128. cols: [
  129. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 90, formatter: '@'},
  130. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 220, formatter: '@'},
  131. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 80, formatter: '@'},
  132. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 110, type: 'Number'},
  133. {title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'},
  134. {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'},
  135. {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 110, type: 'Number'},
  136. {title: '本期完成金额', colSpan: '1', rowSpan: '2', field: 'gather_tp', hAlign: 2, width: 110, type: 'Number'},
  137. {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'total_jiacha', hAlign:3, width: 110, type: 'Number'}
  138. ],
  139. emptyRows: 0,
  140. headRows: 2,
  141. headRowHeight: [25, 25],
  142. defaultRowHeight: 21,
  143. headerFont: '12px 微软雅黑',
  144. font: '12px 微软雅黑',
  145. readOnly: true,
  146. };
  147. // 解析清单汇总数据
  148. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  149. gclGatherModel.loadPosData(pos, curPosData);
  150. let gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  151. return item.qc_qty || item.contract_qty
  152. });
  153. calculateJiaCha(gclGatherData);
  154. // let gclGatherData = gclGatherModel.gatherGclData()
  155. // 获取项目节数据
  156. function loadLeafXmjData(iGclRow) {
  157. const gcl = gclGatherData[iGclRow];
  158. if (gcl) {
  159. for (const [index, xmj] of gcl.leafXmjs.entries()) {
  160. const jiacha = calcOneBQJC(xmj);
  161. gcl.leafXmjs[index].jiacha = jiacha !== 0 ? ZhCalc.round(jiacha, 2) : null;
  162. }
  163. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gcl.leafXmjs);
  164. // 对清单调差工料table的单位数量进行改变
  165. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + gcl.unit + '数量 �';
  166. // SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  167. } else {
  168. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  169. }
  170. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  171. }
  172. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  173. // 项目明细table
  174. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  175. const leafXmjSpreadSetting = {
  176. cols: [
  177. {title: '项目节|编号', colSpan: '2|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  178. {title: '|项目节名称', colSpan: '|1', rowSpan: '|1', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  179. {title: '计量单元|计量单元', colSpan: '2|1', rowSpan: '1|1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  180. {title: '|复核数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 0, width: 80, type: 'Number'},
  181. {title: '部位信息|单位工程', colSpan: '3|1', rowSpan: '1|1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  182. {title: '|分部工程', colSpan: '|1', rowSpan: '|1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  183. {title: '|分项工程', colSpan: '|1', rowSpan: '|1', field: 'fxgc', hAlign: 0, width: 180, formatter: '@'},
  184. {title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  185. {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 80, type: 'Number'},
  186. {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  187. {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'jiacha', hAlign: 2, width: 80, type: 'Number'},
  188. ],
  189. emptyRows: 0,
  190. headRows: 2,
  191. headRowHeight: [25, 25],
  192. defaultRowHeight: 21,
  193. headerFont: '12px 微软雅黑',
  194. font: '12px 微软雅黑',
  195. readOnly: true,
  196. };
  197. // const leafXmjCol = {
  198. // getValue: {
  199. // jiacha: function (data) {
  200. // let sum = 0;
  201. // const sheet = leafXmjSpread.getActiveSheet();
  202. // const select = SpreadJsObj.getSelectObject(sheet);
  203. // const notx = findNotJoinLeafXmj(select);
  204. // if (notx === undefined) {
  205. // for(const ml of materialList) {
  206. // sum = ZhCalc.round(ZhCalc.add(sum, ZhCalc.mul(ZhCalc.mul(data.gather_qty, ml.quantity), getMpSpreadByMBData(ml.mb_id))), 2);
  207. // }
  208. // }
  209. // return sum !== 0 ? sum : null;
  210. // }
  211. // }
  212. // };
  213. // SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  214. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  215. // 加载清单数据
  216. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  217. // 调差清单工料table
  218. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  219. const materialSpreadSetting = {
  220. cols: [
  221. {title: '清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  222. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  223. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  224. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  225. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  226. ],
  227. emptyRows: 0,
  228. headRows: 2,
  229. headRowHeight: [25, 25],
  230. defaultRowHeight: 21,
  231. headerFont: '12px 微软雅黑',
  232. font: '12px 微软雅黑',
  233. };
  234. const materialBase = {
  235. isEdit: function (data) {
  236. // 是否本期添加的工料
  237. return data.order === stage_order;
  238. }
  239. };
  240. const materialCol = {
  241. readOnly: {
  242. isEdit: function (data) {
  243. // const sheet = leafXmjSpread.getActiveSheet();
  244. // const select = SpreadJsObj.getSelectObject(sheet);
  245. // const notx = findNotJoinLeafXmj(select);
  246. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  247. return !(!readOnly && materialBase.isEdit(data));
  248. },
  249. },
  250. };
  251. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  252. // 获取项目节数据
  253. let materialList = [];
  254. function loadMaterialData(iGclRow, iLXmjRow) {
  255. const gcl = gclGatherData[iGclRow];
  256. if (gcl && gcl.leafXmjs[iLXmjRow]) {
  257. const xmj = gcl.leafXmjs[iLXmjRow];
  258. materialList = [];
  259. for (const m of materialListData) {
  260. 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)) {
  261. materialList.push(m);
  262. }
  263. }
  264. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialList);
  265. } else {
  266. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  267. }
  268. SpreadJsObj.reLoadSheetData(leafXmjSpread.getActiveSheet());
  269. }
  270. // SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), )
  271. loadLeafXmjData(0);
  272. loadMaterialData(0, 0);
  273. const sheet = materialSpread.getActiveSheet();
  274. sheet.suspendPaint();
  275. sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  276. sheet.resumePaint();
  277. // 不参与调差数据值变灰
  278. function checkNotJoinMaterialData() {
  279. const sheet = ledgerSpread.getActiveSheet();
  280. const select = SpreadJsObj.getSelectObject(sheet);
  281. const index = gclGatherData.indexOf(select);
  282. if (index !== -1) {
  283. const xmj = gclGatherData[index].leafXmjs;
  284. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  285. for (const [iRow,x] of xmj.entries()) {
  286. const notx = findNotJoinLeafXmj(x);
  287. const color = notx === undefined ? '' : '#d6d8db';
  288. leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
  289. }
  290. }
  291. }
  292. checkNotJoinMaterialData();
  293. // 对添加工料表格赋值
  294. function changeMaterialTable() {
  295. $('#materialBills tr').removeClass('table-secondary');
  296. $('#materialBills').find('input').removeAttr('disabled');
  297. $('#materialBills').find('input').prop('checked', false);
  298. for (const [index, ml] of materialList.entries()) {
  299. const mbIndex = materialBillsData.findIndex(function (item) {
  300. return item.id === ml.mb_id;
  301. });
  302. if (mbIndex !== -1) {
  303. $('#materialBills tr').eq(mbIndex).addClass('table-secondary');
  304. $('#materialBills').find('input').eq(mbIndex).attr('disabled', true);
  305. $('#materialBills').find('input').eq(mbIndex).prop('checked', true);
  306. }
  307. }
  308. }
  309. // 添加调差工料
  310. $('#add_material_bill').click(function () {
  311. // 获取已选工料
  312. $('#materialBills').find('input:disabled').prop('checked', false);
  313. const selectList = $('#materialBills').find('input:checked');
  314. if (selectList.length === 0) {
  315. toastr.warning('请选择调差工料');
  316. $('#materialBills').find('input:disabled').prop('checked', true);
  317. return false;
  318. }
  319. const mb_id = [];
  320. for (let s = 0; s < selectList.length; s++) {
  321. mb_id.push($('#materialBills').find('input:checked').eq(s).val());
  322. }
  323. // 获取当前项目节或部位明细id
  324. const sheet = ledgerSpread.getActiveSheet();
  325. const select = SpreadJsObj.getSelectObject(sheet);
  326. const index = gclGatherData.indexOf(select);
  327. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  328. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  329. const gcl = gclGatherData[index].leafXmjs;
  330. // const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  331. // const xmj = gcl[leafXmjIndex];
  332. // const data = {
  333. // xmj_id: xmj.id,
  334. // gcl_id: xmj.gcl_id,
  335. // mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  336. // mb_id: mb_id,
  337. // gather_qty: xmj.gather_qty,
  338. // };
  339. const datas = [];
  340. for (const xmj of gcl) {
  341. const notx = findNotJoinLeafXmj(xmj);
  342. const data = {
  343. xmj_id: xmj.id,
  344. gcl_id: xmj.gcl_id,
  345. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  346. gather_qty: xmj.gather_qty,
  347. is_join: notx === undefined ? 1 : 0,
  348. };
  349. datas.push(data);
  350. }
  351. // 上传到数据库
  352. console.log(datas, gcl);
  353. postData(window.location.pathname + '/save', {type: 'adds', postData: {xmjs: datas, mbIds: mb_id}}, function (result) {
  354. materialListData = result;
  355. // toastr.success('已成功应用');
  356. calculateJiaCha(gclGatherData);
  357. // const index = gclGatherData.indexOf(ledgerSelect);
  358. loadLeafXmjData(index);
  359. const xmjSheet = leafXmjSpread.getActiveSheet();
  360. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  361. const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  362. loadMaterialData(index, xmjIndex);
  363. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  364. $('#addgl').modal('hide');
  365. });
  366. // postData(window.location.pathname + '/save', {type: 'add', postData: data}, function (result) {
  367. // // 添加到materialList里
  368. // materialListData = result;
  369. // loadMaterialData(index, leafXmjIndex);
  370. // $('#addgl').modal('hide');
  371. // });
  372. $('#materialBills').find('input:disabled').prop('checked', true);
  373. });
  374. if (!readOnly) {
  375. const leafXmjSpreadObj = {
  376. getSelect : function () {
  377. const sheet = ledgerSpread.getActiveSheet();
  378. const select = SpreadJsObj.getSelectObject(sheet);
  379. const index = gclGatherData.indexOf(select);
  380. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  381. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  382. const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
  383. return [index, iRow, leafXmjSheet, leafXmjSelect];
  384. },
  385. checkJoinMaterial: function (type) {
  386. const [iGclRow, iRow, sheet, select] = leafXmjSpreadObj.getSelect();
  387. const color = type === 'join' ? '' : '#d6d8db';
  388. const data = {
  389. type: type,
  390. select: type === 'join' ? findNotJoinLeafXmj(select) : select,
  391. }
  392. // 添加到
  393. postData(window.location.pathname + '/save', data, function (result) {
  394. if (type === 'join') {
  395. const index = findNotJoinLeafXmj(select, 'index');
  396. notJoinList.splice(index, 1);
  397. } else {
  398. notJoinList.push(result);
  399. }
  400. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  401. calculateJiaCha(gclGatherData, iGclRow)
  402. SpreadJsObj.reLoadRowData(sheet, iRow);
  403. sheet.getRange(iRow, -1, 1, -1).backColor(color);
  404. loadMaterialData(iGclRow, iRow);
  405. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  406. });
  407. },
  408. }
  409. // leafXmj右键功能
  410. $.contextMenu({
  411. selector: '#leaf-xmj-spread',
  412. build: function ($trigger, e) {
  413. const target = SpreadJsObj.safeRightClickSelection($trigger, e, leafXmjSpread);
  414. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  415. },
  416. items: {
  417. 'stop': {
  418. name: '不参与调差',
  419. icon: 'fa-remove',
  420. callback: function (key, opt) {
  421. leafXmjSpreadObj.checkJoinMaterial('notjoin');
  422. },
  423. visible: function (key, opt) {
  424. const sheet = leafXmjSpread.getActiveSheet();
  425. const select = SpreadJsObj.getSelectObject(sheet);
  426. const sel = sheet.getSelections()[0];
  427. const notx = findNotJoinLeafXmj(select);
  428. if (!select || sel.rowCount !== 1) {
  429. return false;
  430. }
  431. if (!readOnly && select && notx === undefined) {
  432. return true;
  433. } else {
  434. return false;
  435. }
  436. }
  437. },
  438. 'start': {
  439. name: '参与调差',
  440. icon: 'fa-sign-in',
  441. callback: function (key, opt) {
  442. leafXmjSpreadObj.checkJoinMaterial('join');
  443. },
  444. visible: function (key, opt) {
  445. const sheet = leafXmjSpread.getActiveSheet();
  446. const select = SpreadJsObj.getSelectObject(sheet);
  447. const sel = sheet.getSelections()[0];
  448. const notx = findNotJoinLeafXmj(select);
  449. if (!select || sel.rowCount !== 1) {
  450. return false;
  451. }
  452. if (!readOnly && select && notx === undefined) {
  453. return false;
  454. } else {
  455. return true;
  456. }
  457. },
  458. }
  459. }
  460. });
  461. // material-spread右键功能
  462. const materialSpreadObj = {
  463. del: function () {
  464. const materialSheet = materialSpread.getActiveSheet();
  465. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  466. const sheet = ledgerSpread.getActiveSheet();
  467. const select = SpreadJsObj.getSelectObject(sheet);
  468. const index = gclGatherData.indexOf(select);
  469. const gcl = gclGatherData[index].leafXmjs;
  470. const datas = [];
  471. for (const xmj of gcl) {
  472. const data = {
  473. xmj_id: xmj.id,
  474. gcl_id: xmj.gcl_id,
  475. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  476. };
  477. datas.push(data);
  478. }
  479. console.log(datas, materialSelect.mb_id);
  480. postData(window.location.pathname + '/save', {type: 'dels', postData: { xmjs: datas, mb_id: materialSelect.mb_id }}, function (result) {
  481. materialListData = result;
  482. calculateJiaCha(gclGatherData);
  483. // const index = gclGatherData.indexOf(ledgerSelect);
  484. loadLeafXmjData(index);
  485. const xmjSheet = leafXmjSpread.getActiveSheet();
  486. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  487. const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  488. loadMaterialData(index, xmjIndex);
  489. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  490. });
  491. // postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  492. // const index = materialList.indexOf(select);
  493. // materialList.splice(index, 1);
  494. // sheet.deleteRows(index, 1);
  495. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  496. // const sel = sheet.getSelections();
  497. // sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  498. // const materialListIndex = materialListData.indexOf(select);
  499. // materialListData.splice(materialListIndex, 1);
  500. // const [iGclRow, iRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  501. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  502. // calculateJiaCha(gclGatherData, iGclRow);
  503. // SpreadJsObj.reLoadRowData(lsheet, iRow);
  504. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  505. // });
  506. },
  507. deletePress: function (sheet) {
  508. return;
  509. },
  510. editStarting: function (e, info) {
  511. const col = info.sheet.zh_setting.cols[info.col];
  512. const select = SpreadJsObj.getSelectObject(info.sheet);
  513. if (col.field === 'quantity') {
  514. if (select.expr && select.expr !== '') {
  515. info.sheet.getCell(info.row, info.col).text(select.expr);
  516. }
  517. }
  518. },
  519. editEnded: function (e, info) {
  520. if (info.sheet.zh_setting) {
  521. const select = SpreadJsObj.getSelectObject(info.sheet);
  522. const col = info.sheet.zh_setting.cols[info.col];
  523. // 未改变值则不提交
  524. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  525. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  526. // let orgValue = select[col.field];
  527. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  528. let orgValue;
  529. if (col.field === 'quantity') {
  530. orgValue = validText && validText !== ''
  531. ? _.toNumber(validText) ? select.quantity : select.expr
  532. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  533. } else {
  534. orgValue = select[col.field];
  535. }
  536. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  537. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  538. return;
  539. }
  540. const exprQuantity = {
  541. expr: '',
  542. quantity: 0,
  543. };
  544. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  545. if (!valid) {
  546. toastr.error(msg);
  547. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  548. return;
  549. }
  550. if (isNaN(exprQuantity.quantity)) {
  551. toastr.error('不能输入其它非数字类型字符');
  552. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  553. return;
  554. }
  555. const num = parseFloat(exprQuantity.quantity);
  556. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  557. toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  558. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  559. return;
  560. }
  561. // 更新至服务器
  562. const ledgerSheet = ledgerSpread.getActiveSheet();
  563. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  564. const index = gclGatherData.indexOf(ledgerSelect);
  565. const gcl = gclGatherData[index].leafXmjs;
  566. const datas = [];
  567. for (const xmj of gcl) {
  568. const data = {
  569. xmj_id: xmj.id,
  570. gcl_id: xmj.gcl_id,
  571. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  572. };
  573. datas.push(data);
  574. }
  575. console.log(exprQuantity, datas, select.mb_id);
  576. postData(window.location.pathname + '/save', { type:'updates', updateData: { xmjs: datas, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id } }, function (result) {
  577. materialListData = result;
  578. calculateJiaCha(gclGatherData);
  579. // const index = gclGatherData.indexOf(ledgerSelect);
  580. loadLeafXmjData(index);
  581. const xmjSheet = leafXmjSpread.getActiveSheet();
  582. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  583. const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  584. loadMaterialData(index, xmjIndex);
  585. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  586. }, function () {
  587. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  588. });
  589. // postData(window.location.pathname + '/save', { type:'update', updateData: { id:select.id, quantity: validText, mb_id: select.mb_id } }, function (result) {
  590. // const materialListIndex = materialListData.indexOf(select);
  591. // const index = materialList.indexOf(select);
  592. // select[col.field] = validText;
  593. // materialListData.splice(materialListIndex, 1, select);
  594. // materialList.indexOf(index, 1, select);
  595. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  596. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  597. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  598. // calculateJiaCha(gclGatherData, iGclRow)
  599. // SpreadJsObj.reLoadRowData(sheet, iRow);
  600. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  601. // }, function () {
  602. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  603. // });
  604. }
  605. },
  606. clipboardPasted(e, info) {
  607. const hint = {
  608. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  609. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  610. numberCan: {type: 'error', msg: '请粘贴大于0并且小于6位小数的浮点数'},
  611. };
  612. const range = info.cellRange;
  613. const sortData = info.sheet.zh_data || [];
  614. if (range.row + range.rowCount > sortData.length) {
  615. toastMessageUniq(hint.cellError);
  616. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  617. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  618. return;
  619. }
  620. if (sortData.length > 0 && range.col + range.colCount > 5) {
  621. toastMessageUniq(hint.cellError);
  622. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  623. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  624. return;
  625. }
  626. const data = [];
  627. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  628. let bPaste = true;
  629. const curRow = range.row + iRow;
  630. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  631. const hintRow = range.rowCount > 1 ? curRow : '';
  632. let sameCol = 0;
  633. for (let iCol = 0; iCol < range.colCount; iCol++) {
  634. const curCol = range.col + iCol;
  635. const colSetting = info.sheet.zh_setting.cols[curCol];
  636. if (!colSetting) continue;
  637. // let validText = info.sheet.getText(curRow, curCol);
  638. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  639. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  640. const orgValue = sortData[curRow][colSetting.field];
  641. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  642. sameCol++;
  643. if (range.colCount === sameCol) {
  644. bPaste = false;
  645. }
  646. continue;
  647. }
  648. const exprQuantity = {
  649. expr: '',
  650. quantity: 0,
  651. };
  652. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  653. if (!valid) {
  654. toastMessageUniq(getPasteHint(msg, hintRow));
  655. bPaste = false;
  656. continue;
  657. }
  658. if (isNaN(exprQuantity.quantity)) {
  659. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  660. bPaste = false;
  661. continue;
  662. }
  663. const num = parseFloat(exprQuantity.quantity);
  664. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  665. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  666. bPaste = false;
  667. continue;
  668. }
  669. // materialData[colSetting.field] = validText;
  670. materialData.expr = exprQuantity.expr;
  671. materialData.quantity = exprQuantity.quantity;
  672. }
  673. if (bPaste) {
  674. data.push(materialData);
  675. // rowData.push(curRow);
  676. } else {
  677. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  678. }
  679. }
  680. if (data.length === 0) {
  681. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  682. return;
  683. }
  684. const ledgerSheet = ledgerSpread.getActiveSheet();
  685. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  686. const index = gclGatherData.indexOf(ledgerSelect);
  687. const gcl = gclGatherData[index].leafXmjs;
  688. const datas = [];
  689. for (const xmj of gcl) {
  690. const data2 = {
  691. xmj_id: xmj.id,
  692. gcl_id: xmj.gcl_id,
  693. mx_id: xmj.mx_id !== undefined ? xmj.mx_id : '',
  694. };
  695. datas.push(data2);
  696. }
  697. console.log(data, datas);
  698. // 更新至服务器
  699. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data } }, function (result) {
  700. materialListData = result;
  701. calculateJiaCha(gclGatherData);
  702. // const index = gclGatherData.indexOf(ledgerSelect);
  703. loadLeafXmjData(index);
  704. const xmjSheet = leafXmjSpread.getActiveSheet();
  705. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  706. const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  707. loadMaterialData(index, xmjIndex);
  708. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  709. }, function () {
  710. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  711. });
  712. // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  713. // materialListData = result;
  714. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  715. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  716. // calculateJiaCha(gclGatherData, iGclRow);
  717. // SpreadJsObj.reLoadRowData(sheet, iRow);
  718. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  719. // }, function () {
  720. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  721. // });
  722. },
  723. _checkExprValid(expr) {
  724. if (!expr) return [true, null];
  725. const param = [];
  726. let num = '', base = '';
  727. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  728. if (/^[\d\.%]+/.test(expr[i])) {
  729. if (base !== '') {
  730. param.push({type: 'base', value: base});
  731. base = '';
  732. }
  733. num = num + expr[i];
  734. } else if (expr[i] === '(') {
  735. if (num !== '') {
  736. param.push({type: 'num', value: num});
  737. num = '';
  738. }
  739. if (base !== '') {
  740. param.push({type: 'base', value: base});
  741. base = '';
  742. }
  743. param.push({type: 'left', value: '('});
  744. } else if (expr[i] === ')') {
  745. if (num !== '') {
  746. param.push({type: 'num', value: num});
  747. num = '';
  748. }
  749. if (base !== '') {
  750. param.push({type: 'base', value: base});
  751. base = '';
  752. }
  753. param.push({type: 'right', value: ')'});
  754. } else if (/^[\+\-*\/]/.test(expr[i])) {
  755. if (num !== '') {
  756. param.push({type: 'num', value: num});
  757. num = '';
  758. }
  759. if (base !== '') {
  760. param.push({type: 'base', value: base});
  761. base = '';
  762. }
  763. param.push({type: 'calc', value: expr[i]});
  764. } else {
  765. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  766. }
  767. }
  768. if (num !== '') {
  769. param.push({type: 'num', value: num});
  770. num = '';
  771. }
  772. if (base !== '') {
  773. param.push({type: 'base', value: base});
  774. base = '';
  775. }
  776. if (param.length === 0) return true;
  777. if (param.length > 1) {
  778. if (param[0].value === '-') {
  779. param[1].value = '-' + param[1];
  780. }
  781. param.unshift();
  782. }
  783. const iLen = param.length;
  784. let iLeftCount = 0, iRightCount = 0;
  785. for (const [i, p] of param.entries()) {
  786. if (p.type === 'calc') {
  787. if (i === 0 || i === iLen - 1)
  788. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  789. }
  790. if (p.type === 'num') {
  791. num = p.value.replace('%', '');
  792. if (p.value.length - num.length > 1)
  793. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  794. num = _.toNumber(num);
  795. if (num === undefined || num === null || _.isNaN(num))
  796. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  797. if (i > 0) {
  798. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  799. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  800. } else if (param[i - 1].value === '/' && num === 0) {
  801. return [false, '输入的表达式非法:请勿除0'];
  802. }
  803. }
  804. }
  805. if (p.type === 'base') {
  806. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  807. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  808. }
  809. if (p.type === 'left') {
  810. iLeftCount += 1;
  811. if (i !== 0 && param[i-1].type !== 'calc')
  812. return [false, '输入的表达式非法:(前应有运算符'];
  813. }
  814. if (p.type === 'right') {
  815. iRightCount += 1;
  816. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  817. return [false, '输入的表达式非法:)后应有运算符'];
  818. if (iRightCount > iLeftCount)
  819. return [false, '输入的表达式非法:")"前无对应的"("'];
  820. }
  821. }
  822. if (iLeftCount > iRightCount)
  823. return [false, '输入的表达式非法:"("后无对应的")"'];
  824. return [true, ''];
  825. },
  826. _checkExpr: function (text, data) {
  827. if (text) {
  828. const num = _.toNumber(text);
  829. if (num) {
  830. data.quantity = num;
  831. data.expr = '';
  832. } else {
  833. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  834. const [valid, msg] = this._checkExprValid(expr);
  835. if (!valid) return [valid, msg];
  836. data.expr = expr;
  837. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr);
  838. // const ce = new CalcEvalMin();
  839. // data.quantity = ce.eval(expr);
  840. // console.log(data.quantity);
  841. }
  842. } else {
  843. data.quantity = 0;
  844. data.expr = '';
  845. }
  846. return [true, ''];
  847. },
  848. };
  849. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  850. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  851. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  852. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  853. // 应用调差工料至其他清单明细
  854. $('#user_all_material').click(function () {
  855. const ledgerSheet = ledgerSpread.getActiveSheet();
  856. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  857. if (ledgerSelect.leafXmjs.length < 2) {
  858. toastr.warning('没有需要应用调差工料的其它清单明细');
  859. return false;
  860. }
  861. const xmjSheet = leafXmjSpread.getActiveSheet();
  862. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  863. // 判断需要应用调差工料的清单明细
  864. const needAddList = [];
  865. for (const xmj of ledgerSelect.leafXmjs) {
  866. const notx = findNotJoinLeafXmj(xmj);
  867. if (notx === undefined && xmjSelect !== xmj) {
  868. needAddList.push(xmj);
  869. }
  870. }
  871. if (needAddList.length === 0) {
  872. toastr.warning('没有需要应用调差工料的其它清单明细');
  873. return false;
  874. }
  875. console.log(needAddList, materialList);
  876. // 更新至服务器
  877. // postData(window.location.pathname + '/save', { type:'useOther', postData: { addXmj: needAddList, materialBills: materialList } }, function (result) {
  878. // materialListData = result;
  879. // toastr.success('已成功应用');
  880. // calculateJiaCha(gclGatherData);
  881. // const index = gclGatherData.indexOf(ledgerSelect);
  882. // loadLeafXmjData(index);
  883. // const xmjSheet = leafXmjSpread.getActiveSheet();
  884. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  885. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  886. // loadMaterialData(index, xmjIndex);
  887. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  888. // });
  889. });
  890. $.contextMenu({
  891. selector: '#material-spread',
  892. build: function ($trigger, e) {
  893. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  894. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  895. },
  896. items: {
  897. 'create': {
  898. name: '添加工料',
  899. icon: 'fa-sign-in',
  900. callback: function (key, opt) {
  901. // 获取已选清单
  902. changeMaterialTable();
  903. $('#addgl').modal('show');
  904. },
  905. disabled: function (key, opt) {
  906. const sheet = leafXmjSpread.getActiveSheet();
  907. const select = SpreadJsObj.getSelectObject(sheet);
  908. // const notx = findNotJoinLeafXmj(select);
  909. if (!select) {
  910. return true;
  911. }
  912. // if (!readOnly && notx === undefined) {
  913. // return false;
  914. // } else {
  915. // return true;
  916. // }
  917. return readOnly;
  918. }
  919. },
  920. 'delete': {
  921. name: '删除工料',
  922. icon: 'fa-remove',
  923. callback: function (key, opt) {
  924. materialSpreadObj.del(materialSpread.getActiveSheet());
  925. },
  926. disabled: function (key, opt) {
  927. const sheet = materialSpread.getActiveSheet();
  928. const select = SpreadJsObj.getSelectObject(sheet);
  929. if (!select) {
  930. return true;
  931. }
  932. if (!readOnly && select && materialBase.isEdit(select)) {
  933. return false;
  934. } else {
  935. return true;
  936. }
  937. }
  938. },
  939. }
  940. });
  941. }
  942. // 切换清单行,读取所属项目节数据
  943. ledgerSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  944. if (info.oldSelections !== undefined) {
  945. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  946. if (iNewRow !== iOldRow) {
  947. loadLeafXmjData(iNewRow);
  948. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  949. loadMaterialData(iNewRow, 0);
  950. checkNotJoinMaterialData();
  951. }
  952. }
  953. });
  954. // 切换项目节数据清单明细行,读取已调用的清单工料数据
  955. leafXmjSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  956. if (info.oldSelections !== undefined) {
  957. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  958. if (iNewRow !== iOldRow) {
  959. const sheet = ledgerSpread.getActiveSheet();
  960. const select = SpreadJsObj.getSelectObject(sheet);
  961. const index = gclGatherData.indexOf(select);
  962. loadMaterialData(index, iNewRow);
  963. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  964. }
  965. }
  966. });
  967. // 显示有调差工料清单
  968. $('#show_material_gcl').click(function () {
  969. if ($(this).is(':checked')) {
  970. const hadMaterialGclGatherData = [];
  971. const hadGclIdList = [];
  972. for (const ml of materialListData) {
  973. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  974. hadGclIdList.push(ml.gcl_id);
  975. }
  976. }
  977. for (const gcl of gclGatherData) {
  978. for (const index in gcl.leafXmjs) {
  979. const gcl_id = gcl.leafXmjs[index].gcl_id;
  980. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  981. hadMaterialGclGatherData.push(gcl);
  982. break;
  983. }
  984. }
  985. }
  986. gclGatherData = hadMaterialGclGatherData;
  987. } else {
  988. gclGatherModel.loadLedgerData(ledger, curLedgerData);
  989. gclGatherModel.loadPosData(pos, curPosData);
  990. gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  991. return item.qc_qty || item.contract_qty
  992. });
  993. }
  994. calculateJiaCha(gclGatherData);
  995. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  996. loadLeafXmjData(0);
  997. loadMaterialData(0, 0);
  998. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  999. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1000. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  1001. checkNotJoinMaterialData();
  1002. });
  1003. $.subMenu({
  1004. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1005. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1006. key: 'menu.1.0.0',
  1007. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1008. callback: function (info) {
  1009. if (info.mini) {
  1010. $('.panel-title').addClass('fluid');
  1011. $('#sub-menu').removeClass('panel-sidebar');
  1012. } else {
  1013. $('.panel-title').removeClass('fluid');
  1014. $('#sub-menu').addClass('panel-sidebar');
  1015. }
  1016. autoFlashHeight();
  1017. ledgerSpread.refresh();
  1018. leafXmjSpread.refresh();
  1019. materialSpread.refresh();
  1020. }
  1021. });
  1022. $.divResizer({
  1023. select: '#right-spr',
  1024. callback: function () {
  1025. ledgerSpread.refresh();
  1026. // leafXmjSpread.refresh();
  1027. materialSpread.refresh();
  1028. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1029. setLocalCache('material_list_' + materialID, width);
  1030. }
  1031. });
  1032. // 展开收起月信息价并浏览器记住本期展开收起
  1033. $('a', '.right-nav').bind('click', function () {
  1034. //const main = $('#main-view'), tool = $('#tools-view');
  1035. const tab = $(this), tabPanel = $(tab.attr('content'));
  1036. if (!tab.hasClass('active')) {
  1037. $('a', '.side-menu').removeClass('active');
  1038. $('.tab-content .tab-select-show').removeClass('active');
  1039. tab.addClass('active');
  1040. tabPanel.addClass('active');
  1041. showSideTools(tab.hasClass('active'));
  1042. if (tab.attr('content') === '#material-tab') {
  1043. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1044. setLocalCache('material_list_' + materialID, width);
  1045. }
  1046. } else {
  1047. removeLocalCache('material_list_' + materialID);
  1048. tab.removeClass('active');
  1049. tabPanel.removeClass('active');
  1050. showSideTools(tab.hasClass('active'));
  1051. }
  1052. ledgerSpread.refresh();
  1053. // leafXmjSpread.refresh();
  1054. materialSpread.refresh();
  1055. });
  1056. // 根据浏览器记录展开收起
  1057. if (getLocalCache('material_list_' + materialID)) {
  1058. const tab = $('.right-nav a[content="#material-tab"]'), tabPanel = $(tab.attr('content'));
  1059. $('a', '.side-menu').removeClass('active');
  1060. $('.tab-content .tab-select-show').removeClass('active');
  1061. tab.addClass('active');
  1062. tabPanel.addClass('active');
  1063. $('#right-view').width(getLocalCache('material_list_' + materialID) + '%');
  1064. showSideTools(tab.hasClass('active'));
  1065. ledgerSpread.refresh();
  1066. // leafXmjSpread.refresh();
  1067. materialSpread.refresh();
  1068. }
  1069. });