index.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. let unitPriceObj = {
  2. unitPriceMap: {},
  3. selectedData: null,
  4. setUntiPriceMap: function () {
  5. for (let u of unitPriceList) {
  6. this.unitPriceMap[gljUtil.getIndex(u)] = u;
  7. }
  8. },
  9. mainSpread: null,
  10. mainSetting: {
  11. header: [{
  12. headerName: "编号",
  13. headerWidth: 80,
  14. dataCode: "code",
  15. dataType: "String"
  16. },
  17. {
  18. headerName: "名称",
  19. headerWidth: 160,
  20. dataCode: "name",
  21. dataType: "String"
  22. },
  23. {
  24. headerName: "单位",
  25. headerWidth: 45,
  26. dataCode: "unit",
  27. hAlign: "center",
  28. dataType: "String"
  29. },
  30. {
  31. headerName: "规格",
  32. headerWidth: 120,
  33. dataCode: "specs",
  34. hAlign: "left",
  35. dataType: "String"
  36. },
  37. {
  38. headerName: "类型",
  39. headerWidth: 45,
  40. dataCode: "short_name",
  41. hAlign: "center",
  42. dataType: "String"
  43. },
  44. {
  45. headerName: "定额价",
  46. headerWidth: 70,
  47. dataCode: "basePrice",
  48. hAlign: "right",
  49. dataType: "Number",
  50. validator: "number"
  51. }, //decimalField:'glj.unitPrice',
  52. {
  53. headerName: "预算价",
  54. headerWidth: 70,
  55. dataCode: "marketPrice",
  56. hAlign: "right",
  57. dataType: "Number",
  58. validator: "number"
  59. }, //,decimalField:"glj.unitPrice"
  60. {
  61. headerName: "新工料机",
  62. headerWidth: 70,
  63. dataCode: "is_add",
  64. hAlign: "center",
  65. dataType: "String",
  66. cellType: 'checkBox'
  67. }
  68. ],
  69. view: {
  70. lockColumns: ["code", "name", "specs", "unit", "short_name", "basePrice", 'is_add'],
  71. colHeaderHeight: 36
  72. },
  73. getStyle: function (data, row, activeRow) {
  74. if (row == activeRow) { //选中黄色显示
  75. return {
  76. backColor: "#FFFACD"
  77. };
  78. }
  79. return null;
  80. }
  81. },
  82. subSpread: null,
  83. subSetting: {
  84. header: [{
  85. headerName: "编号",
  86. headerWidth: 80,
  87. dataCode: "code",
  88. dataType: "String"
  89. },
  90. {
  91. headerName: "名称",
  92. headerWidth: 240,
  93. dataCode: "name",
  94. dataType: "String"
  95. },
  96. {
  97. headerName: "规格",
  98. headerWidth: 190,
  99. dataCode: "specs",
  100. dataType: "String"
  101. },
  102. {
  103. headerName: "单位",
  104. headerWidth: 45,
  105. dataCode: "unit",
  106. hAlign: "center",
  107. dataType: "String"
  108. },
  109. {
  110. headerName: "类型",
  111. headerWidth: 45,
  112. dataCode: "short_name",
  113. hAlign: "center",
  114. dataType: "String"
  115. },
  116. {
  117. headerName: "定额价",
  118. headerWidth: 80,
  119. dataCode: "basePrice",
  120. hAlign: "right",
  121. dataType: "Number",
  122. validator: "number"
  123. }, //,decimalField:'glj.unitPrice'
  124. {
  125. headerName: "预算价",
  126. headerWidth: 80,
  127. dataCode: "marketPrice",
  128. hAlign: "right",
  129. dataType: "Number",
  130. validator: "number"
  131. }, //,decimalField:"glj.unitPrice"
  132. {
  133. headerName: "消耗量",
  134. headerWidth: 80,
  135. dataCode: "consumption",
  136. hAlign: "right",
  137. dataType: "Number",
  138. validator: "number",
  139. tofix: 3
  140. }
  141. ],
  142. view: {
  143. lockColumns: [0, 1, 2, 3, 4, 5, 6],
  144. rowHeaderWidth: 25
  145. }
  146. },
  147. initMainSpread: function () {
  148. if (this.mainSpread) return this.mainSpread.refresh();
  149. this.mainSpread = SheetDataHelper.createNewSpread($("#mainSpread")[0]);
  150. sheetCommonObj.spreadDefaultStyle(this.mainSpread);
  151. this.mainSheet = this.mainSpread.getSheet(0);
  152. sheetCommonObj.initSheet(this.mainSheet, this.mainSetting, 30);
  153. this.mainSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, this.onMainSelectionChange);
  154. this.mainSpread.bind(GC.Spread.Sheets.Events.RangeChanged, this.onMainRangeChange);
  155. this.mainSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onMainValueChange);
  156. this.mainSheet.bind(GC.Spread.Sheets.Events.EditStarting, this.onMainEditStarting);
  157. },
  158. showMainDatas: function () {
  159. unitPriceList = gljUtil.sortProjectGLJ(unitPriceList);
  160. this.setData(unitPriceList);
  161. let sel = this.mainSheet.getSelections()[0];
  162. let oldData = this.selectedData;
  163. sheetCommonObj.showData(this.mainSheet, this.mainSetting, unitPriceList);
  164. this.mainSheet.setRowCount(unitPriceList.length);
  165. sel.row = oldData ? _.findIndex(unitPriceList, {
  166. 'id': oldData.id
  167. }) : sel.row;
  168. this.mainSheet.setSelection(sel.row == -1 ? 0 : sel.row, sel.col, sel.rowCount, sel.colCount);
  169. },
  170. getShortNameByType: function (type) {
  171. return gljTypeMap["typeId" + type] ? gljTypeMap["typeId" + type].shortName : '';
  172. },
  173. setData: function (list) {
  174. for (let l of list) {
  175. l.bgColour = "white";
  176. l.basePrice = this.getPrice('base_price', l);
  177. l.marketPrice = this.getPrice('market_price', l);
  178. l.short_name = this.getShortNameByType(l.type);
  179. if (l.base_price == l.market_price) { //如果定额价等于市场价时,改底色。 优先度低于有组成物时的底色
  180. l.bgColour = "#C4CAFB";
  181. }
  182. let lindex = gljUtil.getIndex(l);
  183. if (gljUtil.notEditType.indexOf(l.type) >= 0 && mixRatioMap[lindex] && mixRatioMap[lindex].length > 0) { //有组成物时
  184. l.bgColour = "#E0E0E0";
  185. }
  186. if (gljUtil.isConcreteType(l.type)) l.bgColour = "#E0E0E0"; //混凝土、砂浆、配合比的底色显示为 灰色#E0E0E0,灰色底色提醒用户不可修改。
  187. }
  188. },
  189. getSelectedUnitPrice: function () {
  190. let me = this,
  191. data = null;
  192. let sheet = me.mainSpread.getActiveSheet();
  193. let sel = sheet.getSelections()[0];
  194. let srow = sel.row == -1 || sel.row == "" ? 0 : sel.row;
  195. if (unitPriceList.length > srow) {
  196. data = unitPriceList[srow];
  197. }
  198. return data;
  199. },
  200. onMainSelectionChange: function (sender, args) {
  201. let me = unitPriceObj;
  202. let newSel = args.newSelections[0];
  203. let oldSel = args.oldSelections ? args.oldSelections[0] : {};
  204. args.sheet.suspendPaint();
  205. args.sheet.suspendEvent();
  206. if (newSel.row != oldSel.row) {
  207. let style = me.getSelStyle(true, {});
  208. args.sheet.setStyle(newSel.row, -1, style);
  209. let orow = oldSel.row == '' || oldSel.row == -1 ? 0 : oldSel.row;
  210. if (unitPriceList[orow]) {
  211. let tstyle = me.getSelStyle(false, {}, unitPriceList[orow].bgColour);
  212. args.sheet.setStyle(orow, -1, tstyle);
  213. me.showSubDatas();
  214. me.selectedData = unitPriceList[newSel.row];
  215. }
  216. } else {
  217. args.sheet.repaint();
  218. }
  219. args.sheet.resumeEvent();
  220. args.sheet.resumePaint();
  221. },
  222. onMainEditStarting: function (sender, args) {
  223. let me = unitPriceObj;
  224. let row = args.row;
  225. let col = args.col;
  226. if (me.mainEditChecking(row, col) == false) {
  227. args.cancel = true;
  228. }
  229. },
  230. mainEditChecking: function (row, col, isPaste = false) {
  231. let me = unitPriceObj;
  232. if (row >= unitPriceList.length) return false;
  233. let data = unitPriceList[row];
  234. let setting = me.mainSetting;
  235. let dataCode = setting.header[col].dataCode;
  236. if (isPaste == false && dataCode == 'is_add') { //除了粘贴,拖动填充等操作,其它的都不能编辑
  237. return false;
  238. }
  239. if (dataCode == 'marketPrice') {
  240. if (gljUtil.isConcreteType(data.type)) return false; //混凝土,浆砂,配合比,不能修改市场单价,定额价
  241. let uindex = gljUtil.getIndex(data);
  242. if (mixRatioMap[uindex] && mixRatioMap[uindex].length > 0) return false; //有组成物的不能编辑
  243. if (data.calcMaterial == 1) return false //有材料计算时不能修改
  244. }
  245. return true;
  246. },
  247. onMainValueChange: function (e, info) {
  248. let me = unitPriceObj;
  249. let value = info.newValue;
  250. if (info.newValue === undefined) {
  251. return;
  252. }
  253. if (value && !sheetCommonObj.checkData(info.col, me.mainSetting, value)) {
  254. alert('输入的数据类型不对,请重新输入!');
  255. return me.showMainDatas();
  256. }
  257. me.batchUpdateUnitPrice([{
  258. row: info.row,
  259. col: info.col,
  260. value: value
  261. }]);
  262. },
  263. onMainRangeChange: function (sender, info) {
  264. let me = unitPriceObj;
  265. let canChange = true;
  266. let changeInfo = [];
  267. for (let c of info.changedCells) {
  268. let value = info.sheet.getCell(c.row, c.col).text();
  269. changeInfo.push({
  270. row: c.row,
  271. col: c.col,
  272. value: value
  273. });
  274. if (me.mainEditChecking(c.row, c.col, true) == false) { //如果不能编辑
  275. canChange = false;
  276. break;
  277. }
  278. if (!sheetCommonObj.checkData(c.col, me.mainSetting, value)) {
  279. alert('输入的数据类型不对,请重新输入!');
  280. canChange = false;
  281. break;
  282. }
  283. }
  284. if (canChange == false) return me.showMainDatas();
  285. me.batchUpdateUnitPrice(changeInfo);
  286. },
  287. batchUpdateUnitPrice: async function (changeInfo) {
  288. let me = unitPriceObj;
  289. let updateData = [];
  290. let newValueMap = {};
  291. let refreshList = [];
  292. try {
  293. for (let ci of changeInfo) {
  294. let dataCode = me.mainSetting.header[ci.col].dataCode;
  295. let recode = unitPriceList[ci.row];
  296. let ndata = newValueMap[recode.id] ? newValueMap[recode.id] : {
  297. unit_price: recode
  298. };
  299. if (dataCode == 'basePrice' || dataCode == 'marketPrice') {
  300. let editField = dataCode === 'basePrice' ? "base_price" : "market_price";
  301. let newValue = ci.value;
  302. if (recode && recode[editField] != newValue) {
  303. newValue = scMathUtil.roundForObj(ci.value, 3);
  304. ndata['field'] = editField;
  305. ndata['newval'] = newValue;
  306. newValueMap[recode.id] = ndata;
  307. }
  308. } else {
  309. let ext = {};
  310. if (dataCode === 'is_add') {
  311. value = ci.value == true ? 1 : 0;
  312. }
  313. ext[dataCode] = value;
  314. ndata['ext'] = ext;
  315. newValueMap[recode.id] = ndata;
  316. }
  317. }
  318. for (let key in newValueMap) {
  319. updateData.push(newValueMap[key]);
  320. refreshList.push(newValueMap[key].unit_price)
  321. }
  322. if (updateData.length > 0) {
  323. $.bootstrapLoading.start();
  324. let result = await ajaxPost("/glj/batchUpdatePrices", updateData);
  325. for (let r of refreshList) {
  326. let rdata = newValueMap[r.id];
  327. if (rdata.field) r[rdata.field] = rdata.newval;
  328. if (rdata.ext) {
  329. for (let ekey in rdata.ext) {
  330. r[ekey] = rdata.ext[ekey];
  331. }
  332. }
  333. }
  334. for (let r of result) {
  335. let pdata = r.updateOne.filter;
  336. let set = r.updateOne.update.$set;
  337. for (let skey in set) {
  338. let pindex = gljUtil.getIndex(pdata);
  339. me.unitPriceMap[pindex][skey] = set[skey];
  340. }
  341. }
  342. }
  343. } catch (error) {
  344. console.log(error);
  345. alert(error);
  346. }
  347. $.bootstrapLoading.end();
  348. me.onUnitPriceChange();
  349. },
  350. initSubSpread: function () {
  351. if (this.subSpread) return this.subSpread.refresh();
  352. this.subSpread = SheetDataHelper.createNewSpread($("#subSpread")[0]);
  353. sheetCommonObj.spreadDefaultStyle(this.subSpread);
  354. this.subSheet = this.subSpread.getSheet(0);
  355. sheetCommonObj.initSheet(this.subSheet, this.subSetting, 30);
  356. this.subSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onSubRangeChange);
  357. this.subSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onSubValueChange);
  358. this.initSubRightClick();
  359. },
  360. showSubDatas: function () {
  361. let parentData = this.getSelectedUnitPrice();
  362. this.mixRatioList = parentData?mixRatioMap[gljUtil.getIndex(parentData)]:[];
  363. this.mixRatioList = this.mixRatioList ? this.mixRatioList : [];
  364. this.setMixRatioData(this.mixRatioList);
  365. let sel = this.subSheet.getSelections()[0];
  366. this.subSheet.setRowCount(0);
  367. sheetCommonObj.showData(this.subSheet, this.subSetting, this.mixRatioList);
  368. this.subSheet.setRowCount(this.mixRatioList.length);
  369. this.subSheet.setSelection(sel.row == -1 ? 0 : sel.row, sel.col, sel.rowCount, sel.colCount);
  370. },
  371. onSubValueChange: function (sender, info) {
  372. let me = unitPriceObj;
  373. let value = info.newValue;
  374. if (info.newValue === undefined) {
  375. return;
  376. }
  377. if (value && !sheetCommonObj.checkData(info.col, me.mainSetting, value)) {
  378. alert('输入的数据类型不对,请重新输入!');
  379. return me.showMainDatas();
  380. }
  381. me.batchUpdateConsumption([{
  382. row: info.row,
  383. col: info.col,
  384. value: value
  385. }]);
  386. },
  387. onSubRangeChange: function (sender, info) {
  388. let me = unitPriceObj;
  389. let changeInfo = [];
  390. let canChange = true;
  391. for (let c of info.changedCells) {
  392. let value = info.sheet.getCell(c.row, c.col).text();
  393. if (_.isEmpty(value)) value = 0;
  394. if (!sheetCommonObj.checkData(c.col, me.subSetting, value)) {
  395. alert('输入的数据类型不对,请重新输入!');
  396. canChange = false;
  397. break;
  398. } else {
  399. changeInfo.push({
  400. row: c.row,
  401. col: c.col,
  402. value: value
  403. });
  404. }
  405. }
  406. if (canChange == false) me.showSubDatas();
  407. me.batchUpdateConsumption(changeInfo);
  408. },
  409. calcParentPrice: function (list, updateMap, deleteID) {
  410. let parentMarketPrice = 0;
  411. for (let sub of list) {
  412. if (deleteID && sub.id == deleteID) continue
  413. let marketPrice = scMathUtil.roundForObj(sub.marketPrice, 6);
  414. let basePrice = scMathUtil.roundForObj(sub.basePrice, 6);
  415. let consumption = updateMap[sub.id] ? updateMap[sub.id].consumption : scMathUtil.roundForObj(sub.consumption, 3);
  416. parentMarketPrice = scMathUtil.roundForObj(marketPrice * consumption + parentMarketPrice, 6);
  417. // parentBasePrice = scMathUtil.roundForObj(basePrice*consumption + parentBasePrice,getDecimal("process"));
  418. }
  419. parentMarketPrice = scMathUtil.roundForObj(parentMarketPrice, 2);
  420. return parentMarketPrice;
  421. },
  422. deleteMixRatio: async function (row) {
  423. let me = this,
  424. deleteRecode = me.mixRatioList[row];
  425. let parentMarketPrice = me.calcParentPrice(me.mixRatioList, {}, deleteRecode.id);
  426. let parentData = me.getSelectedUnitPrice();
  427. let updateData = {
  428. id: deleteRecode.id,
  429. connect_key: gljUtil.getIndex(parentData)
  430. };
  431. let ext = {};
  432. ext[parentData.id] = {
  433. marketPrice: parentMarketPrice
  434. };
  435. updateData.parent = {
  436. connect_key: gljUtil.getIndex(parentData),
  437. query: {
  438. id: parentData.id
  439. },
  440. doc: {
  441. market_price: parentMarketPrice
  442. }
  443. };
  444. if (com_electrovalence) { //计算综合电价
  445. let elecP = me.clacNewElecPrice(ext);
  446. if (elecP) updateData.unitPrice = {
  447. connect_key: elecP.connect_key,
  448. query: {
  449. id: elecP.id
  450. },
  451. doc: elecP.doc
  452. };
  453. }
  454. try {
  455. $.bootstrapLoading.start();
  456. await ajaxPost("/glj/delete-ratio", {
  457. id: updateData.id,
  458. parent: updateData.parent,
  459. unitPrice: updateData.unitPrice
  460. });
  461. let mlist = mixRatioMap[updateData.connect_key];
  462. _.remove(mlist, {
  463. id: updateData.id
  464. });
  465. if (updateData.parent) {
  466. let pglj = me.unitPriceMap[updateData.parent.connect_key];
  467. if (pglj) gljUtil.setProperty(pglj, updateData.parent.doc);
  468. }
  469. if (updateData.unitPrice) {
  470. let eglj = me.unitPriceMap[updateData.unitPrice.connect_key];
  471. if (eglj) gljUtil.setProperty(eglj, updateData.unitPrice.doc);
  472. }
  473. } catch (error) {
  474. alert(error);
  475. console.log(error);
  476. }
  477. $.bootstrapLoading.end();
  478. me.onUnitPriceChange();
  479. },
  480. batchUpdateConsumption: async function (changeInfo) {
  481. let me = unitPriceObj;
  482. let updateMap = {},
  483. updateData = [],
  484. parentBasePrice = 0,
  485. parentMarketPrice = 0;
  486. let parentKey = '',
  487. unit_price_file_id = null;
  488. for (let c of changeInfo) {
  489. let record = me.mixRatioList[c.row];
  490. let value = scMathUtil.roundForObj(c.value, 3);
  491. updateMap[record.id] = {
  492. consumption: value,
  493. record: record
  494. };
  495. updateData.push({
  496. type: 'mix_ratio',
  497. connect_key: record.connect_key,
  498. query: {
  499. id: record.id
  500. },
  501. doc: {
  502. consumption: scMathUtil.roundToString(value, 3)
  503. }
  504. });
  505. parentKey = record.connect_key;
  506. unit_price_file_id = record.unit_price_file_id;
  507. }
  508. if (!gljUtil.isConcreteType(parseInt(parentKey.split("|-|")[4]))) { //父类型不属于混凝土浆砂配合比,才要计算
  509. parentMarketPrice = me.calcParentPrice(me.mixRatioList, updateMap);
  510. }
  511. let parentData = me.getSelectedUnitPrice();
  512. if (parentData) {
  513. let ext = {};
  514. ext[parentData.id] = {
  515. marketPrice: parentMarketPrice
  516. };
  517. if (com_electrovalence) { //计算综合电价
  518. let elecP = me.clacNewElecPrice(ext);
  519. if (elecP) {
  520. updateData.push({
  521. type: 'unitPrice',
  522. connect_key: elecP.connect_key,
  523. query: {
  524. id: elecP.id
  525. },
  526. doc: elecP.doc
  527. });
  528. }
  529. }
  530. updateData.push({
  531. type: 'unitPrice',
  532. connect_key: gljUtil.getIndex(parentData),
  533. query: {
  534. id: parentData.id
  535. },
  536. doc: {
  537. market_price: parentMarketPrice
  538. }
  539. });
  540. }
  541. if (updateData.length > 0) {
  542. try {
  543. $.bootstrapLoading.start();
  544. let result = await ajaxPost("/glj/batchUpdateConsumption", updateData);
  545. for (let up of updateData) {
  546. if (up.type == 'unitPrice') {
  547. let nu = me.unitPriceMap[up.connect_key];
  548. if (nu) gljUtil.setProperty(nu, up.doc);
  549. } else {
  550. let nlist = mixRatioMap[up.connect_key];
  551. for (let nc of nlist) {
  552. if (nc.id == up.query.id) {
  553. gljUtil.setProperty(nc, up.doc);
  554. }
  555. }
  556. }
  557. }
  558. } catch (error) {
  559. alert(error);
  560. console.log(error);
  561. }
  562. }
  563. $.bootstrapLoading.end();
  564. me.onUnitPriceChange();
  565. },
  566. clacNewElecPrice: function (ext) {
  567. for (let u of unitPriceList) {
  568. if (u.code == gljUtil.getElecCode() && u.name == "电" && u.unit == "kW·h") { //更新电价
  569. let datas = this.getElectrovalenceDatas(ext);
  570. if (datas.length > 0) {
  571. let marketPrice = this.calcPertElectrovalenceMarketPrice(datas, ext);
  572. if (marketPrice && u.market_price != marketPrice + '') return {
  573. id: u.id,
  574. 'unit_price_file_id': u.unit_price_file_id,
  575. 'connect_key': gljUtil.getIndex(u),
  576. doc: {
  577. 'market_price': marketPrice + ''
  578. }
  579. }
  580. }
  581. }
  582. }
  583. return null;
  584. },
  585. calcPertElectrovalenceMarketPrice: function (datas, ext) {
  586. let total = 0;
  587. for (let d of datas) {
  588. if (ext && ext[d.uid] && gljUtil.isDef(ext[d.uid].marketPrice)) d.marketPrice = ext[d.uid].marketPrice;
  589. if (d.name == "电网电") {
  590. d.electPrice = d.marketPrice;
  591. } else {
  592. let w = parseInt(d.name);
  593. if (!w) continue;
  594. let t = scMathUtil.roundForObj(d.marketPrice / w, 6);
  595. d.electPrice = scMathUtil.roundForObj(t * gljUtil.getElecCoe(), 2);
  596. }
  597. let et = scMathUtil.roundForObj(d.electPrice * d.coe, 6);
  598. total = scMathUtil.roundForObj(et + total, 6);
  599. }
  600. this.total = scMathUtil.roundForObj(total, 2);
  601. return this.total;
  602. },
  603. getElectrovalenceDatas: function (ext) {
  604. let datas = [];
  605. if (com_electrovalence && com_electrovalence.gljList) {
  606. for (let g of com_electrovalence.gljList) {
  607. let u = unitPriceMap[gljUtil.getIndex(g)]
  608. if (u) {
  609. g.uid = u.id;
  610. g.basePrice = this.getPrice("base_price", u);
  611. g.marketPrice = this.getPrice("market_price", u);
  612. datas.push(g);
  613. }
  614. }
  615. }
  616. },
  617. setMixRatioData: function (mixRatioList) {
  618. for (let m of mixRatioList) {
  619. m.short_name = this.getShortNameByType(m.type);
  620. let mu = this.unitPriceMap[gljUtil.getIndex(m)];
  621. if (mu) {
  622. m.basePrice = this.getPrice("base_price", mu);
  623. m.marketPrice = this.getPrice("market_price", mu);
  624. } else {
  625. console.log("组成物的单价信息未找到---" + m.code);
  626. }
  627. }
  628. },
  629. getPrice: function (pricefield, unitprice) {
  630. let quantity = 3;
  631. let unitPriceHasMix = 2;
  632. let unitPrice = 3;
  633. let process_decimal = 6;
  634. let uIndex = gljUtil.getIndex(unitprice);
  635. if (mixRatioMap[uIndex] && mixRatioMap[uIndex].length > 0) {
  636. let total = unitprice[pricefield];
  637. if (pricefield == "market_price") {
  638. total = 0;
  639. for (let m of mixRatioMap[uIndex]) {
  640. let mu = unitPriceObj.unitPriceMap[gljUtil.getIndex(m)];
  641. let price_m = unitPriceObj.getPrice(pricefield, mu);
  642. let temP = scMathUtil.roundForObj(price_m * scMathUtil.roundForObj(m.consumption, quantity), process_decimal);
  643. total = scMathUtil.roundForObj(temP + total, process_decimal);
  644. }
  645. }
  646. return scMathUtil.roundForObj(unitprice[pricefield], unitPriceHasMix);
  647. } else {
  648. return scMathUtil.roundForObj(unitprice[pricefield], unitPrice);
  649. }
  650. },
  651. getSelStyle: function (selected, settingStyle, rcolor) {
  652. let style = new GC.Spread.Sheets.Style();
  653. if (settingStyle) {
  654. for (let key in settingStyle) {
  655. style[key] = settingStyle[key];
  656. }
  657. }
  658. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  659. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  660. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  661. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  662. let selectedColor = "#FFFACD",
  663. recColor = rcolor ? rcolor : 'White';
  664. style.backColor = selected ? selectedColor : recColor;
  665. return style;
  666. },
  667. initSubRightClick: function () {
  668. let me = this;
  669. $.contextMenu({
  670. selector: '#subSpread',
  671. build: function ($trigger, e) {
  672. me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, me.subSpread);
  673. return me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
  674. me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  675. },
  676. items: {
  677. "deleteMixRatio": {
  678. name: "删除",
  679. icon: 'fa-trash-o',
  680. disabled: function () {
  681. return me.rightClickTarget.row === undefined;
  682. },
  683. callback: function (key, opt) {
  684. let row = me.rightClickTarget.row;
  685. me.deleteMixRatio(row);
  686. },
  687. visible: function (key, opt) {
  688. let projectGLJ = me.getSelectedUnitPrice();
  689. return projectGLJ && !gljUtil.isConcreteType(projectGLJ.type);
  690. }
  691. },
  692. "addMixRatio": {
  693. name: '添加',
  694. icon: 'fa-sign-in',
  695. disabled: function () {
  696. let projectGLJ = me.getSelectedUnitPrice();
  697. return !_.includes(compositionTypes, projectGLJ.type);
  698. },
  699. callback: function (key, opt) {
  700. projectGljObject.selectedProjectGLJ = me.getSelectedUnitPrice();
  701. getGLJData('unitPriceAddMix', true, me.getGLJLibData);
  702. },
  703. visible: function (key, opt) {
  704. let projectGLJ = me.getSelectedUnitPrice();
  705. return projectGLJ && !gljUtil.isConcreteType(projectGLJ.type);
  706. }
  707. }
  708. }
  709. });
  710. },
  711. addMixRatio: async function () {
  712. let me = this;
  713. for (let mix of me.mixRatioList) {
  714. let m_key = gljUtil.getIndex(mix);
  715. _.remove(gljOprObj.GLJSelection, n => {
  716. return m_key == n;
  717. });
  718. }
  719. let result = await projectGljObject.addMixRatioFromLib(gljOprObj.GLJSelection)
  720. if (result.mixRatios && result.mixRatios.length > 0) {
  721. let mList = mixRatioMap[result.mixRatios[0].connect_key];
  722. if (mList) {
  723. mixRatioMap[result.mixRatios[0].connect_key] = mixRatioMap[result.mixRatios[0].connect_key].concat(result.mixRatios);
  724. }
  725. }
  726. for (let u of result.newUnitPriceList) {
  727. me.unitPriceMap[gljUtil.getIndex(u)] = u;
  728. unitPriceList.push(u);
  729. }
  730. me.onUnitPriceChange();
  731. },
  732. onUnitPriceChange: async function () {
  733. unitPriceObj.showMainDatas();
  734. unitPriceObj.showSubDatas();
  735. try {
  736. await ajaxPost("/project/markUpdateProject", {
  737. updateInfo: {
  738. unitFileID: unitPriceFileID,
  739. isInclude: true
  740. },
  741. type: "unitFile"
  742. });
  743. socket.emit('unitFileChangeNotify', {
  744. projectID: _.isEmpty(projectID) ? null : parseInt(projectID),
  745. 'unitFileID': unitPriceFileID,
  746. userID: userID
  747. });
  748. } catch (error) {
  749. console.log(error)
  750. alert(error)
  751. }
  752. },
  753. getGLJLibData: function (url, cb) {
  754. //let property = projectObj.project.projectInfo.property;
  755. //let engineerID = property.engineering_id;
  756. CommonAjax.get(url, function (data) {
  757. //编办中有多单价设置
  758. if (data.datas.priceProperties && data.datas.priceProperties.length > 0) {
  759. let tem = _.find(data.datas.priceProperties, {
  760. region: property.region,
  761. taxModel: parseInt(property.taxType)
  762. });
  763. if (tem) {
  764. let dataCode = tem.price.dataCode;
  765. for (let glj of data.datas.stdGLJ) {
  766. if (glj.priceProperty && gljUtil.isDef(glj.priceProperty[dataCode])) glj.basePrice = glj.priceProperty[dataCode];
  767. }
  768. }
  769. };
  770. cb(data);
  771. })
  772. }
  773. }
  774. function initPageHeight() {
  775. let headerHeight = $(".header").height();
  776. $(".main-data-top").height($(window).height() * 0.6 - headerHeight);
  777. $(".main-data-bottom").height($(window).height() - headerHeight - $(".main-data-top").height() - $(".nav-item").height());
  778. }
  779. function initPage() {
  780. $('[data-toggle="tooltip"]').tooltip({
  781. html: true
  782. });
  783. initPageHeight();
  784. unitPriceObj.initMainSpread();
  785. unitPriceObj.initSubSpread();
  786. unitPriceObj.showMainDatas();
  787. unitPriceObj.showSubDatas();
  788. socketObject.connect("unitPrice");
  789. }
  790. unitPriceObj.setUntiPriceMap();
  791. initPage();
  792. $(window).resize(initPage);