12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637 |
- /**
- * Created by CSL on 2017-05-12.
- */
- var gljOprObj = {
- sheet: null,
- libID: null,
- ration: null,
- sheetData: [],
- coeSheetData: [],
- checkb: null,
- coeSheet: null,
- assSheet: null,
- assSheetData: [],
- detailSheet: null,
- detailData: [],
- GLJSelection: [],
- selectedGLJClass: null,
- parentNodeIds: {},
- activeTab: '#linkGLJ',
- setting: {
- header: [
- {headerName: "编码", headerWidth: 100, dataCode: "code", dataType: "String", formatter: "@"},
- {headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String"},
- {headerName: "规格型号", headerWidth: 90, dataCode: "specs", dataType: "String", hAlign: "left"},
- {headerName: "单位", headerWidth: 45, dataCode: "unit", dataType: "String", hAlign: "center"},
- {headerName: "类型", headerWidth: 45, dataCode: "shortName", dataType: "String", hAlign: "center"},
- {
- headerName: "定额消耗",
- headerWidth: 80,
- dataCode: "rationItemQuantity",
- dataType: "Number",
- hAlign: "right",
- decimalField: "glj.quantity"
- }, // dataType: "Number", formatter: "0.00"
- {
- headerName: "自定消耗",
- headerWidth: 80,
- dataCode: "customQuantity",
- dataType: "Number",
- hAlign: "right",
- decimalField: "glj.quantity"
- },
- {
- headerName: "消耗量",
- headerWidth: 80,
- dataCode: "quantity",
- dataType: "Number",
- hAlign: "right",
- decimalField: "glj.quantity"
- },
- {
- headerName: "总消耗量",
- headerWidth: 80,
- dataCode: "totalQuantity",
- dataType: "Number",
- hAlign: "right",
- decimalField: "glj.quantity"
- },
- {
- headerName: "定额价",
- headerWidth: 80,
- dataCode: "basePrice",
- dataType: "Number",
- hAlign: "right",
- decimalField: "glj.unitPrice"
- },
- {
- headerName: "调整价",
- headerWidth: 80,
- dataCode: "adjustPrice",
- dataType: "Number",
- hAlign: "right",
- decimalField: "glj.unitPrice"
- },
- {
- headerName: "市场价",
- headerWidth: 80,
- dataCode: "marketPrice",
- dataType: "Number",
- hAlign: "right",
- decimalField: "glj.unitPrice"
- },
- {
- headerName: "是否暂估",
- headerWidth: 65,
- dataCode: "isEstimate",
- dataType: "String",
- hAlign: "center",
- vAlign: "center",
- cellType: "checkBox"
- }
- ],
- view: {
- comboBox: [{row: -1, col: 12, rowCount: -1, colCount: 1}],
- lockedCells: [{row: -1, col: 3, rowCount: -1, colCount: 1}],
- lockColumns: [0, 4, 5, 7, 8, 10, 12]
- },
- // 工料机类型是混凝土、砂浆、配合比、机械台班时,价格不可编辑。
- editedTyep:[GLJTypeConst.MAIN_MATERIAL,GLJTypeConst.EQUIPMENT]//主材设备
- },
- coeSetting: {
- header: [
- {headerName: "调整", headerWidth: 100, dataCode: "isAdjust", dataType: "String", cellType: "checkBox"},
- {headerName: "条件", headerWidth: 120, dataCode: "name", dataType: "String", cellType: "button"},
- {headerName: "内容", headerWidth: 350, dataCode: "content", dataType: "String", hAlign: "left"}
- ],
- view: {
- lockColumns: [0, 1, 2]
- }
- },
- assSetting: {
- header: [
- {headerName: "调整名称", headerWidth: 100, dataCode: "name", dataType: "String"},
- {headerName: "定额值", headerWidth: 120, dataCode: "stdValue", hAlign: "right", dataType: "String"},
- {headerName: "实际值", headerWidth: 120, dataCode: "actualValue", hAlign: "right", dataType: "String"}
- ],
- view: {
- lockColumns: [0, 1]
- }
- },
- detailSetting: {
- header: [
- {headerName: "名称", headerWidth: 100, dataCode: "name", dataType: "String"},
- {headerName: "计算式", headerWidth: 120, dataCode: "regex", dataType: "String"},
- {
- headerName: "结果(C)",
- headerWidth: 120,
- dataCode: "result",
- dataType: "Number",
- decimalField: "quantity_detail"
- },
- {headerName: "累加", headerWidth: 120, dataCode: "isSummation", dataType: "String", cellType: "checkBox"}
- ],
- view: {
- lockColumns: [2, 3]
- }
- },
- gljTreeSetting: {
- view: {
- //addHoverDom: gljTypeTreeOprObj.addHoverDom,
- //removeHoverDom: gljTypeTreeOprObj.removeHoverDom,
- expandSpeed: "",
- selectedMulti: false
- },
- edit: {
- enable: false,
- editNameSelectAll: true,
- showRemoveBtn: true,
- showRenameBtn: true,
- removeTitle: "删除节点",
- renameTitle: "更改名称"
- },
- data: {
- keep: {
- parent: true,
- leaf: true
- },
- key: {
- children: "items",
- name: "Name"
- },
- simpleData: {
- enable: false,
- idKey: "ID",
- pIdKey: "ParentID",
- rootPId: -1
- }
- },
- callback: {
- onClick: function (event, treeId, treeNode) {
- if (treeId == 'gljTree') {
- let me = gljOprObj, gljTypeId = treeNode.ID;
- if (me.gljCurTypeId !== treeNode.ID) {
- me.gljCurTypeId = treeNode.ID;
- me.filterLibGLJSheetData();
- me.showLibGLJSheetData();
- }
- } else {
- if (treeNode.isParent) {
- $('#class_selected_conf').attr("disabled", "disabled");
- $('#selected_class').val("");
- } else {
- $('#class_selected_conf').removeAttr("disabled");
- $('#selected_class').val(treeNode.ID);
- }
- }
- }
- }
- },
- gljLibSheetSetting: {
- owner: 'gljTree',
- header: [
- {
- headerName: "选择",
- headerWidth: 40,
- dataCode: "select",
- hAlign: "center",
- vAlign: "center",
- cellType: "checkBox"
- },
- {
- headerName: "编码",
- headerWidth: 80,
- dataCode: "code",
- dataType: "String",
- formatter: "@",
- hAlign: "left",
- vAlign: "center"
- },
- {
- headerName: "名称",
- headerWidth: 120,
- dataCode: "name",
- dataType: "String",
- hAlign: "left",
- vAlign: "center"
- },
- {
- headerName: "规格型号",
- headerWidth: 80,
- dataCode: "specs",
- dataType: "String",
- hAlign: "center",
- vAlign: "center"
- },
- {
- headerName: "计量单位",
- headerWidth: 80,
- dataCode: "unit",
- dataType: "String",
- hAlign: "center",
- vAlign: "center"
- },
- {
- headerName: "单价",
- headerWidth: 80,
- dataCode: "basePrice",
- dataType: "Number",
- formatter: "0.00",
- hAlign: "right",
- vAlign: "center"
- },
- {
- headerName: "类型",
- headerWidth: 80,
- dataCode: "gljType",
- dataType: "String",
- hAlign: "center",
- vAlign: "center"
- }
- ],
- view: {
- lockColumns: [0, 1, 2, 3, 4, 5, 6]
- }
- },
- gljLibSheet: null,
- initSheet: function (sheet) {
- var me = this;
- me.sheet = sheet;
- sheetCommonObj.initSheet(me.sheet, me.setting, 30);
- sheet.name('ration_glj');
- me.bindSheetEvent(sheet);
- sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
- sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, me.onCellDoubleClick);
- gljContextMenu.loadGLJSpreadContextMenu();
- },
- initCoeSheet: function (sheet) {
- var me = this;
- me.coeSheet = sheet;
- sheetCommonObj.initSheet(me.coeSheet, me.coeSetting, 30);
- sheet.name('ration_coe');
- me.bindSheetEvent(sheet);
- sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCoeCellClick);
- subSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClick);
- },
- initAssSheet: function (sheet) {
- var me = this;
- me.assSheet = sheet;
- sheetCommonObj.initSheet(me.assSheet, me.assSetting, 30);
- sheet.name('ration_ass');
- me.bindSheetEvent(sheet);
- },
- initDetailSheet: function (sheet) {
- var me = this;
- me.detailSheet = sheet;
- sheetCommonObj.initSheet(me.detailSheet, me.detailSetting, 30);
- // me.detailSheet.selectionUnit(0);//0 cell,1 row,2 col;
- sheet.name('quantity_detail');
- me.bindSheetEvent(sheet);
- },
- showCoeData: function (sheet, setting, datas) {
- sheet.floatingObjects.remove("customerCoe");
- sheetCommonObj.showData(sheet, setting, datas);
- if (datas.length > 0) {
- var cus_index = _.findIndex(datas, function (item) {
- return item.coeID == -1;
- })
- if (cus_index != -1) {
- this.addDropDownList();
- this.addCusButton(cus_index, 1, datas[cus_index].name);
- }
- }
- },
- bindSheetEvent: function (sheet) {
- var me = this;
- sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
- sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
- sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
- sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
- // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
- },
- onClipboardPasting: function (sender, args) {
- var me = gljOprObj;
- if (!me.ration) {
- args.cancel = true;
- }
- },
- onClipboardPasted: function (e, info) {
- var me = gljOprObj;
- console.log('past');
- // if (!me.ration) {return;};
- // your code...
- },
- onEditEnded: function (sender, args) {
- var me = gljOprObj;
- if (args.sheetName == 'ration_glj') {
- me.onEditGLJSheet(args)
- }
- if (args.sheetName == 'ration_ass') {
- me.onEditAssSheet(args);
- }
- if (args.sheetName == 'quantity_detail') {
- me.onEditDetailSheet(args);
- }
- },
- onEditDetailSheet: function (args) {
- var me = gljOprObj;
- if (args.row > me.detailData.length) {
- return;
- }
- if (args.row == me.detailData.length && args.editingText == null) {
- return;
- }
- var selected = projectObj.project.mainTree.selected;//因为使用了延时方法,所以要先取得选中行;
- var detailList = me.detailData;
- args.editingText = args.editingText.replace(/(/g, "(");//替换中文左右括号;
- args.editingText = args.editingText.replace(/)/g, ")");
- setTimeout(function () {//这里须用延时执行的办法,不然的弹窗确认窗口会和spreadjs 的事件有冲突,造成定额工料机数据不会根据树结点更新的问题
- if (args.row == detailList.length) {
- projectObj.project.quantity_detail.saveQuantityDetail(args, me.detailSetting.header[args.col].dataCode, selected);
- }
- if (args.row < detailList.length) {
- projectObj.project.quantity_detail.updateQuantityDetail(args, me.detailSetting.header[args.col].dataCode, detailList[args.row], selected);
- }
- }, 100);
- },
- onEditGLJSheet: function (args) {
- var me = gljOprObj;
- if (args.row >= me.sheetData.length) {
- me.sheet.getCell(args.row, args.col).value(null);
- return;
- }
- me.updateRationGLJ(args);
- },
- onEditAssSheet: function (args) {
- var me = gljOprObj;
- if (args.row >= me.assSheetData.length) {
- me.assSheet.getCell(args.row, args.col).value(null);
- return;
- }
- if (me.assSetting.header[args.col].dataCode == 'actualValue') {//自定义消耗量
- me.updateRationAss(args);
- }
- },
- onButtonClick: function (sender, args) {
- var me = gljOprObj;
- var sheet = args.sheet, row = args.row, col = args.col;
- var cellType = sheet.getCellType(row, col);
- if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
- me.onCusButtonClick(sender, args);
- } else {
- me.onCheckBoxClick(sender, args)
- }
- },
- onCheckBoxClick: function (sender, args) {
- if (args.sheetName == 'ration_glj') {
- return;
- }
- var checkboxValue = args.sheet.getCell(args.row, args.col).value();
- var newval = 0;
- if (checkboxValue) {
- newval = 0;
- args.sheet.getCell(args.row, args.col).value(newval);
- } else {
- newval = 1
- args.sheet.getCell(args.row, args.col).value(newval);
- }
- if (args.sheetName == 'ration_coe') {
- gljOprObj.updateRationCoe(args, newval)
- } else if (args.sheetName == 'quantity_detail') {
- projectObj.project.quantity_detail.isSummationUpdate(args, gljOprObj.detailData, newval);
- } else if (args.sheetName == 'glj_lib') {
- gljOprObj.setGLJSelection(args, newval);
- }
- },
- onCusButtonClick: function (sender, args) {
- var me = gljOprObj;
- var floatingObject = me.coeSheet.floatingObjects.get('customerCoe');
- var isVisable = floatingObject.isVisible();
- if (!isVisable) {
- me.coeSheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(false);
- me.showFloationObject(floatingObject, me.coeSheetData[args.row]);
- } else {
- var result = me.checkIfNeedUpdate();
- if (result.isNeed) {
- projectObj.project.ration_coe.updateCustomerCoe(result);
- }
- floatingObject.isVisible(false);
- }
- },
- onCellClick: function (sender, args) {
- var me = gljOprObj;
- if (args.row >= me.sheetData.length) {
- return;
- }
- me.editChecking(args);
- },
- onCellDoubleClick:function (sender, args) {
- var me = gljOprObj;
- var header = me.setting.header;
- if (args.row >= me.sheetData.length) {
- return;
- }
- if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
- if(me.hasComposition(me.sheetData[args.row])){
- alert("当前工料机的市场价由组成物计算得出,不可直接修改。");
- }
- }
- if (header[args.col] && header[args.col].dataCode == 'basePrice') {
- var isAdd = me.sheetData[args.row].isAdd;
- if(isAdd==1){//是新增但没有组成物时允许修改定额价
- if(me.hasComposition(me.sheetData[args.row])){//如果有组成物,不可修改
- alert("当前工料机的定额价由组成物计算得出,不可直接修改。");
- }
- }
- }
- },
- onCoeCellClick: function (sender, args) {
- var me = gljOprObj;
- var floatingObject = me.coeSheet.floatingObjects.get('customerCoe');
- var isVisable = floatingObject.isVisible();
- /* if($('#dropdown').css("display") == 'none'){
- if(args.col==1&&me.coeSheetData.length>args.row&&me.coeSheetData[args.row].coeID==-1){
- me.showFloationObject(floatingObject,me.coeSheetData[args.row]);
- }
- }*/
- if (isVisable) {
- var result = me.checkIfNeedUpdate();
- if (result.isNeed) {
- projectObj.project.ration_coe.updateCustomerCoe(result);
- }
- floatingObject.isVisible(false);
- // $('#dropdown').hide();
- }
- },
- showFloationObject(floatingObject, data){
- floatingObject.isVisible(true);
- var sheet = this.coeSheet;
- var startRow = this.coeSheetData.length;
- var endRow = startRow + 7;
- floatingObject.startRow(startRow);
- floatingObject.startColumn(1);
- floatingObject.endColumn(2);
- floatingObject.endRow(endRow);
- this.bindFloadingObjectValue(data);
- sheet.repaint();
- // var editPosition = $("#edit").offset();
- //$('#dropdown').show();
- //var top =editPosition.top>=825?825:editPosition.top
- //$('#dropdown').offset({left:editPosition.left,top:top});//top: 791px; left:70px;
- },
- bindFloadingObjectValue(data){
- $('#coe_ration').val(data.coes[0].amount);
- $('#manual').val(data.coes[1].amount);
- $('#material').val(data.coes[2].amount);
- $('#manchine').val(data.coes[3].amount);
- $('#mainM').val(data.coes[4].amount);
- $('#equipment').val(data.coes[5].amount);
- },
- onInputChange(id, name){
- var coe = _.find(gljOprObj.coeSheetData, function (c) {
- return c.coeID == -1;
- });
- var newValue = gljOprObj.numberValueChecking($('#' + id).val());
- if (newValue) {
- newValue = _.round(newValue, 2);
- if (newValue == coe.coes[name].amount) return;
- if (id == 'coe_ration') {
- $('#coe_ration').val(newValue);
- $('#manual').val(newValue);
- $('#material').val(newValue);
- $('#manchine').val(newValue);
- $('#mainM').val(newValue);
- $('#equipment').val(newValue);
- } else {
- $('#' + id).val(newValue);
- }
- } else {
- $('#' + id).val(coe.coes[name].amount);
- }
- },
- checkIfNeedUpdate(){
- var data = _.find(gljOprObj.coeSheetData, function (c) {
- return c.coeID == -1;
- });
- var result = {
- isNeed: false
- }
- var coe_ration = $('#coe_ration').val();
- var manual = $('#manual').val();
- var material = $('#material').val();
- var manchine = $('#manchine').val();
- var mainM = $('#mainM').val();
- var equipment = $('#equipment').val();
- if (coe_ration != data.coes[0].amount) {
- result.isNeed = true;
- data.coes[0].amount = coe_ration;
- }
- if (manual != data.coes[1].amount) {
- result.isNeed = true;
- data.coes[1].amount = manual;
- }
- if (material != data.coes[2].amount) {
- result.isNeed = true;
- data.coes[2].amount = material;
- }
- if (manchine != data.coes[3].amount) {
- result.isNeed = true;
- data.coes[3].amount = manchine;
- }
- if (mainM != data.coes[4].amount) {
- result.isNeed = true;
- data.coes[4].amount = mainM;
- }
- if (equipment != data.coes[5].amount) {
- result.isNeed = true;
- data.coes[5].amount = equipment;
- }
- if (result.isNeed) {
- result.doc = {
- coes: data.coes
- };
- result.query = {
- projectID: data.projectID,
- ID: data.ID,
- rationID: data.rationID
- };
- }
- return result;
- },
- editChecking: function (args) {
- var me = gljOprObj;
- var header = me.setting.header;
- var disable = null;
- if (me.sheetData[args.row] != undefined) {
- if (me.sheetData[args.row].isMixRatio) {
- disable = true;
- }else {
- if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
- if(me.hasComposition(me.sheetData[args.row])){
- disable = true;
- }else {
- disable = false;
- }
- }
- if (header[args.col] && header[args.col].dataCode == 'basePrice') {
- var isAdd = me.sheetData[args.row].isAdd;
- if(isAdd==1){//是新增但没有组成物时允许修改定额价
- if(me.hasComposition(me.sheetData[args.row])){//如果有组成物,不可修改
- disable = true;
- }else {
- disable = false;
- }
- } else {
- disable = true;
- }
- }
- }
- }
- if (disable != null) {
- me.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(disable);
- }
- },
- hasComposition:function (ration_glj) {//判断是否有组成物,有则返回true
- if(notEditType.indexOf(ration_glj.type)!=-1){
- let con_key = this.getIndex(ration_glj,gljKeyArray);
- var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
- if(mixRatioMap[con_key]&&mixRatioMap[con_key].length>0){
- return true;
- }
- }
- return false;
- },
- addDropDownList: function () {
- var sheet = this.coeSheet;
- sheet.suspendPaint();
- var customFloatingObject = new GC.Spread.Sheets.FloatingObjects.FloatingObject("customerCoe");
- var div = document.createElement('div');
- div.innerHTML = this.generateHtmlString();
- customFloatingObject.startRow(1);
- customFloatingObject.startColumn(1);
- customFloatingObject.endColumn(2);
- customFloatingObject.endRow(2);
- $(div).css('background', 'white');
- customFloatingObject.content(div);
- sheet.floatingObjects.add(customFloatingObject);
- customFloatingObject.isVisible(false);
- sheet.resumePaint();
- },
- addCusButton: function (row, col, text) {
- var cus_button = new GC.Spread.Sheets.CellTypes.Button();
- gljOprObj.coeSheet.setCellType(row, col, cus_button, GC.Spread.Sheets.SheetArea.viewport);
- cus_button.marginLeft(0);
- cus_button.marginTop(0);
- cus_button.marginRight(0);
- cus_button.marginBottom(0);
- cus_button.text(text);
- cus_button.buttonBackColor('white');
- gljOprObj.coeSheet.repaint();
- },
- onRangeChanged: function (sender, args) {
- var me = gljOprObj;
- if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
- args.editingText = null;
- if (args.sheetName == 'ration_glj') {
- me.onEditGLJSheet(args);
- }
- if (args.sheetName == 'ration_ass') {
- me.updateRationAss(args);
- }
- }
- ;
- },
- generateHtmlString: function () {
- // return "<div id='edit'><div>";
- var newString = "<form ><table border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;font-size: 10px;>";
- //newString +="<tr><td style='height:15px' colspan='2'>自定义系数</td></tr>"
- newString += this.getOneRow('定额', 0, 'coe_ration');
- newString += this.getOneRow('人工', 1, 'manual');
- newString += this.getOneRow('材料', 2, 'material');
- newString += this.getOneRow('机械', 3, 'manchine');
- newString += this.getOneRow('主材', 4, 'mainM');
- newString += this.getOneRow('设备', 5, 'equipment');
- newString += "</table></form>";
- return newString;
- //"<form id='edit'><table border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;font-size: 10px;><tr style='height:10px'><td style='width: 50px'>定额:</td><td style='width: 70px' align='right'><input type='text'value='1' name='ration' style='width:30px;border:0;height:14px' align='right'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr ><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr></table></form>";
- },
- getOneRow: function (text, name, id) {
- var rowstr = "<tr style='height:10px'><td style='width: 50px'>" + text
- + ":</td><td style='width: 70px' align='right'><input type='text'value='1' name=" + name
- + " style='width:30px;border:0;height:14px' align='right' id=" + id + " onchange='gljOprObj.onInputChange(this.id,this.name)'></td></tr>";
- return rowstr;
- },
- showDataIfRationSelect: function (node) {
- var isShow = false;
- if (node) {
- if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
- return;
- } else {
- this.selectedNodeId = node.getID();
- }
- if (node.sourceType == "ration") {
- this.showRationGLJData(node);
- this.showRationCoeData(node);
- this.showRationAssData(node);
- isShow = true;
- }
- this.showQuantityDetailData(node);
- } else {
- this.selectedNodeId = null;
- }
- if (!isShow) {
- this.clearSheetData();
- }
- //hide floatingObject
- var floatingObject = this.coeSheet.floatingObjects.get('customerCoe');
- if (floatingObject) {
- floatingObject.isVisible(false);
- }
- // $('#dropdown').hide();
- },
- showRationGLJData: function (node) {
- var gljList = [];
- var ration_glj = projectObj.project.ration_glj;
- node = node ? node : projectObj.project.mainTree.selected;
- if (node.sourceType == ModuleNames.ration) {
- let ration = node.data;
- gljList = this.filterGljByRation(ration, ration_glj.datas);
- this.showInSheet(gljList);
- }
- },
- showRationGLJSheetData: function (init) {
- this.combineWithProjectGlj(this.sheetData);
- this.sheet.setRowCount(0);
- //console.log(+new Date())
- //this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true); //这个方法导致加载缓慢
- this.sheetData = sortRationGLJ(this.sheetData);
- this.sumQuantity();//计算总消耗量
- this.addMixRatioToShow();//显示组成物信息
- this.initRationTree(init);
- sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
- },
- initRationTree: function (init) {
- this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType(this.sheetData));
- for (var i = 0; i < this.sheetData.length; i++) {
- if (this.sheetData[i].hasOwnProperty('subList')) {
- var collapsed = false;
- if (init) {
- this.sheetData[i].collapsed = true;
- collapsed = true;
- } else {
- collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
- }
- if (collapsed == true) {
- this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
- }
- //this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).visible(!collapsed);// this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).locked(true);
- //这个方法导致加载缓慢
- }
- }
- },
- filterGljByRation: function (ration, datas) {
- var gljList = [];
- if (datas && datas.length > 0) {
- gljList = _.filter(datas, {'rationID': ration.ID})
- }
- return gljList;
- },
- showInSheet: function (gljList) {
- this.sheetData = gljList;
- this.showRationGLJSheetData(true);
- },
- sumQuantity: function (node) {
- if (this.sheetData.length > 0) {
- node = node ? node : projectObj.project.mainTree.selected;
- let ration = node.data;
- let quantity = ration.quantity;
- quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 1 : quantity;
- for (let glj of this.sheetData) {
- glj.totalQuantity= this.getTotalQuantity(glj,ration);
- }
- }
- },
- getTotalQuantity:function(glj,ration){
- ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
- if(ration){
- let quantity = ration.quantity;
- quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 1 : quantity;
- if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
- return;
- }
- quantity = scMathUtil.roundForObj(quantity, getDecimal("ration.quantity"));//计算前进行4舍5入
- glj.quantity = scMathUtil.roundForObj(glj.quantity, getDecimal("glj.quantity"));
- glj.totalQuantity = scMathUtil.roundToString(quantity * glj.quantity, getDecimal("glj.quantity"));
- if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
- for (let subG of glj.subList) {
- subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
- subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * glj.totalQuantity, getDecimal("glj.quantity"));
- }
- }
- return glj.totalQuantity;
- }
- },
- addMixRatioToShow: function () {
- var newList = [];
- _.remove(this.sheetData, {'isMixRatio': true});
- for (var i = 0; i < this.sheetData.length; i++) {
- newList.push(this.sheetData[i]);
- if (this.sheetData[i].hasOwnProperty('subList')) {
- newList = newList.concat(this.sheetData[i].subList);
- }
- }
- this.sheetData = newList;
- },
- combineWithProjectGlj: function (ration_gljs) {
- var projectGLJData = projectObj.project.projectGLJ.datas;
- var projectGljs = projectGLJData.gljList;
- var mixRatioMap = projectGLJData.mixRatioMap;
- if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
- for (var i = 0; i < ration_gljs.length; i++) {
- var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
- if (glj) {
- let typeString = ration_gljs[i].type + "";
- if (typeString.indexOf("2") != -1) {//只有材料类型才显示是否暂估
- ration_gljs[i].isEstimate = glj.is_evaluate;
- }
- ration_gljs[i].isAdd = glj.unit_price.is_add;
- ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
- var connect_index = this.getIndex(glj, gljKeyArray)
- if (mixRatioMap.hasOwnProperty(connect_index)) {
- var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
- ration_gljs[i].subList = mixRatios;
- }
- }
- }
- }
- return ration_gljs;
- },
- setGLJPrice:function (data,glj) {
- glj = glj?glj:_.find(projectObj.project.projectGLJ.datas.projectGljs, {'id': ration_gljs[i].projectGLJID});
- if(this.calcPriceDiff(glj)==true) {//计取价差
- data.basePrice = glj.unit_price.base_price;
- data.marketPrice = glj.unit_price.market_price;
- data.adjustPrice = projectObj.project.projectGLJ.getAdjustPrice(glj);
- }else {//不计价差
- data.basePrice = glj.unit_price.market_price;
- data.marketPrice = glj.unit_price.market_price;
- data.adjustPrice = glj.unit_price.market_price;
- }
- return data;
- },
- calcPriceDiff:function (glj) {
- let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
- if(glj.is_evaluate==1){//先按是否暂估判断
- return calcOptions.calc_est;
- }
- if(glj.type==gljType.MAIN_MATERIAL||glj.type==gljType.EQUIPMENT){//再判断是否是主材和设备
- return calcOptions.calc_main;
- }
- if(glj.unit_price.is_add==1){//再判断是否新增
- return calcOptions.calc_add;
- }
- return true;
- },
- getIndex(obj, pops){
- let t_index = '';
- let k_arr = [];
- for (let p of pops) {
- let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
- k_arr.push(tmpK);
- }
- t_index = k_arr.join("|-|");
- return t_index;
- },
- getMixRationShowDatas: function (mixRatioList, projectGljs) {
- var temRationGLJs = [];
- for (var i = 0; i < mixRatioList.length; i++) {
- var pg = _.find(projectGljs, {
- 'code': mixRatioList[i].code,
- 'name': mixRatioList[i].name,
- 'specs': mixRatioList[i].specs,
- 'type': mixRatioList[i].type,
- 'unit': mixRatioList[i].unit
- });//改关联关系
- var tem = {
- projectGLJID: pg.id,
- code: pg.code,
- name: pg.name,
- specs: pg.specs,
- unit: pg.unit,
- shortName: pg.unit_price.short_name,
- rationItemQuantity: mixRatioList[i].consumption,
- // quantity:mixRatioList[i].consumption,
- basePrice: pg.unit_price.base_price,
- marketPrice: pg.unit_price.market_price,
- adjustPrice: pg.adjust_price,
- isEstimate: pg.is_evaluate,
- isMixRatio: true,
- isAdd: pg.unit_price.is_add,
- GLJID: pg.glj_id
- }
- temRationGLJs.push(tem);
- }
- temRationGLJs = _.sortBy(temRationGLJs, 'code');
- return temRationGLJs;
- },
- showRationCoeData: function (node) {
- var coeList = [];
- var ration_coe = projectObj.project.ration_coe;
- var ration = node.data;
- if (ration_coe.datas && ration_coe.datas.length > 0) {
- coeList = _.filter(ration_coe.datas, {'projectID': ration.projectID, 'rationID': ration.ID})
- }
- this.showCoeData(this.coeSheet, this.coeSetting, coeList);
- this.coeSheetData = coeList;
- },
- showRationAssData: function (node) {
- var assList = node.data.rationAssList ? node.data.rationAssList : [];
- sheetCommonObj.showData(this.assSheet, this.assSetting, assList);
- this.assSheetData = assList;
- },
- showQuantityDetailData: function (node) {
- var details = [];
- node = node ? node : projectObj.project.mainTree.selected;
- var quantity_detail = projectObj.project.quantity_detail;
- if (node.sourceType == ModuleNames.ration) {
- details = _.filter(quantity_detail.datas, {'rationID': node.data.ID});
- } else if (node.sourceType == ModuleNames.bills) {
- details = _.filter(quantity_detail.datas, {'billID': node.data.ID});
- }
- details = _.sortBy(details, 'seq');
- sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
- this.detailData = details;
- if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
- this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
- }
- },
- clearSheetData: function () {
- sheetCommonObj.showData(this.sheet, this.setting, []);
- sheetCommonObj.showData(this.coeSheet, this.coeSetting, []);
- sheetCommonObj.showData(this.assSheet, this.assSetting, []);
- // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
- this.sheetData = [];
- this.coeSheetData = [];
- this.assSheetData = [];
- //this.detailData=[];
- },
- /* lockRationGLJCell:function(){
- sheetCommonObj.lockCells(this.sheet,this.setting);
- },
- lockRationCoeCell:function () {
- sheetCommonObj.lockCells(this.coeSheet,this.coeSetting);
- /!* if(this.coeSheetData){
- for(var i =0;i<this.coeSheetData.length;i++){
- if(this.coeSheetData[i].coeID==-1){
- this.coeSheet.getCell(i, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
- }
- }
- }*!/
- },
- lockRationGLJCell:function(){
- sheetCommonObj.lockCells(this.sheet,this.setting);
- },*/
- updateRationGLJ: function (args) {
- var me = this;
- var updateField = me.setting.header[args.col].dataCode;
- var recode = me.sheetData[args.row];
- var newval;
- if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
- if (args.editingText == null) {
- updateField == 'marketPrice' ? newval = 0 : newval = "";
- } else {
- var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : getDecimal("glj.unitPrice");
- newval = number_util.checkNumberValue(args.editingText, decimal);
- if (newval == null) {
- me.sheet.getCell(args.row, args.col).value(recode[updateField]);
- return;
- }
- }
- } else {
- if (updateField == 'name' || updateField == 'unit') {
- if (args.editingText === null) {
- alert(me.setting.header[args.col].headerName + '不能为空!');
- me.sheet.getCell(args.row, args.col).value(recode[updateField]);
- return;
- }
- }
- newval = args.editingText == null ? "" : args.editingText;
- }
- if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
- return
- }
- if (updateField == 'marketPrice' || updateField == 'basePrice') {
- projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
- } else {
- projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
- }
- },
- updateRationTypeGLJ: function (value, node, fieldName) {
- console.log(fieldName)
- console.log(value);
- let newval;
- let updatePrice = false;
- if (fieldName == "marketUnitFee") {
- updatePrice = true;
- if (value == null) {
- newval = 0;
- } else {
- var decimal = getDecimal("glj.unitPrice");
- newval = number_util.checkNumberValue(value, decimal);
- }
- } else {
- if (value != null) {
- projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value)
- return;
- //update
- }
- }
- if (newval && updatePrice == true) {
- projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
- return
- }
- projectObj.mainController.refreshTreeNode([node]);
- },
- updateRationAss: function (args) {
- var me = gljOprObj;
- var newval;
- newval = me.numberValueChecking(args.editingText);
- var recode = me.assSheetData[args.row];
- if (args.editingText === null) {
- newval = parseFloat(recode.stdValue);
- }
- var isValidate = false;
- if (newval) {
- isValidate = me.checkingActualValue(recode, newval)
- }
- if (isValidate) {
- newval = scMathUtil.roundTo(newval, -2);
- projectObj.project.ration_ass.updateActualValue(me.assSheetData, args.row, newval)
- } else {
- newval = recode.actualValue;
- me.assSheet.getCell(args.row, args.col).value(newval);
- }
- },
- updateRationCoe: function (args, newval) {
- var me = gljOprObj;
- var recode = me.coeSheetData[args.row];
- projectObj.project.ration_coe.adjustCoeClick(recode, newval);
- },
- numberValueChecking: function (val) {
- var newval = Number(val);
- if (number_util.isNumber(newval)) {
- return newval;
- } else {
- if (val) {
- alert('您输入的数据类型不正确,请重新输入。');
- }
- newval = null;
- }
- return newval;
- },
- checkingActualValue(record, newval){
- var minExist = record.minValue && record.minValue != '0' ? true : false;
- var maxExist = record.maxValue && record.maxValue != '0' ? true : false;
- var minValue = parseFloat(record.minValue);
- var maxValue = parseFloat(record.maxValue);
- var stdVale = parseFloat(record.stdValue);
- if (!maxExist && minExist) {
- if (newval < minValue) {
- alert('实际值应≥' + minValue);
- return false;
- }
- }
- if (maxExist && !minExist) {
- if (newval > maxValue) {
- alert('实际值应≤' + maxValue);
- return false;
- }
- }
- if (maxExist && minExist) {
- if (newval < minValue || newval > maxValue) {
- alert('实际值应介于' + minValue + '~' + maxValue + '之间');
- return false;
- }
- }
- return true;
- },
- showLibGLJSheetData: function () {
- this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
- this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
- sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
- },
- filterLibGLJSheetData: function () {
- let me = this;
- let val = $("input[name='glj']:checked").val();
- if (val == 'allGljs') {
- me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
- } else {
- me.gljLibSheetData = me[val];
- }
- if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
- me.filterLibGLJByType();
- }
- if (me.gljCurTypeId == undefined) {
- return;
- }
- if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
- me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
- return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
- });
- } else {
- me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
- }
- },
- setGLJSelection: function (args, newVal) {
- if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
- this.addGLJsSelection(args, newVal);
- } else {
- this.replaceGLJSelection(args, newVal);
- }
- },
- addGLJsSelection: function (args, newVal) {
- var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
- if (newVal == 1) {
- this.GLJSelection.push(con_key);
- this.gljLibSheetData[args.row].select = 1;
- } else if (newVal == 0) {
- _.pull(this.GLJSelection, con_key);
- this.gljLibSheetData[args.row].select = 0;
- }
- },
- replaceGLJSelection: function (args, newVal) {
- var me = this;
- var oldSelection = this.GLJSelection[0];
- if (newVal == 0) {
- args.sheet.getCell(args.row, args.col).value(1);
- return;
- }
- this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
- this.gljLibSheetData[args.row].select = 1;
- var oindex = _.findIndex(this.gljLibSheetData, function (item) {
- var i_key = me.getIndex(item, gljLibKeyArray);
- return oldSelection == i_key;
- });
- if (oindex != -1) {
- args.sheet.getCell(oindex, args.col).value(0);
- this.gljLibSheetData[oindex].select = 0;
- } else {
- var oldData = _.find(gljOprObj.AllRecode, function (item) {
- var i_key = me.getIndex(item, gljLibKeyArray);
- return oldSelection == i_key;
- });
- oldData ? oldData.select = 0 : "";
- }
- },
- filterLibGLJByType: function () {
- var me = this;
- var selected = me.sheetData[gljContextMenu.selectedRow];
- me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
- },
- getComboData: function (gljDistType) {
- let me = this;
- let distType;
- let distTypeTree = {
- prefix: 'gljType',
- distTypes: {},
- comboDatas: [],
- distTypesArr: []
- };
- gljDistType.forEach(function (typeData) {
- let typeObj = {
- data: typeData,
- children: [],
- parent: null
- }
- distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
- distTypeTree.distTypesArr.push(typeObj);
- });
- gljDistType.forEach(function (typeData) {
- distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
- let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
- if (parent) {
- distType.parent = parent;
- parent.children.push(distType);
- }
- });
- distTypeTree.distTypesArr.forEach(function (distTypeObj) {
- if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
- distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
- }
- });
- return distTypeTree;
- },
- doInsertGLJ: function () {
- var selected = projectObj.project.mainTree.selected;
- var project = projectObj.project;
- if (gljOprObj.GLJSelection.length <= 0) {
- return;
- }
- $("#glj_tree_div").modal('hide');
- project.ration_glj.insertGLJAsRation(gljOprObj.GLJSelection, selected, function (result) {
- project.projectGLJ.loadData();
- gljOprObj.showRationGLJSheetData();
- })
- },
- doAddGLJ: function () {
- var selected = projectObj.project.mainTree.selected;
- var project = projectObj.project;
- gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
- var rg = _.find(gljOprObj.sheetData, function (item) {
- var i_key = gljOprObj.getIndex(item, gljKeyArray);
- return n == i_key
- })
- return rg ? false : true;
- })
- if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
- $("#glj_tree_div").modal('hide');
- project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
- if (result) {
- selected.data.adjustState = result.adjustState;
- //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
- project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
- gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
- gljOprObj.showRationGLJSheetData();
- project.ration_glj.addToMainTree(result.showData);
- project.projectGLJ.loadData();
- project.calcProgram.calculate(selected);
- project.calcProgram.saveNode(selected);
- projectObj.mainController.refreshTreeNode([selected]);
- $.bootstrapLoading.end();
- }
- });//doc.rationID=selected.data.ID;
- } else {
- $("#glj_tree_div").modal('hide');
- }
- },
- doReplaceGLJ: function () {
- var me = this;
- var oldData = me.sheetData[gljContextMenu.selectedRow];
- var project = projectObj.project;
- var selectCode = gljOprObj.GLJSelection[0];
- var selected = projectObj.project.mainTree.selected;
- $("#glj_tree_div").modal('hide');
- project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
- if (result) {
- //result.adjustState;
- var glj_list = projectObj.project.ration_glj.datas;
- var data = result.data;
- var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
- var list_index = _.findIndex(glj_list, {'ID': data.ID});
- var nodes = [selected];
- gljOprObj.sheetData[index] = data;
- glj_list[list_index] = data;
- gljOprObj.showRationGLJSheetData();
- if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
- var node = project.ration_glj.findGLJNodeByID(data.ID);
- if (node) {
- project.ration_glj.transferToNodeData(data);
- node.source = data;
- node.data = data;
- }
- node ? nodes.push(node) : "";
- }
- //project.ration_glj.addToMainTree(data);
- project.projectGLJ.loadData();
- selected.data.adjustState = result.adjustState;
- projectObj.mainController.refreshTreeNode(nodes);
- project.calcProgram.calculate(selected);
- project.calcProgram.saveNode(selected);
- }
- $.bootstrapLoading.end();
- })
- },
- doMReplaceGLJ: function () {
- var me = this;
- var oldData = me.sheetData[gljContextMenu.selectedRow];
- var project = projectObj.project;
- var selectCode = me.GLJSelection[0];
- $("#glj_tree_div").modal('hide');
- project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result) {
- var data = result.data;
- var stateList = result.stateList;
- var n_index = me.getIndex(data.query, gljKeyArray);
- var nodes = [];
- _.forEach(project.ration_glj.datas, function (t) {
- var t_index = me.getIndex(t, gljKeyArray);
- if (n_index == t_index) {
- me.updateProperty(t, data.doc);
- if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
- project.ration_glj.transferToNodeData(t);
- var node = project.ration_glj.findGLJNodeByID(t.ID);
- nodes.push(node);
- }
- }
- })
- me.showRationGLJSheetData();
- project.projectGLJ.loadData();
- var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
- project.calcProgram.calcRationsAndSave(rationNodes);
- $.bootstrapLoading.end();
- })
- },
- updateProperty: function (obj, doc) {
- _.forEach(doc, function (n, key) {
- obj[key] = n;
- });
- },
- refreshStateAfterMreplace: function (stateList, gljNodes) {
- var nodes = [];
- var rationNodes = [];
- _.forEach(stateList, function (s) {
- var node = _.find(projectObj.project.mainTree.items, function (n) {
- return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
- })
- if (node) {
- node.data.adjustState = s.adjustState;
- nodes.push(node);
- rationNodes.push(node);
- }
- });
- gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
- projectObj.mainController.refreshTreeNode(nodes);
- return rationNodes;
- },
- refreshView: function () {
- this.showRationGLJData();
- },
- //
- refreshTreeNode: function (obj) {
- if (!obj) {
- return;
- }
- var objectArray = [];
- var nodes = [];
- if (obj instanceof Array) {
- objectArray.concat(obj);
- } else {
- objectArray.push(obj);
- }
- for (let o of objectArray) {
- var node = _.find(projectObj.project.mainTree.items, function (n) {
- return n.sourceType == o.type && n.data.ID == o.ID;
- })
- if (node) {
- for (var k in o.data) {
- node.data[k] = o.data[k];
- }
- nodes.push(node);
- }
- }
- projectObj.mainController.refreshTreeNode(nodes);
- },
- getTreeNodeCellType: function (data) {
- var ns = GC.Spread.Sheets;
- var rectW = 10;
- var rectH = 10;
- var margin = 3;
- function TreeNodeCellType() {
- }
- function drowRect(ctx, x, y, w, h) {
- ctx.save();
- ctx.strokeStyle = "gray";
- ctx.translate(0.5, 0.5);
- ctx.beginPath();
- var rectX = x + margin;
- var rectY = y + Math.round(h / 2) - rectH / 2;
- ctx.moveTo(rectX, rectY);
- ctx.lineTo(rectX, rectY + rectH);
- ctx.lineTo(rectX + rectW, rectY + rectH);
- ctx.lineTo(rectX + rectW, rectY);
- ctx.lineTo(rectX, rectY);
- ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
- ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
- ctx.stroke();
- ctx.restore();
- }
- function drowSymbol(ctx, x, y, w, h, collapsed) {
- ctx.save();
- ctx.strokeStyle = "#000000";
- ctx.translate(0.5, 0.5);
- ctx.beginPath();
- ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
- ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
- var rectY = y + Math.round(h / 2) - rectH / 2;
- if (collapsed) {
- ctx.moveTo(x + margin + rectW / 2, rectY + 2);
- ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
- }
- ctx.stroke();
- ctx.restore();
- }
- function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
- offset += 6;
- ctx.save();
- ctx.strokeStyle = "gray";
- ctx.translate(0.5, 0.5);
- ctx.beginPath();
- ctx.moveTo(x + offset, y);
- ctx.lineTo(x + offset, y + Math.round(h / 2));
- offset += 9;
- ctx.lineTo(x + offset, y + Math.round(h / 2));
- if (nextItem && nextItem.isMixRatio) {
- ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
- ctx.lineTo(x + offset - 9, y + h);
- }
- ctx.stroke();
- ctx.restore();
- return offset;
- }
- TreeNodeCellType.prototype = new ns.CellTypes.Text();
- TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
- if (value != null) {
- var offset = margin + rectW + 6;
- var recode = data[options.row];
- if (recode && recode.hasOwnProperty('subList')) {
- drowRect(ctx, x, y, w, h);
- var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
- drowSymbol(ctx, x, y, w, h, collapsed);
- } else if (recode && recode.isMixRatio) {
- offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
- offset += 1;
- }
- ctx.fillText(value, x + offset + ctx.measureText(value).width, y + h - 5);
- }
- };
- // override getHitInfo to allow cell type get mouse messages
- TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
- return {
- x: x,
- y: y,
- row: context.row,
- col: context.col,
- cellStyle: cellStyle,
- cellRect: cellRect,
- sheetArea: context.sheetArea
- };
- }
- TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
- var recode = data[hitinfo.row];
- if (recode && recode.hasOwnProperty('subList')) {
- var hoffset = hitinfo.cellRect.x + 3;
- if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
- var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
- collapsed = !collapsed
- recode.collapsed = collapsed;
- //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
- hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
- hitinfo.sheet.invalidateLayout();
- hitinfo.sheet.repaint();
- }
- }
- };
- return new TreeNodeCellType()
- },
- marketPriceReadOnly: function (node) {
- return node.data.type == gljType.CONCRETE || node.data.type == gljType.MORTAR || node.data.type == gljType.MIX_RATIO || node.data.type == gljType.GENERAL_MACHINE || node.data.isEstimate == 1
- }
- }
- $(function () {
- $('#glj_tree_div').on('shown.bs.modal', function (e) {
- if (gljOprObj.gljLibSpresd == undefined) {
- gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
- gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
- gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
- gljOprObj.gljLibSheet.options.isProtected = true;
- gljOprObj.gljLibSheet.name('glj_lib');
- }
- gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
- var selected = null;
- if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
- gljOprObj.GLJSelection = [];
- } else {
- selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
- var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
- gljOprObj.GLJSelection = [connect_key];
- gljOprObj.filterLibGLJByType();
- }
- if (selected != null) {
- var s_key = gljOprObj.getIndex(selected, gljLibKeyArray);
- var r = _.find(gljOprObj.gljLibSheetData, function (item) {
- var item_key = gljOprObj.getIndex(item, gljKeyArray);
- return s_key == item_key;
- });
- r ? r.select = 1 : "";
- }
- gljOprObj.showLibGLJSheetData();
- });
- $('.glj-radio').change(function () {
- let val = $("input[name='glj']:checked").val();
- if (val == 'allGljs') {
- gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
- gljOprObj.filterLibGLJSheetData();
- gljOprObj.showLibGLJSheetData();
- } else {
- gljOprObj.gljLibSheetData = gljOprObj[val];
- gljOprObj.filterLibGLJSheetData();
- gljOprObj.showLibGLJSheetData();
- }
- })
- $('#glj_selected_conf').click(function () {
- if (gljOprObj.GLJSelection.length < 1) {
- return;
- }
- if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
- gljOprObj.doInsertGLJ();
- } else if ($('#actionType').val() == 'add') { //添加工料机
- gljOprObj.doAddGLJ();
- } else if ($('#actionType').val() == 'replace') {//替换工料机
- gljOprObj.doReplaceGLJ();
- } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
- gljOprObj.doMReplaceGLJ();
- }
- })
- $('#class_selected_conf').click(function () {
- var gljClass = $('#selected_class').val();
- var glj = gljOprObj.selectedGLJClass;
- if (glj && gljClass && gljClass != "") {
- //保存到我的工料机库
- /*1 检查是否有组成物
- * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
- * 3 保存
- * */
- var newItem = {
- code: glj.code,
- name: glj.name,
- specs: glj.specs,
- unit: glj.unit,
- basePrice: glj.basePrice,
- gljType: glj.type,
- shortName: glj.shortName,
- component: [],
- gljClass: gljClass
- };
- if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
- for (var i = 0; i < glj.subList.length; i++) {
- let tem = {
- ID: glj.subList[i].GLJID,
- consumeAmt: glj.rationItemQuantity,
- isStd: true
- }
- newItem.component.push(tem);
- }
- }
- var data = getcmpUpdateData([newItem]);
- $.bootstrapLoading.start();
- var callback = function (data) {
- $("#glj_class_div").modal('hide');
- $.bootstrapLoading.end();
- }
- CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
- $.bootstrapLoading.end();
- });
- }
- })
- $('#glj_class_div').on('hidden.bs.modal', function (e) {
- gljOprObj.selectedGLJClass = null;
- $('#class_selected_conf').attr("disabled", "disabled");
- $('#selected_class').val("");
- })
- function getcmpUpdateData(items) {
- var data = {
- "updateItems": [],
- "removeIds": []
- }
- data.addItems = items;
- return data;
- }
- })
- function operationWithRound(value1,value2,field,symble) {
- let decimal = getDecimal(field);
- value1 = scMathUtil.roundForObj(value1,decimal);
- value2 = scMathUtil.roundForObj(value2,decimal);
- let result;
- switch (symble){
- case "+" :
- result=scMathUtil.roundForObj(value1 + value2,decimal);
- break;
- case "-":
- result=scMathUtil.roundForObj(value1 - value2,decimal);
- break;
- case "*":
- result=scMathUtil.roundForObj(value1 * value2,decimal);
- break;
- case "/":
- result=scMathUtil.roundForObj(value1 / value2,decimal);
- break
- }
- return result;
- }
- function getDecimal(fieldID, node) {
- if (node) {
- return decimalObj.decimal(fieldID, node);
- } else if (fieldID.indexOf(".") != -1) {
- var keyArray = fieldID.split(".");
- return decimalObj[keyArray[0]][keyArray[1]];
- } else {
- return decimalObj.decimal(fieldID);
- }
- }
- function getFormatter(decimal) {
- var pre = "0.";
- if (decimal <= 0) {
- return "0";
- }
- for (i = 0; i < decimal; i++) {
- pre += "0"
- }
- return pre;
- }
- function sortRationGLJ(list) {
- list = _.sortByAll(list, [function (item) {
- return item.type + "";
- }, "code"])
- return list;
- }
- function compareRationGLJ(a, b) {
- if ((a.type + "") < (b.type + "")) {
- return true
- }
- if ((a.type + "") == (b.type + "")) {
- if (a.code < b.code) {
- return true
- }
- }
- return false;
- }
|