微信小程序实现打电话​​​​​​​

                                     微信小程序实现打电话

 

phone.wxss
.phone-numbers-title {
  text-align: center;/*文本居中*/
  padding-top: 20rpx;
  padding-bottom: 20rpx;/*顶部底部填充*/
  font-size: 48rpx;
  color:white;/*字体颜色*/
  background-color: #328ca2;/*背景颜色*/
  width:80%;
  margin: 50rpx auto;/*设置4边距*/
}
.phone-numbers-main {
  display: flex;
  flex-direction: column;
  width: 80%;
  margin: 20rpx auto;
  background-color: rgba(38, 165, 197, 0.3)

}
.single-number {
  display: flex;
  padding:24rpx;
  border-bottom: 2px solid rgb(119, 119, 117);
  font-size: 40rpx;
}

.button{
  margin-right: 0.1cm;
  font-size: 30rpx;
  color:white;
  background-color: #4a4e42;
  width:3cm;
}

.text{
  margin-left: 20rpx;
}
phone.wxml
<view class="phone-numbers-title">常用电话</view> 
  <view class="phone-numbers-main">
    <block wx:for="{{phone_numbers}}" wx:key="phone_numbers" wx:for-item="item" >
     <view class="single-number">
        <text>{{item.organization}}</text>
        <text class="text">{{item.num}}</text>  
        <button data-phonenum="{{item.num}}" class="button" bindtap="call">拨打</button> 
        <!--此处data-phonenum 已经将条目中的电话号放入,后端直接调用-->
     </view>
    </block>
  </view>
phone.js


//主要方法
data: {//存放信息的数组
    phone_numbers: [
      {
        id: "num-1",
        organization: "公安",
        num: "110"
      }, {
        id: "num-2",
        organization: "火警",
        num: "119"
      }, {
        id: "num-3",
        organization: "救护",
        num: "120"
      }, {
        id: "num-4",
        organization: "燃气",
        num: "962777"
      }, {
        id: "num-5",
        organization: "物业",
        num: "87855211"
      }]
  },
  //调用手机拨号
  call: function (e) {
    var phone_num = e.target.dataset.phonenum;//获取设置的电话值
    wx.makePhoneCall({
      phoneNumber: phone_num
    })
  },

实现了电话简单的打出,也可改进成将输入的电话号播出,需要使用<input>组件

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值