CooperationApply.js
2.57 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
// components/CooperationApply/CooperationApply.js
import WxValidate from "../../utils/WxValidate";
import util from "../../utils/util"
Component({
/**
* 组件的属性列表
*/
properties: {},
/**
* 组件的初始数据
*/
data: {
tabData: [
{
name: "门店合作申请",
value: 0,
},
{
name: "代理商合作申请",
value: 1,
},
],
tabIndex: 0,
applyForm: {
merchantName: "",
carModel: "",
contactName: "",
contactPhone: "",
},
},
/**
* 组件的方法列表
*/
methods: {
selectTab(e) {
console.log(e.currentTarget.dataset.index);
this.setData({
tabIndex: e.currentTarget.dataset.index,
});
},
// 表单验证规则
initValidate() {
console.log(123123);
const rules = {
merchantName: {
required: true,
},
contactName: {
required: true,
},
contactPhone: {
required: true,
tel: true,
},
};
const messages = {
merchantName: {
required: "请填写门店名称",
},
contactName: {
required: "请填写联系人",
},
contactPhone: {
required: "请填写手机号",
},
};
this.WxValidate = new WxValidate(rules, messages);
},
//报错
showModal(error) {
wx.showToast({
title: error.msg,
icon: "none",
});
},
// 表单输入
handleInput(e) {
let name = e.currentTarget.dataset.name;
let val = e.detail.value;
const form = `applyForm.${name}`;
this.setData({
[form]: val,
});
},
// 校验表单
validateForm() {
let params = this.data.applyForm;
// 校验表单
if (!this.WxValidate.checkForm(params)) {
const error = this.WxValidate.errorList[0];
wx.hideLoading();
this.showModal(error);
return false;
} else {
return [params, this.data.tabIndex];
}
},
// 设置手机号
setPhone(phone) {
this.setData({
['applyForm.contactPhone']: phone,
});
},
},
// 组件页面生周期
lifetimes: {
created: function () {
// 在组件实例刚刚被创建时执行
// 初始化验证规则函数
this.initValidate();
},
attached: function() {
if (util.getUserInfo()&& util.getUserInfo().phone) {
this.setPhone(util.getUserInfo().phone)
console.log(this.data.applyForm)
}
}
},
});