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
<template>
<div class="full-page">
<div class="container addMainPage">
<div class="p-title">
<span class="label">您的基本信息</span>
<span class="link text-orange">默认为户主</span>
</div>
<div class="form">
<div class="table">
<div class="tr">
<div class="td label">姓名</div>
<div class="td text-right">
<input type="text" class="form-control" v-model="userData.name" @blur="BaseValidateName" placeholder="请输入姓名"/>
<span v-show="!BaseValidate.nameState" class="small-hint">(只能是中文或英文,长度1~15位)</span>
</div>
</div>
<div class="tr">
<div class="td label">手机号</div>
<div class="td text-right">
<input type="text" class="form-control" placeholder="请输入有效的手机号码" @blur="BaseValidatePhone" v-model="userData.phone"/>
<span v-show="!BaseValidate.phoneState" class="small-hint">请输入有效的手机号码</span>
</div>
</div>
<div class="tr">
<div class="td label">身份证号</div>
<div class="td text-right">
<input type="text" class="form-control" placeholder="请输入有效身份证" @blur="BaseValidateIdCard" v-model="userData.idCard"/>
<span v-show="!BaseValidate.idCardState" class="small-hint">请输入有效身份证</span>
</div>
</div>
</div>
</div>
<div class="form">
<div class="table">
<div class="tr">
<div class="td label">末次月经时间</div>
<div class="td text-right">
<div class="td-table" @click="openPickerLastMensesTime">
<div class="td-table-cell text">{{userData.lastMensesTime !== '' ? userData.lastMensesTime : '请选择末次月经时间'}}</div>
<div class="td-table-cell icon">
<i class="glyphicon glyphicon-menu-right"></i>
</div>
</div>
<span v-show="!BaseValidate.lastMensesTimeState" class="small-hint">请选择末次月经时间</span>
</div>
</div>
</div>
</div>
<div class="footer">
<button class="btn-default btn-block" :class="btnDisabled?'disabled':''" :disabled="btnDisabled" @click="handelSave">立即领取</button>
</div>
</div>
<!-- 末次月经时间picker -->
<mt-datetime-picker
v-model="pickerLastMensesTimeDefault"
ref="pickerLastMensesTime"
type="date"
year-format="{value} 年"
month-format="{value} 月"
date-format="{value} 日"
@confirm="lastMensesTimePickerConfirm"
:startDate="pickerLastMensesTimeStart"
:endDate="pickerLastMensesTimeEnd">
</mt-datetime-picker>
</div>
</template>
<script>
import { getStore } from '@/util/store'
import { saveMember } from '@/api/basic/basic'
import { validatename, cardid, isvalidatemobile } from '@/util/validate'
import { SubtractDay, getBirthByIdNumber, getSexByIdCard } from '@/util/index'
import { setTimeout } from 'timers'
export default {
name: 'Home',
data () {
return {
userId: getStore({ name: 'user_id' }),
orgId: this.$route.query.orgId ? parseInt(this.$route.query.orgId) : null,
orgName: this.$route.query.orgName ? this.$route.query.orgName : '',
userData: {
name: '',
idCard: '',
phone: '',
lastMensesTime: '' // 末次月经时间
},
BaseValidate: { // 表单各个列是否合法状态
nameState: true,
idCardState: true,
phoneState: true,
lastMensesTimeState: true
},
btnDisabled: false,
pickerLastMensesTimeDefault: new Date(), // 末次月经时间默认选中日期为当天
pickerLastMensesTimeStart: SubtractDay(290), // 末次月经时间起始日期为当天日期前290天
pickerLastMensesTimeEnd: new Date() // 末次月经时间控件结束日期小于当天
}
},
created () {
},
mounted: function () {
},
computed: {
},
components: {
},
methods: {
BaseValidateHandle () { // 表单验证
this.BaseValidateName()
this.BaseValidateIdCard()
this.BaseValidatePhone()
this.BaseValidateMensesLastDate()
},
BaseValidateName () { // 姓名验证
if (validatename(this.userData.name)) {
this.BaseValidate.nameState = true
} else {
this.BaseValidate.nameState = false
}
},
BaseValidateIdCard () { // 身份证验证
if (cardid(this.userData.idCard)[0]) {
this.BaseValidate.idCardState = false
} else {
this.BaseValidate.idCardState = true
}
},
BaseValidatePhone () { // 手机号码验证
if (this.userData.phone === '') {
this.BaseValidate.phoneState = false
} else if (isvalidatemobile(this.userData.phone)[0]) {
this.BaseValidate.phoneState = false
} else {
this.BaseValidate.phoneState = true
}
},
BaseValidateMensesLastDate () { // 末次月经时间验证
if (this.userData.lastMensesTime === '') {
this.BaseValidate.lastMensesTimeState = false
} else {
this.BaseValidate.lastMensesTimeState = true
}
},
openPickerLastMensesTime () {
this.$refs.pickerLastMensesTime.open()
},
lastMensesTimePickerConfirm (date) {
const selectedDate = new Date(date)
let month = selectedDate.getMonth() + 1
if (selectedDate.getMonth() + 1 <= 9) {
month = '0' + (selectedDate.getMonth() + 1)
}
this.userData.lastMensesTime = selectedDate.getFullYear() + '-' + month + '-' + selectedDate.getDate()
},
handelSave () {
console.log('submit')
this.BaseValidateHandle()
if (!this.BaseValidate.nameState || !this.BaseValidate.phoneState || !this.BaseValidate.idCardState || !this.BaseValidate.lastMensesTimeState) {
return true
}
let params = {
userId: this.userId,
name: this.userData.name,
phone: this.userData.phone,
idCard: this.userData.idCard,
sex: getSexByIdCard(this.userData.idCard),
lastMensesTime: this.userData.lastMensesTime,
orgId: this.orgId,
orgName: this.orgName,
relationType: '0',
birth: getBirthByIdNumber(this.userData.idCard)
}
this.btnDisabled = true
this.$Indicator.open()
saveMember(params).then(res => {
this.btnDisabled = false
this.$Indicator.close()
if (res.code === 0 && res.data) {
this.$toast({
message: '保存成功',
position: 'center',
duration: 3000
})
let that = this
setTimeout(function () {
that.$router.push({
path: '/'
})
}, 2500)
} else {
this.$toast({
message: '保存失败',
position: 'center',
duration: 3000
})
}
}).catch((error) => {
this.$toast({
message: error.message,
position: 'center',
duration: 3000
})
})
}
}
}
</script>
<style scoped>
.full-page {
background-color: #f5f6f7;
}
.addMainPage .footer{
padding: 4em 0;
}
.addMainPage .p-title {
padding: 1em 0 0 0;
}
.addMainPage .form > .table > .tr > .td.label {
color: #9aa0a4;
font-weight: normal;
}
</style>