| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- var _request = require('../../../../utils/request.js')
- var validator = require('../../../../utils/validator.js')
- var _handle = require('../../../../utils/handle.js')
- Page({
- data: {
- address: '请选择',
- region: ['北京市', '北京市', '东城区'],
- name: '',
- tel: 0,
- more: '',
- countdown: 0,
- yzm:'',
- remark:''
- },
- onLoad: function (options) {
- },
- getTel (val) {
- console.log(val)
- if (val.detail.encryptedData) {
- this.bindWxTel(val.detail)
- }
- },
- bindWxTel (res) {
- var str = JSON.stringify({
- encryptedData: res.encryptedData,
- iv: res.iv
- })
- var that = this
- var url = 'v1/wxuser/one_click/binding/phonumer'
- var params = {
- userinfo: str
- }
- var success = function (res) {
- console.log(res);
- }
- _request.$post(url, params, success)
- },
- getYzm (e) {
- _handle.setFormId(e)
- if (validator.telphone(this.data.tel)) {
- this.requireYzm()
- } else {
- wx.showToast({
- title: '手机号码格式不正确',
- icon: 'none',
- duration: 2000
- })
- }
- },
- startCountdown: function () {
- var smsRequestTime = wx.getStorageSync('sms_request_time')
- if (smsRequestTime) {
- var count = parseInt((60000 - (new Date() - smsRequestTime)) / 1000)
- this.setData({
- countdown: count
- })
- if (this.data.countdown > 0) {
- var timer = setInterval(() => {
- var countdown = this.data.countdown - 1
- this.setData({
- countdown: countdown
- })
- if (this.data.countdown <= 0) {
- clearInterval(timer)
- }
- }, 1000)
- // clearInterval(this.interval)
- }
- } else {
- }
- },
- requireYzm () {
- var that = this
- var url = 'v1/code/send'
- console.log(typeof(this.data.tel))
- var params = {
- tel: this.data.tel,
- valid_type: 'shop_application'
- }
- var success = function (res) {
- wx.setStorageSync('sms_request_time', Date.now())
- that.startCountdown()
- }
- _request.$post(url, params, success)
- },
- bindPhone (e) {
- this.setData({
- tel: e.detail.value
- })
- },
- bindYzm (e) {
- this.setData({
- yzm: e.detail.value
- })
- },
- bindName: function (e) {
- this.setData({
- name: e.detail.value
- })
- },
- bindMore: function (e) {
- this.setData({
- more: e.detail.value
- })
- },
- bindRemark: function (e) {
- this.setData({
- remark: e.detail.value
- })
- },
- validate () {
- var msg
- if (!validator.required(this.data.name)) {
- msg = '姓名不能为空'
- } else if (!validator.required(this.data.tel)) {
- msg = '联系电话不能为空'
- } else if (!validator.telphone(this.data.tel)) {
- msg = '手机号码格式不正确'
- } else if (this.data.address === '请选择') {
- msg = '请选择所在地区'
- } else if (!validator.required(this.data.more)) {
- msg = '详细地址不能为空'
- }
- return { isOk: !msg, msg }
- },
- save: function (e) {
- _handle.setFormId(e)
- var { isOk, msg } = this.validate()
- if (isOk) {
- this.shopApplication()
- } else {
- wx.showToast({
- title: msg,
- icon: 'none',
- duration: 2000
- })
- }
- },
- shopApplication () {
- var that = this
- var url = 'v1/user/shop_application'
- var params = {
- name: this.data.name,
- mobile: this.data.tel,
- code:this.data.yzm,
- province: this.data.region[0],
- city: this.data.region[1],
- district: this.data.region[2],
- address: this.data.more,
- remark: this.data.remark
- }
- var success = function (res) {
- wx.showToast({
- title: '申请成功@',
- icon: 'none',
- duration: 2000
- })
- }
- _request.$put(url, params, success)
- },
- bindRegionChange: function (e) {
- console.log(e)
- this.setData({
- region: e.detail.value,
- address: e.detail.value[0] + e.detail.value[1] + e.detail.value[2]
- })
- },
- onShareAppMessage: function (val) {
- return _request.share({
- sc: 'xcx_user_newaddress'
- })
- }
- })
|