博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
小程序获取用户默认地址的代码
阅读量:4682 次
发布时间:2019-06-09

本文共 6252 字,大约阅读时间需要 20 分钟。

 

ps:今天好不开心,有个bug有复现了,不需要安慰不需要安慰

代码在下面

wxml:

收货人
{
{receiver}}
{
{mobile}}
收货地址
{
{address}}
请点击选择收货地址
/* 地址 */.address-wraper {    padding: 0 30rpx 35rpx;    background: #ffffff;    margin-bottom: 24rpx;    background: #ffffff url(https://buy.fishqc.com/img/address-line.png) no-repeat left bottom;    background-size: contain;    overflow: hidden;}.address-mesg {    margin-top: 20rpx;    position: relative;}.mesg-title {    width: 128rpx;    padding-right: 15rpx;    font-family: 'PingFangSC-Light';    font-size: 28rpx;    color: #848a95;    letter-spacing: 0;    line-height: 40rpx;}.mesg-content-p {    font-family: 'PingFangSC-Light';    font-size: 24rpx;    color: #2f3736;    letter-spacing: 0;    line-height: 36rpx;}.flex-between {    justify-content: space-between;    -webkit-justify-content: space-between;}.addressee {    overflow: hidden;    text-overflow: ellipsis;    white-space: nowrap;    width: 270rpx;}.address-arrow {    width: 17rpx;    height: 30rpx;    position: absolute;    right: 0;    top: 50%;    transform: translate(-50%, -50%);    -webkit-transform: translate(-50%, -50%);}.choose-address {    min-height: 40rpx;    background: url(https://try.fishqc.com/img/address.jpg) no-repeat;    background-size: 32rpx 40rpx;    padding-left: 50rpx;    font-family: 'PingFangSC-Light';    font-size: 32rpx;    color: #2f3736;    letter-spacing: 0;    line-height: 40rpx;}.flex-one {    -webkit-box-flex: 1;    -webkit-flex: 1;    flex: 1;}.vertical-center {    align-items: center;    -webkit-align-items: center;}.horizontal-between {    justify-content: space-between;    -webkit-justify-content: space-between;}.flex-container {  display:flex;}

  js部分

judgeAuth:function(authStr) {        return new Promise((resolve, reject) => {            wx.getSetting({                success(res) {                    if (!(authStr in res.authSetting) || res.authSetting[authStr]) {                        // 同意授权且调用对应api后取消操作                        resolve(true)                    } else {                        // 未同意授权时,打开微信授权设定列表重新尝试获得授权                        resolve(false)                    }                },                fail(err) {                    reject(err)                }            })        })    },    chooseAddress: function chooseAddress() {        if (this.pay_coundDown_flag) {            return;        }        var that = this;        // 先判断是否已经授权        this.judgeAuth('scope.address').then(function (isSuccess) {            if (isSuccess) {                wx.chooseAddress({                    success: function success(res) {                        // 賦值                        that.setData({                             address: '' + res.provinceName + res.cityName + res.countyName + res.detailInfo,                            receiver: res.userName,                            mobile: res.telNumber,                                user_address_flag:true                         })                        console.log(that.data.address,101010)                        //缓存收货信息                        wx.setStorage({                            key: 'receiver',                            data: res.userName                        });                        wx.setStorage({                            key: 'mobile',                            data: res.telNumber                        });                        wx.setStorage({                            key: 'address',                            data: that.data.address                        });                    },                    fail: function fail() {                        // that.$parent.toasttips('选择地址失败')                    }                });            } else {                // 未授权则提醒用户打开授权列表                wx.showModal({                    title: '小鱼提示',                    content: '请允许我们读取您的通信地址',                    showCancel: false,                    success: function success(res) {                        if (res.confirm) {                            wx.openSetting({                                success: function success(res) {                                    if (res.authSetting['scope.address']) {                                        // 使用 call 调用将 this 指向指回 EvaluateCard 类上的原因是,这里直接调用 that.methods 会导致 this 指向 methods                                        // 使其函数重新执行时,上面的this指向全部变为了methods                                        that.methods.chooseAddress.call(that);                                    } else {                                        that.$parent.toasttips('选择地址需同意授权');                                    }                                    if (res.confirm) {                                        console.log('用户点击确定')                                    } else if (res.cancel) {                                        console.log('用户点击取消')                                    }                                },                                fail: function fail() {                                    that.$parent.toasttips('调用授权列表管理失败');                                }                            });                        }                    }                });            }        });    },

  

receiver:'',        mobile:'',        address:'',        upAvater:false,        avatar:''

  

onLoad: function() {        if (wx.getStorageSync('receiver') && wx.getStorageSync('mobile') && wx.getStorageSync('address')) {            this.setData({                user_address_flag:true,                receiver:wx.getStorageSync('receiver'),                mobile: wx.getStorageSync('mobile'),                address: wx.getStorageSync('address')            })        }        var that = this        that.getuserInfo()          },

  告辞!

转载于:https://www.cnblogs.com/antyhouse/p/9301707.html

你可能感兴趣的文章
cocos3 log
查看>>
django 1.10以上版本,引入js
查看>>
CSS3 transform
查看>>
cookie 和session 的区别详解
查看>>
JDK11 | 第六篇 : Epsilon 垃圾收集器
查看>>
The Divide and Conquer Approach - 归并排序
查看>>
网络对抗技术_实验四_恶意代码技术
查看>>
开一个线程来处理 耗时的操作
查看>>
Docker 搭建 etcd 集群配置
查看>>
Java列表、数组、字符串
查看>>
phpcms <= v9.15 任意文件读取漏洞的分析和利用
查看>>
[20160727][文件夹重命名]
查看>>
OA Software Service Manager for BizTalk Server
查看>>
CSS3中动画属性transform、transition 和 animation
查看>>
Linux日常开发中常用命令
查看>>
Http Cookie机制及Cookie的实现原理
查看>>
生成验证码的代码
查看>>
php--->依赖注入(DI)实现控制反转(IOC)
查看>>
while 循环
查看>>
nginx配置文件中的location详解
查看>>