index.js 24 KB

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