wuxw
2019-07-18 a54a28a5a26e86d6b32990bfbb174c350b917b47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
(function(vc,vm){
 
    vc.extends({
        data:{
            addRoomUnits:[],
            addRoomInfo:{
                unitId:'',
                roomNum:'',
                layer:'',
                section:'',
                apartment:'',
                builtUpArea:'',
                unitPrice:'',
                state:'',
                remark:'',
                communityId:''
            }
        },
         _initMethod:function(){
 
         },
         _initEvent:function(){
             vc.on('addRoom','addRoomModel',function(_params){
                vc.component.refreshAddRoomInfo();
                vc.component.loadUnitsFromAddRoom(_params.floorId);
                $('#addRoomModel').modal('show');
                vc.component.addRoomInfo.floorId = _params.floorId;
                vc.component.addRoomInfo.communityId = vc.getCurrentCommunity().communityId;
            });
        },
        methods:{
            /**
                根据楼ID加载房屋
            **/
            loadUnitsFromAddRoom:function(_floorId){
                vc.component.addRoomUnits = [];
                var param = {
                    params:{
                        floorId:_floorId,
                        communityId:vc.getCurrentCommunity().communityId
                    }
                }
                vc.http.get(
                    'addRoom',
                    'loadUnits',
                     param,
                     function(json,res){
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        if(res.status == 200){
                            var tmpUnits = JSON.parse(json);
                            vc.component.addRoomUnits = tmpUnits;
                            /*if(tmpUnits == null || tmpUnits.length == 0){
                                return ;
                            }
                            for(var unitIndex = 0; unitIndex < tmpUnits.length;unitIndex++){
                               vc.component.addRoomInfo.units[unitIndex] = tmpUnits[unitIndex];
                            }*/
                            return ;
                        }
                        vc.message(json);
                     },
                     function(errInfo,error){
                        console.log('请求失败处理');
 
                        vc.message(errInfo);
                     });
            },
            addRoomValidate:function(){
                        return vc.validate.validate({
                            addRoomInfo:vc.component.addRoomInfo
                        },{
                            'addRoomInfo.unitId':[
                                {
                                    limit:"required",
                                    param:"",
                                    errInfo:"小区楼房屋不能为空"
                                }
                            ],
                            'addRoomInfo.roomNum':[
                                {
                                    limit:"required",
                                    param:"",
                                    errInfo:"房屋编号不能为空"
                                },
                                {
                                    limit:"maxLength",
                                    param:"12",
                                    errInfo:"房屋编号长度不能超过12位"
                                },
                            ],
                            'addRoomInfo.layer':[
                                {
                                    limit:"required",
                                    param:"",
                                    errInfo:"房屋楼层高度不能为空"
                                },
                                {
                                    limit:"num",
                                    param:"",
                                    errInfo:"房屋楼层高度必须为数字"
                                }
                            ],
                            'addRoomInfo.section':[
                                {
                                    limit:"required",
                                    param:"",
                                    errInfo:"房间数不能为空"
                                },
                                {
                                    limit:"num",
                                    param:"",
                                    errInfo:"房间数必须为数字"
                                }
                            ],
                            'addRoomInfo.apartment':[
                                {
                                    limit:"required",
                                    param:"",
                                    errInfo:"户型不能为空"
                                }
                            ],
                            'addRoomInfo.state':[
                                {
                                    limit:"required",
                                    param:"",
                                    errInfo:"房间状态不能为空"
                                }
                            ],
                            'addRoomInfo.builtUpArea':[
                                {
                                    limit:"required",
                                    param:"",
                                    errInfo:"建筑面积不能为空"
                                },
                                {
                                    limit:"money",
                                    param:"",
                                    errInfo:"建筑面积错误,如 300.00"
                                },
                                {
                                  limit:"maxLength",
                                  param:"12",
                                  errInfo:"建筑面积数字长度不能超过6位"
                                }
                            ],
                            'addRoomInfo.unitPrice':[
                                {
                                    limit:"required",
                                    param:"",
                                    errInfo:"房屋单价不能为空"
                                },
                                {
                                    limit:"money",
                                    param:"",
                                    errInfo:"房屋单价错误 如 300.00"
                                },
                                 {
                                   limit:"maxLength",
                                   param:"12",
                                   errInfo:"房屋单价数字长度不能超过12位"
                                 }
                            ],
                            'addRoomInfo.remark':[
                                {
                                    limit:"maxLength",
                                    param:"200",
                                    errInfo:"备注长度不能超过200位"
                                },
                            ]
 
                        });
             },
            addRoom:function(){
                if(!vc.component.addRoomValidate()){
                    vc.message(vc.validate.errInfo);
                    return ;
                }
 
                vc.http.post(
                    'addRoom',
                    'save',
                    JSON.stringify(vc.component.addRoomInfo),
                    {
                        emulateJSON:true
                     },
                     function(json,res){
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        if(res.status == 200){
                            //关闭model
                            $('#addRoomModel').modal('hide');
                            vc.emit('room','loadData',{
                                floorId:vc.component.addRoomInfo.floorId
                            });
                            return ;
                        }
                        vc.message(json);
                     },
                     function(errInfo,error){
                        console.log('请求失败处理');
 
                        vc.message(errInfo);
                     });
            },
            refreshAddRoomInfo:function(){
                vc.component.addRoomInfo= {
                  unitId:'',
                  roomNum:'',
                  layer:'',
                  section:'',
                  apartment:'',
                  builtUpArea:'',
                  unitPrice:'',
                  remark:'',
                  state:'',
                  communityId:''
                }
            }
        }
    });
 
})(window.vc,window.vc.component);