zhangjiaqing
8 天以前 1cef3adee31c6934c0da4b4f0b8a6f5ac03b364f
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/**
 入驻小区
 **/
(function (vc) {
    vc.extends({
        data: {
            addVisitSpaceInfo: {
                vName: '',
                visitGender: '',
                phoneNumber: '',
                visitTime: vc.dateTimeFormat(new Date().getTime()),
                departureTime: '',
                carNum: '',
                entourage: 0,
                paId: '',
                psId: '',
                num: '',
                parkingSpaceNum: '',
                ownerId: '',
                ownerName: '',
                parkingAreas: [],
                parkingSpaces: [],
                visitCase: "",
                reasonType: "",
                reasonTypes: [],
                photo: "",
                visitPhotoUrl: "",
                communityId: vc.getCurrentCommunity().communityId,
                rooms: [],
                roomId: '',
            }
        },
        _initMethod: function () {
            vc.initDateTime('addVisitTime', function (_value) {
                $that.addVisitSpaceInfo.visitTime = _value;
            });
            vc.initDateTime('addDepartureTime', function (_value) {
                $that.addVisitSpaceInfo.departureTime = _value;
                let start = Date.parse(new Date($that.addVisitSpaceInfo.visitTime))
                let end = Date.parse(new Date($that.addVisitSpaceInfo.departureTime))
                if (start - end >= 0) {
                    vc.toast("结束时间必须大于开始时间")
                    $that.addVisitSpaceInfo.departureTime = '';
                }
            });
            vc.getDict('s_visit_info', "reason_type", function (_data) {
                $that.addVisitSpaceInfo.reasonTypes = _data;
            });
            $that.checkFlow();
        },
        _initEvent: function () {
            vc.on('visitForOwner', 'ownerInfo', function (_info) {
                $that.addVisitSpaceInfo.ownerId = _info.ownerId;
                $that.addVisitSpaceInfo.ownerName = _info.name + "(" + _info.link + ")";
                $that._loadOwnerRoomInfo();
            });
            vc.on("addVisitSpace", "notifyUploadImage", function (_param) {
                if (_param.length > 0) {
                    vc.component.addVisitSpaceInfo.photo = _param[0].fileId;
                    vc.component.addVisitSpaceInfo.visitPhotoUrl = _param[0].url;
                } else {
                    vc.component.addVisitSpaceInfo.photo = '';
                    vc.component.addVisitSpaceInfo.visitPhotoUrl = '';
                }
            });
        },
        methods: {
            _openSearchOwnerModel: function (_ownerId) {
                vc.emit('searchOwner', 'openSearchOwnerModel', {});
            },
            addVisitSpaceValidate() {
                return vc.validate.validate({
                    addVisitSpaceInfo: vc.component.addVisitSpaceInfo
                }, {
                    'addVisitSpaceInfo.vName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "访客姓名不能为空"
                        }
                    ],
                    'addVisitSpaceInfo.visitGender': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "访客性别不能为空"
                        }
                    ],
                    'addVisitSpaceInfo.entourage': [
                        {
                            limit: "num",
                            param: "",
                            errInfo: "随行人数有误"
                        }
                    ],
                    'addVisitSpaceInfo.phoneNumber': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "访客手机号不能为空"
                        },
                        {
                            limit: "phone",
                            param: "",
                            errInfo: "访客手机号不正确"
                        }
                    ],
                    'addVisitSpaceInfo.visitTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "访客时间不能为空"
                        },
                        {
                            limit: "dateTime",
                            param: "",
                            errInfo: "访客时间格式错误"
                        }
                    ],
                    'addVisitSpaceInfo.departureTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "访客时间不能为空"
                        },
                        {
                            limit: "dateTime",
                            param: "",
                            errInfo: "访客时间格式错误"
                        }
                    ],
                    'addVisitSpaceInfo.visitCase': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "拜访事由不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "512",
                            errInfo: "拜访事由过长"
                        }
                    ],
                    'addVisitSpaceInfo.reasonType': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "事由类型不能为空"
                        }
                    ],
                    'addVisitSpaceInfo.ownerId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "访问业主不能为空"
                        }
                    ],
                    'addVisitSpaceInfo.roomId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "访问房屋不能为空"
                        }
                    ]
                });
            },
            _addVisitFinish: function () {
                if (!vc.component.addVisitSpaceValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
               
                vc.http.apiPost(
                    '/visit.saveVisit',
                    JSON.stringify($that.addVisitSpaceInfo), {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            vc.toast(_json.msg);
                            vc.goBack();
                            return;
                        } else {
                            vc.toast(_json.msg);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    }
                );
            },
            checkFlow: function () {
                let param = {
                    params: {
                        page: 1,
                        row: 1,
                        auditWay: 'Y',
                        state: 'C',
                        communityId: vc.getCurrentCommunity().communityId,
                    }
                };
                //发送get请求
                vc.http.apiGet('/visit.listVisitSetting',
                    param,
                    function (json, res) {
                        let _visitSettingManageInfo = JSON.parse(json);
                        if (_visitSettingManageInfo.data && _visitSettingManageInfo.data.length > 0) {
                            $that._loadStaffOrg(_visitSettingManageInfo.data[0].flowId);
                        }
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _loadStaffOrg: function (_flowId) {
                let param = {
                    params: {
                        communityId: vc.getCurrentCommunity().communityId,
                        flowId: _flowId
                    }
                };
                //发送get请求
                vc.http.apiGet('/oaWorkflow.queryFirstAuditStaff',
                    param,
                    function (json, res) {
                        var _staffInfo = JSON.parse(json);
                        if (_staffInfo.code != 0) {
                            //vc.toast(_staffInfo.msg);
                            return;
                        }
                        let _data = _staffInfo.data;
                        if (_data[0].assignee == '-2') {
                            vc.toast('流程的第一审核人必须指定固定人(代理人)');
                        }
                    },
                    function () {
                        console.log('请求失败处理');
                    }
                );
            },
            _loadOwnerRoomInfo: function () {
                let param = {
                    params: {
                        communityId: vc.getCurrentCommunity().communityId,
                        ownerId:$that.addVisitSpaceInfo.ownerId 
                    }
                };
                //发送get请求
                vc.http.apiGet('/room.queryRoomsByOwner',
                    param,
                    function (json) {
                        var _roomInfo = JSON.parse(json);
                        vc.component.addVisitSpaceInfo.rooms = _roomInfo.rooms;
                    },
                    function () {
                        console.log('请求失败处理');
                    }
                );
            },
        }
    });
})(window.vc);