index.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. gljType = gljUtil.gljType;
  2. let unitPriceObj = {
  3. unitPriceMap:{},
  4. selectedData : null,
  5. setUntiPriceMap:function(){
  6. for(let u of unitPriceList){
  7. this.unitPriceMap[gljUtil.getIndex(u)] = u;
  8. }
  9. },
  10. mainSpread:null,
  11. mainSetting:{
  12. header: [
  13. {headerName: "编号", headerWidth: 80, dataCode: "code", dataType: "String"},
  14. {headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String"},
  15. {headerName: "单位", headerWidth: 45, dataCode: "unit", hAlign: "center", dataType: "String"},
  16. {headerName: "规格", headerWidth: 120, dataCode: "specs", hAlign: "left", dataType: "String"},
  17. {headerName: "类型", headerWidth: 45, dataCode: "short_name", hAlign: "center", dataType: "String"},
  18. {headerName: "定额价", headerWidth: 70, dataCode: "basePrice", hAlign: "right", dataType: "Number",validator:"number"},//decimalField:'glj.unitPrice',
  19. {headerName: "预算价", headerWidth: 70, dataCode: "marketPrice", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:"glj.unitPrice"
  20. {headerName: "是否\n新增", headerWidth: 50, dataCode: "is_add", hAlign: "center", dataType: "String",cellType:'checkBox'}
  21. ],
  22. view: {
  23. lockColumns: ["code","name","specs","unit","short_name","basePrice"],
  24. colHeaderHeight:36
  25. },
  26. getStyle:function (data,row,activeRow) {
  27. if(row == activeRow){//选中黄色显示
  28. return {backColor:"#FFFACD"};
  29. }
  30. return null;
  31. }
  32. },
  33. subSpread:null,
  34. subSetting:{
  35. header:[
  36. {headerName: "编号", headerWidth: 80, dataCode: "code", dataType: "String"},
  37. {headerName: "名称", headerWidth: 240, dataCode: "name", dataType: "String"},
  38. {headerName: "规格", headerWidth: 190, dataCode: "specs", dataType: "String"},
  39. {headerName: "单位", headerWidth: 45, dataCode: "unit", hAlign: "center", dataType: "String"},
  40. {headerName: "类型", headerWidth: 45, dataCode: "short_name", hAlign: "center", dataType: "String"},
  41. {headerName: "定额价", headerWidth: 80, dataCode: "basePrice", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:'glj.unitPrice'
  42. {headerName: "预算价", headerWidth: 80, dataCode: "marketPrice", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:"glj.unitPrice"
  43. {headerName: "消耗量", headerWidth: 80, dataCode: "consumption", hAlign: "right", dataType: "Number",validator:"number",tofix:3}
  44. ],
  45. view: {
  46. lockColumns: [0,1,2,3,4,5,6],
  47. rowHeaderWidth: 25
  48. }
  49. },
  50. initMainSpread:function () {
  51. if(this.mainSpread) return this.mainSpread.refresh();
  52. this.mainSpread = SheetDataHelper.createNewSpread($("#mainSpread")[0]);
  53. sheetCommonObj.spreadDefaultStyle(this.mainSpread);
  54. this.mainSheet = this.mainSpread.getSheet(0);
  55. sheetCommonObj.initSheet(this.mainSheet, this.mainSetting, 30);
  56. this.mainSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onMainSelectionChange);
  57. this.mainSpread.bind(GC.Spread.Sheets.Events.RangeChanged, this.onMainRangeChange);
  58. this.mainSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onMainValueChange);
  59. this.mainSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onMainEditStarting);
  60. },
  61. showMainDatas:function(){
  62. unitPriceList = gljUtil.sortProjectGLJ(unitPriceList);
  63. this.setData(unitPriceList);
  64. let sel = this.mainSheet.getSelections()[0];
  65. let oldData = this.selectedData;
  66. sheetCommonObj.showData(this.mainSheet, this.mainSetting,unitPriceList);
  67. this.mainSheet.setRowCount(unitPriceList.length);
  68. sel.row = oldData?_.findIndex(unitPriceList,{'id':oldData.id}):sel.row ;
  69. this.mainSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
  70. },
  71. getShortNameByType : function (type) {
  72. return gljTypeMap["typeId" + type]?gljTypeMap["typeId" + type].shortName:'';
  73. },
  74. setData:function(list){
  75. for(let l of list){
  76. l.bgColour = "white";
  77. l.basePrice = this.getPrice('base_price',l);
  78. l.marketPrice = this.getPrice('market_price',l);
  79. l.short_name = this.getShortNameByType(l.type);
  80. if(l.base_price == l.market_price){//如果定额价等于市场价时,改底色。 优先度低于有组成物时的底色
  81. l.bgColour = "#C4CAFB";
  82. }
  83. let lindex = gljUtil.getIndex(l);
  84. if (gljUtil.notEditType.indexOf(l.type) >= 0 && mixRatioMap[lindex] && mixRatioMap[lindex].length>0) {//有组成物时
  85. l.bgColour = "#E0E0E0";
  86. }
  87. }
  88. },
  89. getSelectedUnitPrice:function () {
  90. let me = this,data = null;
  91. let sheet = me.mainSpread.getActiveSheet();
  92. let sel = sheet.getSelections()[0];
  93. let srow = sel.row == -1||sel.row == ""?0:sel.row;
  94. if(unitPriceList.length>srow){
  95. data = unitPriceList[srow];
  96. }
  97. return data;
  98. },
  99. onMainSelectionChange:function(sender,args){
  100. let me = unitPriceObj;
  101. let newSel = args.newSelections[0];
  102. let oldSel = args.oldSelections?args.oldSelections[0]:{};
  103. args.sheet.suspendPaint();
  104. args.sheet.suspendEvent();
  105. if(newSel.row != oldSel.row){
  106. let style = me.getSelStyle(true,{});
  107. args.sheet.setStyle(newSel.row, -1, style);
  108. let orow = oldSel.row==''||oldSel.row==-1?0:oldSel.row;
  109. if(unitPriceList[orow]){
  110. let tstyle = me.getSelStyle(false,{},unitPriceList[orow].bgColour);
  111. args.sheet.setStyle(orow, -1, tstyle);
  112. me.showSubDatas();
  113. me.selectedData = unitPriceList[newSel.row];
  114. }
  115. }else{
  116. args.sheet.repaint();
  117. }
  118. args.sheet.resumeEvent();
  119. args.sheet.resumePaint();
  120. },
  121. onMainEditStarting:function(sender, args){
  122. let me = unitPriceObj;
  123. let row = args.row;
  124. let col = args.col;
  125. if(me.mainEditChecking(row,col)==false){
  126. args.cancel = true;
  127. }
  128. },
  129. mainEditChecking:function(row,col,isPaste=false){
  130. let me = unitPriceObj;
  131. if(row>=unitPriceList.length) return false;
  132. let data = unitPriceList[row];
  133. let setting = me.mainSetting;
  134. let dataCode = setting.header[col].dataCode;
  135. if(isPaste == false &&dataCode=='is_add'){//除了粘贴,拖动填充等操作,其它的都不能编辑
  136. return false;
  137. }
  138. if(dataCode=='marketPrice'){
  139. let uindex = gljUtil.getIndex(data);
  140. if(mixRatioMap[uindex] && mixRatioMap[uindex].length > 0) return false;//有组成物的不能编辑
  141. if(data.calcMaterial == 1) return false //有材料计算时不能修改
  142. }
  143. return true;
  144. },
  145. onMainValueChange:function(e,info){
  146. let me = unitPriceObj;
  147. let value = info.newValue;
  148. if(info.newValue === undefined){
  149. return;
  150. }
  151. if(value && !sheetCommonObj.checkData(info.col,me.mainSetting,value)) {
  152. alert('输入的数据类型不对,请重新输入!');
  153. return me.showMainDatas();
  154. }
  155. me.batchUpdateUnitPrice([{row:info.row,col:info.col,value:value}]);
  156. },
  157. onMainRangeChange:function(sender,info){
  158. let me = unitPriceObj;
  159. let canChange = true;
  160. let changeInfo = [];
  161. for(let c of info.changedCells){
  162. let value= info.sheet.getCell(c.row, c.col).text();
  163. changeInfo.push({row:c.row,col:c.col,value:value});
  164. if(me.mainEditChecking(c.row,c.col,true)==false){//如果不能编辑
  165. canChange = false;
  166. break;
  167. }
  168. if (!sheetCommonObj.checkData(c.col,me.mainSetting,value)) {
  169. alert('输入的数据类型不对,请重新输入!');
  170. canChange = false;
  171. break;
  172. }
  173. }
  174. if(canChange == false) return me.showMainDatas();
  175. me.batchUpdateUnitPrice(changeInfo);
  176. },
  177. batchUpdateUnitPrice:async function(changeInfo){
  178. let me = unitPriceObj;
  179. let updateData = [];
  180. let newValueMap = {};
  181. let refreshList = [];
  182. try {
  183. for(let ci of changeInfo){
  184. let dataCode = me.mainSetting.header[ci.col].dataCode;
  185. let recode = unitPriceList[ci.row];
  186. let ndata = newValueMap[recode.id]?newValueMap[recode.id]:{unit_price:recode};
  187. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  188. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  189. let newValue = ci.value;
  190. if(recode && recode[editField]!=newValue){
  191. newValue= scMathUtil.roundForObj(ci.value,3);
  192. ndata['field'] = editField;
  193. ndata['newval'] = newValue;
  194. newValueMap[recode.id]=ndata;
  195. }
  196. }else{
  197. let ext = {};
  198. if(dataCode === 'is_add'){
  199. value = ci.value == true?1:0;
  200. }
  201. ext[dataCode] = value;
  202. ndata['ext'] = ext;
  203. newValueMap[recode.id]=ndata;
  204. }
  205. }
  206. for(let key in newValueMap){
  207. updateData.push(newValueMap[key]);
  208. refreshList.push(newValueMap[key].unit_price)
  209. }
  210. if(updateData.length > 0){
  211. $.bootstrapLoading.start();
  212. let result = await ajaxPost("/glj/batchUpdatePrices",updateData);
  213. for(let r of refreshList){
  214. let rdata = newValueMap[r.id];
  215. if(rdata.field) r[rdata.field] = rdata.newval;
  216. if(rdata.ext){
  217. for(let ekey in rdata.ext){
  218. r[ekey] = rdata.ext[ekey];
  219. }
  220. }
  221. }
  222. for(let r of result){
  223. let pdata = r.updateOne.filter;
  224. let set = r.updateOne.update.$set;
  225. for(let skey in set){
  226. let pindex = gljUtil.getIndex(pdata);
  227. me.unitPriceMap[pindex][skey] = set[skey];
  228. }
  229. }
  230. }
  231. } catch (error) {
  232. console.log(error);
  233. alert(error);
  234. }
  235. $.bootstrapLoading.end();
  236. me.onUnitPriceChange();
  237. },
  238. initSubSpread:function () {
  239. if(this.subSpread) return this.subSpread.refresh();
  240. this.subSpread = SheetDataHelper.createNewSpread($("#subSpread")[0]);
  241. sheetCommonObj.spreadDefaultStyle(this.subSpread);
  242. this.subSheet = this.subSpread.getSheet(0);
  243. sheetCommonObj.initSheet(this.subSheet, this.subSetting, 30);
  244. this.subSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onSubRangeChange);
  245. this.subSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onSubValueChange);
  246. this.initSubRightClick();
  247. },
  248. showSubDatas:function(){
  249. let parentData = this.getSelectedUnitPrice();
  250. this.mixRatioList = parentData?mixRatioMap[gljUtil.getIndex(parentData)]:[];
  251. this.mixRatioList = this.mixRatioList?this.mixRatioList:[];
  252. this.setMixRatioData(this.mixRatioList);
  253. let sel = this.subSheet.getSelections()[0];
  254. this.subSheet.setRowCount(0);
  255. sheetCommonObj.showData(this.subSheet, this.subSetting,this.mixRatioList);
  256. this.subSheet.setRowCount(this.mixRatioList.length);
  257. this.subSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
  258. },
  259. onSubValueChange:function(sender,info){
  260. let me = unitPriceObj;
  261. let value = info.newValue;
  262. if(info.newValue === undefined){
  263. return;
  264. }
  265. if(value && !sheetCommonObj.checkData(info.col,me.mainSetting,value)) {
  266. alert('输入的数据类型不对,请重新输入!');
  267. return me.showMainDatas();
  268. }
  269. me.batchUpdateConsumption([{row:info.row,col:info.col,value:value}]);
  270. },
  271. onSubRangeChange:function(sender,info){
  272. let me = unitPriceObj;
  273. let changeInfo=[];
  274. let canChange = true;
  275. for(let c of info.changedCells){
  276. let value = info.sheet.getCell(c.row, c.col).text();
  277. if(_.isEmpty(value)) value = 0;
  278. if (!sheetCommonObj.checkData(c.col,me.subSetting,value)) {
  279. alert('输入的数据类型不对,请重新输入!');
  280. canChange = false;
  281. break;
  282. }else {
  283. changeInfo.push({row:c.row,col:c.col,value:value});
  284. }
  285. }
  286. if(canChange == false) me.showSubDatas();
  287. me.batchUpdateConsumption(changeInfo);
  288. },
  289. calcParentPrice:function(list,updateMap,deleteID){
  290. let parentMarketPrice = 0;
  291. for(let sub of list){
  292. if(deleteID && sub.id == deleteID) continue
  293. let marketPrice = scMathUtil.roundForObj(sub.marketPrice,6);
  294. let basePrice = scMathUtil.roundForObj(sub.basePrice,6);
  295. let consumption = updateMap[sub.id]?updateMap[sub.id].consumption:scMathUtil.roundForObj(sub.consumption,3);
  296. parentMarketPrice = scMathUtil.roundForObj(marketPrice*consumption + parentMarketPrice,6);
  297. // parentBasePrice = scMathUtil.roundForObj(basePrice*consumption + parentBasePrice,getDecimal("process"));
  298. }
  299. parentMarketPrice = scMathUtil.roundForObj(parentMarketPrice,2);
  300. return parentMarketPrice;
  301. },
  302. deleteMixRatio:async function(row){
  303. let me = this, deleteRecode = me.mixRatioList[row];
  304. let parentMarketPrice = me.calcParentPrice(me.mixRatioList,{},deleteRecode.id);
  305. let parentData = me.getSelectedUnitPrice();
  306. let updateData = {id: deleteRecode.id,connect_key:gljUtil.getIndex(parentData)};
  307. updateData.parent = {connect_key:gljUtil.getIndex(parentData),query:{id:parentData.id},doc:{market_price: parentMarketPrice}};
  308. try {
  309. $.bootstrapLoading.start();
  310. await ajaxPost("/glj/delete-ratio",{id: updateData.id,parent:updateData.parent,unitPrice:updateData.unitPrice});
  311. let mlist = mixRatioMap[updateData.connect_key];
  312. _.remove(mlist,{id:updateData.id});
  313. if(updateData.parent){
  314. let pglj = me.unitPriceMap[updateData.parent.connect_key];
  315. if(pglj) gljUtil.setProperty(pglj,updateData.parent.doc);
  316. }
  317. } catch (error) {
  318. alert(error);
  319. console.log(error);
  320. }
  321. $.bootstrapLoading.end();
  322. me.onUnitPriceChange();
  323. },
  324. batchUpdateConsumption:async function(changeInfo){
  325. let me = unitPriceObj;
  326. let updateMap = {},updateData = [],parentBasePrice = 0,parentMarketPrice = 0;
  327. let parentKey = '',unit_price_file_id=null;
  328. for(let c of changeInfo){
  329. let record = me.mixRatioList[c.row];
  330. let value = scMathUtil.roundForObj(c.value,3);
  331. updateMap[record.id] = {consumption: value,record:record};
  332. updateData.push({type:'mix_ratio',connect_key:record.connect_key,query:{id:record.id},doc:{consumption:scMathUtil.roundToString(value,3)}});
  333. parentKey = record.connect_key;
  334. unit_price_file_id = record.unit_price_file_id;
  335. }
  336. parentMarketPrice = me.calcParentPrice(me.mixRatioList,updateMap);
  337. let parentData = me.getSelectedUnitPrice();
  338. if(parentData){
  339. updateData.push({type:'unitPrice',connect_key:gljUtil.getIndex(parentData),query:{id:parentData.id},doc:{market_price:parentMarketPrice}});
  340. }
  341. if(updateData.length > 0){
  342. try {
  343. $.bootstrapLoading.start();
  344. let result = await ajaxPost("/glj/batchUpdateConsumption",updateData);
  345. for(let up of updateData){
  346. if(up.type == 'unitPrice'){
  347. let nu = me.unitPriceMap[up.connect_key];
  348. if(nu) gljUtil.setProperty(nu,up.doc);
  349. }else{
  350. let nlist = mixRatioMap[up.connect_key];
  351. for(let nc of nlist){
  352. if(nc.id == up.query.id){
  353. gljUtil.setProperty(nc,up.doc);
  354. }
  355. }
  356. }
  357. }
  358. } catch (error) {
  359. alert(error);
  360. console.log(error);
  361. }
  362. }
  363. $.bootstrapLoading.end();
  364. me.onUnitPriceChange();
  365. },
  366. setMixRatioData:function(mixRatioList){
  367. for(let m of mixRatioList){
  368. m.short_name = this.getShortNameByType(m.type);
  369. let mu = this.unitPriceMap[gljUtil.getIndex(m)];
  370. if(mu){
  371. m.basePrice = this.getPrice("base_price",mu);
  372. m.marketPrice = this.getPrice("market_price",mu);
  373. }else{
  374. console.log("组成物的单价信息未找到---"+m.code);
  375. }
  376. }
  377. },
  378. getPrice:function(pricefield,unitprice){
  379. let quantity = 3;
  380. let unitPriceHasMix = 2;
  381. let unitPrice = 3;
  382. let process_decimal = 6;
  383. let uIndex = gljUtil.getIndex(unitprice);
  384. if(mixRatioMap[uIndex] && mixRatioMap[uIndex].length > 0){
  385. let total = unitprice[pricefield];
  386. if(pricefield == "market_price"){
  387. total = 0;
  388. for(let m of mixRatioMap[uIndex]){
  389. let mu = unitPriceObj.unitPriceMap[gljUtil.getIndex(m)];
  390. let price_m = unitPriceObj.getPrice(pricefield,mu);
  391. let temP = scMathUtil.roundForObj(price_m * scMathUtil.roundForObj(m.consumption,quantity),process_decimal);
  392. total = scMathUtil.roundForObj(temP+total,process_decimal);
  393. }
  394. }
  395. return scMathUtil.roundForObj(unitprice[pricefield],unitPriceHasMix);
  396. }else{
  397. return scMathUtil.roundForObj(unitprice[pricefield],unitPrice);
  398. }
  399. },
  400. getSelStyle: function (selected,settingStyle,rcolor) {
  401. let style = new GC.Spread.Sheets.Style();
  402. if(settingStyle){
  403. for(let key in settingStyle){
  404. style[key] = settingStyle[key];
  405. }
  406. }
  407. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  408. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  409. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  410. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  411. let selectedColor = "#FFFACD",
  412. recColor = rcolor?rcolor:'White';
  413. style.backColor = selected ? selectedColor : recColor;
  414. return style;
  415. },
  416. initSubRightClick:function(){
  417. let me = this;
  418. $.contextMenu({
  419. selector: '#subSpread',
  420. build: function ($trigger, e) {
  421. me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, me.subSpread);
  422. return me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
  423. me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  424. },
  425. items: {
  426. "deleteMixRatio": {
  427. name: "删除",
  428. icon: 'fa-trash-o',
  429. disabled: function () {
  430. return me.rightClickTarget.row === undefined;
  431. },
  432. callback: function (key, opt) {
  433. let row = me.rightClickTarget.row;
  434. me.deleteMixRatio(row);
  435. },
  436. visible: function(key, opt){
  437. let projectGLJ = me.getSelectedUnitPrice();
  438. return projectGLJ;
  439. }
  440. },
  441. "addMixRatio":{
  442. name: '添加',
  443. icon: 'fa-sign-in',
  444. disabled: function () {
  445. let projectGLJ = me.getSelectedUnitPrice();
  446. return !_.includes(compositionTypes,projectGLJ.type);
  447. },
  448. callback: function (key, opt) {
  449. projectGljObject.selectedProjectGLJ = me.getSelectedUnitPrice();
  450. getGLJData('unitPriceAddMix',me.getGLJDataPaging, true, null);
  451. },
  452. visible: function(key, opt){
  453. let projectGLJ = me.getSelectedUnitPrice();
  454. return projectGLJ ;
  455. }
  456. }
  457. }
  458. });
  459. },
  460. addMixRatio:async function(){
  461. let me = this;
  462. for(let mix of me.mixRatioList){
  463. let m_key = gljUtil.getIndex(mix);
  464. _.remove(gljOprObj.GLJSelection,n =>{
  465. return m_key == n;
  466. });
  467. }
  468. let result = await projectGljObject.addMixRatioFromLib(gljOprObj.GLJSelection)
  469. if(result.mixRatios && result.mixRatios.length > 0){
  470. let mList = mixRatioMap[result.mixRatios[0].connect_key];
  471. if(mList){
  472. mixRatioMap[result.mixRatios[0].connect_key] = mixRatioMap[result.mixRatios[0].connect_key].concat(result.mixRatios);
  473. }
  474. }
  475. for(let u of result.newUnitPriceList){
  476. me.unitPriceMap[gljUtil.getIndex(u)] = u;
  477. unitPriceList.push(u);
  478. }
  479. me.onUnitPriceChange();
  480. },
  481. onUnitPriceChange:async function(){
  482. unitPriceObj.showMainDatas();
  483. unitPriceObj.showSubDatas();
  484. try {
  485. await ajaxPost("/project/markUpdateProject",{updateInfo:{unitFileID:unitPriceFileID,isInclude:true},type:"unitFile"});
  486. socket.emit('unitFileChangeNotify', {projectID:_.isEmpty(projectID)?null:parseInt(projectID),'unitFileID':unitPriceFileID,userID:userID});
  487. } catch (error) {
  488. console.log(error)
  489. alert(error)
  490. }
  491. },
  492. getGLJDataPaging : function (condition, cb) {
  493. gljOprObj.loadingPagination = true;
  494. CommonAjax.post('/rationGlj/getGLJDataPaging', {condition}, function (data) {
  495. gljOprObj.curPageTotal = data.total;
  496. data.complementaryGLJs.forEach(glj => {
  497. glj.isComplementary = true;
  498. });
  499. const gljType = condition.type === gljOprObj.pagingType.stdGLJ
  500. ? 'stdGLJ'
  501. : 'complementaryGLJs';
  502. const newData = data[gljType];
  503. // 添加组成物,类型为主材时,需要排除自身
  504. if (projectGljObject.selectedProjectGLJ.type === gljType.MAIN_MATERIAL) {
  505. const pIndex = gljOprObj.getIndex(projectGljObject.selectedProjectGLJ, gljKeyArray);
  506. const delIndex = newData.findIndex(item => gljOprObj.getIndex(item, gljLibKeyArray) === pIndex);
  507. if (!~delIndex) {
  508. newData.splice(delIndex, 1);
  509. }
  510. }
  511. if (condition.init) {
  512. gljOprObj.treeData = data.treeData;
  513. gljOprObj.distTypeTree = gljOprObj.getComboData(data.distTypeTree);
  514. }
  515. // 需要重置当前页面数据(点击了分类树、搜索等等)
  516. if (condition.reset) {
  517. gljOprObj.stdGLJ = data.stdGLJ;
  518. gljOprObj.complementaryGLJs = data.complementaryGLJs;
  519. gljOprObj.AllRecode = [...gljOprObj.stdGLJ, ...gljOprObj.complementaryGLJs];
  520. } else {
  521. gljOprObj[gljType].splice(condition.index, 0, ...newData);
  522. gljOprObj.AllRecode.splice(condition.index, 0, ...newData);
  523. }
  524. // 根据缓存选中数据,设置人材机是否选中
  525. newData.forEach(item => {
  526. const connectKey = gljOprObj.getIndex(item, gljLibKeyArray);
  527. if (gljOprObj.GLJSelection.includes(connectKey)) {
  528. item.select = 1;
  529. }
  530. });
  531. // 设置人材机类型名称
  532. gljOprObj.setTypeName(gljOprObj.distTypeTree.comboDatas, newData);
  533. if (data.priceProperties && data.priceProperties.length > 0) {
  534. let tregion = '全省';
  535. if(!_.isEmpty(region)) tregion = region;
  536. let tmp = _.find(data.priceProperties, {region: tregion, taxModel: parseInt(taxType)});
  537. if (tmp) {
  538. let dataCode = tmp.price.dataCode;
  539. let allData = data.stdGLJ.concat(data.complementaryGLJs);
  540. for (let glj of allData) {
  541. if (glj.priceProperty && gljUtil.isDef(glj.priceProperty[dataCode])) {
  542. glj.basePrice = glj.priceProperty[dataCode];
  543. }
  544. }
  545. }
  546. }
  547. if (data.libData) {
  548. const html = data.libData.reduce((acc, lib) => acc += `<option ${lib.isDefault ? 'selected="selected"' : ''} value="${lib.gljLibId}">${lib.name}</option>`, '');
  549. $('#glj-lib-select').html(html);
  550. }
  551. cb(data[gljType], data);
  552. gljOprObj.loadingPagination = false;
  553. }, function () {
  554. if ($.bootstrapLoading.isLoading()) {
  555. $.bootstrapLoading.end();
  556. }
  557. });
  558. }
  559. }
  560. function initPageHeight(){
  561. let headerHeight = $(".header").height();
  562. $(".main-data-top").height($(window).height()*0.6-headerHeight);
  563. $(".main-data-bottom").height($(window).height()-headerHeight-$(".main-data-top").height()-$(".nav-item").height());
  564. }
  565. function initPage(){
  566. $('[data-toggle="tooltip"]').tooltip({html: true});
  567. initPageHeight();
  568. unitPriceObj.initMainSpread();
  569. unitPriceObj.initSubSpread();
  570. unitPriceObj.showMainDatas();
  571. unitPriceObj.showSubDatas();
  572. socketObject.connect("unitPrice");
  573. }
  574. unitPriceObj.setUntiPriceMap();
  575. initPage();
  576. $(window).resize(initPage);