完善功能
This commit is contained in:
@ -163,7 +163,7 @@
|
||||
<view class="form-item-row no-border">
|
||||
<view class="label">联系电话</view>
|
||||
<input class="input-grey" type="number" placeholder="请填写联系方式"
|
||||
placeholder-class="placeholder-style-small" v-model="formData.phone" />
|
||||
placeholder-class="placeholder-style-small" v-model="formData.mobile" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@ -227,8 +227,8 @@ export default {
|
||||
card: '',
|
||||
},
|
||||
parents: [
|
||||
{ name: '', both: '', card: '' },
|
||||
{ name: '', both: '', card: '' }
|
||||
{ id: 0, name: '', both: '', card: '' },
|
||||
{ id: 0, name: '', both: '', card: '' }
|
||||
],
|
||||
child: {
|
||||
name: '',
|
||||
@ -239,15 +239,102 @@ export default {
|
||||
group_id: 0
|
||||
},
|
||||
id: 0,
|
||||
isSubmitting: false
|
||||
isSubmitting: false,
|
||||
setting: {
|
||||
company: {}
|
||||
},
|
||||
info: {}, // 用户信息数据
|
||||
}
|
||||
},
|
||||
onLoad(args) {
|
||||
this.comboType = args.type || 'adult'
|
||||
this.id = args.id
|
||||
this.formData.group_id = this.id
|
||||
this.handleInit()
|
||||
this.handleGetSetting()
|
||||
},
|
||||
methods: {
|
||||
handleInit() {
|
||||
let self = this;
|
||||
self._post(
|
||||
'ground.group/getGroupData',
|
||||
{
|
||||
group_id: self.id
|
||||
},
|
||||
result => {
|
||||
if (result.code && result.data) {
|
||||
const data = result.data;
|
||||
self.info = data;
|
||||
|
||||
self.formData.mobile = data.mobile || '';
|
||||
|
||||
if (data.group_id == 1 ) {
|
||||
// 青年卡
|
||||
self.formData.youth = {
|
||||
name: data.name,
|
||||
both: data.both,
|
||||
card: data.card,
|
||||
}
|
||||
}
|
||||
|
||||
if (data.group_id == 2) {
|
||||
// 成人卡
|
||||
self.formData.adult = {
|
||||
name: data.name,
|
||||
both: data.both,
|
||||
card: data.card,
|
||||
}
|
||||
}
|
||||
|
||||
if (data.group_id == 3 || data.group_id == 4) {
|
||||
// 亲子卡
|
||||
if (data.parent && data.parent.length > 0) {
|
||||
self.formData.parents[0] = {
|
||||
id: data.parent[0].id,
|
||||
name: data.parent[0].name,
|
||||
both: data.parent[0].both,
|
||||
card: data.parent[0].card,
|
||||
}
|
||||
}
|
||||
|
||||
if (data.parent && data.parent.length > 1) {
|
||||
self.formData.parents[1] = {
|
||||
id: data.parent[0].id,
|
||||
name: data.parent[1].name,
|
||||
both: data.parent[1].both,
|
||||
card: data.parent[1].card,
|
||||
}
|
||||
}
|
||||
|
||||
self.formData.child = {
|
||||
name: data.name,
|
||||
both: data.both,
|
||||
card: data.card,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
false,
|
||||
() => {
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
handleGetSetting() {
|
||||
let self = this;
|
||||
self._post(
|
||||
'ground.ground/groundSetting',
|
||||
{
|
||||
app_id: self.getAppId()
|
||||
},
|
||||
function(res) {
|
||||
if (res.code) {
|
||||
self.info = res.data;
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
onYouthDateChange(e) {
|
||||
this.formData.youth.both = e.detail.value;
|
||||
},
|
||||
@ -265,13 +352,39 @@ export default {
|
||||
},
|
||||
|
||||
contactUs() {
|
||||
uni.showToast({ title: '正在连接客服...', icon: 'none' });
|
||||
console.log("🚀 ~ this.setting:", this.setting)
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: this.setting.company.contact
|
||||
});
|
||||
},
|
||||
|
||||
submitForm() {
|
||||
let self = this;
|
||||
const regex = /^[1-9]\d{5}(18|19|20)?\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
|
||||
|
||||
const validateCardAndAgeMatch = (card, both, prefix, ageRule) => {
|
||||
let idBirthStr = card.length === 15 ? '19' + card.substring(6, 12) : card.substring(6, 14);
|
||||
let idDateStr = `${idBirthStr.substring(0, 4)}-${idBirthStr.substring(4, 6)}-${idBirthStr.substring(6, 8)}`;
|
||||
if (idDateStr !== both) {
|
||||
return `${prefix}出生日期选错了与身份证不符`;
|
||||
}
|
||||
if (ageRule) {
|
||||
const today = new Date();
|
||||
let age = today.getFullYear() - parseInt(idBirthStr.substring(0, 4));
|
||||
const m = (today.getMonth() + 1) - parseInt(idBirthStr.substring(4, 6));
|
||||
if (m < 0 || (m === 0 && today.getDate() < parseInt(idBirthStr.substring(6, 8)))) {
|
||||
age--;
|
||||
}
|
||||
if (ageRule === 'adult' && age < 18) {
|
||||
return `${prefix}必须满18周岁`;
|
||||
}
|
||||
if (ageRule === 'child' && age >= 18) {
|
||||
return `${prefix}须未满18周岁`;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// id == 1 验证 youth 属性
|
||||
if (self.id == 1) {
|
||||
let youth = self.formData.youth;
|
||||
@ -281,6 +394,8 @@ export default {
|
||||
if (!regex.test(youth.card)) {
|
||||
return uni.showToast({ title: '请输入正确的身份证号码', icon: 'none' });
|
||||
}
|
||||
let err = validateCardAndAgeMatch(youth.card, youth.both, '', 'child');
|
||||
if (err) return uni.showToast({ title: err, icon: 'none' });
|
||||
}
|
||||
|
||||
// 成人卡
|
||||
@ -293,6 +408,8 @@ export default {
|
||||
if (!regex.test(adult.card)) {
|
||||
return uni.showToast({ title: '请输入正确的身份证号码', icon: 'none' });
|
||||
}
|
||||
let err = validateCardAndAgeMatch(adult.card, adult.both, '', 'adult');
|
||||
if (err) return uni.showToast({ title: err, icon: 'none' });
|
||||
}
|
||||
|
||||
// id == 3(第一个亲子卡) 或 4 时,验证 parents[0] 和 child 属性
|
||||
@ -304,6 +421,8 @@ export default {
|
||||
if (!regex.test(p0.card)) {
|
||||
return uni.showToast({ title: '请输入正确的家长1身份证号码', icon: 'none' });
|
||||
}
|
||||
let err0 = validateCardAndAgeMatch(p0.card, p0.both, '家长1', 'adult');
|
||||
if (err0) return uni.showToast({ title: err0, icon: 'none' });
|
||||
|
||||
// id == 4 时(第二个亲子卡),还需要额外验证 parents[1] 属性
|
||||
if (self.id == 4) {
|
||||
@ -314,6 +433,8 @@ export default {
|
||||
if (!regex.test(p1.card)) {
|
||||
return uni.showToast({ title: '请输入正确的家长2身份证号码', icon: 'none' });
|
||||
}
|
||||
let err1 = validateCardAndAgeMatch(p1.card, p1.both, '家长2', 'adult');
|
||||
if (err1) return uni.showToast({ title: err1, icon: 'none' });
|
||||
}
|
||||
|
||||
let child = self.formData.child;
|
||||
@ -323,15 +444,17 @@ export default {
|
||||
if (!regex.test(child.card)) {
|
||||
return uni.showToast({ title: '请输入正确的子女身份证号码', icon: 'none' });
|
||||
}
|
||||
let errC = validateCardAndAgeMatch(child.card, child.both, '子女', 'child');
|
||||
if (errC) return uni.showToast({ title: errC, icon: 'none' });
|
||||
}
|
||||
|
||||
// 所有场景必填联系电话
|
||||
if (!self.formData.phone) {
|
||||
if (!self.formData.mobile) {
|
||||
return uni.showToast({ title: '请填写联系电话', icon: 'none' });
|
||||
}
|
||||
|
||||
const phoneReg = /^1[3-9]\d{9}$/;
|
||||
if (!phoneReg.test(self.formData.phone)) {
|
||||
if (!phoneReg.test(self.formData.mobile)) {
|
||||
return uni.showToast({ title: '请输入正确的手机号码', icon: 'none' });
|
||||
}
|
||||
|
||||
@ -381,6 +504,7 @@ export default {
|
||||
this.showSuccessPopup = false;
|
||||
// 点击好的之后,可以跳转或返回上一页
|
||||
uni.navigateBack();
|
||||
this.getOpenerEventChannel().emit('data', {notice: 'success'});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user