Commit 31ca577d authored by 黄媛媛's avatar 黄媛媛

地址自动获取功能

parent 79c331f6
<template> <template>
<view class="addressStyle" v-if="!isloading" :style="{'height':contentHeight}"> <view class="addressStyle" v-if="!isloading" :style="{ height: contentHeight }">
<scroll-view <scroll-view :scroll-y="true" :enable-back-to-top="true" :enable-flex="true" :style="{ height: '100%' }">
:scroll-y="true"
:enable-back-to-top="true"
:enable-flex="true"
:style="{ height: '100%' }"
>
<view v-for="(item, index) in list" :key="index" class="addresbox" @click="chosenHandler(item)"> <view v-for="(item, index) in list" :key="index" class="addresbox" @click="chosenHandler(item)">
<view class="addresclo"> <view class="addresclo">
<Text>收件人:{{item.Name}}</Text> <Text>收件人:{{ item.Name }}</Text>
<Text>{{item.Mobile}}</Text> <Text>{{ item.Mobile }}</Text>
</view> </view>
<Text style='width: 100%;'>收货地址:{{item.DistrictAddress}}{{item.Address}}</Text> <Text style="width: 100%;">收货地址:{{ item.DistrictAddress }}{{ item.Address }}</Text>
<view style="width: 100%;height: 2rpx;background: #f5f5f5;margin-top: 15rpx;"></view> <view style="width: 100%;height: 2rpx;background: #f5f5f5;margin-top: 15rpx;"></view>
<view class="addresclo"> <view class="addresclo">
<u-checkbox-group @change="isdefault(item)"> <u-checkbox-group @change="isdefault(item)">
<u-checkbox v-model="item.IsDefault==1?true:false" shape="circle" :active-color="mainColor"> <u-checkbox v-model="item.IsDefault == 1 ? true : false" shape="circle" :active-color="mainColor">
<Text <Text :style="{ color: item.IsDefault == 1 ? mainColor : '#c8c9cc' }">{{ item.IsDefault == 1 ? '已设为默认' : '设为默认' }}</Text>
:style="{'color':item.IsDefault==1?mainColor:'#c8c9cc' }"
>{{item.IsDefault==1?'已设为默认':'设为默认'}}</Text>
</u-checkbox> </u-checkbox>
</u-checkbox-group> </u-checkbox-group>
<view style="display: flex;flex-direction: row;align-items: center;"> <view style="display: flex;flex-direction: row;align-items: center;">
<view <view style="display: flex;flex-direction: row;align-items: center;" @click.stop="btn_edit(item)">
style="display: flex;flex-direction: row;align-items: center;"
@click.stop="btn_edit(item)"
>
<u-icon name="edit" color="#c8c9cc" size="40"></u-icon> <u-icon name="edit" color="#c8c9cc" size="40"></u-icon>
<Text style="color:#c8c9cc;">编辑</Text> <Text style="color:#c8c9cc;">编辑</Text>
</view> </view>
<view <view style="display: flex;flex-direction: row;align-items: center;margin: 0 30rpx" @click.stop="btn_delete(item)">
style="display: flex;flex-direction: row;align-items: center;margin: 0 30rpx"
@click.stop="btn_delete(item)"
>
<u-icon name="delete" color="#c8c9cc" size="40"></u-icon> <u-icon name="delete" color="#c8c9cc" size="40"></u-icon>
<Text style="color:#c8c9cc;">删除</Text> <Text style="color:#c8c9cc;">删除</Text>
</view> </view>
...@@ -40,7 +27,7 @@ ...@@ -40,7 +27,7 @@
</view> </view>
</view> </view>
<view class="bottom_btn"> <view class="bottom_btn">
<view class="bottom_btn_item" :style="{'background':mainColor}" @click="ManualAdd"> <view class="bottom_btn_item" :style="{ background: mainColor }" @click="ManualAdd">
<u-icon name="add-o" color="#fff" size="30"></u-icon> <u-icon name="add-o" color="#fff" size="30"></u-icon>
<Text style="color:#fff;margin-left: 10rpx;">手动添加</Text> <Text style="color:#fff;margin-left: 10rpx;">手动添加</Text>
</view> </view>
...@@ -52,96 +39,94 @@ ...@@ -52,96 +39,94 @@
</view> </view>
</scroll-view> </scroll-view>
<!-- 删除的弹框 --> <!-- 删除的弹框 -->
<u-modal <u-modal v-model="showModal" content="确实删除收货地址" :show-cancel-button="true" :show-title="false" @confirm="confirm"></u-modal>
v-model="showModal"
content="确实删除收货地址"
:show-cancel-button="true"
:show-title="false"
@confirm="confirm"
></u-modal>
<u-toast ref="uToast" /> <u-toast ref="uToast" />
<auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth= 'gbAuth'></auth> <auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth="gbAuth"></auth>
</view> </view>
</template> </template>
<script> <script>
import auth from "../../components/auth/index.vue"; import auth from '../../components/auth/index.vue';
export default { export default {
data() { data() {
return { return {
pageTitle:'收货地址', pageTitle: '收货地址',
loading: true, loading: true,
list: [], list: [],
showAuth: false, showAuth: false,
mainColor: "", mainColor: '',
u: {}, u: {},
contentHeight: 0, contentHeight: 0,
showModal: false, showModal: false,
deleteID: 0, deleteID: 0,
msg:{ msg: {
Name:'', Name: '',
IsDefault:0, IsDefault: 0,
Mobile:'', Mobile: ''
}, },
source: "", source: '',
defaultId: 0, defaultId: 0,
currentAddress: {}, currentAddress: {},
list: [], list: [],
mc:"", mc: '',
addressmsg: {
Id: 0,
Name: '',
Mobile: '',
Province: '',
City: '',
District: '',
Address: ''
}
}; };
}, },
components: { components: {
auth auth
}, },
created() { created() {
this.contentHeight = this.$utils.calcContentHeight(-40) + "px"; this.contentHeight = this.$utils.calcContentHeight(-40) + 'px';
this.mainColor = this.$uiConfig.mainColor; this.mainColor = this.$uiConfig.mainColor;
}, },
mounted() { mounted() {
let currentPages = getCurrentPages(); let currentPages = getCurrentPages();
let u = "/" + currentPages[currentPages.length - 1].route; let u = '/' + currentPages[currentPages.length - 1].route;
let pages = wx.getStorageSync("basedata") let pages = wx.getStorageSync('basedata') ? wx.getStorageSync('basedata').bar_title : [];
? wx.getStorageSync("basedata").bar_title pages.forEach(x => {
: [];
pages.forEach((x) => {
if (x.value == u) { if (x.value == u) {
this.pageTitle = x.new_name ? x.new_name : x.name; this.pageTitle = x.new_name ? x.new_name : x.name;
} }
}); });
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
title: this.pageTitle, title: this.pageTitle
}); });
}, },
onLoad(option) { onLoad(option) {
this.u = uni.getStorageSync("mall_UserInfo"); this.u = uni.getStorageSync('mall_UserInfo');
if (!this.u) { if (!this.u) {
this.u = { this.u = {
nickName: "未登录", nickName: '未登录',
avatarUrl: "" avatarUrl: ''
}; };
this.showAuth = true; this.showAuth = true;
}else{ } else {
this.init(); this.init();
} }
if (option && option.form) { if (option && option.form) {
(this.source = option.form), (this.defaultId = option.id); (this.source = option.form), (this.defaultId = option.id);
} }
}, },
methods: { methods: {
chosenHandler(item){ chosenHandler(item) {
console.log("chosenHandler",item) console.log('chosenHandler', item);
let pages = getCurrentPages() let pages = getCurrentPages();
let prevPage = pages[ pages.length - 2 ] let prevPage = pages[pages.length - 2];
prevPage.$vm.formData.address_id = item.Id; prevPage.$vm.formData.address_id = item.Id;
prevPage.$vm.formdata.AddressId = item.Id; prevPage.$vm.formdata.AddressId = item.Id;
prevPage.$vm.adressInfo=item; prevPage.$vm.adressInfo = item;
uni.navigateBack({ uni.navigateBack({
delta: 1 delta: 1
}) });
}, },
init() { init() {
this.loading = false; this.loading = false;
...@@ -154,8 +139,7 @@ export default { ...@@ -154,8 +139,7 @@ export default {
}, },
res => { res => {
uni.hideNavigationBarLoading(); uni.hideNavigationBarLoading();
if(res.resultCode==1){ if (res.resultCode == 1) {
this.isloading = false; this.isloading = false;
this.list = res.data; this.list = res.data;
} }
...@@ -163,13 +147,13 @@ export default { ...@@ -163,13 +147,13 @@ export default {
); );
}, },
reloadUserinfo() { reloadUserinfo() {
this.u = uni.getStorageSync("mall_UserInfo"); this.u = uni.getStorageSync('mall_UserInfo');
this.showAuth = false; this.showAuth = false;
this.init(); this.init();
}, },
//关闭登录窗口 //关闭登录窗口
gbAuth(){ gbAuth() {
uni.navigateBack() uni.navigateBack();
}, },
isdefault(item) { isdefault(item) {
//设置默认地址 //设置默认地址
...@@ -178,7 +162,7 @@ export default { ...@@ -178,7 +162,7 @@ export default {
{ {
url: '/api/AppletUser/SetUserShippingAddressDefault', url: '/api/AppletUser/SetUserShippingAddressDefault',
data: { data: {
AddressId:item.Id AddressId: item.Id
} }
}, },
...@@ -190,7 +174,7 @@ export default { ...@@ -190,7 +174,7 @@ export default {
}, },
btn_edit(item) { btn_edit(item) {
uni.navigateTo({ uni.navigateTo({
url: "/pages/address/AddAddress?AddressId="+item.Id url: '/pages/address/AddAddress?AddressId=' + item.Id
}); });
}, },
btn_delete(item) { btn_delete(item) {
...@@ -201,10 +185,9 @@ export default { ...@@ -201,10 +185,9 @@ export default {
uni.showNavigationBarLoading(); uni.showNavigationBarLoading();
this.request2( this.request2(
{ {
url: "/api/AppletUser/DelUserShippingAddress", url: '/api/AppletUser/DelUserShippingAddress',
data: { data: {
AddressId:this.deleteID AddressId: this.deleteID
} }
}, },
...@@ -215,64 +198,71 @@ export default { ...@@ -215,64 +198,71 @@ export default {
); );
}, },
automatic() { automatic() {
this.$refs.uToast.show({ // this.$refs.uToast.show({
title: "正在开发,敬请期待!" // title: "正在开发,敬请期待!"
}); // });
// wx.getSetting({
// success(res) {
// console.log("vres.authSetting['scope.address']:",res.authSetting['scope.address'])
// if (res.authSetting['scope.address']) {
// console.log("111")
// wx.chooseAddress({
// success(res) {
// console.log(res.userName)
// console.log(res.postalCode)
// console.log(res.provinceName)
// console.log(res.cityName)
// console.log(res.countyName)
// console.log(res.detailInfo)
// console.log(res.nationalCode)
// console.log(res.telNumber)
// }
// })
// // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
// } else { let that = this;
// if (res.authSetting['scope.address'] == false) { if (wx.chooseAddress) {
// console.log("222") wx.chooseAddress({
// wx.openSetting({ success: function(res) {
// success(res) { console.log(res);
// console.log(res.authSetting) let nameList = [res.provinceName, res.cityName, res.countyName];
that.addressmsg.Name = res.userName;
that.addressmsg.Mobile = res.telNumber;
that.addressmsg.Address = res.detailInfo;
that.getDestination(nameList);
},
fail: function(err) {
that.$refs.uToast.show({
title: '授权失败,请重新点击自动获取',
type: 'error'
});
}
});
} else {
that.$refs.uToast.show({
title: '当前微信版本不支持自动获取收货地址',
type: 'error'
});
}
},
getDestination(nameList) {
this.request2(
{
url: '/api/AppletUser/GetDestinationListByNames',
data: {
area: nameList
}
},
// } res => {
// }) console.log('res', res);
// } else { this.addressmsg.Province = res.data[0].ID;
// console.log("eee") this.addressmsg.City = res.data[1].ID;
// wx.chooseAddress({ this.addressmsg.District = res.data[2].ID;
// success(res) { if (res.data.length > 0) {
// console.log(res.userName) this.request2(
// console.log(res.postalCode) {
// console.log(res.provinceName) url: '/api/AppletUser/SetUserShippingAddress',
// console.log(res.cityName) data: this.addressmsg
// console.log(res.countyName) },
// console.log(res.detailInfo) res => {
// console.log(res.nationalCode) uni.showToast({ title: '保存成功', icon: 'none' });
// console.log(res.telNumber) this.init();
// } }
// }) );
// } }
// } }
// } );
// })
}, },
ManualAdd() { ManualAdd() {
//手动添加 //手动添加
uni.navigateTo({ uni.navigateTo({
url: "/pages/address/AddAddress" url: '/pages/address/AddAddress'
}); });
} }
}, }
}; };
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment