form.vue
3.5 KB
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
<template>
<view class="scheduleForm-v ncc-wrap">
<u-toast ref="uToast" />
<u-form :model="dataForm" :rules="rules" ref="dataForm" :errorType="['toast']" label-position="left"
label-width="150" label-align="left">
<u-form-item label="开始时间" prop="startTime" required>
<ncc-date-time type="date" v-model="dataForm.startTime" placeholder="开始时间">
</ncc-date-time>
</u-form-item>
<u-form-item label="结束时间" prop="endTime" required>
<ncc-date-time type="date" v-model="dataForm.endTime" placeholder="结束时间"></ncc-date-time>
</u-form-item>
<u-form-item label="记录内容" prop="content" required>
<u-input v-model="dataForm.content" type="textarea" placeholder="请输入记录内容" />
</u-form-item>
<view class="ncc-card">
<u-form-item label="提醒设置" prop="early">
<u-input v-model="dataForm.early" type="number" placeholder="默认一小时提醒我" />
</u-form-item>
<u-form-item label="APP提醒" prop="appAlert">
<ncc-switch v-model="dataForm.appAlert"></ncc-switch>
</u-form-item>
<u-form-item label="微信提醒" prop="weChatAlert">
<ncc-switch v-model="dataForm.weChatAlert"></ncc-switch>
</u-form-item>
<u-form-item label="邮件提醒" prop="mailAlert">
<ncc-switch v-model="dataForm.mailAlert"></ncc-switch>
</u-form-item>
<u-form-item label="短信提醒" prop="mobileAlert">
<ncc-switch v-model="dataForm.mobileAlert"></ncc-switch>
</u-form-item>
</view>
</u-form>
<view class="com-saveBox">
<u-button type="primary" @click="save">保存</u-button>
</view>
</view>
</template>
<script>
import {
getScheduleInfo,
create,
update
} from '@/api/apply/schedule.js'
export default {
data() {
return {
dataForm: {
appAlert: 0,
colour: "",
content: "",
early: '',
endTime: '',
mailAlert: 0,
mobileAlert: 0,
startTime: '',
weChatAlert: 0
},
rules: {
startTime: [{
required: true,
message: '开始时间不能为空',
trigger: 'change',
type: 'number'
}],
endTime: [{
required: true,
message: '结束时间不能为空',
trigger: 'change',
type: 'number'
}],
content: [{
required: true,
message: '记录不能为空',
trigger: 'change',
}],
}
}
},
onReady() {
this.$refs.dataForm.setRules(this.rules);
},
onLoad(option) {
if (option.id) {
this.dataForm.id = option.id
uni.setNavigationBarTitle({
title: '编辑日程'
});
getScheduleInfo(option.id).then(res => {
this.dataForm = res.data
})
} else {
uni.setNavigationBarTitle({
title: '新增日程'
});
}
},
methods: {
save() {
if (this.dataForm.startTime > this.dataForm.endTime) {
this.$refs.uToast.show({
title: '开始时间不能大于结束时间',
type: 'error'
})
this.dataForm.startTime = '';
this.dataForm.endTime = '';
return
}
this.$refs.dataForm.validate((valid) => {
if (valid) {
const formMethod = this.dataForm.id ? update : create;
formMethod(this.dataForm).then(res => {
uni.showToast({
title: res.msg,
complete: () => {
setTimeout(() => {
uni.redirectTo({
url: './index',
});
}, 1500)
}
})
})
}
})
}
}
}
</script>
<style lang="scss">
page {
background-color: #f0f2f6;
}
.scheduleForm-v {
padding-bottom: 110rpx;
}
</style>