uniapp框架下开发微信小程序常用到的方法与一些代码块

//修改搜索框里的内容

getValue(e) {
     this.keyword=e.detail.value
},


//隐藏、显示输入框提示
setMpt(e){
            if(e==1){
                this.inputMpt=""
            }
            else{
                this.inputMpt="请输入城市/门店名称"
            }
},

//打开地图------
        openmap(e){
            var latitude = parseFloat(e.currentTarget.dataset.lat)
            var longitude = parseFloat(e.currentTarget.dataset.lng)
            var name = e.currentTarget.dataset.name
            var add = e.currentTarget.dataset.add
            uni.openLocation({
              latitude:latitude,
              longitude:longitude,
              scale: 28,
              name:name,
              address:add
            })
        },
 

//拉取订阅消息机会
        getMessage(url){
            var tmpid=this.tmpid
            uni.getSetting({
                withSubscriptions:true,
                success(res){
                    //console.log(res)
                    if(res['authSetting']['scope.subscribeMessage']==undefined){
                        uni.requestSubscribeMessage({
                          tmplIds: [tmpid],
                          success (res) { 
                              if(res[tmpid]=="accept"){
                                  uni.navigateTo({
                                      url:url,
                                  });
                              }
                              else{
                                  uni.showToast({
                                      title: '请先授权订阅消息,以便接收客服消息通知',
                                      mask:true,
                                      icon:'none',
                                      duration:4000
                                  });
                              }  
                          },
                          fail(res){
                              uni.navigateTo({
                                url:url,
                              });
                          }
                        })
                    }
                    else if(res['authSetting']['scope.subscribeMessage']){
                        if(res.subscriptionsSetting.mainSwitch==undefined){
                            if(res.subscriptionsSetting.itemSettings[tmpid]=="accept"){
                                uni.navigateTo({
                                    url:url,
                                });
                            }
                            else{
                                uni.openSetting()
                            }
                        }
                        else{
                            uni.requestSubscribeMessage({
                              tmplIds: [tmpid],
                              success (res) { 
                                  if(res[tmpid]=="accept"){
                                      uni.navigateTo({
                                          url:url,
                                      });
                                  }
                                  else{
                                      uni.openSetting()
                                  }  
                              },
                              fail(res){
                                  uni.navigateTo({
                                      url:url,
                                  });
                              }
                            })
                        }  
                    }
                    else{
                        uni.openSetting()
                    }
                },
                fail(res){
                    uni.navigateTo({
                        url:url,
                    });
                }
            })
        }
    

//预览图片
        bigImg(e) {
            var that = this
            //图片预览
            uni.previewImage({
              current: e.currentTarget.dataset.img, // 当前显示图片的http链接
              urls: [that.webconfig.wxqr] // 需要预览的图片http链接列表
            })
        },


/*调起微信客服(企业微信号,不是指一般微信号)
        传入参数e:e.url为企业微信生成的客服链接,在企业微信后台能产成;
                            e.qiyeid为企业微信的ID
*/
function wxKefu(e){
    e=e.currentTarget.dataset
    uni.openCustomerServiceChat({
      extInfo: {url: e.url},
      corpId: e.qiyeid,
      success(res) {
          //console.log(res)
      }
    })
}

/* 打电话方法
    传入参数:e ;e.realname姓名,e.number电话号码,e.company公司,e.job职位,e.mode: 1为只打电话,2为打电话加添加通讯录
*/
function makePhone(e){
    //console.log(e)
    e=e.currentTarget.dataset
    if(e.mode==2){
        uni.showActionSheet({
          itemList: ['直接拨打', '添加到通讯录'],  
          success: function(res) {  
            if (res.tapIndex === 0) {
              uni.makePhoneCall({
                phoneNumber: e.number,
              })
            } else if (res.tapIndex === 1) {   
              uni.addPhoneContact({
                firstName: e.realname,
                organization: e.company,
                title: e.job,
                mobilePhoneNumber: e.number,
                success(res){
                    //console.log("成功调用")
                    //console.log(res)
                }
              }) 
            }  
          }  
        }); 
    }
    else{
        uni.makePhoneCall({
          phoneNumber: e.number,
        })
    }
}

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值