material_list.js 53 KB

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