吴学文
2019-07-10 4ee6445f67bbb56caa2b2f981afce6e87cc602af
WebService/src/main/resources/components/sell-room/sellRoom.js
@@ -2,109 +2,101 @@
    入驻小区
**/
(function(vc){
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROW = 10;
    vc.extends({
        data:{
            roomUnits:[],
            roomInfo:{
                rooms:[],
                total:0,
                records:1,
                floorId:'',
                unitId:'',
            sellRoomInfo:{
                ownerId:'',
                roomId:'',
                state:'',
                roomNum:''
                remark:'',
                ownerInfo:{
                    ownerId:"",
                    name:"",
                    age:"",
                    sex:"",
                    userName:"",
                    remark:"",
                    link:"",
                },
            }
        },
        _initMethod:function(){
        },
        _initEvent:function(){
            vc.on('room','listRoom',function(_param){
                  vc.component.listRoom();
            });
            vc.on('room','loadData',function(_param){
                vc.component.roomInfo.floorId = _param.floorId;
                vc.component.roomInfo.unitId = '';
                vc.component.roomInfo.state = '';
                vc.component.roomInfo.roomNum = '';
            vc.on('sellRoom','notify',function(_param){
                  vc.copyObject(_param,vc.component.sellRoomInfo.ownerInfo);
                vc.component.listRoom(DEFAULT_PAGE,DEFAULT_ROW);
                vc.component.loadUnits(_param.floorId);
            });
            vc.on('pagination','page_event',function(_currentPage){
                vc.component.listRoom(_currentPage,DEFAULT_ROW);
                  if(_param.hasOwnProperty("ownerId")){
                    vc.component.sellRoomInfo.ownerId = _param.ownerId;
                  }
                   if(_param.hasOwnProperty("roomId")){
                      vc.component.sellRoomInfo.roomId = _param.roomId;
                    }
                if(_param.hasOwnProperty("otherState")){
                   vc.component.sellRoomInfo.state = _param.otherState;
                 }
                  if(_param.hasOwnProperty("otherRemark")){
                     vc.component.sellRoomInfo.remark = _param.otherRemark;
                   }
            });
        },
        methods:{
            listRoom:function(_page,_row){
                var param = {
                    params:{
                        page:_page,
                        row:_row,
                        communityId:vc.getCurrentCommunity().communityId,
                        floorId:vc.component.roomInfo.floorId,
                        unitId:vc.component.roomInfo.unitId,
                        state:vc.component.roomInfo.state,
                        roomNum:vc.component.roomInfo.roomNum
            sellRoomValidate:function(){
                        return vc.validate.validate({
                            sellRoomInfo:vc.component.sellRoomInfo
                        },{
                            'sellRoomInfo.ownerId':[
                                {
                                    limit:"required",
                                    param:"",
                                    errInfo:"未选择业主"
                                }
                            ],
                            'sellRoomInfo.roomId':[
                                {
                                    limit:"required",
                                    param:"",
                                    errInfo:"未选择房屋"
                                }
                            ],
                            'sellRoomInfo.state':[
                                {
                                    limit:"required",
                                    param:"",
                                    errInfo:"未选择出售状态"
                                }
                            ],
                    }
                        });
             },
            doSellRoom:function(){
                //
                if(!vc.component.sellRoomValidate()){
                    vc.message(vc.validate.errInfo);
                    return ;
                }
               //发送get请求
               vc.http.get('room',
                            'listRoom',
                             param,
                             function(json,res){
                                var listRoomData =JSON.parse(json);
                                vc.component.roomInfo.total = listRoomData.total;
                                vc.component.roomInfo.records = listRoomData.records;
                                vc.component.roomInfo.rooms = listRoomData.rooms;
                                vc.emit('pagination','init',{
                                    total:vc.component.roomInfo.records,
                                    currentPage:_page
                                });
                             },function(errInfo,error){
                                console.log('请求失败处理');
                             }
                           );
            },
            _openEditRoomModel:function(_room){
                _room.floorId = vc.component.roomInfo.floorId;
                vc.emit('editRoom','openEditRoomModal',_room);
            },
            _openDelRoomModel:function(_room){
                 _room.floorId = vc.component.roomInfo.floorId;
                 vc.emit('deleteRoom','openRoomModel',_room);
            },
            /**
                根据楼ID加载房屋
            **/
            loadUnits:function(_floorId){
                vc.component.addRoomUnits = [];
                var param = {
                    params:{
                        floorId:_floorId,
                        communityId:vc.getCurrentCommunity().communityId
                    }
                }
                vc.http.get(
                    'room',
                    'loadUnits',
                     param,
                vc.component.sellRoomInfo.communityId=vc.getCurrentCommunity().communityId;
            vc.http.post(
                    'sellRoom',
                    'sell',
                    JSON.stringify(vc.component.sellRoomInfo),
                    {
                        emulateJSON:true
                     },
                     function(json,res){
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        if(res.status == 200){
                            var tmpUnits = JSON.parse(json);
                            vc.component.roomUnits = tmpUnits;
                            /*if(tmpUnits == null || tmpUnits.length == 0){
                                return ;
                            }
                            for(var unitIndex = 0; unitIndex < tmpUnits.length;unitIndex++){
                               vc.component.addRoomInfo.units[unitIndex] = tmpUnits[unitIndex];
                            }*/
                            //关闭model
                            vc.jumpToPage("/flow/ownerRoomFlow?" + vc.objToGetParam(vc.component.sellRoomInfo.ownerInfo));
                            return ;
                        }
                        vc.message(json);
@@ -114,27 +106,8 @@
                        vc.message(errInfo);
                     });
            },
            queryRoomMethod:function(){
                vc.component.listRoom(DEFAULT_PAGE,DEFAULT_ROW);
            },
            showState:function(_state){
                if(_state == '2001'){
                    return "房屋已售";
                }else if(_state == '2002'){
                    return "房屋未售";
                }else if(_state == '2003'){
                    return "已交定金";
                }
                else if(_state == '2004'){
                    return "已出租";
                }else{
                    return "未知";
                }
            },
            doSellRoom:function(){
                            //
                        }
            }
        }
    });
})(window.vc);