当前位置:   article > 正文

微信小程序自定义弹出框组件,模拟wx.showModal_wx.showmodal源码

wx.showmodal源码

微信小程序开发交流qq群   173683895

效果图:

代码

wxml

  1. <view wx:if='{{showModal}}'>
  2. <view class='mask_layer' bindtap='modal_click_Hidden' />
  3. <view class='modal_box'>
  4. <view class="title">取消订单</view>
  5. <view class='content'>
  6. <text class='modalMsg'></text>
  7. <textarea class='input_show1' bindinput='changeCancelReason' auto-height value='{{modalMsg}}' bindfocus='bindfocus' bindblur='bindblur' placeholder='{{modalMsg_placeholder}}'></textarea>
  8. </view>
  9. <view class='btn1'>
  10. <view bindtap='modal_click_Hidden' class='cancel'>取消</view>
  11. <view bindtap='Sure' class='Sure'>确定</view>
  12. </view>
  13. </view>
  14. </view>

css

  1. .mask_layer {
  2. width: 100%;
  3. height: 100%;
  4. position: fixed;
  5. z-index: 999;
  6. left:0;top:0;
  7. background: #000;
  8. opacity: 0.5;
  9. overflow: hidden;
  10. }
  11. .modal_box {
  12. width: 76%;
  13. overflow: hidden;
  14. position: fixed;
  15. top: 50%;
  16. left: 0;
  17. z-index: 1001;
  18. background: #fafafa;
  19. margin: -150px 12% 0 12%;
  20. border-radius: 3px;
  21. }
  22. .title {
  23. padding: 15px;
  24. text-align: center;
  25. background-color: gazure;
  26. }
  27. .content {
  28. overflow-y: scroll; /*超出父盒子高度可滚动*/
  29. }
  30. .input_show1{
  31. margin: 0 auto;
  32. width: 80%;
  33. margin-left: 10%;
  34. font-size: 32rpx;
  35. text-align: center;
  36. }
  37. .btn1 {
  38. width: 100%;
  39. margin-top: 65rpx;
  40. display: flex;
  41. flex-direction: row;
  42. align-items: center;
  43. justify-content: space-between;
  44. box-sizing: border-box;
  45. background-color: white;
  46. }
  47. .cancel {
  48. width: 100%;
  49. padding: 10px;
  50. text-align: center;
  51. color: black;
  52. }
  53. .Sure {
  54. width: 100%;
  55. padding: 10px;
  56. color: #44b549;
  57. background-color: white;
  58. border-left: 1px solid #d0d0d0;
  59. text-align: center;
  60. }
  61. .modalMsg {
  62. text-align: center;
  63. margin-top: 45rpx;
  64. display: block;
  65. }

js

  1. showCancelOrder: function() {
  2. this.setData({
  3. showModal:true
  4. })
  5. },
  6. modal_click_Hidden: function () {
  7. this.setData({
  8. showModal: false,
  9. })
  10. },
  11. // 确定
  12. Sure: function () {
  13. console.log(this.data.text)
  14. if (this.data.cancelReason==''){
  15. wx.showToast({
  16. title: '请填写订单取消原因',
  17. icon:'none'
  18. })
  19. return
  20. }else{
  21. // 提交到后端
  22. this.cancelOrder();
  23. }
  24. },
  25. changeCancelReason: function(e) {
  26. this.setData({
  27. cancelReason: e.detail.value
  28. })
  29. },
  30. cancelOrder: function() {
  31. var token = wx.getStorageSync('token');
  32. var that = this;
  33. util.POST({
  34. params: {
  35. 'token': token,
  36. 'id': this.data.order.id,
  37. 'cancel_reason': this.data.cancelReason
  38. },
  39. API_URL: 'Doctor/cancelOrder',
  40. success: (res) => {
  41. res = res.data;
  42. if (res.code == 200) {
  43. wx.showToast({
  44. title: res.msg,
  45. icon: 'success',
  46. duration: 2000
  47. })
  48. setTimeout(function() {
  49. that.getOrderDetails();
  50. }, 2000)
  51. } else {
  52. wx.showToast({
  53. title: res.msg,
  54. icon: 'none',
  55. duration: 2000
  56. })
  57. }
  58. that.setData({
  59. showModal: false
  60. })
  61. },
  62. fail: function() {
  63. }
  64. })
  65. },

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/88255
推荐阅读
相关标签
  

闽ICP备14008679号