首次提交
This commit is contained in:
323
my/address/add.vue
Normal file
323
my/address/add.vue
Normal file
@@ -0,0 +1,323 @@
|
||||
<template>
|
||||
<view class="" v-if="XCXIsSelect=='是'">
|
||||
<form>
|
||||
<view class="cu-form-group">
|
||||
<view class="title">联系人</view>
|
||||
<input placeholder="请输入联系人" name="input" v-model="form.userName"></input>
|
||||
</view>
|
||||
<view class="cu-form-group">
|
||||
<view class="title">联系电话</view>
|
||||
<input placeholder="请输入联系电话" name="input" v-model="form.userPhone" maxlength="11"></input>
|
||||
</view>
|
||||
<view class="cu-form-group" @click="pickerShow">
|
||||
<view class="title">所在地区</view>
|
||||
<input placeholder="请选择地区" name="input" disabled v-model="form.address"></input>
|
||||
<text class='cuIcon-locationfill text-orange'></text>
|
||||
</view>
|
||||
<view class="cu-form-group">
|
||||
<view class="title">详细地址</view>
|
||||
<input placeholder="请输入详细地址" name="input" v-model="form.addressDetail"></input>
|
||||
</view>
|
||||
<view class="cu-form-group">
|
||||
<view class="title">设为默认</view>
|
||||
<switch @change="SwitchA" :class="form.addressDefault?'checked':''"
|
||||
:checked="form.addressDefault?true:false"></switch>
|
||||
</view>
|
||||
</form>
|
||||
|
||||
<view class="btn" v-if="!id">
|
||||
<view class="address_push" @click="submit">保存</view>
|
||||
</view>
|
||||
<view class="btn" v-if="id">
|
||||
<view class="address_push" @click="updata">修改</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else>
|
||||
<view style="font-size: 28upx;" v-html="content"></view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
requestAndroidPermission,
|
||||
gotoAppPermissionSetting
|
||||
} from '@/components/permission.js'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
form: {
|
||||
addressId: '',
|
||||
userName: '',
|
||||
userPhone: '',
|
||||
address: '',
|
||||
addressDetail: '',
|
||||
addressDefault: 0, //默认地址 0不默认 1默认
|
||||
lng: '',
|
||||
lat: ''
|
||||
},
|
||||
// switchA: false,
|
||||
region: '',
|
||||
|
||||
id: '',
|
||||
latitude: '',
|
||||
longitude: '',
|
||||
XCXIsSelect: '是',
|
||||
content: ''
|
||||
}
|
||||
},
|
||||
onLoad(option) {
|
||||
this.XCXIsSelect = this.$queue.getData('XCXIsSelect') ? this.$queue.getData('XCXIsSelect') : '是';
|
||||
if (this.XCXIsSelect == '否') {
|
||||
this.getGuize()
|
||||
uni.setNavigationBarTitle({
|
||||
title: '隐私政策'
|
||||
});
|
||||
} else {
|
||||
uni.setNavigationBarTitle({
|
||||
title: '添加地址'
|
||||
});
|
||||
}
|
||||
this.id = option.id
|
||||
if (option.id) {
|
||||
this.getAddressDet(option.id)
|
||||
uni.setNavigationBarTitle({
|
||||
title: "修改地址"
|
||||
})
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getGuize() {
|
||||
this.$Request.getT('/app/common/type/237').then(res => {
|
||||
if (res.code == 0) {
|
||||
this.content = res.data.value;
|
||||
// this.tit = res.data.min
|
||||
}
|
||||
});
|
||||
},
|
||||
pickerShow() {
|
||||
let that = this
|
||||
// An highlighted block
|
||||
uni.chooseLocation({
|
||||
success: function(res) {
|
||||
console.log(res)
|
||||
console.log('位置名称:' + res.name);
|
||||
console.log('详细地址:' + res.address);
|
||||
console.log('纬度:' + res.latitude);
|
||||
console.log('经度:' + res.longitude);
|
||||
let latitude = res.latitude; //纬度
|
||||
let longitude = res.longitude; //经度
|
||||
that.form.lng = longitude
|
||||
that.form.lat = latitude
|
||||
|
||||
that.form.addressDetail = res.name
|
||||
|
||||
let data = {
|
||||
lat: latitude,
|
||||
lng: longitude
|
||||
}
|
||||
that.$Request.get("/app/address/selectCity", data).then(res => {
|
||||
if (res.code == 0) {
|
||||
that.form.province = res.data.province
|
||||
that.form.city = res.data.city
|
||||
that.form.district = res.data.district
|
||||
that.form.address = res.data.province + res.data.city + res.data
|
||||
.district
|
||||
}
|
||||
});
|
||||
},fail(e) {
|
||||
console.log(e)
|
||||
uni.showModal({
|
||||
title: '温馨提示',
|
||||
content: '您的定位权限未开启,请开启后再来刷新操作吧!',
|
||||
showCancel: true,
|
||||
cancelText: '取消',
|
||||
confirmText: '确认',
|
||||
success: res => {
|
||||
if(res.confirm){
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.openSetting({ // 打开设置页
|
||||
success(rea) {
|
||||
console.log(rea.authSetting)
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
gotoAppPermissionSetting()
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
SwitchA(e) {
|
||||
console.log(e.detail.value)
|
||||
this.form.addressDefault = e.detail.value
|
||||
},
|
||||
// 选择地区回调
|
||||
regionConfirm(e) {
|
||||
console.log(e)
|
||||
this.form.province = e.province.label
|
||||
this.form.city = e.city.label
|
||||
this.form.area = e.area.label
|
||||
this.region = e.province.label + '-' + e.city.label + '-' + e.area.label;
|
||||
console.log(this.region)
|
||||
},
|
||||
// 提交
|
||||
submit() {
|
||||
if (!this.form.userName) {
|
||||
uni.showToast({
|
||||
title: '请输入姓名',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!this.form.userPhone) {
|
||||
uni.showToast({
|
||||
title: '请输入联系电话',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (this.form.userPhone.length<=10) {
|
||||
uni.showToast({
|
||||
title: '请输入正确联系电话',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!this.form.address) {
|
||||
uni.showToast({
|
||||
title: '请选择所在地区',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!this.form.addressDetail) {
|
||||
uni.showToast({
|
||||
title: '请输入详细地址',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
this.form.addressDefault = this.form.addressDefault ? 1 : 0
|
||||
this.$Request.postJson("/app/address/insertAddress", this.form).then(res => {
|
||||
if (res.code == 0) {
|
||||
uni.showToast({
|
||||
title: '保存成功',
|
||||
icon: 'none'
|
||||
})
|
||||
setTimeout(function() {
|
||||
uni.navigateBack()
|
||||
}, 1000)
|
||||
}
|
||||
});
|
||||
},
|
||||
// 修改
|
||||
updata() {
|
||||
if (!this.form.userName) {
|
||||
uni.showToast({
|
||||
title: '请输入姓名',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!this.form.userPhone) {
|
||||
uni.showToast({
|
||||
title: '请输入联系电话',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!this.form.address) {
|
||||
uni.showToast({
|
||||
title: '请选择所在地区',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!this.form.addressDetail) {
|
||||
uni.showToast({
|
||||
title: '请输入详细地址',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let data = {
|
||||
addressId: this.form.addressId,
|
||||
userName: this.form.userName,
|
||||
userPhone: this.form.userPhone,
|
||||
province: this.form.province,
|
||||
city: this.form.city,
|
||||
district: this.form.district,
|
||||
address: this.form.address,
|
||||
addressDetail: this.form.addressDetail,
|
||||
addressDefault: this.form.addressDefault ? 1 : 0,
|
||||
lng: this.form.lng,
|
||||
lat: this.form.lat,
|
||||
}
|
||||
this.$Request.postJson("/app/address/updateAddress", data).then(res => {
|
||||
if (res.code == 0) {
|
||||
uni.showToast({
|
||||
title: '修改成功',
|
||||
icon: 'none'
|
||||
})
|
||||
setTimeout(function() {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
}
|
||||
});
|
||||
},
|
||||
// 根据id获取地址详情
|
||||
getAddressDet(e) {
|
||||
this.$Request.get("/app/address/selectAddressById?addressId=" + e).then(res => {
|
||||
if (res.code == 0) {
|
||||
this.form.addressId = res.data.addressId
|
||||
this.form.userName = res.data.userName
|
||||
this.form.userPhone = res.data.userPhone
|
||||
this.form.address = res.data.province + res.data.city + res.data.district
|
||||
this.form.addressDetail = res.data.addressDetail
|
||||
this.form.lng = res.data.lng
|
||||
this.form.lat = res.data.lat
|
||||
this.form.addressDefault = res.data.addressDefault
|
||||
that.form.province = res.data.province
|
||||
that.form.city = res.data.v
|
||||
that.form.district = res.data.district
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
page {
|
||||
background-color: #fff !important;
|
||||
}
|
||||
|
||||
/* 添加收货地址 */
|
||||
.btn {
|
||||
/* position: fixed;
|
||||
bottom: 0rpx; */
|
||||
width: 100%;
|
||||
height: 100rpx;
|
||||
line-height: 100rpx;
|
||||
background-color: white;
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
.address_push {
|
||||
width: 90%;
|
||||
height: 80rpx;
|
||||
margin: 0 auto;
|
||||
background: #FCD202;
|
||||
border-radius: 20rpx;
|
||||
color: white;
|
||||
text-align: center;
|
||||
line-height: 80rpx;
|
||||
font-size: 35rpx;
|
||||
}
|
||||
</style>
|
||||
335
my/address/index.vue
Normal file
335
my/address/index.vue
Normal file
@@ -0,0 +1,335 @@
|
||||
<template>
|
||||
<view class="address" v-if="XCXIsSelect=='是'">
|
||||
<view class="bg-white radius margin-sm" v-for="(item, index) in list" :key="index">
|
||||
<view class="content_top" @click="goBack(item)">
|
||||
<view class="content_part1">
|
||||
<view class="content_name">{{item.userName}}</view>
|
||||
<view class="content_number">
|
||||
{{item.userPhone}}
|
||||
</view>
|
||||
<view class="content_btn" v-if="item.addressDefault">默认</view>
|
||||
</view>
|
||||
<view class="content_part2">
|
||||
{{item.province}}{{item.city}}{{item.district}}{{item.addressDetail}}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 线条 -->
|
||||
<!-- <u-line color="#c1c1c1" border-style="solid" direction="row"></u-line> -->
|
||||
<view class="content_bottom">
|
||||
<view class="bottom_right">
|
||||
<view class="write" @click.stop="update(item)">
|
||||
<image src="../static/address/write.png"></image>
|
||||
</view>
|
||||
<view class="dete" @click.stop="del(item)">
|
||||
<image src="../static/address/dete.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<empty v-if="list.length == 0"></empty>
|
||||
|
||||
<view style="height: 100rpx;"></view>
|
||||
<!-- 添加收货地址 -->
|
||||
<view class="btn">
|
||||
<view class="address_push" @click="addAddress">添加收货地址</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import empty from '@/components/empty.vue'
|
||||
export default {
|
||||
components: {
|
||||
empty
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
list: [],
|
||||
checked: false,
|
||||
page: 1,
|
||||
limit: 10,
|
||||
add: 0,
|
||||
addressType: '',
|
||||
totalCount: 0,
|
||||
XCXIsSelect: '是',
|
||||
}
|
||||
},
|
||||
onLoad(option) {
|
||||
this.XCXIsSelect = this.$queue.getData('XCXIsSelect') ? this.$queue.getData('XCXIsSelect') : '是';
|
||||
if (this.XCXIsSelect == '否') {
|
||||
this.getGuize()
|
||||
uni.setNavigationBarTitle({
|
||||
title: '隐私政策'
|
||||
});
|
||||
} else {
|
||||
uni.setNavigationBarTitle({
|
||||
title: '地址管理'
|
||||
});
|
||||
}
|
||||
this.add = option.add ? option.add : 0
|
||||
|
||||
if (option.addressType) {
|
||||
this.addressType = option.addressType
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.page = 1
|
||||
this.getAddressList()
|
||||
},
|
||||
methods: {
|
||||
bindOrdersure() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/order_sure/order_sure'
|
||||
})
|
||||
},
|
||||
// 添加地址
|
||||
addAddress() {
|
||||
uni.navigateTo({
|
||||
url: '/my/address/add?page=2'
|
||||
})
|
||||
},
|
||||
// 获取地址列表
|
||||
getAddressList() {
|
||||
let data = {
|
||||
page: this.page,
|
||||
limit: this.limit
|
||||
}
|
||||
this.$Request.get("/app/address/selectAddressList", data).then(res => {
|
||||
if (res.code == 0) {
|
||||
this.totalCount = res.data.totalCount
|
||||
if (this.page == 1) {
|
||||
this.list = res.data.list
|
||||
} else {
|
||||
this.list = [...this.list, ...res.data.list]
|
||||
}
|
||||
}
|
||||
uni.stopPullDownRefresh();
|
||||
uni.hideLoading();
|
||||
});
|
||||
},
|
||||
// 设为默认地址
|
||||
checkboxChange(e) {
|
||||
console.log(e)
|
||||
// this.list.forEach(res => {
|
||||
// if (res.addressId == e.addressId) {
|
||||
let data = {
|
||||
addressId: e.addressId,
|
||||
userName: e.userName,
|
||||
userPhone: e.userPhone,
|
||||
address: e.address,
|
||||
addressDetail: e.addressDetail,
|
||||
addressDefault: e.addressDefault ? 0 : 1
|
||||
}
|
||||
this.$Request.postJson("/app/address/updateAddress", data).then(res => {
|
||||
if (res.code == 0) {
|
||||
this.getAddressList()
|
||||
}
|
||||
});
|
||||
// } else {
|
||||
// res.addressDefault = 0
|
||||
// }
|
||||
// })
|
||||
},
|
||||
// 跳转修改
|
||||
update(e) {
|
||||
uni.navigateTo({
|
||||
url: '/my/address/add?id=' + e.addressId
|
||||
})
|
||||
},
|
||||
// 删除地址
|
||||
del(e) {
|
||||
let that = this
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确认删除吗',
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
console.log('用户点击确定');
|
||||
that.$Request.post("/app/address/deleteAddress", {
|
||||
addressId: e.addressId
|
||||
}).then(res => {
|
||||
if (res.code == 0) {
|
||||
uni.showToast({
|
||||
title: '删除成功',
|
||||
icon: 'none'
|
||||
})
|
||||
that.page = 1
|
||||
that.getAddressList()
|
||||
}
|
||||
});
|
||||
} else if (res.cancel) {
|
||||
console.log('用户点击取消');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
// 点击地址返回上一页
|
||||
goBack(e) {
|
||||
console.log(e)
|
||||
if (this.add) {
|
||||
let pages = getCurrentPages();
|
||||
let prevPage = pages[pages.length - 2];
|
||||
// 修改上一页面的addressId
|
||||
// #ifdef MP-WEIXIN
|
||||
prevPage.$vm._data.addressId = e.addressId
|
||||
prevPage.$vm._data.addressType = this.addressType
|
||||
uni.navigateBack()
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
prevPage._data.addressId = e.addressId
|
||||
prevPage._data.addressType = this.addressType
|
||||
uni.navigateBack()
|
||||
// #endif
|
||||
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
uni.setStorageSync('addressId',e.addressId)
|
||||
uni.setStorageSync('addressType',this.addressType)
|
||||
setTimeout(function(){
|
||||
uni.navigateBack()
|
||||
},10)
|
||||
// #endif
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
onReachBottom: function() {
|
||||
if(this.list.length<this.totalCount) {
|
||||
this.page = this.page + 1;
|
||||
this.getAddressList()
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '已经到底了',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
onPullDownRefresh: function() {
|
||||
this.page = 1;
|
||||
this.getAddressList();
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
background-color: #eeeeee;
|
||||
background-size: cover;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.address {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.address_content {
|
||||
width: 100%;
|
||||
background: #FFFFFF;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.content_top {
|
||||
width: 90%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.content_part1 {
|
||||
font-size: 32rpx;
|
||||
color: #333333;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-top: 30rpx;
|
||||
}
|
||||
|
||||
.content_name {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.content_number {
|
||||
margin-left: 20rpx;
|
||||
}
|
||||
|
||||
.content_btn {
|
||||
padding: 4rpx 10rpx;
|
||||
border-radius: 10rpx;
|
||||
border: 1rpx solid #FCD202;
|
||||
color: #FCD202;
|
||||
margin-left: 20rpx;
|
||||
font-size: 22rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.content_part2 {
|
||||
color: #999999;
|
||||
font-size: 28rpx;
|
||||
margin-top: 20rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.content_bottom {
|
||||
display: flex;
|
||||
width: 90%;
|
||||
margin: 0 auto;
|
||||
height: 60rpx;
|
||||
}
|
||||
|
||||
.bottom_left {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: left;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.bottom_right {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.write image {
|
||||
width: 35rpx;
|
||||
height: 35rpx;
|
||||
}
|
||||
|
||||
.dete image {
|
||||
width: 35rpx;
|
||||
height: 35rpx;
|
||||
}
|
||||
|
||||
.write {
|
||||
position: absolute;
|
||||
right: 75rpx;
|
||||
}
|
||||
|
||||
.dete {
|
||||
position: absolute;
|
||||
right: 0rpx;
|
||||
}
|
||||
|
||||
/* 添加收货地址 */
|
||||
.btn {
|
||||
position: fixed;
|
||||
bottom: 0rpx;
|
||||
width: 100%;
|
||||
height: 100rpx;
|
||||
line-height: 100rpx;
|
||||
background-color: white;
|
||||
padding-top: 10rpx;
|
||||
}
|
||||
|
||||
.address_push {
|
||||
width: 90%;
|
||||
height: 80rpx;
|
||||
margin: 0 auto;
|
||||
background: #FCD202;
|
||||
border-radius: 20rpx;
|
||||
color: white;
|
||||
text-align: center;
|
||||
line-height: 80rpx;
|
||||
font-size: 35rpx;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user