material_list.js 54 KB

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