addressList、小程序id

dev
zhouzhenyuan 1 year ago
parent a0c5a46f8b
commit 425336526f
  1. 2
      manifest.json
  2. 605
      pages/address/index.vue
  3. 216
      pages/news/park/addressEdit.vue
  4. 178
      pages/news/park/addressList.vue

@ -92,7 +92,7 @@
"quickapp" : {},
/* */
"mp-weixin" : {
"appid" : "wx34920eb219864734",
"appid" : "wx68d198de972a9e9d",
"libVersion" : "latest",
"setting" : {
// TLS

@ -1,307 +1,312 @@
<template>
<view class="container" :style="appThemeStyle">
<view class="addres-list">
<view class="address-item" v-for="(item, index) in list" :key="index">
<view class="contacts">
<text class="name">{{ item.name }}</text>
<text class="phone">{{ item.phone }}</text>
</view>
<view class="address">
<text class="region" v-for="(region, idx) in item.region" :key="idx">{{ region }}</text>
<text class="detail">{{ item.detail }}</text>
</view>
<view class="line"></view>
<view class="item-option">
<view class="_left">
<view class="item-radio" @click="handleSetDefault(item.address_id)">
<radio class="radio" :color="appTheme.mainBg" :checked="item.address_id == defaultId"></radio>
<text class="text">{{ item.address_id == defaultId ? '默认' : '选择' }}</text>
</view>
</view>
<view class="_right">
<view class="events">
<view class="event-item" @click="handleUpdate(item.address_id)">
<text class="iconfont icon-edit"></text>
<text class="title">编辑</text>
</view>
<view class="event-item" @click="handleRemove(item.address_id)">
<text class="iconfont icon-delete"></text>
<text class="title">删除</text>
</view>
</view>
</view>
</view>
</view>
</view>
<empty v-if="!list.length" :isLoading="isLoading" tips="亲,暂无收货地址" />
<!-- 底部操作按钮 -->
<view class="footer-fixed">
<view class="btn-wrapper">
<view class="btn-item btn-item-main" @click="handleCreate()">添加新地址</view>
</view>
</view>
</view>
<view class="container" :style="appThemeStyle">
<view class="addres-list">
<view class="address-item" v-for="(item, index) in list" :key="index">
<view class="contacts">
<text class="name">{{ item.name }}</text>
<text class="phone">{{ item.phone }}</text>
</view>
<view class="address">
<text class="region" v-for="(region, idx) in item.region" :key="idx">{{ region }}</text>
<text class="detail">{{ item.detail }}</text>
</view>
<view class="line"></view>
<view class="item-option">
<view class="_left">
<view class="item-radio" @click="handleSetDefault(item.address_id)">
<radio class="radio" :color="appTheme.mainBg" :checked="item.address_id == defaultId">
</radio>
<text class="text">{{ item.address_id == defaultId ? '默认' : '选择' }}</text>
</view>
</view>
<view class="_right">
<view class="events">
<view class="event-item" @click="handleUpdate(item.address_id)">
<text class="iconfont icon-edit"></text>
<text class="title">编辑</text>
</view>
<view class="event-item" @click="handleRemove(item.address_id)">
<text class="iconfont icon-delete"></text>
<text class="title">删除</text>
</view>
</view>
</view>
</view>
</view>
</view>
<empty v-if="!list.length" :isLoading="isLoading" tips="亲,暂无收货地址" />
<!-- 底部操作按钮 -->
<view class="footer-fixed">
<view class="btn-wrapper">
<view class="btn-item btn-item-main" @click="handleCreate()">添加新地址</view>
</view>
</view>
</view>
</template>
<script>
import * as AddressApi from '@/api/address'
import Empty from '@/components/empty'
export default {
components: {
Empty
},
data() {
return {
//
options: {},
//
isLoading: true,
//
list: [],
//
defaultId: null
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
//
this.options = options
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
//
this.getPageData()
},
methods: {
//
getPageData() {
const app = this
app.isLoading = true
Promise.all([app.getDefaultId(), app.getAddressList()])
.then(() => {
//
app.onReorder()
})
.finally(() => app.isLoading = false)
},
//
getAddressList() {
const app = this
return new Promise((resolve, reject) => {
AddressApi.list()
.then(result => {
app.list = result.data.list
resolve(result)
})
.catch(reject)
})
},
//
getDefaultId() {
return new Promise((resolve, reject) => {
const app = this
AddressApi.defaultId()
.then(result => {
app.defaultId = result.data.defaultId
resolve(result)
})
.catch(reject)
})
},
//
onReorder() {
const app = this
app.list.sort(item => {
return item.address_id == app.defaultId ? -1 : 1
})
},
/**
* 添加新地址
*/
handleCreate() {
this.$navTo('pages/address/create')
},
/**
* 编辑地址
* @param {int} addressId 收货地址ID
*/
handleUpdate(addressId) {
this.$navTo('pages/address/update', { addressId })
},
/**
* 删除收货地址
* @param {int} addressId 收货地址ID
*/
handleRemove(addressId) {
const app = this
uni.showModal({
title: "提示",
content: "您确定要删除当前收货地址吗?",
success({ confirm }) {
confirm && app.onRemove(addressId)
}
});
},
/**
* 确认删除收货地址
* @param {int} addressId 收货地址ID
*/
onRemove(addressId) {
const app = this
AddressApi.remove(addressId)
.then(result => {
app.getPageData()
})
},
/**
* 设置为默认地址
* @param {Object} addressId
*/
handleSetDefault(addressId) {
const app = this
AddressApi.setDefault(addressId)
.then(result => {
app.defaultId = addressId
app.options.from === 'checkout' && uni.navigateBack()
})
}
}
}
import * as AddressApi from '@/api/address'
import Empty from '@/components/empty'
export default {
components: {
Empty
},
data() {
return {
//
options: {},
//
isLoading: true,
//
list: [],
//
defaultId: null
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
//
this.options = options
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
//
this.getPageData()
},
methods: {
//
getPageData() {
const app = this
app.isLoading = true
Promise.all([app.getDefaultId(), app.getAddressList()])
.then(() => {
//
app.onReorder()
})
.finally(() => app.isLoading = false)
},
//
getAddressList() {
const app = this
return new Promise((resolve, reject) => {
AddressApi.list()
.then(result => {
app.list = result.data.list
resolve(result)
})
.catch(reject)
})
},
//
getDefaultId() {
return new Promise((resolve, reject) => {
const app = this
AddressApi.defaultId()
.then(result => {
app.defaultId = result.data.defaultId
resolve(result)
})
.catch(reject)
})
},
//
onReorder() {
const app = this
app.list.sort(item => {
return item.address_id == app.defaultId ? -1 : 1
})
},
/**
* 添加新地址
*/
handleCreate() {
this.$navTo('pages/address/create')
},
/**
* 编辑地址
* @param {int} addressId 收货地址ID
*/
handleUpdate(addressId) {
this.$navTo('pages/address/update', {
addressId
})
},
/**
* 删除收货地址
* @param {int} addressId 收货地址ID
*/
handleRemove(addressId) {
const app = this
uni.showModal({
title: "提示",
content: "您确定要删除当前收货地址吗?",
success({
confirm
}) {
confirm && app.onRemove(addressId)
}
});
},
/**
* 确认删除收货地址
* @param {int} addressId 收货地址ID
*/
onRemove(addressId) {
const app = this
AddressApi.remove(addressId)
.then(result => {
app.getPageData()
})
},
/**
* 设置为默认地址
* @param {Object} addressId
*/
handleSetDefault(addressId) {
const app = this
AddressApi.setDefault(addressId)
.then(result => {
app.defaultId = addressId
app.options.from === 'checkout' && uni.navigateBack()
})
}
}
}
</script>
<style lang="scss" scoped>
.addres-list {
padding-top: 20rpx;
// ios线
padding-bottom: calc(constant(safe-area-inset-bottom) + 140rpx);
padding-bottom: calc(env(safe-area-inset-bottom) + 140rpx);
}
//
.address-item {
margin: 0 auto 20rpx auto;
padding: 30rpx 40rpx;
width: 94%;
box-shadow: 0 1rpx 5rpx 0 rgba(0, 0, 0, 0.05);
border-radius: 16rpx;
background: #fff;
}
.contacts {
font-size: 30rpx;
margin-bottom: 16rpx;
.name {
margin-right: 16rpx;
}
}
.address {
font-size: 28rpx;
.region {
margin-right: 10rpx;
}
}
.line {
margin: 20rpx 0;
border-bottom: 1rpx solid #f3f3f3;
}
.item-option {
display: flex;
justify-content: space-between;
height: 48rpx;
//
.item-radio {
font-size: 28rpx;
.radio {
vertical-align: middle;
transform: scale(0.76)
}
.text {
vertical-align: middle;
}
}
//
.events {
display: flex;
align-items: center;
line-height: 48rpx;
.event-item {
font-size: 28rpx;
margin-right: 26rpx;
color: #4c4c4c;
&:last-child {
margin-right: 0;
}
.title {
margin-left: 8rpx;
}
}
}
}
//
.footer-fixed {
position: fixed;
bottom: var(--window-bottom);
left: 0;
right: 0;
z-index: 11;
// ios线
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
.btn-wrapper {
height: 120rpx;
padding: 0 40rpx;
}
.btn-item {
flex: 1;
font-size: 28rpx;
height: 86rpx;
color: #fff;
border-radius: 50rpx;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 1rpx 5rpx 0 rgba(0, 0, 0, 0.05);
}
.btn-item-main {
background: linear-gradient(to right, $main-bg, $main-bg2);
color: $main-text;
}
}
</style>
.addres-list {
padding-top: 20rpx;
// ios线
padding-bottom: calc(constant(safe-area-inset-bottom) + 140rpx);
padding-bottom: calc(env(safe-area-inset-bottom) + 140rpx);
}
//
.address-item {
margin: 0 auto 20rpx auto;
padding: 30rpx 40rpx;
width: 94%;
box-shadow: 0 1rpx 5rpx 0 rgba(0, 0, 0, 0.05);
border-radius: 16rpx;
background: #fff;
}
.contacts {
font-size: 30rpx;
margin-bottom: 16rpx;
.name {
margin-right: 16rpx;
}
}
.address {
font-size: 28rpx;
.region {
margin-right: 10rpx;
}
}
.line {
margin: 20rpx 0;
border-bottom: 1rpx solid #f3f3f3;
}
.item-option {
display: flex;
justify-content: space-between;
height: 48rpx;
//
.item-radio {
font-size: 28rpx;
.radio {
vertical-align: middle;
transform: scale(0.76)
}
.text {
vertical-align: middle;
}
}
//
.events {
display: flex;
align-items: center;
line-height: 48rpx;
.event-item {
font-size: 28rpx;
margin-right: 26rpx;
color: #4c4c4c;
&:last-child {
margin-right: 0;
}
.title {
margin-left: 8rpx;
}
}
}
}
//
.footer-fixed {
position: fixed;
bottom: var(--window-bottom);
left: 0;
right: 0;
z-index: 11;
// ios线
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
.btn-wrapper {
height: 120rpx;
padding: 0 40rpx;
}
.btn-item {
flex: 1;
font-size: 28rpx;
height: 86rpx;
color: #fff;
border-radius: 50rpx;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 1rpx 5rpx 0 rgba(0, 0, 0, 0.05);
}
.btn-item-main {
background: linear-gradient(to right, $main-bg, $main-bg2);
color: $main-text;
}
}
</style>

@ -1,16 +1,16 @@
<template>
<view class="addressList">
<template>
<view class="addressList">
<view class="addressList-hd">
<view class="item">
<view class="a">收货人</view>
<view class="b">
<input type="text" placeholder="请输入收货人姓名" />
<input v-model="form.name" type="text" placeholder="请输入收货人姓名" />
</view>
</view>
<view class="item">
<view class="a">手机号</view>
<view class="b">
<input type="number" placeholder="请输入收货人手机号" />
<input v-model="form.phone" type="number" placeholder="请输入收货人手机号" />
</view>
</view>
<view class="item">
@ -24,7 +24,7 @@
<view class="items">
<view class="a">详细地址</view>
<view class="b">
<input type="text" placeholder="请输入详细地址" />
<input v-model="form.detail" type="text" placeholder="请输入详细地址" />
</view>
</view>
</view>
@ -35,105 +35,139 @@
</view>
</view>
<view class="addressList-fd">
<view class="btn">保存收货地址</view>
</view>
</view>
</template>
<script>
export default {
data() {
<view class="btn" @click="saveAddress">保存收货地址</view>
</view>
</view>
</template>
<script>
import * as AddressApi from '@/api/address'
export default {
data() {
return {
checked: false,
value: ""
};
}
}
</script>
<style lang="scss" scoped>
.addressList{
padding: 0 0 20rpx;
overflow: hidden;
&-hd{
background-color: #fff;
padding: 0 25rpx 25rpx;
checked: false,
value: "",
form: {
content: '',
name: '',
phone: '',
region: [],
detail: ''
},
};
},
methods: {
saveAddress() {
//
const that = this
AddressApi.add(that.form)
.then(result => {
that.$toast(result.message)
uni.navigateBack()
})
.finally(() => {
})
},
}
}
</script>
<style lang="scss" scoped>
.addressList {
padding: 0 0 20rpx;
overflow: hidden;
.item{
padding: 20rpx 0;
line-height: 50rpx;
font-size: 28rpx;
color: #212121;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #F7F7F7;
.b{
&-hd {
background-color: #fff;
padding: 0 25rpx 25rpx;
overflow: hidden;
.item {
padding: 20rpx 0;
line-height: 50rpx;
font-size: 28rpx;
color: #9D9D9D;
flex: 1;
text-align: right;
input{
width: 100%;
line-height: 50rpx;
color: #212121;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #F7F7F7;
.b {
font-size: 28rpx;
color: #212121;
}
.select{
color: #C7C7C7;
&-on{
color: #9D9D9D;
flex: 1;
text-align: right;
input {
width: 100%;
line-height: 50rpx;
font-size: 28rpx;
color: #212121;
}
.select {
color: #C7C7C7;
&-on {
color: #212121;
}
}
}
}
}
.items{
padding: 20rpx 0;
line-height: 50rpx;
font-size: 28rpx;
color: #212121;
.b{
.items {
padding: 20rpx 0;
line-height: 50rpx;
font-size: 28rpx;
flex: 1;
text-align: left;
input{
width: 100%;
line-height: 50rpx;
color: #212121;
.b {
font-size: 28rpx;
color: #212121;
margin-top: 20rpx;
flex: 1;
text-align: left;
input {
width: 100%;
line-height: 50rpx;
font-size: 28rpx;
color: #212121;
margin-top: 20rpx;
}
}
}
}
}
&-bd{
background-color: #fff;
padding: 25rpx;
overflow: hidden;
margin-top: 20rpx;
display: flex;
align-items: center;
justify-content: space-between;
}
&-fd{
width: 100%;
position: fixed;
left: 0;
bottom: 0;
padding: 30rpx;
background-color: #fafafa;
box-sizing: border-box;
.btn{
&-bd {
background-color: #fff;
padding: 25rpx;
overflow: hidden;
margin-top: 20rpx;
display: flex;
align-items: center;
justify-content: space-between;
}
&-fd {
width: 100%;
line-height: 96rpx;
background: #F34A40;
border-radius: 8rpx;
text-align: center;
font-size: 28rpx;
font-weight: 500;
color: #FFFFFF;
position: fixed;
left: 0;
bottom: 0;
padding: 30rpx;
background-color: #fafafa;
box-sizing: border-box;
.btn {
width: 100%;
line-height: 96rpx;
background: #F34A40;
border-radius: 8rpx;
text-align: center;
font-size: 28rpx;
font-weight: 500;
color: #FFFFFF;
}
}
}
}
</style>
</style>

@ -1,73 +1,127 @@
<template>
<view class="addressList">
<view class="item" v-for="i in 9" :key="i">
<view class="a">张小艾 188****9890<text>默认</text></view>
<template>
<view class="addressList">
<view class="item" v-for="(item,index) in addressList" :key="index">
<view class="a">{{item.name}} {{item.phone}}<text>默认</text></view>
<view class="b">
<view class="d">
广州市越秀区东风中路269号1109-1110
{{item.detail}}
</view>
<image src="/static/order/edit.png"></image>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
};
}
}
</script>
<style lang="scss" scoped>
.addressList{
padding: 0 0 0 50rpx;
background-color: #FFFFFF;
overflow: hidden;
.item{
padding: 35rpx 0;
overflow: hidden;
border-bottom: 1px solid #EEEEEE;
.a{
font-size: 32rpx;
font-weight: 500;
color: #1E1E1E;
padding-bottom: 20rpx;
display: flex;
align-items: center;
text{
width: 66rpx;
line-height: 34rpx;
background: #F32020;
border-radius: 4rpx;
text-align: center;
display: block;
margin-left: 10rpx;
font-size: 24rpx;
font-weight: 400;
color: #FFFFFF;
border-radius: 5rpx;
}
</view>
<view class="footer">
<view class="operaBtn" @click="addAddress">
新增收货地址
</view>
</view>
</view>
</template>
<script>
import * as AddressApi from '@/api/address'
export default {
data() {
return {
addressList: []
};
},
onShow() {
this.getAddressList()
},
methods: {
getAddressList() {
const that = this
return new Promise((resolve, reject) => {
AddressApi.list()
.then(result => {
that.addressList = result.data.list
})
.catch(reject)
})
},
addAddress(){
uni.navigateTo({
url:'/pages/news/park/addressEdit'
})
},
}
.b{
display: flex;
align-items: flex-start;
justify-content: space-between;
.d{
}
</script>
<style lang="scss" scoped>
.addressList {
padding: 0 0 0 50rpx;
background-color: #FFFFFF;
overflow: hidden;
.item {
padding: 35rpx 0;
overflow: hidden;
border-bottom: 1px solid #EEEEEE;
.a {
font-size: 32rpx;
font-weight: 400;
color: #979797;
max-width: 600rpx;
font-weight: 500;
color: #1E1E1E;
padding-bottom: 20rpx;
display: flex;
align-items: center;
text {
width: 66rpx;
line-height: 34rpx;
background: #F32020;
border-radius: 4rpx;
text-align: center;
display: block;
margin-left: 10rpx;
font-size: 24rpx;
font-weight: 400;
color: #FFFFFF;
border-radius: 5rpx;
}
}
image{
width: 36rpx;
height: 36rpx;
margin-right: 50rpx;
.b {
display: flex;
align-items: flex-start;
justify-content: space-between;
.d {
font-size: 32rpx;
font-weight: 400;
color: #979797;
max-width: 600rpx;
}
image {
width: 36rpx;
height: 36rpx;
margin-right: 50rpx;
}
}
}
}
}
</style>
.footer{
display: flex;
width: 100%;
height: 120rpx;
justify-content: center;
position: fixed;
bottom: 0;
left: 0;
.operaBtn{
width: 686rpx;
height: 92rpx;
background: #F34A40;
border-radius: 8rpx 8rpx 8rpx 8rpx;
opacity: 1;
line-height: 92rpx;
font-size: 28rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 600;
color: #FFFFFF;
text-align: center;
}
}
</style>
Loading…
Cancel
Save