wxml 内
<view class='product-contact' wx:if="{{contact!=''}}" data-contact1="{{contact1}}" data-contact2="{{contact2}}" catchtap='makeCall'>立即联系</view>
js 内
data: { contact: '123456,654321', contact1: '123456', contact2: '' }, makeCall: function (e) { var phone1 = e.currentTarget.dataset.contact1, //手机号 phone2 = e.currentTarget.dataset.contact2; //固话 console.log('phone1:',phone1,',phone2:',phone2); if (phone1 && phone2 && phone1 != phone2) { console.log('两个电话均存在'); wx.showActionSheet({ itemList: [phone1, phone2], success(res) { if (res.tapIndex === 0) { wx.makePhoneCall({ phoneNumber: phone1, success: function () { console.log('拨打电话成功' + phone1) }, fail: function () { console.log("拨打电话失败") } }) } else if (res.tapIndex === 1) { wx.makePhoneCall({ phoneNumber: phone2, success: function () { console.log('拨打电话成功' + phone2) }, fail: function () { console.log("拨打电话失败") } }) } }, fail(res) { console.log("拨打电话失败") } }) } else if (phone1 && phone2 && phone1 === phone2) { console.log('两个电话相同'); wx.showModal({ content: "确认拨打" + phone2 + "吗", confirmColor: '#2EA7E0', success(res) { if (res.cancel) { // 用户点击了取消属性的按钮 return false } else if (res.confirm) { wx.makePhoneCall({ //调用小程序拨打电话的api phoneNumber: phone2, //获取到的电话号码 success: function () { console.log('拨打电话成功') }, fail: function () { console.log("拨打电话失败") } }) } } }) } else if (!phone1 && phone2) { //弹出dialog弹出框 console.log('一个电话存在'); wx.showModal({ content: "确认拨打" + phone2 + "吗", confirmColor: '#2EA7E0', success(res) { if (res.cancel) { // 用户点击了取消属性的按钮 return false } else if (res.confirm) { wx.makePhoneCall({ //调用小程序拨打电话的api phoneNumber: phone2, //获取到的电话号码 success: function () { console.log('拨打电话成功') }, fail: function () { console.log("拨打电话失败") } }) } } }) } else if (!phone2 && phone1) { //弹出dialog弹出框 console.log('一个电话存在'); wx.showModal({ content: "确认拨打" + phone1 + "吗", confirmColor: '#2EA7E0', success(res) { if (res.cancel) { // 用户点击了取消属性的按钮 return false } else if (res.confirm) { wx.makePhoneCall({ //调用小程序拨打电话的api phoneNumber: phone1, //获取到的电话号码 success: function () { console.log('拨打电话成功') }, fail: function () { console.log("拨打电话失败") } }) } } }) } else if (!phone2 && !phone2) { console.log('两个电话均不存在'); wx.showModal({ content: "暂无联系电话", confirmColor: '#2EA7E0', showCancel: false, //不显示取消按钮 success(res) { if (res.confirm) { return false } } }) } }
标签:console,log,phone2,微信,phone1,res,点击,拨打 From: https://www.cnblogs.com/shuihanxiao/p/18110558