| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- let unitPriceObj = {
- unitPriceMap:{},
- setUntiPriceMap:function(){
- for(let u of unitPriceList){
- this.unitPriceMap[gljUtil.getIndex(u)] = u;
- }
- },
- mainSpread:null,
- mainSetting:{
- header: [
- {headerName: "编号", headerWidth: 80, dataCode: "code", dataType: "String"},
- {headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String"},
- {headerName: "单位", headerWidth: 45, dataCode: "unit", hAlign: "center", dataType: "String"},
- {headerName: "规格", headerWidth: 120, dataCode: "specs", hAlign: "left", dataType: "String"},
- {headerName: "类型", headerWidth: 45, dataCode: "short_name", hAlign: "center", dataType: "String"},
- {headerName: "定额价", headerWidth: 70, dataCode: "basePrice", hAlign: "right", dataType: "Number",validator:"number"},//decimalField:'glj.unitPrice',
- {headerName: "预算价", headerWidth: 70, dataCode: "marketPrice", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:"glj.unitPrice"
- {headerName: "是否新增", headerWidth: 50, dataCode: "is_add", hAlign: "center", dataType: "String",cellType:'checkBox'}
- ],
- view: {
- lockColumns: ["code","name","specs","unit","short_name","basePrice","is_add"],
- colHeaderHeight:36
- },
- getStyle:function (data,row,activeRow) {
- if(row == activeRow){//选中黄色显示
- return {backColor:"#FFFACD"};
- }
- return null;
- }
- },
- subSpread:null,
- subSetting:{
- header:[
- {headerName: "编号", headerWidth: 80, dataCode: "code", dataType: "String"},
- {headerName: "名称", headerWidth: 240, dataCode: "name", dataType: "String"},
- {headerName: "规格", headerWidth: 190, dataCode: "specs", dataType: "String"},
- {headerName: "单位", headerWidth: 45, dataCode: "unit", hAlign: "center", dataType: "String"},
- {headerName: "类型", headerWidth: 45, dataCode: "short_name", hAlign: "center", dataType: "String"},
- {headerName: "定额价", headerWidth: 80, dataCode: "basePrice", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:'glj.unitPrice'
- {headerName: "预算价", headerWidth: 80, dataCode: "marketPrice", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:"glj.unitPrice"
- {headerName: "消耗量", headerWidth: 80, dataCode: "consumption", hAlign: "right", dataType: "Number",validator:"number",tofix:3}
- ],
- view: {
- lockColumns: [0,1,2,3,4,5,6,7],
- rowHeaderWidth: 25
- }
- },
- initMainSpread:function () {
- if(this.mainSpread) return this.mainSpread.refresh();
- this.mainSpread = SheetDataHelper.createNewSpread($("#mainSpread")[0]);
- sheetCommonObj.spreadDefaultStyle(this.mainSpread);
- this.mainSheet = this.mainSpread.getSheet(0);
- sheetCommonObj.initSheet(this.mainSheet, this.mainSetting, 30);
- this.mainSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onMainSelectionChange);
- this.mainSpread.bind(GC.Spread.Sheets.Events.RangeChanged, this.onMainRangeChange);
- this.mainSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onMainValueChange);
- // this.sheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onElectrovalenceEditStarting);
- /* if(projectReadOnly){
- disableSpread(this.spread);
- } */
- },
- showMainDatas:function(){
- unitPriceList = gljUtil.sortProjectGLJ(unitPriceList);
- this.setData(unitPriceList);
- let sel = this.mainSheet.getSelections()[0];
- let oldData = sel.row<unitPriceList.length?unitPriceList[sel.row]:"";
- sheetCommonObj.showData(this.mainSheet, this.mainSetting,unitPriceList);
- this.mainSheet.setRowCount(unitPriceList.length);
- sel.row = oldData?_.findIndex(unitPriceList,{'id':oldData.id}):sel.row ;
- this.mainSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
-
- },
- getShortNameByType : function (type) {
- return gljTypeMap["typeId" + type]?gljTypeMap["typeId" + type].shortName:'';
- },
- setData:function(list){
- for(let l of list){
- l.bgColour = "white";
- l.basePrice = this.getPrice('base_price',l);
- l.marketPrice = this.getPrice('market_price',l);
- l.short_name = this.getShortNameByType(l.type);
- if(l.base_price == l.market_price){//如果定额价等于市场价时,改底色。 优先度低于有组成物时的底色
- l.bgColour = "#C4CAFB";
- }
- let lindex = gljUtil.getIndex(l);
- if (gljUtil.notEditType.indexOf(l.type) >= 0 && mixRatioMap[lindex] && mixRatioMap[lindex].length>0) {//有组成物时
- l.bgColour = "#E0E0E0";
- }
- if(gljUtil.isConcreteType(l.type)) l.bgColour = "#E0E0E0";//混凝土、砂浆、配合比的底色显示为 灰色#E0E0E0,灰色底色提醒用户不可修改。
- }
- },
- getSelectedUnitPrice:function () {
- let me = this,data = null;
- let sheet = me.mainSpread.getActiveSheet();
- let sel = sheet.getSelections()[0];
- let srow = sel.row == -1||sel.row == ""?0:sel.row;
- if(unitPriceList.length>srow){
- data = unitPriceList[srow];
- }
- return data;
- },
- onMainSelectionChange:function(sender,args){
- let me = unitPriceObj;
- let newSel = args.newSelections[0];
- let oldSel = args.oldSelections?args.oldSelections[0]:{};
- args.sheet.suspendPaint();
- args.sheet.suspendEvent();
- if(newSel.row != oldSel.row){
- let style = me.getSelStyle(true,{});
- args.sheet.setStyle(newSel.row, -1, style);
- let orow = oldSel.row==''||oldSel.row==-1?0:oldSel.row;
- if(unitPriceList[orow]){
- let tstyle = me.getSelStyle(false,{},unitPriceList[orow].bgColour);
- args.sheet.setStyle(orow, -1, tstyle);
- me.showSubDatas();
- }
- }else{
- args.sheet.repaint();
- }
- args.sheet.resumeEvent();
- args.sheet.resumePaint();
- },
- onMainValueChange:function(e,info){
- let me = unitPriceObj;
- let value = info.newValue;
- if(info.newValue === undefined){
- return;
- }
- if(value && !sheetCommonObj.checkData(info.col,me.mainSetting,value)) {
- alert('输入的数据类型不对,请重新输入!');
- return me.showMainDatas();
- }
- me.batchUpdateUnitPrice([{row:info.row,col:info.col,value:value}]);
- },
- onMainRangeChange:function(sender,info){
- let me = unitPriceObj;
- let canChange = true;
- for(let c of info.changedCells){
- let value= info.sheet.getCell(c.row, c.col).text();
- changeInfo.push({row:c.row,col:c.col,value:value});
- if (!sheetCommonObj.checkData(c.col,me.mainSetting,value)) {
- alert('输入的数据类型不对,请重新输入!');
- canChange = false;
- break;
- }
- }
- if(canChange == false) return me.showMainDatas();
- me.batchUpdateUnitPrice(changeInfo);
- },
- batchUpdateUnitPrice:async function(changeInfo){
- let me = unitPriceObj;
- let updateData = [];
- let newValueMap = {};
- let refreshList = [];
- try {
- for(let ci of changeInfo){
- let dataCode = me.mainSetting.header[ci.col].dataCode;
- let recode = unitPriceList[ci.row];
- if(dataCode=='basePrice'||dataCode=='marketPrice'){
- let editField = dataCode === 'basePrice'?"base_price":"market_price";
- let newValue = ci.value;
- if(recode && recode[editField]!=newValue){
- newValue= scMathUtil.roundForObj(ci.value,3);
- updateData.push({unit_price: recode, field: editField, newval: newValue});
- newValueMap[recode.id]={field:editField,value:newValue};
- refreshList.push(recode);
- }
- }
- }
- if(updateData.length > 0){
- $.bootstrapLoading.start();
- let result = await ajaxPost("/glj/batchUpdatePrices",updateData);
- for(let r of refreshList){
- r[newValueMap[r.id].field] = newValueMap[r.id].value;
- }
- for(let r of result){
- let pdata = r.updateOne.filter;
- let set = r.updateOne.update.$set;
- for(let skey in set){
- let pindex = gljUtil.getIndex(pdata);
- me.unitPriceMap[pindex][skey] = set[skey];
- }
- }
- }
- } catch (error) {
- alert(error);
- }
- $.bootstrapLoading.end();
- me.showMainDatas();
- },
- initSubSpread:function () {
- if(this.subSpread) return this.subSpread.refresh();
- this.subSpread = SheetDataHelper.createNewSpread($("#subSpread")[0]);
- sheetCommonObj.spreadDefaultStyle(this.subSpread);
- this.subSheet = this.subSpread.getSheet(0);
- sheetCommonObj.initSheet(this.subSheet, this.subSetting, 30);
- // this.sheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onElectrovalenceSelectionChange);
- // this.sheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onElectrovalenceValueChange);
- // this.sheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onElectrovalenceEditStarting);
- /* if(projectReadOnly){
- disableSpread(this.spread);
- } */
- },
- showSubDatas:function(){
- let parentData = this.getSelectedUnitPrice();
- this.mixRatioList = mixRatioMap[gljUtil.getIndex(parentData)];
- this.mixRatioList = this.mixRatioList?this.mixRatioList:[];
- this.setMixRatioData(this.mixRatioList);
- let sel = this.subSheet.getSelections()[0];
- this.subSheet.setRowCount(0);
- sheetCommonObj.showData(this.subSheet, this.subSetting,this.mixRatioList);
- this.subSheet.setRowCount(this.mixRatioList.length);
- this.subSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
- },
- setMixRatioData:function(mixRatioList){
- for(let m of mixRatioList){
- m.short_name = this.getShortNameByType(m.type);
- let mu = this.unitPriceMap[gljUtil.getIndex(m)];
- if(mu){
- m.basePrice = this.getPrice("base_price",mu);
- m.marketPrice = this.getPrice("market_price",mu);
- }else{
- console.log("组成物的单价信息未找到---"+m.code);
- }
- }
- },
- getPrice:function(pricefield,unitprice){
- let quantity = 3;
- let unitPriceHasMix = 2;
- let unitPrice = 3;
- let process_decimal = 6;
- let uIndex = gljUtil.getIndex(unitprice);
- if(mixRatioMap[uIndex] && mixRatioMap[uIndex].length > 0){
- let total = unitprice[pricefield];
- if(pricefield == "market_price"){
- total = 0;
- for(let m of mixRatioMap[uIndex]){
- let mu = unitPriceObj.unitPriceMap[gljUtil.getIndex(m)];
- let price_m = unitPriceObj.getPrice(pricefield,mu);
- let temP = scMathUtil.roundForObj(price_m * scMathUtil.roundForObj(m.consumption,quantity),process_decimal);
- total = scMathUtil.roundForObj(temP+total,process_decimal);
- }
- }
- return scMathUtil.roundForObj(unitprice[pricefield],unitPriceHasMix);
- }else{
- return scMathUtil.roundForObj(unitprice[pricefield],unitPrice);
- }
- },
- getSelStyle: function (selected,settingStyle,rcolor) {
- let style = new GC.Spread.Sheets.Style();
- if(settingStyle){
- for(let key in settingStyle){
- style[key] = settingStyle[key];
- }
- }
- style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
- style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
- style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
- style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
- let selectedColor = "#FFFACD",
- recColor = rcolor?rcolor:'White';
- style.backColor = selected ? selectedColor : recColor;
- return style;
- },
- }
- function initPageHeight(){
- let headerHeight = $(".header").height();
- $(".main-data-top").height($(window).height()*0.6-headerHeight);
- $(".main-data-bottom").height($(window).height()-headerHeight-$(".main-data-top").height()-$(".nav-item").height());
- }
- function initPage(){
- $('[data-toggle="tooltip"]').tooltip({html: true});
- initPageHeight();
- unitPriceObj.initMainSpread();
- unitPriceObj.initSubSpread();
- unitPriceObj.showMainDatas();
- }
- unitPriceObj.setUntiPriceMap();
- initPage();
- $(window).resize(initPage);
|