CooperationApply.js
3.8 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
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
// components/CooperationApply/CooperationApply.js
import WxValidate from "../../utils/WxValidate";
import util from "../../utils/util"
import {
componentsMixin
} from "../../mixins/index";
Component({
behaviors: [componentsMixin],
options: {
// 基础库2.2.3开始支持
addGlobalClass: true
},
/**
* 组件的属性列表
*/
properties: {},
/**
* 组件的初始数据
*/
data: {
tabData: [{
name: "增值转化",
value: 0,
},
{
name: "系统订阅",
value: 1,
},
],
tabIndex: 0,
applyForm: {
applyType: '1',
merchantName: "",
carModel: "",
contactName: "",
contactPhone: "",
},
foldFlag: false,
selectApply: 1
},
/**
* 组件的方法列表
*/
methods: {
selectTab(e) {
this.setData({
tabIndex: e.currentTarget.dataset.index,
});
this.selectComponent("#sceneBox").resetScene()
},
// 合作方式切换
applyChange(e) {
this.setData({
selectApply: e.detail.value,
});
// this.selectComponent("#sceneBox").resetScene()
},
// 展开收起
handleFold() {
this.setData({
foldFlag: !this.data.foldFlag
})
},
// 表单验证规则
initValidate() {
const rules = {
applyType: {
required: true,
},
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, this.data.applyForm.applyType];
let selectScene = this.selectComponent("#sceneBox").getSceneItems();
if (selectScene && !selectScene[2]) {
wx.hideLoading();
wx.showToast({
title: "请至少选择一个产品",
icon: "none",
});
return false
}
if (selectScene) {
params.businessScenario = selectScene[0].title;
params.productItems = selectScene[1].join(",");
}
let applyType = this.data.tabIndex == 0 ? '增值转化' : '系统订阅';
let ccoperationType = this.data.selectApply == 1 ? '门店' : '代理商';
params.merchantName = params.merchantName + '(' + applyType + '-' + ccoperationType + ')'
return params
}
},
// 设置手机号
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)
}
}
},
});