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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
(function (vc) {
    vc.extends({
        data: {
            addMaintainancePlanInfo: {
                planId: '',
                planName: '',
                standardId: '',
                standards: [],
                planPeriod: '',
                startDate: vc.dateFormat(new Date()),
                endDate: ' ',
                state: '2020025',
                remark: '',
                machineId: '',
                months: [],
                days: [],
                everyDays: [],
                staffs: [],
                machines: []
            }
        },
        watch: {
            'addMaintainancePlanInfo.machines': function () { //'goodList'是我要渲染的对象,也就是我要等到它渲染完才能调用函数
                this.$nextTick(function () {
                    $('#machineIds').selectpicker({
                        title: '必填,请选择保养设备',
                        styleBase: 'form-control',
                        width: 'auto'
                    });
                    $('#machineIds').selectpicker('refresh');
                })
            }
        },
        _initMethod: function () {
            vc.component._initDateInfo();
            $that._listAddEquipmentAccounts();
            $that._listAddMaintainanceStandards();
            vc.emit('selectStaffs', 'setStaffs', $that.addMaintainancePlanInfo.staffs);
        },
        _initEvent: function () {
            vc.on("addMaintainancePlanInfo", "notify", function (_param) {
                if (_param.hasOwnProperty("staffId")) {
                    vc.component.addMaintainancePlanInfo.staffId = _param.staffId;
                    vc.component.addMaintainancePlanInfo.staffName = _param.staffName;
                }
            });
        },
        methods: {
            _initDateInfo: function () {
                $('.addMaintainancePlanStartDate').datetimepicker({
                    language: 'zh-CN',
                    fontAwesome: 'fa',
                    format: 'yyyy-mm-dd',
                    minView: "month",
                    initTime: true,
                    initialDate: new Date(),
                    autoClose: 1,
                    todayBtn: true
                });
                $('.addMaintainancePlanStartDate').datetimepicker()
                    .on('changeDate', function (ev) {
                        var value = $(".addMaintainancePlanStartDate").val();
                        vc.component.addMaintainancePlanInfo.startDate = value;
                    });
                $('.addMaintainancePlanEndDate').datetimepicker({
                    language: 'zh-CN',
                    fontAwesome: 'fa',
                    format: 'yyyy-mm-dd',
                    minView: "month",
                    initTime: true,
                    initialDate: new Date(),
                    autoClose: 1,
                    todayBtn: true
                });
                $('.addMaintainancePlanEndDate').datetimepicker()
                    .on('changeDate', function (ev) {
                        var value = $(".addMaintainancePlanEndDate").val();
                        var start = Date.parse(new Date(vc.component.addMaintainancePlanInfo.startDate))
                        var end = Date.parse(new Date(value))
                        if (start - end >= 0) {
                            vc.toast("结租时间必须大于起租时间")
                            $(".addMaintainancePlanEndDate").val('')
                        } else {
                            vc.component.addMaintainancePlanInfo.endDate = value;
                        }
                    });
                //防止多次点击时间插件失去焦点
                document.getElementsByClassName('form-control addMaintainancePlanStartDate')[0].addEventListener('click', myfunc)
 
                function myfunc(e) {
                    e.currentTarget.blur();
                }
 
                document.getElementsByClassName("form-control addMaintainancePlanEndDate")[0].addEventListener('click', myfunc)
 
                function myfunc(e) {
                    e.currentTarget.blur();
                }
            },
            addMaintainancePlanValidate() {
                return vc.validate.validate({
                    addMaintainancePlanInfo: vc.component.addMaintainancePlanInfo
                }, {
                    'addMaintainancePlanInfo.planName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "计划名称不能为空"
                        },
                        {
                            limit: "maxin",
                            param: "1,100",
                            errInfo: "巡检计划名称不能超过100位"
                        }
                    ],
                    'addMaintainancePlanInfo.standardId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "保养标准不能为空"
                        }
                    ],
                    'addMaintainancePlanInfo.planPeriod': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "保养周期不能为空"
                        },
                        {
                            limit: "maxin",
                            param: "1,12",
                            errInfo: "保养周期格式错误"
                        }
                    ],
                    'addMaintainancePlanInfo.startDate': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "计划开始时间不能为空"
                        },
                        {
                            limit: "date",
                            param: "",
                            errInfo: "计划开始时间不是有效的时间格式"
                        }
                    ],
                    'addMaintainancePlanInfo.endDate': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "计划结束时间不能为空"
                        },
                        {
                            limit: "date",
                            param: "",
                            errInfo: "计划结束时间不是有效的时间格式"
                        }
                    ],
                    'addMaintainancePlanInfo.state': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "状态不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "签到方式格式错误"
                        }
                    ],
                    'addMaintainancePlanInfo.remark': [
                        {
                            limit: "maxLength",
                            param: "200",
                            errInfo: "备注信息不能超过200位"
                        }
                    ],
                });
            },
            /* _initAddMaintainancePlanDateInfo: function () {
                 vc.initDate('addMaintainancePlanStartDate', function (_value) {
                     $that.addMaintainancePlanInfo.startDate = _value;
                 });
                 vc.initDate('addMaintainancePlanEndDate', function (_value) {
                     $that.addMaintainancePlanInfo.endDate = _value;
                 });
             },*/
            saveMaintainancePlanInfo: function () {
                if (!vc.component.addMaintainancePlanValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                if (vc.component.addMaintainancePlanInfo.planPeriod && vc.component.addMaintainancePlanInfo.planPeriod == '2020022') { //月、天
                    if (vc.component.addMaintainancePlanInfo.months == null || vc.component.addMaintainancePlanInfo.months == []
                        || vc.component.addMaintainancePlanInfo.months == undefined || vc.component.addMaintainancePlanInfo.months.length < 1) {
                        vc.toast("月不能为空!");
                        return;
                    }
                    if (vc.component.addMaintainancePlanInfo.days == null || vc.component.addMaintainancePlanInfo.days == []
                        || vc.component.addMaintainancePlanInfo.days == undefined || vc.component.addMaintainancePlanInfo.days.length < 1) {
                        vc.toast("天不能为空!");
                        return;
                    }
                }
                if (vc.component.addMaintainancePlanInfo.planPeriod && vc.component.addMaintainancePlanInfo.planPeriod == '2020023') { //固定
                    if (vc.component.addMaintainancePlanInfo.everyDays == null || vc.component.addMaintainancePlanInfo.everyDays == undefined
                        || vc.component.addMaintainancePlanInfo.everyDays == [] || vc.component.addMaintainancePlanInfo.everyDays == '' || vc.component.addMaintainancePlanInfo.everyDays.length < 1) {
                        vc.toast("固定天数不能为空!");
                        return;
                    }
                }
                vc.component.addMaintainancePlanInfo.communityId = vc.getCurrentCommunity().communityId;
                $that.addMaintainancePlanInfo.maintainanceMonth = $that.addMaintainancePlanInfo.months.join(',');
                $that.addMaintainancePlanInfo.maintainanceDay = $that.addMaintainancePlanInfo.days.join(',');
                $that.addMaintainancePlanInfo.maintainanceEveryday = $that.addMaintainancePlanInfo.everyDays;
                //不提交数据将数据 回调给侦听处理
                vc.http.apiPost(
                    '/maintainancePlan.saveMaintainancePlan',
                    JSON.stringify(vc.component.addMaintainancePlanInfo), {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            vc.toast('添加成功');
                            vc.goBack();
                            return;
                        } else {
                            vc.toast(_json.msg);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            /*_changeMaintainancePeriod: function () {
                $that.addMaintainancePlanInfo.months = [];
                $that.addMaintainancePlanInfo.days = [];
                $that.addMaintainancePlanInfo.everyDays = [];
                if ($that.addMaintainancePlanInfo.planPeriod == '2020022') {
                    for (let _month = 1; _month < 13; _month++) {
                        $that.addMaintainancePlanInfo.months.push(_month);
                    }
                    for (let _day = 1; _day < 32; _day++) {
                        $that.addMaintainancePlanInfo.days.push(_day);
                    }
                } else {
                    for (let _day = 1; _day < 8; _day++) {
                        $that.addMaintainancePlanInfo.everyDays.push(_day);
                    }
                }
            },*/
            _listAddMaintainanceStandards: function () {
                let param = {
                    params: {
                        page: 1,
                        row: 100,
                        communityId: vc.getCurrentCommunity().communityId
                    }
                };
                //发送get请求
                vc.http.apiGet('/maintainance.listMaintainanceStandard',
                    param,
                    function (json, res) {
                        let _maintainanceRouteManageInfo = JSON.parse(json);
                        $that.addMaintainancePlanInfo.standards = _maintainanceRouteManageInfo.data;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listAddEquipmentAccounts: function (_page, _row) {
                let param = {
                    params: {
                        page: 1,
                        row: 100,
                        communityId: vc.getCurrentCommunity().communityId
                    }
                };
                //发送get请求
                vc.http.apiGet('/equipmentAccount.listEquipmentAccount',
                    param,
                    function (json, res) {
                        var _equipmentAccountManageInfo = JSON.parse(json);
                        vc.component.addMaintainancePlanInfo.machines = _equipmentAccountManageInfo.data;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
        }
    });
})(window.vc);