| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- 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: '',
- type: 0,//0为新建,1为编辑
- remark:''
- },
- onLoad: function (options) {
- console.log('options',options)
- if(options.type == 1){
- var address = wx.getStorageSync('editAddr');
- console.log('addrhere',address)
- this.setData({
- type: 1,
- tel:address.tel,
- name:address.contact,
- addrid:address.id,
- remark:address.remark
- })
- }
- },
- bindName: function (e) {
- this.setData({
- name: e.detail.value
- })
- },
- bindTel: function (e) {
- this.setData({
- tel: e.detail.value
- })
- },
- bindRemark: function (e) {
- this.setData({
- remark: e.detail.value
- })
- },
- bindMore: function (e) {
- this.setData({
- more: e.detail.value
- })
- },
- validate () {
- var msg
- if (!validator.required(this.data.name)) {
- msg = '提货人不能为空'
- } else if (!validator.required1(this.data.name)) {
- msg = '国家安全局规定:运单禁止出现“先生”,“小姐”,“女士”等,请填写完整名字'
- } else if (!validator.required(this.data.tel)) {
- msg = '联系电话不能为空'
- } else if (!validator.telphone(this.data.tel)) {
- msg = '手机号码格式不正确'
- }
- return { isOk: !msg, msg }
- },
- save: function (e) {
- _handle.setFormId(e)
- var { isOk, msg } = this.validate()
- if (isOk) {
- this.requestAddress()
- } else {
- wx.showToast({
- title: msg,
- icon: 'none',
- duration: 2000
- })
- }
- },
- requestAddress () {
- console.log('requestAddress')
- var that = this
-
- if(that.data.type == 1){
- var url = 'v1/pick_address/'+that.data.addrid;
- }else{
- var url = 'v1/pick_address';
- }
- var params = {
- contact: this.data.name,
- tel: this.data.tel,
- set_default: 1,
- }
- var success = function (res) {
- wx.navigateBack({
- delta: 1
- })
- }
- if(that.data.type == 1){
- _request.$put(url, params, success)
- }else{
- _request.$post(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'
- })
- }
- })
|