123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- //index.js
- //获取应用实例
- const city = require('../../../../utils/city.js');
- const cityObjs = require('../../../../utils/city.js');
- const config = require('../../../../utils/config.js');
- const app = getApp()
- Page({
- data: {
- indicatorDots: true,
- datatype: '',
- id: '',
- city: '',
- county: '',
- consignee: '',
- phone: '',
- address: '',
- canIUse: wx.canIUse('button.open-type.getUserInfo')
- },
- //事件处理函数
- bindViewTap: function() {
- wx.navigateTo({
- url: '../logs/logs'
- })
- },
- onLoad: function(options) {
- if (app.globalData.userphone != null) {
- this.setData({
- phone: app.globalData.userphone
- })
- }
- var that = this
- if (JSON.stringify(options) == "{}") {
- wx.getLocation({
- type: 'wgs84',
- success: function(res) {
- let latitude = res.latitude
- let longitude = res.longitude
- wx.request({
- url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${config.key}`,
- success: res => {
- that.setData({
- city: res.data.result.ad_info.city,
- currentCityCode: res.data.result.ad_info.adcode,
- county: res.data.result.ad_info.district
- })
- },
- fail() {
- app.timeOut()
- }
- })
- },
- fail() {
- app.timeOut()
- }
- })
- } else if (options.type == "bill") {
- this.setData({
- datatype: options.type
- })
- wx.getLocation({
- type: 'wgs84',
- success: function(res) {
- let latitude = res.latitude
- let longitude = res.longitude
- wx.request({
- url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${config.key}`,
- success: res => {
- that.setData({
- city: res.data.result.ad_info.city,
- currentCityCode: res.data.result.ad_info.adcode,
- county: res.data.result.ad_info.district
- })
- },
- fail() {
- app.timeOut()
- }
- })
- }
- })
- } else if (options.type == "chose") {
- this.setData({
- datatype: options.type
- })
- wx.getLocation({
- type: 'wgs84',
- success: function(res) {
- let latitude = res.latitude
- let longitude = res.longitude
- wx.request({
- url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${config.key}`,
- success: res => {
- that.setData({
- city: res.data.result.ad_info.city,
- currentCityCode: res.data.result.ad_info.adcode,
- county: res.data.result.ad_info.district
- })
- }
- })
- },
- fail() {
- app.timeOut()
- }
- })
- } else {
- this.setData({
- datatype: options.datatype,
- address: options.address,
- city: options.city,
- consignee: options.consignee,
- county: options.county,
- id: options.id,
- phone: options.phone
- })
- }
- let _this = this;
- _this.setData({
- navH: app.globalData.navHeight
- })
- },
- // hrefCl: function(e) {
- // wx.navigateTo({
- // url: '/pages/consultant/consultant'
- // })
- // },
- // hrefPm: function(e) {
- // wx.navigateTo({
- // url: '/pages/promotion/promotion'
- // })
- // },
- // hrefEq: function(e) {
- // wx.navigateTo({
- // url: '/pages/equipment/equipment'
- // })
- // },
- hrefswitchcity: function() {
- wx.navigateTo({
- url: '/pages/switchcity/switchcity'
- });
- },
- inputconsignee: function(e) {
- this.setData({
- consignee: e.detail.value
- })
- },
- inputphone: function(e) {
- this.setData({
- phone: e.detail.value
- })
- },
- inputaddress: function(e) {
- this.setData({
- address: e.detail.value
- })
- },
- commit: function() {
- if (this.data.consignee == null || this.data.consignee == '') {
- wx.showToast({
- title: '请正确输入收货人!',
- icon: 'none',
- duration: 1500
- })
- return false;
- }
- var myphone = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
- if (!myphone.test(this.data.phone)) {
- wx.showToast({
- title: '请正确输入手机号!',
- icon: 'none',
- duration: 1500
- })
- return false;
- }
- if (this.data.address == null || this.data.address == '') {
- wx.showToast({
- title: '请输入详细地址!',
- icon: 'none',
- duration: 1500
- })
- return false;
- }
- wx.showLoading({
- title: '保存中......',
- icon: 'loading',
- duration: 5500
- })
- if (this.data.datatype == "update") {
- wx.request({
- url: app.globalData.url + '/updateWXUserAddress',
- method: 'post',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- data: {
- xa_phone: this.data.phone,
- xa_consignee: this.data.consignee,
- xa_city: this.data.city,
- xa_county: this.data.county,
- xa_address: this.data.address,
- id: this.data.id
- },
- success: function(res) {
- wx.hideLoading()
- wx.showToast({
- title: '保存成功!',
- icon: 'success',
- duration: 1500
- })
- var pages = getCurrentPages();
- var currPage = pages[pages.length - 1];
- var prevPage = pages[pages.length - 2];
- wx.request({
- url: app.globalData.url + '/getWXUserAddress',
- method: 'get',
- data: {
- xu_openid: app.globalData.openid
- },
- success: function(res2) {
- prevPage.setData({
- addressList: res2.data
- })
- wx.navigateBack({
- delta: 1
- })
- }
- })
- },
- fail() {
- app.timeOut()
- }
- })
- } else if (this.data.datatype == "bill") {
- wx.request({
- url: app.globalData.url + '/insertWXUserAddress',
- method: 'post',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- data: {
- xu_openid: app.globalData.openid,
- xa_phone: this.data.phone,
- xa_consignee: this.data.consignee,
- xa_city: this.data.city,
- xa_county: this.data.county,
- xa_address: this.data.address
- },
- success: function(res) {
- wx.hideLoading()
- wx.showToast({
- title: '保存成功!',
- icon: 'success',
- duration: 1500
- })
- var pages = getCurrentPages();
- var currPage = pages[pages.length - 1];
- var prevPage = pages[pages.length - 2];
- wx.request({
- url: app.globalData.url + '/getEqUserAddress',
- method: 'get',
- data: {
- xu_openid: app.globalData.openid
- },
- success: function(resbill) {
- prevPage.setData({
- xa_consignee: resbill.data.xa_consignee,
- xa_city: resbill.data.xa_city,
- xa_county: resbill.data.xa_county,
- xa_address: resbill.data.xa_address,
- xa_phone: resbill.data.xa_phone,
- })
- wx.navigateBack({
- delta: 1
- })
- }
- })
- },
- fail() {
- app.timeOut()
- }
- })
- } else if (this.data.datatype == "chose") {
- wx.request({
- url: app.globalData.url + '/insertWXUserAddress',
- method: 'post',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- data: {
- xu_openid: app.globalData.openid,
- xa_phone: this.data.phone,
- xa_consignee: this.data.consignee,
- xa_city: this.data.city,
- xa_county: this.data.county,
- xa_address: this.data.address
- },
- success: function(res) {
- wx.hideLoading()
- wx.showToast({
- title: '保存成功!',
- icon: 'success',
- duration: 1500
- })
- var pages = getCurrentPages();
- var currPage = pages[pages.length - 1];
- var prevPage = pages[pages.length - 2];
- wx.request({
- url: app.globalData.url + '/getWXUserAddress',
- method: 'get',
- data: {
- xu_openid: app.globalData.openid
- },
- success: function(resbill) {
- prevPage.setData({
- addressList: resbill.data,
- datatype: 'bill'
- })
- wx.navigateBack({
- delta: 1
- })
- }
- })
- },
- fail() {
- app.timeOut()
- }
- })
- } else {
- wx.request({
- url: app.globalData.url + '/insertWXUserAddress',
- method: 'post',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- data: {
- xu_openid: app.globalData.openid,
- xa_phone: this.data.phone,
- xa_consignee: this.data.consignee,
- xa_city: this.data.city,
- xa_county: this.data.county,
- xa_address: this.data.address
- },
- success: function(res) {
- wx.hideLoading()
- wx.showToast({
- title: '保存成功!',
- icon: 'success',
- duration: 1500
- })
- var pages = getCurrentPages();
- var currPage = pages[pages.length - 1];
- var prevPage = pages[pages.length - 2];
- wx.request({
- url: app.globalData.url + '/getWXUserAddress',
- method: 'get',
- data: {
- xu_openid: app.globalData.openid
- },
- success: function(res) {
- prevPage.setData({
- addressList: res.data
- })
- wx.navigateBack({
- delta: 1
- })
- },
- fail() {
- app.timeOut()
- }
- })
- },
- fail() {
- app.timeOut()
- }
- })
- }
- }
- })
|