123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845 |
- /**
- * Created by CSL on 2017-05-12.
- */
- var gljOprObj = {
- sheet: null,
- libID: null,
- ration: null,
- sheetData: [],
- checkb: null,
- rationGljEditObj:null,//编辑定额工料机还没提交的缓存数据
- cancelUpdate:true,
- mainTreeSelectedChange:false,
- detailSheet: null,
- detailData: [],
- GLJSelection: [],
- pagingType: {
- stdGLJ: 1,
- complementaryGLJs: 2
- },
- // 是否正在分页
- loadingPagination: false,
- // 当前筛选条件下总数据数,用于判断是否需要继续分页
- curPageTotal: 0,
- selectedGLJClass: null,
- parentNodeIds: {},
- preActiveTab: '', //提升焦点变换性能 2019年4月12日
- activeTab: '#linkGLJ',
- rationTab:'#linkGLJ',
- billsTab:'#linkQDJL',
- setting: {},
- 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],
- rowHeaderWidth:25
- }
- },
- gljTreeSetting: {
- view: {
- 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 (treeNode.ID) {
- me.gljCurTypeId = treeNode.ID;
- /* me.filterLibGLJSheetData();
- me.showLibGLJSheetData();*/
- me.loadPageData(gljOprObj.gljLibSheet, true, 0);
- //gljOprObj.initSelection({row: me.gljLibSheet.getActiveRowIndex()});
- }
- } 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: 160, dataCode: "name", dataType: "String", hAlign: "left", vAlign: "center"},
- {headerName: "规格型号", headerWidth: 160, dataCode: "specs", dataType: "String", hAlign: "left", vAlign: "center"},
- {headerName: "单位", headerWidth: 40, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center"},
- {headerName: "单价", headerWidth: 55, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
- {headerName: "类型", headerWidth: 60, dataCode: "typeName", dataType: "String", hAlign: "center", vAlign: "center"},
- {headerName: "新增", headerWidth: 40, dataCode: "isComplementary", dataType: "String", hAlign: "center", vAlign: "center", cellType: "checkBox", readOnly: true}
- ],
- view: {
- lockColumns: [0, 1, 2, 3, 4, 5, 6]
- }
- },
- gljLibSheet: null,
- scopeSetting:{},
- scopeSpread:null,
- scopeSheet:null,
- scopeDatas:[],
- scopeSelectedIDMap:{},
- 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.CellDoubleClick, me.onCellDoubleClick);
- sheet.bind(GC.Spread.Sheets.Events.ClipboardChanged, me.onClipboardChanged);
- subSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClick);
- if(!projectReadOnly){
- gljContextMenu.loadGLJSpreadContextMenu();
- me.bindGLJEnterKey(subSpread,sheet);
- }
- sheet.bind(GC.Spread.Sheets.Events.SelectionChanged,me.onRationGLJSelectionChange);
- sheet.bind(GC.Spread.Sheets.Events.CellClick,function () {
- //这里主要记录是否点击了sheet以外的地方,如果点击了sheet里的单元格,则将cancelUpdate设置为true不触发提交更新操作
- me.cancelUpdate = true;//取消延时任务由selection change 事件处理
- });
- },
- onRationGLJSelectionChange:function(sender,args){
- let me = gljOprObj;
- let selected = args.newSelections[0] ? args.newSelections[0] : {row: 0, col: 0};
- console.log("selected changed-------");
- //这主要记录是否点击了sheet以外的地方,如果点击了sheet里的单元格,则将cancelUpdate设置为true不触发提交更新操作
- me.cancelUpdate = true;//取消延时任务由这里进行判断处理
- console.log("change to true");
- me.sheetInitSelection(selected);
- if(me.rationGljEditObj){
- if(ifNeedUpdate(selected)){
- me.updateGljFromCache();
- }
- }
- function ifNeedUpdate(selected) {
- let navigationRightCol = me.setting.navigationRightCol , fieldID = me.setting.header[selected.col].dataCode;
- if(me.rationGljEditObj.row == selected.row && navigationRightCol.indexOf(fieldID)!= -1){//如果换行或者超出了三个编辑列,则提交更新
- return false;
- }
- return true;
- }
- },
- updateGljFromCache:function () {
- let me = this;
- if(me.rationGljEditObj){
- projectObj.project.ration_glj.submitChange(me.rationGljEditObj.recode, me.rationGljEditObj.doc);
- }
- me.rationGljEditObj = null;
- },
- bindGLJEnterKey:function (spread,sheet) {
- let me = this;
- subSpread.commandManager().register('myEnter', enterKeyAction);
- subSpread.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.enter, false, false, false, false);
- subSpread.commandManager().setShortcutKey('myEnter', GC.Spread.Commands.Key.enter, false, false, false, false);
- function enterKeyAction(spd,sheeName) {
- let editRow = sheet.getActiveRowIndex(),orgCol = sheet.getActiveColumnIndex();
- let fieldID = me.setting.header[orgCol].dataCode;
- if(sheeName=="ration_glj" && me.setting.navigationRightCol.indexOf(fieldID) != -1){
- if(sheet.isEditing()) sheet.endEdit();
- GC.Spread.Sheets.Commands.navigationRight.execute(spd,sheeName);
- }else {
- GC.Spread.Sheets.Commands.commitInputNavigationDown.execute(spd,sheeName);
- }
- }
- },
- sheetInitSelection: function (selected) {
- let me = gljOprObj;
- let style = {};
- if(selected.row < me.sheetData.length){
- if(me.setting.getStyle) style = me.setting.getStyle(me.sheetData[selected.row]);
- me.sheet.setStyle(selected.row, -1, me.getSelStyle(true,style));
- }
- me.sheet.repaint();
- if(me.preGljSelection && me.preGljSelection.row !== selected.row){
- if(me.setting.getStyle && me.preGljSelection.row < me.sheetData.length) style = me.setting.getStyle(me.sheetData[me.preGljSelection.row]);
- me.sheet.setStyle(me.preGljSelection.row, -1, me.getSelStyle(false,style));
- }
- me.preGljSelection = selected;
- },
- 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);
- },
- detailSheetReadonly:function () {
- let selected = projectObj.project.mainTree.selected;
- let Bills = projectObj.project.Bills;
- if(selected) {
- //清单锁定时只读
- if(selected.sourceType == ModuleNames.bills && projectObj.project.isBillsLocked() && projectObj.project.withinBillsLocked(selected)){
- return true;
- }
- //大项费用、分部节点层次时,工程量明细只读。
- if(indicativeInfoObj.isDXFY(selected) || indicativeInfoObj.isFB(selected)){
- return true;
- }
- //是主材或者是设备时只读
- if(selected.sourceType == ModuleNames.ration_glj){
- return true;
- }else if(gljOprObj.isInstallationNode(selected) || OVER_HEIGHT.isOverHeight(selected)){//是补项或者是安装、超高类型的定额时只读
- return true;
- }
- return false;
- }
- return true;
- },
- 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.EditStarting, me.startEditChecking);
- // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
- },
- onClipboardPasting: function (sender, args) {
- var me = gljOprObj;
- if(args.sheetName!="quantity_detail"&&(args.cellRange.rowCount!=1||args.cellRange.colCount!=1)){//工程量明细做特殊处理
- args.cancel = true;
- }
- },
- onClipboardPasted: function (e, info) {
- var me = gljOprObj;
- console.log('past');
- // if (!me.ration) {return;};
- // your code...
- },
- startEditChecking:function (sender,args) {
- let me = gljOprObj;
- let selected = projectObj.project.mainTree.selected;
- if($.bootstrapLoading.isLoading()) args.cancel = true;
- if(selected){
- if(me.isInstallationNode(selected)==true || OVER_HEIGHT.isOverHeight(selected)){
- args.cancel = true;
- }else {
- if(args.sheetName == 'quantity_detail'){//工程量明细表
- if(me.detailSheetReadonly()){
- args.cancel = true;
- }else {
- if(args.sheet.getValue(args.row,args.col)==null){//这里是为了解决当单元格里的值是null的时候,在单元格里输入数据,按键盘箭头移动光标的时候,会直接结束编辑,跳到另外的单元格。
- args.sheet.setValue(args.row,args.col,"");
- }
- }
- }
- if(args.sheetName == 'ration_glj'){//定额工料机表
- if(!me.rationGLJEditCheck(args)) args.cancel = true;
- }
- }
- }else {
- args.cancel = true;
- }
- },
- isInstallationNode:function(node){
- if(node.sourceType == ModuleNames.ration&&node.data.type == rationType.install){//是定额安装费类型时只读,原先是补项的时候也是控制只读的||(node.sourceType == ModuleNames.bills&&node.data.type==billType.BX)){//是定额安装费类型或者补项
- return true;
- }
- return false
- },
- onEditEnded: function (sender, args) {
- var me = gljOprObj;
- if (args.sheetName == 'ration_glj') {
- me.onEditGLJSheet(args)
- }
- if (args.sheetName == 'quantity_detail') {
- me.onEditDetailSheet(args);
- }
- },
- onEditDetailSheet: function (args,callback) {
- 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;
- if(args.editingText){
- args.editingText = args.editingText.replace(/(/g, "(");//替换中文左右括号;
- args.editingText = args.editingText.replace(/)/g, ")");
- }
- if (args.row == detailList.length) {
- projectObj.project.quantity_detail.saveQuantityDetail(args, me.detailSetting.header[args.col].dataCode, selected,callback);
- }
- if (args.row < detailList.length) {
- projectObj.project.quantity_detail.updateQuantityDetail(args, me.detailSetting.header[args.col].dataCode, detailList[args.row], selected,callback);
- }
- },
- 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);
- },
- onSelectionChanged: function (sender, args) {
- let me = gljOprObj;
- me.initSelection(args.newSelections.length > 0 ? {row: args.newSelections[0].row} : {row: 0});
- },
- onTopRowChanged: function (sender, args) {
- const me = gljOprObj;
- const topRow = args.newTopRow;
- const bottomRow = args.sheet.getViewportBottomRow(1);
- const radioType = $("input[name='glj']:checked").val();
- const curRecord = radioType === 'stdGLJ' ? me.stdGLJ : me.complementaryGLJs;
- // 当前表显示数据数大于等于当前筛选情况下最大数据数,不获取下一分页
- if (curRecord.length >= me.curPageTotal ||
- me.loadingPagination) {
- return;
- }
- if (curRecord.length -1 === bottomRow) {
- // 获取第curRecord.length行开始的数据
- me.loadPageData(args.sheet, false, curRecord.length);
- }
- },
- loadPageData: function (sheet, reset, index) {
- let condition = this.getPagingCondition(false, reset, false, index);
- projectObj.project.ration_glj.getGLJDataPaging(condition, function (data) {
- sheetCommonObj.appendData(sheet, condition.index, 0, gljOprObj.gljLibSheetSetting, data);
- gljOprObj.initSelection({row: gljOprObj.gljLibSheet.getActiveRowIndex()});
- });
- },
- getSelStyle: function (selected,settingStyle) {
- 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 colorOpts = optionsOprObj.getOption(optionsOprObj.optionsTypes.COLOROPTS);
- let selectedColor = colorOpts.SELECTED.backColor,
- recColor = 'White';
- style.backColor = selected ? selectedColor : recColor;
- return style;
- },
- initSelection: function (sel) {
- let me = gljOprObj;
- if(sel){
- sel.row = !sel.row || sel.row == -1 ? 0 : sel.row;
- me.gljLibSheet.setStyle(sel.row, -1, me.getSelStyle(true));
- }
- if(me.preGljLibSelection && me.preGljLibSelection.row !== sel.row){
- me.gljLibSheet.setStyle(me.preGljLibSelection.row, -1, me.getSelStyle(false));
- }
- me.preGljLibSelection = sel;
- },
- onButtonClick: function (sender, args) {
- if(args.sheet.isEditing()){
- args.sheet.endEdit();
- }
- 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) {
- if(args.sheetName == 'rationInstallSheet'){
- installationFeeObj.onPositionButtonClick(sender,args);
- }
- } else {
- me.onCheckBoxClick(sender, args)
- }
- },
- onCheckBoxClick: function (sender, args) {
- let selected = projectObj.project.mainTree.selected;
- if(selected.sourceType == ModuleNames.ration_glj){//选中的是工料机时不可编辑
- return ;
- }
- let checkboxValue = args.sheet.getCell(args.row, args.col).value();
- if(args.sheetName == 'rationInstallSheet' && checkboxValue){
- return;
- }
- if(gljOprObj.isInstallationNode(selected)==true || OVER_HEIGHT.isOverHeight(selected)){
- return;
- }
- let newval = checkboxValue? 0:1;
- args.sheet.getCell(args.row, args.col).value(newval);
- if (args.sheetName == 'ration_glj') {
- gljOprObj.updateIsEstimate(args,newval);
- } else if (args.sheetName == 'quantity_detail') {
- projectObj.project.quantity_detail.isSummationUpdate(args, gljOprObj.detailData, newval);
- } else if (args.sheetName == 'glj_lib') {
- if (gljOprObj.gljLibSheetSetting.header[args.col].readOnly) {
- args.sheet.getCell(args.row, args.col).value(checkboxValue);
- return;
- }
- if(gljOprObj.gljLibSheetSetting.header[args.col].dataCode === 'select'){
- gljOprObj.setGLJSelection(args, newval);
- }
- }else if(args.sheetName == 'rationInstallSheet'){
- args.newValue = newval;
- installationFeeObj.onRationInstallValueChange(sender,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("当前工料机的定额价由组成物计算得出,不可直接修改。");
- }
- }
- }*/
- },
- onClipboardChanged: function (sender, info) {
- let cDatas = sheetCommonObj.getTableData(info.sheet, null);
- sheetCommonObj.copyTextToClipboard(cDatas);
- return;
- },
- rationGLJEditCheck:function (args) {//true 可以编辑,false 不能编辑
- let me = gljOprObj,header = me.setting.header;
- let dataCode = header[args.col] && header[args.col].dataCode?header[args.col].dataCode:null,recode = me.sheetData[args.row];
- if(me.sheet.getTag(args.row,args.col)=="locked") return false;//如果是双击树节点编号里设置了锁定标记,不能编辑
- if (_.includes(me.setting.view.lockColumns, args.col)) return false;//如果是锁定的列,不能编辑
- if(recode != undefined){
- if(recode.isMixRatio){//对于组成物列
- return dataCode == 'marketPrice'//允许修改组成物市单价,其它的不可以
- }else {
- if (dataCode && dataCode == 'marketPrice') {
- return !me.marketPriceReadOnly({data:me.sheetData[args.row]});
- }
- if (dataCode && dataCode == 'basePrice') {
- var isAdd = recode.isAdd;
- if(isAdd==1){//是新增但没有组成物时允许修改定额价
- return !me.marketPriceReadOnly({data:recode});//如果有组成物,不可修改
- } else {
- return false;
- }
- }
- if(me.isExtraType(recode.type)&&(dataCode == 'name'||dataCode == 'specs'||dataCode == 'unit')){//人材机窗口中的“企业管理费”“利润”“一般风险费”的名称、规格、单位改为只读。
- return false;
- }
- return true;
- }
- }else {
- return false
- }
- },
- hasComposition:function (ration_glj,isRationType) {//判断是否有组成物,有则返回true 现在主材类型的工料机也有可能有组成物。
- let type = isRationType==true? ration_glj.subType:ration_glj.type;
- if(gljUtil.notEditType.indexOf(type)!=-1||type==gljType.MAIN_MATERIAL){
- let keyArray = isRationType==true? rationKeyArray:gljKeyArray;
- let con_key = this.getIndex(ration_glj,keyArray);
- var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
- if(mixRatioMap[con_key]&&mixRatioMap[con_key].length>0){
- return true;
- }
- }
- return false;
- },
- onRangeChanged: function (sender, args) {
- var me = gljOprObj;
- if(args.sheetName == 'quantity_detail'){
- me.batchUpdateQuantityDetail(args);
- }else {
- if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
- args.editingText = null;
- }else if(args.action == GC.Spread.Sheets.RangeChangedAction.paste){
- args.editingText = args.sheet.getCell(args.row,args.col).value();
- }else {
- return;
- }
- if (args.sheetName == 'ration_glj') {
- me.onEditGLJSheet(args);
- }
- }
- },
- batchUpdateQuantityDetail:function (args) {
- let me = gljOprObj;
- let updateArray = [];
- for(let i =0;i<args.changedCells.length;i++){
- let c = args.changedCells[i];
- let tem = {
- row:c.row,
- col:c.col,
- editingText:args.sheet.getCell(c.row,c.col).text(),
- sheet:args.sheet,
- sheetName:args.sheetName,
- index:i
- };
- updateArray.push(tem);
- }
- if(updateArray.length>0){
- updateArray.length == 1?me.onEditDetailSheet(updateArray[0]):me.onEditDetailSheet(updateArray[0],updateCallback);
- }
- function updateCallback(i_args) {
- let index = i_args.index;
- if(index < updateArray.length-1){
- let nextIndex = index+1;
- updateArray[nextIndex].replace = i_args.replace;
- if(nextIndex == updateArray.length-1){//是最后一个,则不用调callback了
- me.onEditDetailSheet(updateArray[nextIndex]);
- }else {
- me.onEditDetailSheet(updateArray[nextIndex],updateCallback);
- }
- }
- }
- },
- showDataIfRationSelect: function (node,selectedNodeId) {
- var isShow = false;
- if(projectReadOnly && this.setting.view.lockColumns){
- this.setting.view.lockColumns = null;
- }
- if(selectedNodeId){
- this.selectedNodeId = selectedNodeId;
- }
- if (node) {
- if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
- return;
- } else {
- //恢复底色
- this.sheet.setStyle(this.sheet.getActiveRowIndex(), -1, this.getSelStyle(false,this.setting.style));
- this.selectedNodeId = node.getID();
- }
- if (node.sourceType == "ration") {
- if(node.data.type==rationType.gljRation){
- if($('#linkGLJ').hasClass('active')) this.showMixRatio(node);
- }else {
- if($('#linkGLJ').hasClass('active')){
- this.showRationGLJData(node);
- subObj.showGljSubTabData();
- // MaterialController.showReplaceDiv(node);
- }
- if($('#linkAZZJF').hasClass('active')) installationFeeObj.showRationInstallationData(node);
- if($('#linkMBZM').hasClass('active')) mbzm_obj.showMBZMData(node);
- }
- isShow = true;
- }
- if(node.sourceType == ModuleNames.ration_glj){
- if($('#linkGLJ').hasClass('active')) this.showMixRatio(node);
- MaterialController.hideReplaceDiv();
- isShow = true;
- }
- if($('#linkGCLMX').hasClass('active')) this.showQuantityDetailData(node);
- } else {
- this.selectedNodeId = null;
- }
- if (!isShow) {
- this.clearSheetData();
- MaterialController.hideReplaceDiv();
- }
- //子目换算
- //zmhs_obj.showZMHSData(node);
- // $('#dropdown').hide();
- },
- showMixRatio:function (node) {//显示组成物到定额工料机
- let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
- let projectGljs = projectObj.project.projectGLJ.datas.gljList;
- let indexArray =node.sourceType==ModuleNames.ration?rationKeyArray:gljKeyArray;
- let connect_index = this.getIndex(node.data,indexArray);
- let gljList=[];
- if(mixRatioMap[connect_index]){ //说明是有组成物的类型
- gljList = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
- }
- if(gljList.length>0){//计算总消耗量
- if(node.sourceType==ModuleNames.ration){
- this.calcMixRationTotalQuantity(gljList,node.data.quantity);
- }else {
- let totalQuantity = this.getTotalQuantity(node.data);
- this.calcMixRationTotalQuantity(gljList,totalQuantity)
- }
- }
- this.sheetData = gljList;
- this.sheet.setRowCount(0);
- this.sheetData = gljUtil.sortRationGLJ(this.sheetData);
- this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType([]));
- sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
- //初始选择
- this.preGljSelection = null;
- this.sheetInitSelection({row: this.sheet.getActiveRowIndex(), col: 0});
- this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true);//锁住定额工料机的所有列
- this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);//锁住工程量明细的所有列
- },
- showRationGLJData: function (node) {
- let startTime = +new Date();
- let gljList = [];
- let ration_glj = projectObj.project.ration_glj;
- node = node ? node : projectObj.project.mainTree.selected;
- if (node.sourceType == ModuleNames.ration) {
- if(node.data.type==rationType.gljRation){
- this.showMixRatio(node);
- }else {
- let ration = node.data;
- gljList = this.filterGljByRation(ration, ration_glj.datas);
- this.showInSheet(gljList);
- }
- }else if(node.sourceType == ModuleNames.ration_glj){
- this.showMixRatio(node);
- }
- },
- showRationGLJSheetData: function (init) {
- let me = this;
- let selected = this.sheet.getSelections();
- this.combineWithProjectGlj(this.sheetData);
- this.sheet.setRowCount(0);
- this.sheetData = gljUtil.sortRationGLJ(this.sheetData);
- this.sumQuantity();//计算总消耗量
- this.addMixRatioToShow();//显示组成物信息
- let itreeTime = +new Date();
- this.initRationTree(init,this.getUnitPriceCodeMap());
- sheetCommonObj.showData(this.sheet, this.setting, this.sheetData,null,function () {
- if(me.mainTreeSelectedChange == true){
- me.sheet.setSelection(0,1,1,1);//默认选中第一行,第二列(名称列)
- me.mainTreeSelectedChange = false;
- }else if(selected){//定位光标到之前的位置
- me.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
- }
- //初始选择
- me.preGljSelection = null;
- me.sheetInitSelection({row: me.sheet.getActiveRowIndex(), col: me.sheet.getActiveColumnIndex()});
- });
- },
- getSelectedRationGlj:function () {
- let selected = this.sheet.getSelections()[0];
- let ration_glj = this.sheetData[selected.row];
- return ration_glj;
- },
- getUnitPriceCodeMap : function () {//取单价文件中,编码前缀一样的映射表
- let codeMap = {};
- let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
- if(priceMap){
- for(let connectKey in priceMap){
- let code = priceMap[connectKey].code;
- let name = priceMap[connectKey].name;
- let specs = priceMap[connectKey].specs;
- if(code){
- let displayText = code +" "+name +" "+specs;
- let preCode = code.split("-")[0];
- if(codeMap[preCode]) {
- codeMap[preCode].push({text:displayText,value:connectKey});
- }else {
- codeMap[preCode]=[{text:displayText ,value:connectKey}];
- }
- }
- }
- }
- return codeMap;
- },
- initRationTree: function (init,codeMap) {
- this.sheet.suspendPaint();
- this.sheet.suspendEvent();
- this.sheet.setRowCount(this.sheetData.length >30?this.sheetData.length:30);
- for (var i = 0; i < this.sheetData.length; i++) {
- let options = this.getCodeOptions(this.sheetData[i],codeMap);
- this.sheet.setCellType(i, 0,this.getTreeNodeCellType(this.sheetData,options),GC.Spread.Sheets.SheetArea.viewport);
- if (this.sheetData[i].hasOwnProperty('subList')) {
- var 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.resumeEvent();
- this.sheet.resumePaint();
- },
- getCodeOptions:function (recode,codeMap) {
- let options = [];
- if(recode.isMixRatio ===true){
- return null;
- }
- let code = recode.code;
- if(code) {
- let preCode = code.split("-")[0];
- if( codeMap[preCode]) options = codeMap[preCode];
- if(options.length>0) _.remove(options,{'value':gljOprObj.getIndex(recode, gljKeyArray)})//去掉本身
- }
- return _.sortBy(options,'text');
- },
- 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 == "") ? 0 : quantity;
- for (let glj of this.sheetData) {
- glj.totalQuantity= this.getTotalQuantity(glj,ration);
- }
- }
- },
- getTotalQuantity:function(glj,ration){
- if (glj.isMixRatio == true) return;//如果是用于显示的组成物,则不用计算,跳过
- ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
- glj.totalQuantity = gljUtil.getTotalQuantity(glj,ration,getDecimal("ration.quantity"),getDecimal("glj.quantity"));
- if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
- this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
- }
- return glj.totalQuantity;
- },
- calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
- for (let subG of mList) {
- subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
- subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"));
- }
- },
- 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,needRatio=true,ration,p_gljMap) {
- let projectGLJData = projectObj.project.projectGLJ.datas;
- let projectGljs = projectGLJData.gljList;
- let mixRatioMap = projectGLJData.mixRatioMap;
- if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
- let pgljMap = p_gljMap?p_gljMap:_.indexBy(projectGljs, 'id');
- for (let i = 0; i < ration_gljs.length; i++) {
- let glj = pgljMap[ration_gljs[i].projectGLJID];
- if (glj) {
- if(projectObj.project.projectGLJ.isEstimateType(ration_gljs[i].type )){
- ration_gljs[i].isEstimate = glj.is_evaluate;
- }
- ration_gljs[i].shortName =projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
- ration_gljs[i].isAdd = glj.unit_price.is_add;
- ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
- let connect_index = this.getIndex(glj, gljKeyArray);
- if (needRatio==true&&mixRatioMap.hasOwnProperty(connect_index)) {
- let mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
- ration_gljs[i].subList = mixRatios;
- }
- if(ration) gljOprObj.getTotalQuantity(ration_gljs[i], ration);
- }else {
- console.log("没有找到工料机:"+ration_gljs[i].name)
- }
- }
- }
- return ration_gljs;
- },
- setGLJPrice:function (data,glj,isRadio = false) {//isRadio 标记是否算组成物的价格
- let proGLJ = projectObj.project.projectGLJ;
- let calcOptions=projectObj.project.projectInfo.property.calcOptions;
- let decimalObj = projectObj.project.projectInfo.property.decimal;
- let labourCoeDatas = projectObj.project.labourCoe.datas;
- let tenderCoe = projectObj.project.projectGLJ.getTenderPriceCoe(glj);
- glj = glj?glj:_.find(proGLJ.datas.gljList, {'id': data.projectGLJID});
- if(glj){
- let result = gljUtil.getGLJPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
- data.marketPrice = result.marketPrice;
- data.tenderPrice = result.tenderPrice;
- data.basePrice = result.basePrice;
- data.adjustPrice = result.adjustPrice;
- data.marketUnitFee = data.marketPrice;//更新树节点市场单价列的值
- }
- return data;
- },
- getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
- let proGLJ = projectObj.project.projectGLJ;
- let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
- if(this.calcPriceDiff(glj)==true){
- return proGLJ.getBasePrice(glj);
- }else {
- return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
- }
- },
- calcPriceDiff:function (glj) {
- let calcOptions=projectObj.project.projectInfo.property.calcOptions;
- return gljUtil.calcPriceDiff(glj,calcOptions);
- },
- getIndex(obj, pops){
- return gljUtil.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;*/
- },
- getConditionByKey(conKey){//将连接字符串转换成对象
- let valueArray = conKey.split("|-|");
- let obj ={};
- for(let i = 0;i<valueArray.length;i++){
- if(valueArray[i]!='null'){
- if(gljKeyArray[i]=='type'){
- valueArray[i] = parseInt(valueArray[i]);
- }
- obj[gljKeyArray[i]]=valueArray[i];
- }
- }
- return obj;
- },
- getMixRationShowDatas: function (mixRatioList, projectGljs) {
- var temRationGLJs = [];
- for (var i = 0; i < mixRatioList.length; i++) {
- let mIndex = gljOprObj.getIndex(mixRatioList[i],gljKeyArray);
- var pg = _.find(projectGljs, function (item) {
- return gljOprObj.getIndex(item,gljKeyArray) == mIndex
- });//改关联关系
- if(pg){
- let tem = {
- projectGLJID: pg.id,
- code: pg.code,
- name: pg.name,
- specs: pg.specs,
- unit: pg.unit,
- type:mixRatioList[i].type,
- shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
- consumption:mixRatioList[i].consumption,
- 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
- };
- if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
- tem.isEstimate = pg.is_evaluate;
- }
- this.setGLJPrice(tem,pg);
- temRationGLJs.push(tem);
- }else {
- console.log("没有找到工料机:"+mIndex)
- }
- }
- temRationGLJs = gljUtil.sortRationGLJ(temRationGLJs);
- return temRationGLJs;
- },
- showQuantityDetailData: function (node) {
- node = node ? node : projectObj.project.mainTree.selected;
- var quantity_detail = projectObj.project.quantity_detail;
- let field = node.sourceType == ModuleNames.ration?'rationID':'billID';
- let details = quantity_detail.getListByID(node.data.ID,field);
- 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 () {
- if($('#linkGLJ').hasClass('active')){
- sheetCommonObj.showData(this.sheet, this.setting, []);
- }
- if($('#linkAZZJF').hasClass('active')){
- installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
- sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
- }
- // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
- this.sheetData = [];
- installationFeeObj.rationInstallData = [];
- //this.detailData=[];
- },
- updateRationGLJ: function (args) {
- var me = this;
- var updateField = me.setting.header[args.col].dataCode;
- var recode = me.sheetData[args.row];
- var newval;
- if(!me.rationGLJEditCheck(args)){
- recode? me.sheet.getCell(args.row, args.col).value(recode[updateField]): me.sheet.getCell(args.row, args.col).value(null);
- return;
- }
- if(args.editingText){
- args.editingText = args.editingText.replace(/[\r\n]/g, "");//去掉回车换行等字符;
- me.sheet.getCell(args.row, args.col).value(args.editingText);
- }
- if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
- if (args.editingText == null) {
- updateField == 'marketPrice' ? newval = 0 : newval = "";
- } else {
- var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : 6;//对于市场价和定额价,这里只是中间的小数位数,后面更新前会根据有没有组成物再取值
- 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;
- }
- }
- if(updateField == 'code'){
- if (!gljUtil.isDef(args.editingText)||args.editingText==''||args.editingText.indexOf('|-|') === -1||this.isRationGLJExit(args.editingText)) {//说明是选中自已,或者是已存在的工料机
- 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 if(updateField == 'code'){//替换单价文件中已经有的工料机
- projectObj.project.ration_glj.updateRationGLJByChangeCode(recode, updateField, newval);
- }else if(me.setting.navigationRightCol.indexOf(updateField) != -1){//对于名称、规格、单位先跳到下一列,保存至缓存
- me.setToEditCache(recode,updateField, newval,args);
- } else {
- projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
- }
- },
- setToEditCache:function(recode,updateField,value,args){
- let me = this;
- if(me.rationGljEditObj == null){
- me.rationGljEditObj = {
- recode:recode,
- doc:{},
- row:args.row
- }
- me.rationGljEditObj.doc[updateField] = value;
- }else {
- if(me.rationGljEditObj.recode.ID == recode.ID){//确保编辑的是同一条数据
- me.rationGljEditObj.doc[updateField] = value;
- }
- }
- },
- isRationGLJExit:function (connectKey) {
- for(let rg of gljOprObj.sheetData){
- if(rg.isMixRatio == true){
- continue;
- }
- if(gljOprObj.getIndex(rg, gljKeyArray) == connectKey){//存在一样的工料机
- return true;
- }
- }
- return false;
- },
- updateRationTypeGLJ: function (value, node, fieldName,editingText) {
- 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,editingText);
- return;
- }
- }
- if (newval && updatePrice == true) {
- projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
- return
- }
- projectObj.mainController.refreshTreeNode([node]);
- },
- updateIsEstimate:function (args, newval) {
- var me = gljOprObj;
- if(me.setting.header[args.col].dataCode=="isEstimate"){
- var pspread= new ProjectGLJSpread();
- var recode = me.sheetData[args.row];
- let projectGljs = projectObj.project.projectGLJ.datas.gljList;
- let glj = _.find(projectGljs, {'id': recode.projectGLJID});
- if(glj){
- glj["is_evaluate"]=newval;
- args.fromRG=true;
- pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
- }
- }
- },
- showLibGLJSheetData: function () {
- this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
- sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
- this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
- },
- // 根据人材机类型,设置人材机类型显示名称
- setTypeName: function (distTypeData, data) {
- data.forEach(item => {
- let typeData = distTypeData.find(typeItem => typeItem.value === item.gljType);
- if (typeData) {
- item.typeName = typeData.text;
- }
- });
- },
- /*
- * 获取分页查询所需要的条件数据
- * @param {Boolean}init 是否是初始化
- * {Boolean}reset 是否重置数据 (点击分类树等)
- * {Boolean}location 是否定位(替换初始化)
- * {Number}index 下一页数据开始索引,根据这个值获取上次分页最大的编码数据(不用skip进行分页,skip跳过大量数据会降低性能,用$gt: data.code)
- * @return {Object}
- * */
- getPagingCondition: function (init, reset, location, index) {
- // 上一次分页的最末人材机编码,index为0时,code为空
- const code = gljOprObj.AllRecode && gljOprObj.AllRecode[index - 1] ? gljOprObj.AllRecode[index - 1].code : '';
- // 初始化情况下的条件
- let condition = {
- code,
- // 是否重置数据
- reset,
- // 是否定位
- location,
- index,
- // 限制条数
- limit: 50,
- // 初始化
- init: init,
- // 所在部分(标准、补充)
- type: this.pagingType.stdGLJ,
- // 替换数据,替换操作下有数据:编码、名称、规格、单位、类型
- replace: null,
- // 添加组成物的查询扩展
- queryExtend: {},
- // 所在分类节点
- classList: [],
- // 搜索文本
- search: ''
- };
- // 触发入口(添加、替换、批量替换)
- const actionType = $('#actionType').val();
- const replaceActions = ['replace', 'm_replace'];
- // 替换相关
- if (replaceActions.includes(actionType)) {
- // 定额人材机界面选中的人材机
- const selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
- condition.replace = {
- code: selected.code,
- name: selected.name,
- specs: selected.specs,
- unit: selected.unit,
- gljType: selected.type
- };
- } else if (actionType === 'addMix') {
- condition.queryExtend = projectGljObject.getQueryExtForMixRatio();
- }
- if (init) {
- return condition;
- }
- condition.init = false;
- // 标准、补充的选择
- if ($('#glj_tree_div').is(':visible')) {
- let radioType = $("input[name='glj']:checked").val();
- condition.type = this.pagingType[radioType];
- }
- // 选中的分类
- if (this.treeObj) {
- let selNode = this.treeObj.getNodeByParam('ID', this.gljCurTypeId);
- // 不为最顶层节点时,才赋值给withinClass
- if (selNode && selNode.ParentID !== -1) {
- const classList = this.parentNodeIds['_pNodeId_' + this.gljCurTypeId];
- condition.classList = classList ? classList : [this.gljCurTypeId];
- }
- }
- // 搜索文本
- let searchStr = $('#gljSearchKeyword').val().trim();
- if(searchStr){
- condition.search = searchStr;
- }
- return condition;
- },
- 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();
- }else if($('#actionType').val() == 'addMix'){
- projectGljObject.filterLibGLJForMixRatio();
- }
- //文本筛选
- let searchStr = $('#gljSearchKeyword').val();
- if(searchStr && searchStr.trim() != ''){
- let reg = new RegExp(searchStr);
- me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
- return reg.test(data.code) || reg.test(data.name);
- });
- }
- 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'|| $('#actionType').val() == 'addMix') {
- this.addGLJsSelection(args, newVal);
- } else {
- this.replaceGLJSelection(args, newVal);
- }
- },
- addGLJsSelection: function (args, newVal) {
- const curGLJ = this.AllRecode[args.row];
- const con_key = this.getIndex(curGLJ, gljLibKeyArray);
- if (newVal == 1) {
- this.GLJSelection.push(con_key);
- } else if (newVal == 0) {
- _.pull(this.GLJSelection, con_key);
- }
- },
- 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;
- }
- const curGLJ = this.AllRecode[args.row];
- const connectKey = this.getIndex(curGLJ, gljLibKeyArray);
- this.GLJSelection = [connectKey];
- var oindex = _.findIndex(this.AllRecode, function (item) {
- var i_key = me.getIndex(item, gljLibKeyArray);
- return oldSelection == i_key;
- });
- if (oindex != -1) {
- args.sheet.getCell(oindex, args.col).value(0);
- } else {
- var oldData = _.find(gljOprObj.AllRecode, function (item) {
- var i_key = me.getIndex(item, gljLibKeyArray);
- return oldSelection == i_key;
- });
- }
- },
- filterLibGLJByType: function () {
- var me = this;
- var selected = me.sheetData[gljContextMenu.selectedRow];
- //当前人材机类型是“混凝土、砂浆、配合比、商品混凝土、商品砂浆”时,筛选的可替换的人材机类型应是“混凝土、或砂浆、或配合比、或商品混凝土、或商品砂浆”。
- let materialTypes = [202, 203, 204, 205, 206];//除了普通材料
- let filterTypes = materialTypes.includes(selected.type) ? materialTypes : [selected.type];
- me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
- return filterTypes.includes(data.gljType);
- });
- },
- 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 me = this;
- var selected = projectObj.project.mainTree.selected;
- var project = projectObj.project;
- if (me.GLJSelection.length <= 0) {
- return;
- }
- $.bootstrapLoading.start();
- project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
- let newNode=null;
- for (let r_glj of data) {
- r_glj.quantity = r_glj.quantity + "";
- project.Ration.datas.push(r_glj);
- }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
- project.projectGLJ.loadData(function () {
- for(let r_glj of data){
- r_glj = me.setGLJPrice(r_glj);//设置工料机价格
- newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
- newNode.source = r_glj;
- newNode.sourceType = project.Ration.getSourceType();
- newNode.data = r_glj;
- ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
- }
- project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
- projectObj.mainController.refreshTreeNode([newNode]);
- if(me.hasComposition(newNode.data,true)){
- me.showMixRatio(newNode);
- }else {
- me.showRationGLJSheetData();
- }
- $.bootstrapLoading.end();
- });
- })
- },
- 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) {
- if(item.isMixRatio == true){
- return false;
- }
- 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) {
- 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);
- project.projectGLJ.loadData(function () {
- project.ration_glj.addToMainTree(result.showData);
- gljOprObj.showRationGLJSheetData();
- project.calcProgram.calcAndSave(selected);
- projectObj.mainController.refreshTreeNode([selected]);
- $.bootstrapLoading.end();
- });
- }
- });//doc.rationID=selected.data.ID;
- }
- },
- doReplaceGLJ: function () {
- let me = this;
- let oldData = me.sheetData[gljContextMenu.selectedRow];
- let project = projectObj.project;
- let selectCode = gljOprObj.GLJSelection[0];
- let selected = projectObj.project.mainTree.selected;
- project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
- if (result) {
- //result.adjustState;
- let glj_list = projectObj.project.ration_glj.datas;
- let data = result.data;
- let index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
- let list_index = _.findIndex(glj_list, {'ID': data.ID});
- let nodes = [selected];
- gljOprObj.sheetData[index] = data;
- glj_list[list_index] = data;
- project.projectGLJ.loadData(function () {//加载完项目工料机再计算
- gljOprObj.showRationGLJSheetData();
- let node = project.ration_glj.updateGLJNodeAfterReplace(data);
- if(node) nodes.push(node);
- /*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);
- selected.data.adjustState = result.adjustState;
- selected.data.name = result.name;
- projectObj.mainController.refreshTreeNode(nodes);
- project.calcProgram.calcAndSave(selected, function () {
- OVER_HEIGHT.reCalcOverHeightFee();
- });
- $.bootstrapLoading.end();
- });
- }
- })
- },
- doMReplaceGLJ: function () {
- let me = this;
- let oldData = me.sheetData[gljContextMenu.selectedRow];
- let project = projectObj.project;
- let selectCode = me.GLJSelection[0];
- project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result,updateMap) {
- if(result == null){
- return;
- }
- let data = result.data;
- let stateList = result.stateList;
- //let n_index = me.getIndex(data.query, gljKeyArray);
- let nodes = [];
- _.forEach(project.ration_glj.datas, function (t) {
- // let t_index = me.getIndex(t, gljKeyArray);
- if (updateMap[t.ID]) {
- me.updateProperty(t, data.doc);
- me.updateProperty(t, updateMap[t.ID]);
- if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
- project.ration_glj.transferToNodeData(t);
- var node = project.ration_glj.findGLJNodeByID(t.ID);
- node ? nodes.push(node):'';
- }
- }
- })
- project.projectGLJ.loadData(function () {
- me.showRationGLJSheetData();
- var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
- project.calcProgram.calcNodesAndSave(rationNodes, function () {
- OVER_HEIGHT.reCalcOverHeightFee();
- });
- $.bootstrapLoading.end();
- });
- })
- },
- updateProperty: function (obj, doc) {
- _.forEach(doc, function (n, key) {
- obj[key] = n;
- });
- },
- refreshStateAfterMreplace: function (stateList, gljNodes) {
- let nodes = [];
- let rationNodes = [];
- _.forEach(stateList, function (s) {
- let 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;
- node.data.name = s.name;
- nodes.push(node);
- rationNodes.push(node);
- }
- });
- gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
- projectObj.mainController.refreshTreeNode(nodes);
- return rationNodes;
- },
- refreshView: function () {
- let node = projectObj.project.mainTree.selected;
- this.showDataIfRationSelect(node,"111111");
- },
- refreshTreeNode: function (obj) {
- if (!obj) {
- return;
- }
- let objectArray = [];
- let nodes = [];
- if (obj instanceof Array) {
- objectArray.concat(obj);
- } else {
- objectArray.push(obj);
- }
- for (let o of objectArray) {
- let node = this.updateDataNodeProperty(o.ID,o.data);
- if (node) {
- nodes.push(node);
- }
- }
- projectObj.mainController.refreshTreeNode(nodes);
- return nodes;
- },
- updateDataNodeProperty:function(nodeID,data){
- let node = projectObj.project.mainTree.findNode(nodeID);
- if (node) {
- for (let k in data) {
- node.data[k] = data[k];
- }
- }
- return node;
- },
- getTreeNodeCellType: function (data,comboboxOptions) {
- let ns = GC.Spread.Sheets;
- let rectW = 10;
- let rectH = 10;
- let margin = 3;
- function TreeNodeCellType() {
- this.ctx = null;
- }
- TreeNodeCellType.prototype = comboboxOptions?sheetCommonObj.getDynamicCombo():new ns.CellTypes.Text();
- TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
- this.ctx= ctx;
- if (style.backColor) {//先画背景色
- ctx.save();
- ctx.fillStyle = style.backColor;
- ctx.fillRect(x, y, w, h);
- ctx.restore();
- } else {
- ctx.clearRect(x, y, w, h);
- }
- if (value != null) {
- let offset = margin + rectW + 6;
- let recode = data[options.row];
- if (recode && recode.hasOwnProperty('subList')) {
- sheetCommonObj.drowRect(ctx, x, y, w, h,rectW,rectH,margin);
- let collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
- sheetCommonObj.drowSymbol(ctx, x, y, w, h,rectW,rectH,margin, collapsed);
- } else if (recode && recode.isMixRatio) {
- let hasNext = data[options.row + 1] && data[options.row + 1].isMixRatio;
- offset = sheetCommonObj.drowSubItem(ctx, x, y, w, h, offset,hasNext);
- offset += 1;
- }
- arguments[2] = x + offset;
- arguments[4] = w - offset;
- //x = x + offset;
- //w = w - offset;
- GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
- }
- };
- TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
- if(x < cellRect.x+cellRect.width -15){//这里要判断点击的位置来决定return的内容,不能直接用combobox的方法
- return {
- x: x,
- y: y,
- row: context.row,
- col: context.col,
- cellStyle: cellStyle,
- cellRect: cellRect,
- sheetArea: context.sheetArea
- };
- }else {
- return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
- }
- };
- TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
- let recode = data[hitinfo.row];
- if(hitinfo.x < hitinfo.cellRect.x+hitinfo.cellRect.width -15){
- hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,"locked")//通过这个来控制除了点击下拉框的三角形,点击其它地方不充许进入编辑状态,不然不好控制下拉框超出页面后调整滚动条
- }
- if (recode && recode.hasOwnProperty('subList')) {
- let hoffset = hitinfo.cellRect.x + 3;
- if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
- let 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;
- }
- }
- if(comboboxOptions&&hitinfo.x > hitinfo.cellRect.x+hitinfo.cellRect.width -15){//点击了下拉框按钮,这里要判断下拉框是否会被挡住,从而决定是否自动调整滚动条
- hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,"");
- sheetCommonObj.scrollSheetForOption(hitinfo.sheet,this.ctx,hitinfo.cellRect,hitinfo.row,comboboxOptions);//下拉框超出显示后自动调整滚动条
- GC.Spread.Sheets.CellTypes.ComboBox.prototype.processMouseDown.apply(this, arguments);
- }
- };
- let cellType = new TreeNodeCellType();
- if(comboboxOptions){
- cellType.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
- cellType.itemHeight(comboboxOptions.length).items(comboboxOptions);
- }
- return cellType;
- },
- marketPriceReadOnly: function (node) {
- let hasCom = false;
- if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
- hasCom = this.hasComposition(node.data,true);
- }else {
- hasCom = this.hasComposition(node.data);
- }
- return hasCom;//2018-9-14 需求变更暂估工料机也能修改市场价原语句:return hasCom|| node.data.isEstimate == 1
- },
- locateZTree: function(ID) {
- let zTree = $.fn.zTree.getZTreeObj("gljTree");
- let node = null;
- if (ID) node = zTree.getNodesByParam('ID', ID, null)[0];
- if (!node) node = zTree.getNodeByTId('gljTree_1');
- zTree.selectNode(node);
- gljOprObj.gljCurTypeId = ID;
- //--gljOprObj.filterLibGLJSheetData();
- //--gljOprObj.showLibGLJSheetData();
- },
- isExtraType:function (type) {
- return _.includes(gljUtil.extraType,type)
- },
- setNodeShowTab:function () {
- let node = projectObj.project.mainTree.selected;
- if(node && node.sourceType==ModuleNames.ration){
- gljOprObj.rationTab = gljOprObj.activeTab;
- }else {
- gljOprObj.billsTab = gljOprObj.activeTab;
- }
- },
- //初始化分类树
- //@param {String}type(标准或补充) {Array}treeData(树数据)
- initClassTree: function (type, treeData, initSel = false) {
- let me = this;
- if (me.treeObj) {
- me.treeObj.destroy();
- me.parentNodeIds = {};
- }
- zTreeHelper.createTree(treeData, me.gljTreeSetting, "gljTree", me);
- if (initSel) {
- let rootNode = me.treeObj.getNodes()[0];
- if(rootNode && rootNode.isParent && rootNode.isFirstNode){
- me.rootNode = rootNode;
- }
- if(me.rootNode){
- me.treeObj.selectNode(me.rootNode);
- me.gljTreeSetting.callback.onClick(null, 'gljTree', me.rootNode);
- }
- }
- },
- initScopeSpread:function() {
- if (this.scopeSpread) return this.scopeSpread.repaint();
- this.scopeSpread = SheetDataHelper.createNewSpread($('#scopeSpread')[0]);
- sheetCommonObj.spreadDefaultStyle(this.scopeSpread);
- this.scopeTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
- this.scopeTreeController = TREE_SHEET_CONTROLLER.createNew(this.scopeTree, this.scopeSpread.getActiveSheet(), this.scopeSetting);
- this.scopeSheet = this.scopeSpread.getActiveSheet();
- this.scopeSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, this.onScopeChecked);
- },
- showScopeDatas:function () {
- this.initScopeSpread();
- this.scopeDatas =this.getScopeDatas();
- this.scopeTree.loadDatas(this.scopeDatas);
- this.scopeTreeController.showTreeData();
- },
- getScopeDatas:function () {
- let controller = projectObj.mainController, project = projectObj.project;
- let allNodes = [],datas = []
- for(let rootNode of controller.tree.roots){
- allNodes.push(rootNode);
- controller.tree.getAllSubNode(rootNode.source,allNodes);
- }
- for(let n of allNodes){
- let temData = {
- ID:n.data.ID,
- NextSiblingID:n.data.NextSiblingID,
- ParentID:n.data.ParentID,
- unit : n.data.unit,
- code : n.data.code,
- selected:0,
- name : n.data.name,
- quantity:calcTools.uiNodeQty(n)?calcTools.uiNodeQty(n):"",
- };
- if(n.data.feesIndex && n.data.feesIndex.common){
- temData.unitPrice = n.data.feesIndex.common.unitFee;
- temData.totalPrice = n.data.feesIndex.common.totalFee;
- }
- datas.push(temData);
- }
- return datas;
- },
- onScopeChecked:function (e,args) {
- let me = gljOprObj,nodes = [];
- var checkboxValue = args.sheet.getCell(args.row, args.col).value();
- var newval = checkboxValue?0:1;
- let node = me.scopeTree.items[args.row];
- setNodeAndChildreSelected(node,newval,nodes);
- me.scopeTreeController.refreshTreeNode(nodes);
- function setNodeAndChildreSelected(n,val,arr){
- n.data.selected = val;
- nodes.push(n);
- for(let c of n.children){
- setNodeAndChildreSelected(c,val,arr)
- }
- }
- },
- setScopeSelection:function () {
- for(let node of this.scopeTree.items){
- //挑出选中数,过滤父节点
- if(node.data.selected == 1 && node.children.length == 0) this.scopeSelectedIDMap[node.data.ID] = true
- }
- }
- }
- // 人材机选择界面的功能进行了适合分页的重构
- // 重构时,只有添加、替换、批量替换的入口。因此只对这三个入口相关的地方进行重构,其他入口的代码没有变更
- // 若以后放开其他入口,需要将其他入口的相应方法进行重构
- $(function () {
- $('#glj_tree_div').on('hidden.bs.modal', function () {
- // 清空搜索框
- $('#gljSearchKeyword').val('');
- });
- $('#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);
- sheetCommonObj.spreadDefaultStyle(gljOprObj.gljLibSpresd);
- gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
- gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
- gljOprObj.gljLibSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, gljOprObj.onSelectionChanged);
- gljOprObj.gljLibSheet.bind(GC.Spread.Sheets.Events.TopRowChanged, _.debounce(gljOprObj.onTopRowChanged, 100));
- gljOprObj.gljLibSheet.setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
- gljOprObj.gljLibSheet.options.isProtected = true;
- gljOprObj.gljLibSheet.name('glj_lib');
- sheetCommonObj.setSheetBySetting(gljOprObj.gljLibSheet, gljOprObj.gljLibSheetSetting);
- }
- let gljClass = 0,
- selected,
- connect_key;
- const actionType = $('#actionType').val();
- const addActions = ['add', 'insert', 'addMix'];
- const replaceActions = ['m_replace', 'replace'];
- if (addActions.includes(actionType)) {//插入,添加,添加组成物(项目人材机页面)
- gljOprObj.GLJSelection = [];
- } else if(replaceActions.includes(actionType)){//替换、批量替换
- selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
- connect_key = gljOprObj.getIndex(selected, gljKeyArray);
- gljOprObj.GLJSelection = [connect_key];
- // 找到定位的分类树
- const locatedItem = gljOprObj.AllRecode.find(item => gljOprObj.getIndex(item, gljLibKeyArray) === connect_key);
- if (locatedItem) {
- gljClass = locatedItem.gljClass;
- locatedItem.select = 1;
- }
- }
- //替换,焦点定位至当前选中人材机
- if (replaceActions.includes(actionType)) {
- gljOprObj.locateZTree(gljClass);
- sheetCommonObj.appendData(gljOprObj.gljLibSheet, 0, 0, gljOprObj.gljLibSheetSetting, gljOprObj.AllRecode);
- const index = gljOprObj.AllRecode.findIndex(item => gljOprObj.getIndex(item, gljLibKeyArray) === connect_key);
- gljOprObj.gljLibSheet.showRow(index, GC.Spread.Sheets.VerticalPosition.center);
- gljOprObj.gljLibSheet.setActiveCell(index, 0);
- gljOprObj.initSelection({row: index});
- gljOprObj.gljLibSpresd.focus(true);
- } else if (actionType === 'add' || actionType === 'addMix') {
- gljOprObj.locateZTree(null);
- sheetCommonObj.appendData(gljOprObj.gljLibSheet, 0, 0, gljOprObj.gljLibSheetSetting, gljOprObj.AllRecode);
- gljOprObj.gljLibSheet.showRow(0, GC.Spread.Sheets.VerticalPosition.top);
- gljOprObj.gljLibSheet.setActiveCell(0, 0);
- gljOprObj.initSelection({row: 0});
- } else {
- gljOprObj.showLibGLJSheetData();
- }
- console.timeEnd('getGLJData');
- });
- $('#mreplace_next_div').on('shown.bs.modal', function (e) {
- gljOprObj.scopeSelectedIDMap = {};
- gljOprObj.showScopeDatas();
- });
- // 人材机选择界面标准、补充单选
- $('.glj-radio').change(function () {
- const val = $("input[name='glj']:checked").val();
- if (val === 'stdGLJ') {
- gljOprObj.initClassTree('std', gljOprObj.treeData.std, true);
- } else {
- gljOprObj.initClassTree('comple', gljOprObj.treeData.comple, true);
- }
- gljOprObj.initSelection({row: 0});
- });
- // 人材机选择页面搜索框
- $('#gljSearchKeyword').bind('keyup', _.debounce(function() {
- gljOprObj.loadPageData(gljOprObj.gljLibSheet, true, 0);
- }, 500));
- $('#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();
- }else if($('#actionType').val() == 'addMix'){
- projectGljObject.addMixRatio();
- }
- $("#glj_tree_div").modal('hide');
- })
- $('#scope_position_confirm').click(function () {
- gljOprObj.setScopeSelection();
- gljOprObj.doMReplaceGLJ();
- });
- $('#replace_next_btn').click(function () {
- $("#glj_tree_div").modal('hide');
- $("#mreplace_next_div").modal('show');
- });
- $('#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("");
- })
- $("#subSpread").focusout(function(e){//当本身或子元素失去焦点时这个事件都会发生,而且不好判断点击的是哪里。
- if(gljOprObj.rationGljEditObj){
- gljOprObj.cancelUpdate = false;
- gljOprObj.timeStamp = e.timeStamp;//设置时间戳,有可能用户在表格上乱点,这个事件被触发多次
- setTimeout(function () {//延时执行提交操作,如果点击的是spread里的地方,会把cancelUpdate改成true,这样的话就不执行提交操作
- if(gljOprObj.timeStamp == e.timeStamp && gljOprObj.cancelUpdate !== true){//时间戳要相同
- gljOprObj.updateGljFromCache();
- }
- },200)
- }
- });
- 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 compareRationGLJ(a, b) {
- if ((a.type + "") < (b.type + "")) {
- return true
- }
- if ((a.type + "") == (b.type + "")) {
- if (a.code < b.code) {
- return true
- }
- }
- return false;
- }
|