收货地址

This commit is contained in:
Kiyan 2017-05-10 14:15:17 +08:00
parent 404d571561
commit 573c016ae0
6 changed files with 113 additions and 51 deletions

View File

@ -1,8 +1,8 @@
{
"pages": [
"pages/address/select",
"pages/address/list",
"pages/address/add",
"pages/address/select",
"pages/mine/mine",
"pages/login/login",
"pages/index/index",

View File

@ -4,7 +4,8 @@ import {
addUserAddr, getUserAddr
} from '../../utils/apis'
import {
alert, getCurrentAddress,
alert,
getCurrentAddress, reverseGeocoder,
getPrevPage
} from '../../utils/util'
Page({
@ -12,7 +13,7 @@ Page({
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.id = options.id || 194
this.id = options.id
this.callback = options.callback
this.initValidate()
if (this.id) {
@ -60,6 +61,34 @@ Page({
})
})
},
onChooseLocation(e) {
var that = this
that.setData({
disabled: true
})
wx.chooseLocation({
success: function (res) {
var {
name: title, address,
longitude, latitude
} = res
var location = {
longitude, latitude
}
reverseGeocoder({
location,
success(data) {
that.setData({
address: Object.assign({
title, address, location
}, data),
disabled: false,
})
}
})
},
})
},
loadData() {
var that = this
var addr_id = this.id
@ -70,7 +99,7 @@ Page({
that.setData({
receiver: data.receiver,
phone: data.phone,
detail: data.detail,
detail: data.detail,
address: {
title: data.addr,
city: data.city_name,
@ -110,7 +139,7 @@ Page({
} = e.detail.value
addUserAddr({
receiver, phone, detail,
address,
address,
addr_id: that.id,
success(data) {
that.setData({

View File

@ -17,7 +17,7 @@
<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 weui-cell_access" bindtap="onChooseLocation">
<view class="weui-cell__hd">
<view class="weui-label">收货地址</view>
</view>
@ -35,7 +35,7 @@
</view>
</view>
<view class="button-sp-area">
<button class="weui-btn" type="primary" loading="{{loading}}" formType="submit">
<button disabled="{{disabled}}" class="weui-btn" type="primary" loading="{{loading}}" formType="submit">
保存
</button>
</view>

View File

@ -1,45 +1,21 @@
// pages/address/select.js
import {
getUserAddrs, deleteUserAddr
} from '../../utils/apis'
import {
confirm
} from '../../utils/util'
Page({
data: {
selectedId: 170,
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.setData({
selectedId: options.id
})
this.loadData()
},
onReady: function () {
// 页面渲染完成
@ -52,5 +28,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()
}
})
}
})
}
})

View File

@ -1,3 +1,4 @@
{
"navigationBarTitleText": "收货地址"
"navigationBarTitleText": "收货地址",
"enablePullDownRefresh": true
}

View File

@ -1,4 +1,3 @@
<!--pages/address/select.wxml-->
<view class="address-select">
<view class="address-select__hd">
@ -13,16 +12,20 @@
<view class="grey-color">
{{item.addr}}
</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 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>
</view>
</view>
</view>
<navigator class="address-add-btn" url="/pages/address/add">
新增地址
新增地址
</navigator>