新增, 修改地址
This commit is contained in:
parent
6c2f94b236
commit
404d571561
@ -1,5 +1,8 @@
|
||||
{
|
||||
"pages": [
|
||||
"pages/address/list",
|
||||
"pages/address/add",
|
||||
"pages/address/select",
|
||||
"pages/mine/mine",
|
||||
"pages/login/login",
|
||||
"pages/index/index",
|
||||
@ -8,9 +11,6 @@
|
||||
"pages/order/show",
|
||||
"pages/order/quasi",
|
||||
"pages/order/list",
|
||||
"pages/address/list",
|
||||
"pages/address/add",
|
||||
"pages/address/select",
|
||||
"pages/shop/category",
|
||||
"pages/shop/search"
|
||||
],
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 768 B |
@ -1,19 +1,129 @@
|
||||
// pages/address/add.js
|
||||
import WxValidate from '../../utils/WxValidate'
|
||||
import {
|
||||
addUserAddr, getUserAddr
|
||||
} from '../../utils/apis'
|
||||
import {
|
||||
alert, getCurrentAddress,
|
||||
getPrevPage
|
||||
} from '../../utils/util'
|
||||
Page({
|
||||
data:{},
|
||||
onLoad:function(options){
|
||||
// 页面初始化 options为页面跳转所带来的参数
|
||||
data: {
|
||||
},
|
||||
onReady:function(){
|
||||
onLoad: function (options) {
|
||||
// 页面初始化 options为页面跳转所带来的参数
|
||||
this.id = options.id || 194
|
||||
this.callback = options.callback
|
||||
this.initValidate()
|
||||
if (this.id) {
|
||||
this.loadData()
|
||||
} else {
|
||||
this.initAddress()
|
||||
}
|
||||
},
|
||||
onReady: function () {
|
||||
// 页面渲染完成
|
||||
},
|
||||
onShow:function(){
|
||||
onShow: function () {
|
||||
// 页面显示
|
||||
},
|
||||
onHide:function(){
|
||||
onHide: function () {
|
||||
// 页面隐藏
|
||||
},
|
||||
onUnload:function(){
|
||||
onUnload: function () {
|
||||
// 页面关闭
|
||||
}
|
||||
},
|
||||
initValidate() {
|
||||
this.validate = new WxValidate({
|
||||
receiver: {
|
||||
required: true,
|
||||
},
|
||||
phone: {
|
||||
required: true,
|
||||
tel: true,
|
||||
},
|
||||
}, {
|
||||
receiver: {
|
||||
required: '请输入您的姓名'
|
||||
},
|
||||
phone: {
|
||||
required: '请输入手机号',
|
||||
tel: '请输入有效手机号码'
|
||||
},
|
||||
})
|
||||
},
|
||||
initAddress() {
|
||||
var that = this
|
||||
getCurrentAddress(address => {
|
||||
that.setData({
|
||||
address
|
||||
})
|
||||
})
|
||||
},
|
||||
loadData() {
|
||||
var that = this
|
||||
var addr_id = this.id
|
||||
wx.showNavigationBarLoading()
|
||||
getUserAddr({
|
||||
addr_id,
|
||||
success(data) {
|
||||
that.setData({
|
||||
receiver: data.receiver,
|
||||
phone: data.phone,
|
||||
detail: data.detail,
|
||||
address: {
|
||||
title: data.addr,
|
||||
city: data.city_name,
|
||||
district: data.district_name,
|
||||
city_id: data.city_id,
|
||||
district_id: data.district_id,
|
||||
gps: `${data.longitude},${data.latitude}`
|
||||
}
|
||||
})
|
||||
wx.hideNavigationBarLoading()
|
||||
},
|
||||
error() {
|
||||
wx.hideNavigationBarLoading()
|
||||
}
|
||||
})
|
||||
},
|
||||
formSubmit(e) {
|
||||
var that = this
|
||||
var {loading, address} = this.data
|
||||
if (loading) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!address) {
|
||||
return alert('请选择收货地址')
|
||||
}
|
||||
|
||||
if (!this.validate.checkForm(e)) {
|
||||
const error = this.validate.errorList[0]
|
||||
return alert(error.msg)
|
||||
}
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
var {
|
||||
receiver, phone, detail
|
||||
} = e.detail.value
|
||||
addUserAddr({
|
||||
receiver, phone, detail,
|
||||
address,
|
||||
addr_id: that.id,
|
||||
success(data) {
|
||||
that.setData({
|
||||
loading: false
|
||||
})
|
||||
getPrevPage()[that.callback]()
|
||||
wx.navigateBack()
|
||||
},
|
||||
error() {
|
||||
that.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
})
|
@ -1,41 +1,42 @@
|
||||
|
||||
<!--pages/address/add.wxml-->
|
||||
<view class="weui-cells">
|
||||
<view class="weui-cell weui-cell_input">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">联系人</view>
|
||||
<form catchsubmit="formSubmit">
|
||||
<view class="weui-cells">
|
||||
<view class="weui-cell weui-cell_input">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">联系人</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd">
|
||||
<input value="{{receiver}}" name="receiver" class="weui-input" placeholder="您的姓名" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd">
|
||||
<input class="weui-input" placeholder="您的姓名" />
|
||||
<view class="weui-cell weui-cell_input">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">手机号</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd">
|
||||
<input value="{{phone}}" name="phone" type="digit" maxlength="11" class="weui-input" placeholder="配送人员联系您的电话" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="weui-cell weui-cell_access">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">收货地址</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd weui-cell__ft_in-access">
|
||||
{{address.title}}
|
||||
</view>
|
||||
</view>
|
||||
<view class="weui-cell weui-cell_input">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">门牌号</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd">
|
||||
<input name="detail" value="{{detail}}" class="weui-input" placeholder="请输入门牌号等详细信息" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="weui-cell weui-cell_input">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">手机号</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd">
|
||||
<input class="weui-input" placeholder="配送人员联系您的电话" />
|
||||
</view>
|
||||
<view class="button-sp-area">
|
||||
<button class="weui-btn" type="primary" loading="{{loading}}" formType="submit">
|
||||
保存
|
||||
</button>
|
||||
</view>
|
||||
<view class="weui-cell weui-cell_access">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">收货地址</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd weui-cell__ft_in-access">
|
||||
松散
|
||||
</view>
|
||||
</view>
|
||||
<view class="weui-cell weui-cell_input">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">门牌号</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd">
|
||||
<input class="weui-input" placeholder="请输入门牌号等详细信息" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="button-sp-area">
|
||||
<button class="weui-btn" type="primary">
|
||||
保存
|
||||
</button>
|
||||
</view>
|
||||
</form>
|
@ -1,44 +1,17 @@
|
||||
// pages/address/list.js
|
||||
import {
|
||||
getUserAddrs, deleteUserAddr
|
||||
} from '../../utils/apis'
|
||||
import {
|
||||
confirm
|
||||
} from '../../utils/util'
|
||||
Page({
|
||||
data: {
|
||||
list: [
|
||||
{
|
||||
"addr_id": "170",
|
||||
"user_id": "4",
|
||||
"city_id": "330300",
|
||||
"district_id": null,
|
||||
"addr": "龙华大厦",
|
||||
"detail": "",
|
||||
"longitude": "120.69101",
|
||||
"latitude": "28.002974",
|
||||
"receiver": "test4",
|
||||
"phone": "13000000005",
|
||||
"create_time": "2017-02-20 10:38:11",
|
||||
"delete": "0",
|
||||
"district_name": "",
|
||||
"city_name": "温州市"
|
||||
},
|
||||
{
|
||||
"addr_id": "160",
|
||||
"user_id": "4",
|
||||
"city_id": "330300",
|
||||
"district_id": null,
|
||||
"addr": "电商大厦",
|
||||
"detail": "",
|
||||
"longitude": "120.737561",
|
||||
"latitude": "27.979617",
|
||||
"receiver": "test4",
|
||||
"phone": "13000000004",
|
||||
"create_time": "2016-12-16 13:37:10",
|
||||
"delete": "0",
|
||||
"district_name": "",
|
||||
"city_name": "温州市"
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
onLoad: function (options) {
|
||||
// 页面初始化 options为页面跳转所带来的参数
|
||||
this.loadData()
|
||||
},
|
||||
onReady: function () {
|
||||
// 页面渲染完成
|
||||
@ -51,5 +24,58 @@ Page({
|
||||
},
|
||||
onUnload: function () {
|
||||
// 页面关闭
|
||||
},
|
||||
onPullDownRefresh(){
|
||||
this.loadData(function() {
|
||||
wx.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
loadData(cb) {
|
||||
var that = this
|
||||
var {loading} = this.data
|
||||
if(loading) {
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
wx.showNavigationBarLoading()
|
||||
getUserAddrs({
|
||||
success(data) {
|
||||
that.setData({
|
||||
list: data,
|
||||
loading: false
|
||||
})
|
||||
wx.hideNavigationBarLoading()
|
||||
cb && cb()
|
||||
},
|
||||
error() {
|
||||
that.setData({
|
||||
loading: false
|
||||
})
|
||||
wx.hideNavigationBarLoading()
|
||||
cb && cb()
|
||||
}
|
||||
})
|
||||
},
|
||||
callback() {
|
||||
this.loadData()
|
||||
},
|
||||
onDelete(e) {
|
||||
var that = this
|
||||
var {id} = e.currentTarget
|
||||
var address = this.data.list[id]
|
||||
confirm({
|
||||
content: `是否删除地址 ${address.addr} ${address.detail}`,
|
||||
confirmText: '删除',
|
||||
ok() {
|
||||
deleteUserAddr({
|
||||
addr_id: address.addr_id,
|
||||
success(data) {
|
||||
that.loadData()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
@ -1,3 +1,4 @@
|
||||
{
|
||||
"navigationBarTitleText": "我的地址"
|
||||
"navigationBarTitleText": "我的地址",
|
||||
"enablePullDownRefresh": true
|
||||
}
|
@ -9,18 +9,22 @@
|
||||
{{item.receiver}} {{item.phone}}
|
||||
</view>
|
||||
<view class="grey-color">
|
||||
{{item.addr}}
|
||||
{{item.addr}} {{item.detail}}
|
||||
</view>
|
||||
<view class="address-actions">
|
||||
<navigator url="/pages/address/add?id={{item.addr_id}}&callback=callback" class="address-actions__item">
|
||||
<image class="address-actions__item-img" src="/images/address_edit_white.png">
|
||||
</image>
|
||||
</navigator>
|
||||
<view id="{{index}}" bindtap="onDelete" class="address-actions__item">
|
||||
<image class="address-actions__item-img" src="/images/delete@2x.png">
|
||||
</image>
|
||||
</view>
|
||||
</view>
|
||||
<navigator url="/pages/address/add?id={{item.addr_id}}" class="address__item-edit">
|
||||
<image
|
||||
class="address__item-edit-img"
|
||||
src="/images/address_edit_white.png">
|
||||
</image>
|
||||
</navigator>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<navigator class="address-add-btn" url="/pages/address/add">
|
||||
新增地址
|
||||
</navigator>
|
||||
<navigator class="address-add-btn" url="/pages/address/add?callback=callback">
|
||||
新增地址
|
||||
</navigator>
|
@ -1,54 +1,72 @@
|
||||
/* pages/address/select.wxss */
|
||||
|
||||
page {
|
||||
padding-bottom: 50px;
|
||||
padding-bottom: 50px;
|
||||
}
|
||||
|
||||
.address-select__hd {
|
||||
padding: 5px 15px;
|
||||
font-size: 14px;
|
||||
color: #999;
|
||||
border-bottom: 1rpx solid #e8e8e8;
|
||||
padding: 5px 15px;
|
||||
font-size: 14px;
|
||||
color: #999;
|
||||
border-bottom: 1rpx solid #e8e8e8;
|
||||
}
|
||||
|
||||
.address__list {
|
||||
background-color: #fff;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.address__item {
|
||||
position: relative;
|
||||
padding: 10px 15px;
|
||||
border-bottom: 1rpx solid #e8e8e8;
|
||||
position: relative;
|
||||
padding: 10px 15px;
|
||||
border-bottom: 1rpx solid #e8e8e8;
|
||||
}
|
||||
|
||||
.address__item-selected-img {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 29px;
|
||||
height: 28px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 29px;
|
||||
height: 28px;
|
||||
}
|
||||
|
||||
.address__item-edit {
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
top: 50%;
|
||||
padding: 5px 10px;
|
||||
transform: translateY(-50%);
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
top: 50%;
|
||||
padding: 5px 10px;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.address__item-edit-img {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.address-add-btn {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 50px;
|
||||
line-height: 50px;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
background-color: #ff5801;
|
||||
}
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 50px;
|
||||
line-height: 50px;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
background-color: #ff5801;
|
||||
}
|
||||
|
||||
.address-actions {
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.address-actions__item {
|
||||
display: inline-block;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
.address-actions__item-img {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
@ -88,19 +88,14 @@ Page({
|
||||
if(loading) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.validate.checkForm(e)) {
|
||||
const error = this.validate.errorList[0]
|
||||
return alert(error.msg)
|
||||
}
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
if (!this.validate.checkForm(e)) {
|
||||
const error = this.validate.errorList[0]
|
||||
that.setData({
|
||||
loading: false
|
||||
})
|
||||
return alert(error.msg)
|
||||
}
|
||||
|
||||
var {phone, code} = e.detail.value
|
||||
login({
|
||||
phone, code,
|
||||
|
@ -103,7 +103,7 @@ export function login(options) {
|
||||
// 退出账号
|
||||
export function logout(options) {
|
||||
const {
|
||||
phone,
|
||||
phone,
|
||||
success, error
|
||||
} = options
|
||||
fetch({
|
||||
@ -138,3 +138,142 @@ export function getLoginInfo(options) {
|
||||
})
|
||||
}
|
||||
|
||||
// 获取用户地址列表
|
||||
export function getUserAddrs(options) {
|
||||
const {
|
||||
success, error
|
||||
} = options
|
||||
|
||||
getApp().getLoginInfo(loginInfo => {
|
||||
if (!loginInfo.user_info) {
|
||||
return alert('用户未登录')
|
||||
}
|
||||
var {user_id, user_token} = loginInfo.user_info
|
||||
fetch({
|
||||
url: 'index.php?m=Mall&c=User&a=getUserAddrs',
|
||||
data: {
|
||||
user_id, user_token
|
||||
},
|
||||
success, error
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
// 获取用户地址
|
||||
export function getUserAddr(options) {
|
||||
const {
|
||||
addr_id,
|
||||
success, error
|
||||
} = options
|
||||
|
||||
getApp().getLoginInfo(loginInfo => {
|
||||
if (!loginInfo.user_info) {
|
||||
return alert('用户未登录')
|
||||
}
|
||||
var {user_id, user_token} = loginInfo.user_info
|
||||
fetch({
|
||||
url: 'index.php?m=Mall&c=User&a=getUserAddr',
|
||||
data: {
|
||||
user_id, user_token,
|
||||
addr_id
|
||||
},
|
||||
success, error
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// 新增用户地址
|
||||
export function addUserAddr(options) {
|
||||
if(options.addr_id) {
|
||||
return updateUserAddr(options)
|
||||
}
|
||||
const {
|
||||
receiver, phone, detail, address,
|
||||
success, error
|
||||
} = options
|
||||
getApp().getLoginInfo(loginInfo => {
|
||||
if (!loginInfo.user_info) {
|
||||
return alert('用户未登录')
|
||||
}
|
||||
var {user_id, user_token} = loginInfo.user_info
|
||||
var gps = address.gps
|
||||
if(!gps) {
|
||||
var location = coordFormat(address.location)
|
||||
gps = `${location.longitude},${location.latitude}`
|
||||
}
|
||||
fetch({
|
||||
url: 'index.php?m=Mall&c=User&a=addUserAddr',
|
||||
data: {
|
||||
user_id, user_token,
|
||||
receiver, phone, detail,
|
||||
gps,
|
||||
addr: address.title,
|
||||
city_id: address.city_id,
|
||||
city_name: address.city,
|
||||
district_id: address.district_id,
|
||||
district_name: address.district,
|
||||
},
|
||||
success, error
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// 修改地址
|
||||
export function updateUserAddr(options) {
|
||||
const {
|
||||
receiver, phone, detail, address,
|
||||
addr_id,
|
||||
success, error
|
||||
} = options
|
||||
getApp().getLoginInfo(loginInfo => {
|
||||
if (!loginInfo.user_info) {
|
||||
return alert('用户未登录')
|
||||
}
|
||||
var {user_id, user_token} = loginInfo.user_info
|
||||
var gps = address.gps
|
||||
if(!gps) {
|
||||
var location = coordFormat(address.location)
|
||||
gps = `${location.longitude},${location.latitude}`
|
||||
}
|
||||
fetch({
|
||||
url: 'index.php?m=Mall&c=User&a=updateUserAddr',
|
||||
data: {
|
||||
user_id, user_token,
|
||||
receiver, phone, detail,
|
||||
gps, addr_id,
|
||||
addr: address.title,
|
||||
city_id: address.city_id,
|
||||
city_name: address.city,
|
||||
district_id: address.district_id,
|
||||
district_name: address.district_name,
|
||||
},
|
||||
success, error
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// 删除地址
|
||||
export function deleteUserAddr(options) {
|
||||
const {
|
||||
addr_id,
|
||||
success, error
|
||||
} = options
|
||||
getApp().getLoginInfo(loginInfo => {
|
||||
if (!loginInfo.user_info) {
|
||||
return alert('用户未登录')
|
||||
}
|
||||
var {user_id, user_token} = loginInfo.user_info
|
||||
fetch({
|
||||
url: 'index.php?m=Mall&c=User&a=deleteUserAddr',
|
||||
data: {
|
||||
user_id, user_token,
|
||||
addr_id
|
||||
},
|
||||
success, error
|
||||
})
|
||||
|
||||
})
|
||||
}
|
@ -202,10 +202,11 @@ export function alert(content, callback) {
|
||||
}
|
||||
// 确认框
|
||||
export function confirm(options) {
|
||||
const {
|
||||
var {
|
||||
content, confirmText,
|
||||
ok,
|
||||
} = options
|
||||
confirmText = confirmText || '确定'
|
||||
wx.showModal({
|
||||
content,
|
||||
confirmText,
|
||||
|
Loading…
x
Reference in New Issue
Block a user