微信小程序4种弹框

发布于:2024-07-01 ⋅ 阅读:(15) ⋅ 点赞:(0)

1、wx.showModal 确认弹框

 delete(){
    wx.showModal({
      title: '',
      content: '是否确认删除',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }

 2、wx.showToast 提示弹框

success 显示成功图标
error 显示失败图标
loading 显示加载图标
none 不显示图标
wx.showToast({
  title: '成功',
  icon: 'success',
  duration: 2000
})

3、wx.showLoading loading弹框

wx.showLoading({
  title: '加载中',
})

setTimeout(function () {
  wx.hideLoading()
}, 2000)

4、wx.showActionSheet  操作弹框

wx.showActionSheet({
  itemList: ['A', 'B', 'C'],
  success (res) {
    console.log(res.tapIndex)
  },
  fail (res) {
    console.log(res.errMsg)
  }
})

 customer.wxml

<button class="fixed-service"  bindtap="getPhone">

  <text class="iconfont icon-kefu"></text>

  <view>客服</view>

</button>

customer.css

/* 联系客服 */

.fixed-service {
  display: inline-block;
  bottom: 13%;
  right: 30rpx;
  width: 80rpx;
  height: 80rpx;
  position: fixed;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  text-align: center;
  color: #fff;
  box-sizing: border-box;
  font-size: 20rpx;
  padding: 10rpx;
  line-height: 1.2;
  z-index: 100;
}
.fixed-share .iconfont {
  font-size: 30rpx;
}

customer.js

  getPhone:function (params) {
    var that=this;
    let arr=[];
		wx.request({
			url: newurl.getKfPhone,
			method: 'post',
			success (res) {
				if (res.data.status == 200) {
					console.log(res.data.data);
					that.setData({
							kfphone: res.data.data,
          });
          wx.showActionSheet({
            itemList:['拨打客服电话1','拨打客服电话2'], //文字数组
            success: (ress) => {
              switch(ress.tapIndex) {
                case 0:
                  console.log(res.data.data.kfphone1)
                  wx.makePhoneCall({
                    phoneNumber: res.data.data.kfphone1
                  });
                  break;
                case 1:
                  wx.makePhoneCall({
                    phoneNumber: res.data.data.kfphone2
                  });
                  console.log(res.data.data.kfphone2)
                  break;	
              };
            
            },
            fail (ress) {
              console.log('取消选项')
            }
          })
			} 
			}
		});
  },