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
/**
 入驻小区
 **/
(function (vc) {
    vc.extends({
        data: {
            hireParkingSpaceInfo: {
                carNum: '',
                carBrand: '',
                carType: '',
                carColor: '',
                remark: "",
                startTime: '',
                endTime: '',
                leaseType: 'H',
                carAttrs: '',
                attrs: [],
                value: '',
                ownerId: '',
                ownerName: '',
                psId: '',
                psName: '',
                carTypes: [
                    {
                        key: '9901',
                        value: '家用小汽车'
                    },
                    {
                        key: '9902',
                        value: '客车'
                    },
                    {
                        key: '9903',
                        value: '货车'
                    }
                ]
            }
        },
        _initMethod: function () {
            let _ownerId = vc.getParam('ownerId');
            if (_ownerId) {
                $that.hireParkingSpaceInfo.ownerId = _ownerId;
                $that.hireParkingSpaceInfo.ownerName = vc.getParam('ownerName');
            }
            vc.getDict('owner_car', "car_type", function (_data) {
                $that.hireParkingSpaceInfo.carTypes = _data;
            });
            vc.initDate('addStartTime', function (_value) {
                $that.hireParkingSpaceInfo.startTime = _value;
            });
            vc.initDate('addEndTime', function (_value) {
                $that.hireParkingSpaceInfo.endTime = _value;
            });
            $that._loadCarAttrSpec();
        },
        _initEvent: function () {
            vc.on('hireParkingSpace', 'chooseOwner', function (_owner) {
                $that.hireParkingSpaceInfo.ownerName = _owner.name;
                $that.hireParkingSpaceInfo.ownerId = _owner.memberId;
            });
            vc.on('hireParkingSpace', 'chooseParkingSpace', function (_parkingSpace) {
                vc.copyObject(_parkingSpace, $that.hireParkingSpaceInfo);
                $that.hireParkingSpaceInfo.psName = _parkingSpace.areaNum + "-" + _parkingSpace.num;
            });
        },
        methods: {
            addCarValidate: function () {
                return vc.validate.validate({
                    hireParkingSpaceInfo: $that.hireParkingSpaceInfo
                }, {
                    'hireParkingSpaceInfo.carNum': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "车牌号不能为空"
                        },
                        {
                            limit: "maxin",
                            param: "2,12",
                            errInfo: "车牌号不正确"
                        }
                    ],
                    'hireParkingSpaceInfo.carBrand': [
                        {
                            limit: "maxLength",
                            param: "50",
                            errInfo: "车品牌超出限制"
                        }
                    ],
                    'hireParkingSpaceInfo.carType': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "车类型不能为空"
                        }
                    ],
                    'hireParkingSpaceInfo.carColor': [
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "车颜色超出限制"
                        }
                    ]
                });
            },
            _loadCarAttrSpec: function () {
                $that.hireParkingSpaceInfo.attrs = [];
                vc.getAttrSpec('owner_car_attr', function (data) {
                    data.forEach(item => {
                        item.value = '';
                        if (item.specShow == 'Y') {
                            item.values = [];
                            $that._loadAttrValue(item.specCd, item.values);
                            $that.hireParkingSpaceInfo.attrs.push(item);
                        }
                        console.log('attrs : ', $that.hireParkingSpaceInfo.attrs);
                    });
                });
            },
            _loadAttrValue: function (_specCd, _values) {
                vc.getAttrValue(_specCd, function (data) {
                    data.forEach(item => {
                        if (item.valueShow == 'Y') {
                            _values.push(item);
                        }
                    });
                });
            },
            _openChooseOwner: function () {
                vc.emit('searchOwner', 'openSearchOwnerModel', {
                    ownerTypeCd:''
                });
            },
            openSearchParkingSpaceModel() {
                vc.emit('searchParkingSpace', 'openSearchParkingSpaceModel', {});
            },
            _changeLeaseType: function () {
                $that.hireParkingSpaceInfo.startTime = '';
                $that.hireParkingSpaceInfo.endTime = '';
            },
            saveAddCarInfo: function () {
                // 验证attr必填项
                let msg = '';
                $that.hireParkingSpaceInfo.attrs.forEach((item) => {
                    if (item.required == 'Y' && item.value == "") {
                        msg = item.specHoldplace;
                    }
                })
                if (msg) {
                    vc.toast(msg);
                    return;
                }
                if (!$that.addCarValidate()) {
                    //侦听回传
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.hireParkingSpaceInfo.communityId = vc.getCurrentCommunity().communityId;
                vc.http.apiPost(
                    '/owner.saveOwnerCar',
                    JSON.stringify($that.hireParkingSpaceInfo), {
                        emulateJSON: true
                    },
                    function (_json, res) {
                        let json = JSON.parse(_json);
                        if (json.code == 0) {
                            vc.toast("请记得收费哦!");
                            vc.goBack();
                            return;
                        } else {
                            vc.toast(json.msg);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    }
                );
            },
            _goBack: function () {
                vc.goBack();
            }
        }
    });
})(window.vc);