diff --git a/app/app.json b/app/app.json
index e595f3a..2be788e 100644
--- a/app/app.json
+++ b/app/app.json
@@ -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"
],
diff --git a/app/images/takeout_ic_address.png b/app/images/takeout_ic_address.png
index 5c7319f..2e2204e 100644
Binary files a/app/images/takeout_ic_address.png and b/app/images/takeout_ic_address.png differ
diff --git a/app/pages/address/add.js b/app/pages/address/add.js
index 7796ae2..0e159cf 100644
--- a/app/pages/address/add.js
+++ b/app/pages/address/add.js
@@ -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
+ })
+ }
+ })
+ },
})
\ No newline at end of file
diff --git a/app/pages/address/add.wxml b/app/pages/address/add.wxml
index 5464296..fc6cec7 100644
--- a/app/pages/address/add.wxml
+++ b/app/pages/address/add.wxml
@@ -1,41 +1,42 @@
-
-
-
-
- 联系人
+
\ No newline at end of file
diff --git a/app/pages/address/list.js b/app/pages/address/list.js
index 751e00f..f9f696a 100644
--- a/app/pages/address/list.js
+++ b/app/pages/address/list.js
@@ -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()
+ }
+ })
+ }
+ })
}
})
\ No newline at end of file
diff --git a/app/pages/address/list.json b/app/pages/address/list.json
index 0c66b5b..10007c1 100644
--- a/app/pages/address/list.json
+++ b/app/pages/address/list.json
@@ -1,3 +1,4 @@
{
- "navigationBarTitleText": "我的地址"
+ "navigationBarTitleText": "我的地址",
+ "enablePullDownRefresh": true
}
\ No newline at end of file
diff --git a/app/pages/address/list.wxml b/app/pages/address/list.wxml
index 12db1ff..e59381f 100644
--- a/app/pages/address/list.wxml
+++ b/app/pages/address/list.wxml
@@ -9,18 +9,22 @@
{{item.receiver}} {{item.phone}}
- {{item.addr}}
+ {{item.addr}} {{item.detail}}
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
- 新增地址
-
+
+ 新增地址
+
\ No newline at end of file
diff --git a/app/pages/address/select.wxss b/app/pages/address/select.wxss
index 82e6c4e..e8e926d 100644
--- a/app/pages/address/select.wxss
+++ b/app/pages/address/select.wxss
@@ -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;
-}
\ No newline at end of file
+ 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;
+}
diff --git a/app/pages/login/login.js b/app/pages/login/login.js
index ffe93ce..696cefc 100644
--- a/app/pages/login/login.js
+++ b/app/pages/login/login.js
@@ -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,
diff --git a/app/utils/apis.js b/app/utils/apis.js
index 2f4491b..2c6560f 100644
--- a/app/utils/apis.js
+++ b/app/utils/apis.js
@@ -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
+ })
+
+ })
+}
\ No newline at end of file
diff --git a/app/utils/util.js b/app/utils/util.js
index 55d6cfe..21fa109 100644
--- a/app/utils/util.js
+++ b/app/utils/util.js
@@ -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,