Skip to content

Commit

Permalink
wx.toast的提取,其他page暂未修改过来
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaobinwu committed Jun 2, 2017
1 parent 9046c06 commit af74f3d
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 7 deletions.
14 changes: 14 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ App({
phone: '',
hasData: false
},
//geo page address
geoAddress: {
province: null,
city: null,
district: null,
province_name: null,
city_name: null,
district_name: null,
addressline: null,
address_lng: null,
address_lat: null,
hasLocationStore: null
},
//购物车数据
cartData:{
list:[],
totalCount:1,
Expand Down
123 changes: 121 additions & 2 deletions pages/address-switch/address-switch.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
// pages/address-switch/address-switch.js
var util = require('../../utils/util.js');
var ports = require('../../utils/ports.js');
var location = require('../../utils/address.js');
//获取app实例
var appInstance = getApp();
Page({

/**
* 页面的初始数据
*/
data: {

// 是否显示搜索面板
showSearch: false,
// 地址列表
addressList: [],
// 当前定位数据
currentPos: {
addressline:'获取定位中...'
},
geoAddress: {},

},
showSearchPanel: function(e){
console.log(e)
Expand All @@ -14,7 +28,112 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {

var finalAddress = JSON.parse(util.getStorage('final_address')),
regionShowName = '请选择';
if (finalAddress && finalAddress.region_name){
regionShowName = finalAddress.region_name;
}
appInstance.globalData.geoAddress.city_name = regionShowName;
//定位当前位置
this.getCurrentPos();
//我的收货地址
this.getAddressList();
},
// 定位到当前位置
getCurrentPos: function(type){
var _self = this;
location.getLocation({
token: false,
gpsError(err) {
// 主动触发
if (type == 'active') {
wx.showModal({
title: '提示',
content: '未获得您的设备定位服务,更多门店优惠,等您开启~~',
showCancel: false,
confirmColor: '#e61773'
})
}
}
}).then(result => {
var data = result.data,
fnData = data.final_address;
this.setData({
currentPos: {
city: fnData.region_id,
city_name: fnData.region_name,
addressline: fnData.location_addr,
address_lng: fnData.lng,
address_lat: fnData.lat,
hasLocationStore: data.has_location_store
}
});
// 主动触发
if (type == 'active') {
this.selectAddress(this.data.currentPos, this.data.currentPos.hasLocationStore, 'currentPos');
}
}).catch(e => {
console.log('switch:created:getLocation=>' + e)
});
},
// 获取用户地址列表
getAddressList: function() {
util.getToken().then(token => {
return util.wxRequest({
url: ports.addressList,
header: { 'X-Auth-Token': token, 'content-type': 'application/x-www-form-urlencoded'}
});
}).then(res => {
this.setData({
addressList: res.data
});
}).catch(err => {
if (err.status === 4002) {
wx.navigateTo({
url: '../login/login'
})
return;
}
return wx.showToast({
title: err,
image: '../../image/wrong.png',
duration: 1000
});

})
},
// 本界面选择某个地址
selectAddress: function(add, status, type) {

// 无法获取到定位时
if (type == 'currentPos' && !this.data.currentPos.addressline) {
return;
}

// 不支持配送情况
if (status !== 1) {
return wx.showModal({
title: '提示',
content: '该地址暂无门店支持配送,是否继续跳转?',
confirmColor: '#e61773',
success: function (res) {
if (res.confirm) {
location.setCurrentAddress(add);
wx.redirectTo({
url: '../index/index'
})
}
}
});
}

// 设置当前地址
location.setCurrentAddress(add);

// 跳转到首页
wx.redirectTo({
url: '../index/index'
});
},

/**
Expand Down
4 changes: 2 additions & 2 deletions pages/address-switch/address-switch.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<view class="warning-bar">因就近匹配门店配送服务,请选择准确收货地址</view>
<view class="location-local gray-title">当前位置</view>
<view class="local-address" bindtap="selectAddress" data-current-pos="{{currentPos}}" data-send-sta="{{sendSta}}" data-type="currentPos" class="{{!showSendSta ? 'spb' : ''}}">
<text>{{addressLine}}</text>
<text class="address-line">{{addressLine}}</text>
<block wx:if="{{showSendSta}}">
<text class="send-status" wx:if="{{sendSta == 1}}">支持配送</text>
<text class="send-status no" wx:if="{{sendSta == 0}}">不支持配送</text>
Expand All @@ -25,7 +25,7 @@
<view class="gray-title">我的收货地址</view>
<view class="my-address-list">
<view class="address-list">
<view class="address-item" wx:for="{{addressList}}" data-item="{{item}}" data-delivery-sta="{{item.delivery_sta}}" bindtap="selectAddress">
<view class="address-item {{addressList.length - 1 == index ? 'last-address-item' : ''}}" wx:for="{{addressList}}" data-item="{{item}}" data-delivery-sta="{{item.delivery_sta}}" bindtap="selectAddress">
<view class="basic-info">
<text class="user-name">{{item.username}}</text>
<text class="user-phone">{{item.tel}}</text>
Expand Down
119 changes: 118 additions & 1 deletion pages/address-switch/address-switch.wxss
Original file line number Diff line number Diff line change
@@ -1 +1,118 @@
/* pages/address-switch/address-switch.wxss */
/* pages/address-switch/address-switch.wxss */
.warning-bar{
padding: 20rpx;
background-color: #fff9e3;
border-bottom: 1px solid #efe5a6;
font-size: 26rpx;
color: #d08d3d;
}
.gray-title{
padding: 40rpx 20rpx 8rpx;
background-color: #e8e8e8;
font-size: 28rpx;
color:#999;
}
.send-status{
padding: 4rpx;
display: inline-block;
border: solid #25ae5f 1px;
border-radius: 4rpx;
font-size: 22rpx;
color:#25ae5f;
}
.send-status.yes{
color:#25ae5f;
border-color: #25ae5f;
}
.send-status.no{
color:#999;
border-color: #999;
}
.get-pos-again{
padding: 20rpx 50rpx 20rpx 20rpx;
color: #e61773;
font-size: 28rpx;
}
.area-search-bar{
display: flex;
justify-content:space-between;
align-items:center;
padding: 20rpx;
border-bottom: 1px solid #e8e8e8;
background-color: #fff;
}
.area-search-bar .city-select{
flex-shrink:0;
display: flex;
padding-right: 20rpx;
font-size: 28rpx;
}
.area-search-bar .area-search-ipt{
display: block;
flex-grow:1;
padding: 20rpx;
border-radius: 50rpx;
background: #e8e8e8;
border: none;
font-size: 28rpx;
outline: none;
}
.area-search-bar .area-search-ipt::-webkit-input-placeholder{
border-radius: 5rpx;
font-size: 28rpx;
color:#ccc;
}
.area-search-bar .area-search-btn{
flex-shrink:0;
padding-right: 15rpx;
background: none;
border: none;
font-size: 28rpx;
color:#222;
}
.local-address{
display: flex;
align-items:center;
padding: 30rpx 20rpx;
height: 88rpx;
border-top: solid #e8e8e8 1px;
background-color: #fff;
}
.local-address .address-line{
padding-right: 20rpx;
font-size: 28rpx;
}
.local-address.spb{
justify-content: space-between;
}
.local-address.spb text{
display: block;
}
.my-address-list .address-item{
padding: 30rpx 20rpx;
display: flex;
flex-direction: column;
background-color: #fff;
border-bottom: solid #e8e8e8 1px;
font-size: 28rpx;
}
.my-address-list .address-item.last-address-item{
border-bottom: none;
}
.my-address-list .basic-info{
display: flex;
align-items: center;
margin-bottom: 30rpx;
}
.my-address-list .basic-info text{
margin-right: 15rpx;
}
.my-address-list .basic-info .is-default{
padding: 2rpx 6rpx;
border-radius: 20rpx;
background-color: #e61773;
color:#fff;
}
.my-address-list .address-info{
color:#999;
}
9 changes: 9 additions & 0 deletions pages/editphone/editphone.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Page({
if(!this.checkPhone(e.detail.value)){
return wx.showToast({
title: '旧手机号格式不正确或为空',
image: '../../image/wrong.png',
duration: 1000
});
}
Expand All @@ -45,6 +46,7 @@ Page({
if(res.status !== 0){
return wx.showToast({
title: res.msg,
image: '../../image/wrong.png',
duration: 1000
});
}
Expand All @@ -55,6 +57,7 @@ Page({
}).catch((err) => {
return wx.showToast({
title: err,
image: '../../image/wrong.png',
duration: 1000
});
});
Expand All @@ -74,6 +77,7 @@ Page({
if(!this.checkPhone(this.data.newUserPhone)){
return wx.showToast({
title: '新手机号格式不正确或为空',
image: '../../image/wrong.png',
duration: 1000
});
}
Expand All @@ -99,6 +103,7 @@ Page({
}).catch((err) => {
return wx.showToast({
title: err,
image: '../../image/wrong.png',
duration: 1000
});
});
Expand All @@ -109,12 +114,14 @@ Page({
if(!this.checkPhone(this.data.newUserPhone)){
return wx.showToast({
title: '手机号格式不正确或为空',
image: '../../image/wrong.png',
duration: 1000
});
}
if(!/^\d{6}$/.test(this.data.code)){
return wx.showToast({
title: '验证码为6个数字',
image: '../../image/wrong.png',
duration: 1000
});
}
Expand Down Expand Up @@ -146,12 +153,14 @@ Page({
}else{
return wx.showToast({
title: res.msg,
image: '../../image/wrong.png',
duration: 1000
});
}
}).catch((err) => {
return wx.showToast({
title: err,
image: '../../image/wrong.png',
duration: 1000
});
});
Expand Down
1 change: 1 addition & 0 deletions pages/more/more.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Page({
}).catch((e)=>{
wx.showToast({
title: '获取数据失败',
image: '../../image/wrong.png',
duration: 2000
});
});
Expand Down
Loading

0 comments on commit af74f3d

Please sign in to comment.