123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- //index.js
- //获取应用实例
- const app = getApp()
- import WxValidate from '../../utils/wxValidate';
- Page({
- data: {
- form: {},
- // 省份
- provinceList: [],
- // 市区
- cityList: [],
- // 套餐列表
- setList: [],
- },
- initValidate() {
- const rules = {
- mobile: { required: true, tel: true },
- password: { required: true, },
- province: { required: true, },
- city: { required: false, },
- set: { required: true, },
- name: { required: true, },
- id_card: { required: true, idcard: true },
- wxaccount: { required: true, },
- }
- // 验证字段的提示信息,若不传则调用默认的信息
- const messages = {
- mobile: { required: '请输入新办理号码', },
- password: { required: '请输入密码', },
- province: { required: '请选择省份', },
- city: { required: '请选择市区', },
- set: { required: '请选择套餐', },
- name: { required: '请输入姓名', },
- id_card: { required: '请输入身份证号', },
- wxaccount: { required: '请输入微信账号', },
- };
- this.WxValidate = new WxValidate(rules, messages)
- },
- // 选择省份
- provinceChange: function (e) {
- this.setData({ "form.province": this.data.provinceList[e.detail.value].code })
- this.setData({ "form.provinces": this.data.provinceList[e.detail.value].name })
- // 查询市
- wx.request({
- url: app.globalData.publicUrl + '/api/htyd/xzqh',
- method: "get",
- data: { pcode: this.data.provinceList[e.detail.value].code },
- success: (res) => {
- if (res.data.errcode == '0') {
- this.setData({ cityList: res.data.data })
- // 根据查询市,判断查询套餐
- if (res.data.total === 0) {
- // 套餐
- wx.request({
- url: app.globalData.publicUrl + '/api/htyd/set',
- method: "get",
- data: { contact: this.data.provinceList[e.detail.value].code },
- success: (res) => {
- if (res.data.errcode == '0') {
- this.setData({ setList: res.data.data })
- } else {
- wx.showToast({
- title: '查询失败',
- icon: 'error',
- duration: 2000
- })
- }
- }
- })
- }
- } else {
- wx.showToast({
- title: '查询失败',
- icon: 'error',
- duration: 2000
- })
- }
- }
- })
- },
- // 选择市区
- cityChange: function (e) {
- this.setData({ "form.city": this.data.cityList[e.detail.value].code })
- this.setData({ "form.citys": this.data.cityList[e.detail.value].name })
- // 套餐
- wx.request({
- url: app.globalData.publicUrl + '/api/htyd/set',
- method: "get",
- data: { contact: this.data.cityList[e.detail.value].code },
- success: (res) => {
- if (res.data.errcode == '0') {
- this.setData({ setList: res.data.data })
- } else {
- wx.showToast({
- title: '查询失败',
- icon: 'error',
- duration: 2000
- })
- }
- }
- })
- },
- // 选择套餐
- setChange: function (e) {
- this.setData({ "form.set": this.data.setList[e.detail.value].id })
- this.setData({ "form.sets": this.data.setList[e.detail.value].title })
- },
- //事件处理函数
- formSubmit: function (e) {
- const params = e.detail.value;
- if (!this.WxValidate.checkForm(params)) {
- const error = this.WxValidate.errorList[0];
- wx.showToast({
- title: error.msg,
- icon: 'none',
- duration: 2000
- })
- return false
- } else {
- console.log(params);
- }
- wx.request({
- url: app.globalData.publicUrl + '/api/htyd/card',
- method: "post",
- data: params,
- success: (res) => {
- if (res.data.errcode == '0') {
- wx.showToast({
- title: '办卡成功',
- icon: 'success',
- duration: 2000
- })
- wx.redirectTo({
- url: '/pages/home/home',
- })
- } else {
- wx.showToast({
- title: '办卡失败',
- icon: 'error',
- duration: 2000
- })
- }
- }
- })
- },
- onLoad: function (options) {
- this.initValidate()//验证规则函数
- // 获取推荐人信息
- let data = app.globalData.userInfo;
- if (data) {
- console.log('function in if');
- this.setData({ "form.recommend": data.name })
- this.setData({ "form.r_mobile": data.mobile })
- } else {
- let qrUrl = decodeURIComponent(options.q)
- let mobile = this.getQueryString(qrUrl, 'mobile');
- let name = this.getQueryString(qrUrl, 'name');
- console.log('function in else');
- console.log(`mobile:${mobile}`);
- console.log(`name:${name}`);
- if (name && mobile) {
- this.setData({ "form.recommend": name })
- this.setData({ "form.r_mobile": mobile })
- }
- }
- // 查询省
- wx.request({
- url: app.globalData.publicUrl + '/api/htyd/xzqh',
- method: "get",
- data: {},
- success: (res) => {
- if (res.data.errcode == '0') {
- this.setData({ provinceList: res.data.data })
- } else {
- wx.showToast({
- title: '查询失败',
- icon: 'error',
- duration: 2000
- })
- }
- }
- })
- },
- getQueryString: function (url, name) {
- const query = url.split('?')[1];
- const objs = query.split('&');
- let res;
- for (const obj of objs) {
- const kv = obj.split('=');
- if (name == kv[0]) res = kv[1];
- }
- return res;
- }
- })
|