123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- let App = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- disabled: false,
- nav_select: false, // 快捷导航
- name: '',
- region: '',
- phone: '',
- detail: '',
- error: '',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- },
- /**
- * 表单提交
- */
- saveData: function(e) {
- let _this = this,
- values = e.detail.value
- values.region = this.data.region;
- // 表单验证
- if (!_this.validation(values)) {
- App.showError(_this.data.error);
- return false;
- }
- // 按钮禁用
- _this.setData({
- disabled: true
- });
- // 提交到后端
- App._post_form('address/add', values, function(result) {
- App.showSuccess(result.msg, function() {
- wx.navigateBack();
- });
- }, false, function() {
- // 解除禁用
- _this.setData({
- disabled: false
- });
- });
- },
- /**
- * 表单验证
- */
- validation: function(values) {
- if (values.name === '') {
- this.data.error = '收件人不能为空';
- return false;
- }
- if (values.phone.length < 1) {
- this.data.error = '手机号不能为空';
- return false;
- }
- // if (values.phone.length !== 11) {
- // this.data.error = '手机号长度有误';
- // return false;
- // }
- let reg = /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/;
- if (!reg.test(values.phone)) {
- this.data.error = '手机号不符合要求';
- return false;
- }
- if (!this.data.region) {
- this.data.error = '省市区不能空';
- return false;
- }
- if (values.detail === '') {
- this.data.error = '详细地址不能为空';
- return false;
- }
- return true;
- },
- /**
- * 修改地区
- */
- bindRegionChange: function(e) {
- this.setData({
- region: e.detail.value
- })
- },
- /**
- * 获取微信地址
- */
- chooseAddress: function() {
- let _this = this;
- wx.chooseAddress({
- success: function(res) {
- _this.setData({
- name: res.userName,
- phone: res.telNumber,
- region: [res.provinceName, res.cityName, res.countyName],
- detail: res.detailInfo
- });
- }
- })
- },
- })
|