uni-app在详情页中给电话信息添加点击拨打电话的功能按钮
2023-06-01 00:00:00
uni
需求:在详情页中的电话信息后面添加一个图标按钮,点击自己拨打该电话
uni-app官方手册示例
https://uniapp.dcloud.io/api/system/phone?id=makephonecall
进入步骤:
我去根据id去后端接口请求数据过来,已展示出来了
不说了,直接贴代码
视图:
<template>
<view>
<view>{{shopData.bankid_name}}{{shopData.citys2_name}}{{shopData.bankname}}网点信息</view>
<view>
<view class="uni-flex uni-row">
<view style="width: 25%;">网点地址:</view>
<view style="width: 75%;">{{shopData.bankaddress}}</view>
</view>
<view class="uni-flex uni-row">
<view style="width: 25%;">营业时间:</view>
<view style="width: 75%;">{{shopData.workdate}}</view>
</view>
<view class="uni-flex uni-row">
<view style="width: 25%;">网点电话:</view>
<view style="width: 75%;">{{shopData.tel}}</view>
//点击拨打电话按钮
<view class="flex-item det_tel" @click.stop="openPhone(shopData.tel)" v-if="shopData.tel">
<view class="lg cuIcon-dianhua"></view>
</view>
</view>
<view></view>
<view class="uni-flex uni-row">
<view style="width: 25%;">兑换外币:</view>
<view style="width: 75%;">不可兑换</view>
</view>
</view>
</view>
</template>
js:
<script>
export default {
data() {
return {
share: false,
shopData: {},
per: {},
}
},
onLoad(e:any) {
this.per = e;
this.getDetailsData();
},
onShow(){
},
computed: {
},
methods: {
getDetailsData() {
let that = this;
console.log(that.per.id,'1111111111')
this.$request.get("/api/wdbankwdlistpage", {
data: {
wdid: this.per.id
}
}).then(res => {
console.log(res.data, "xxxx")
let data = res.data;
//#ifdef MP-BAIDU
//setTKD(JSON.parse(data.tdk))
//#endif
uni.setNavigationBarTitle({
title: data.bankid_name + data.citys2_name + data.bankname
})
let b
if(data.s1){
b = data.s1 + '至' + data.s2 + '' +
(data.s3!=null?data.s3:'') + '' + (data.s4!=null?data.s4:'') + '-' +
(data.s5!=null?data.s5:'') + '' + (data.s6!=null?data.s6:'') + '' +
(data.s7!=null?data.s7:'') + '' + (data.s8!=null?data.s8:'') + '' + (data.s9!=null?data.s9:'')
}else{
if(data.m4){
b = data.m4 + '-' + data.m5
}else {
b = '周一至周五09:00-12:00,14:00-17:00'
}
}
data.workdate = b;
let tel
tel = data.teltype == 1?data.banktel1:data.dstel1
data.tel = tel
that.shopData = data;
})
},
openPhone(phone) {
uni.showModal({
title: "提示",
content: "是否拨打电话" + phone,
success(e) {
console.log(e)
if (e.confirm) {
uni.makePhoneCall({
phoneNumber: phone
})
}
}
})
},
}
}
</script>
css:
<style scoped>
.mheight {
height: 10px;
}
.uni-flex {
display: flex;
flex-direction: row;
}
.uni-row {
flex-direction: row;
}
.flex-item {
padding-bottom: 10px;
}
.det {
color: #666;
min-height: 600upx;
.det_title {
font-size: $uni-font-size-lg;
position: relative;
color: #000;
font-weight: bold;
padding: 20px;
text-align: center;
}
.det_center {
padding: 5px 30px 0px 25px;
}
.det_tel {
font-size: 40px;
position: fixed;
right: 50px;
color: #333;
border-left: 1upx solid #eee;
}
}
</style>
效果图:(点击图标的时候弹出)
相关文章