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: {
            editMaintainancePlanInfo: {
                planId: '',
                planName: '',
                standardId: '',
                standards: [],
                planPeriod: '',
                startDate: vc.dateFormat(new Date()),
                endDate: ' ',
                state: '2020025',
                remark: '',
                months: [],
                days: [],
                everyDays: [],
                staffs: [],
                machines: []
            }
        },
        _initMethod: function () {
            $that.editMaintainancePlanInfo.planId = vc.getParam('planId');
            vc.component._initEditMaintainancePlanDateInfo();
            $that._listEditMaintainanceStandards();
            $that._listMaintainancePlans();
            $that._listMaintainancePlanStaffs();
        },
        _initEvent: function () {
            vc.on("editMaintainancePlanInfo", "notify", function (_param) {
                if (_param.hasOwnProperty("staffId")) {
                    vc.component.editMaintainancePlanInfo.staffId = _param.staffId;
                    vc.component.editMaintainancePlanInfo.staffName = _param.staffName;
                }
            });
        },
        methods: {
            editMaintainancePlanValidate() {
                return vc.validate.validate({
                    editMaintainancePlanInfo: vc.component.editMaintainancePlanInfo
                }, {
                    'editMaintainancePlanInfo.planName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "计划名称不能为空"
                        },
                        {
                            limit: "maxin",
                            param: "1,100",
                            errInfo: "巡检计划名称不能超过100位"
                        }
                    ],
                    'editMaintainancePlanInfo.standardId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "保养标准不能为空"
                        }
                    ],
                    'editMaintainancePlanInfo.planPeriod': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "执行周期不能为空"
                        },
                        {
                            limit: "maxin",
                            param: "1,12",
                            errInfo: "执行周期格式错误"
                        }
                    ],
                    'editMaintainancePlanInfo.startDate': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "计划开始时间不能为空"
                        },
                        {
                            limit: "date",
                            param: "",
                            errInfo: "计划开始时间不是有效的时间格式"
                        }
                    ],
                    'editMaintainancePlanInfo.endDate': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "计划结束时间不能为空"
                        },
                        {
                            limit: "date",
                            param: "",
                            errInfo: "计划结束时间不是有效的时间格式"
                        }
                    ],
                    'editMaintainancePlanInfo.state': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "状态不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "签到方式格式错误"
                        }
                    ],
                    'editMaintainancePlanInfo.remark': [
                        {
                            limit: "maxLength",
                            param: "200",
                            errInfo: "备注信息不能超过200位"
                        }
                    ]
                });
            },
            _initEditMaintainancePlanDateInfo: function () {
                vc.initDate('editMaintainancePlanStartDate', function (_value) {
                    $that.editMaintainancePlanInfo.startDate = _value;
                });
                vc.initDate('editMaintainancePlanEndDate', function (_value) {
                    $that.editMaintainancePlanInfo.endDate = _value;
                });
            },
            saveMaintainancePlanInfo: function () {
                if (!vc.component.editMaintainancePlanValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                if (vc.component.editMaintainancePlanInfo.planPeriod && vc.component.editMaintainancePlanInfo.planPeriod == '2020022') { //月、天
                    if (vc.component.editMaintainancePlanInfo.months == null || vc.component.editMaintainancePlanInfo.months == []
                        || vc.component.editMaintainancePlanInfo.months == undefined || vc.component.editMaintainancePlanInfo.months.length < 1) {
                        vc.toast("月不能为空!");
                        return;
                    }
                    if (vc.component.editMaintainancePlanInfo.days == null || vc.component.editMaintainancePlanInfo.days == []
                        || vc.component.editMaintainancePlanInfo.days == undefined || vc.component.editMaintainancePlanInfo.days.length < 1) {
                        vc.toast("天不能为空!");
                        return;
                    }
                }
                if (vc.component.editMaintainancePlanInfo.planPeriod && vc.component.editMaintainancePlanInfo.planPeriod == '2020023') { //固定
                    if (vc.component.editMaintainancePlanInfo.everyDays == null || vc.component.editMaintainancePlanInfo.everyDays == undefined
                        || vc.component.editMaintainancePlanInfo.everyDays == [] || vc.component.editMaintainancePlanInfo.everyDays == '' || vc.component.editMaintainancePlanInfo.everyDays.length < 1) {
                        vc.toast("固定天数不能为空!");
                        return;
                    }
                }
                vc.component.editMaintainancePlanInfo.communityId = vc.getCurrentCommunity().communityId;
                $that.editMaintainancePlanInfo.maintainanceMonth = $that.editMaintainancePlanInfo.months.join(',');
                $that.editMaintainancePlanInfo.maintainanceDay = $that.editMaintainancePlanInfo.days.join(',');
                $that.editMaintainancePlanInfo.maintainanceEveryday = $that.editMaintainancePlanInfo.everyDays;
                //不提交数据将数据 回调给侦听处理
                vc.http.apiPost(
                    '/maintainancePlan.updateMaintainancePlan',
                    JSON.stringify(vc.component.editMaintainancePlanInfo), {
                        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.editMaintainancePlanInfo.months = [];
                $that.editMaintainancePlanInfo.days = [];
                $that.editMaintainancePlanInfo.everyDays = [];
                if ($that.editMaintainancePlanInfo.planPeriod == '2020022') {
                    for (let _month = 1; _month < 13; _month++) {
                        $that.editMaintainancePlanInfo.months.push(_month);
                    }
                    for (let _day = 1; _day < 32; _day++) {
                        $that.editMaintainancePlanInfo.days.push(_day);
                    }
                } else {
                    for (let _day = 1; _day < 8; _day++) {
                        $that.editMaintainancePlanInfo.everyDays.push(_day);
                    }
                }
            },*/
            _listEditMaintainanceStandards: 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.editMaintainancePlanInfo.standards = _maintainanceRouteManageInfo.data;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listMaintainancePlans: function (_page, _rows) {
                let param = {
                    params: {
                        page: 1,
                        row: 1,
                        communityId: vc.getCurrentCommunity().communityId,
                        planId: $that.editMaintainancePlanInfo.planId
                    }
                };
                //发送get请求
                vc.http.apiGet('/maintainancePlan.listMaintainancePlan',
                    param,
                    function (json, res) {
                        let _maintainancePlanManageInfo = JSON.parse(json);
                        let _params = _maintainancePlanManageInfo.data[0];
                        vc.copyObject(_params, $that.editMaintainancePlanInfo);
                        $that.editMaintainancePlanInfo.months = _params.maintainanceMonth.split(',');
                        $that.editMaintainancePlanInfo.days = _params.maintainanceDay.split(',');
                        $that.editMaintainancePlanInfo.everyDays = _params.maintainanceEveryday;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listMaintainancePlanStaffs: function (_page, _rows) {
                let param = {
                    params: {
                        page: 1,
                        row: 100,
                        communityId: vc.getCurrentCommunity().communityId,
                        planId: $that.editMaintainancePlanInfo.planId
                    }
                };
                //发送get请求
                vc.http.apiGet('/maintainancePlan.listMaintainancePlanStaff',
                    param,
                    function (json, res) {
                        let _maintainancePlanManageInfo = JSON.parse(json);
                        _maintainancePlanManageInfo.data.forEach(item => {
                            item.userId = item.staffId;
                            item.name = item.staffName;
                        });
                        $that.editMaintainancePlanInfo.staffs = _maintainancePlanManageInfo.data;
                        vc.emit('selectStaffs', 'setStaffs', $that.editMaintainancePlanInfo.staffs);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
        }
    });
})(window.vc);