getPhone.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view>
  3. <block v-if="systemInfo.is_vip == 1">
  4. <!-- #ifdef MP-WEIXIN -->
  5. <block v-if="userInfo.mobile">
  6. <view hover-class="none" class="home-btn" @click="onGetphone">
  7. <image src="https://zxzhdc.zx-xcx.com/dining/home6.png"></image>
  8. </view>
  9. </block>
  10. <block v-else>
  11. <button hover-class="none" class="home-btn" open-type="getPhoneNumber"
  12. @getphonenumber="onGetphoneNumber">
  13. <image src="https://zxzhdc.zx-xcx.com/dining/home6.png"></image>
  14. </button>
  15. </block>
  16. <!-- #endif -->
  17. <!-- #ifdef MP-ALIPAY -->
  18. <view @click="onGetphone" class="home-btn">
  19. <image src="https://zxzhdc.zx-xcx.com/dining/home6.png"></image>
  20. </view>
  21. <!-- #endif -->
  22. </block>
  23. <Vphone :getPhonePop="getPhonePop" @close="setClose"></Vphone>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. mapState,
  29. mapMutations
  30. } from 'vuex'
  31. let hideLoading = true;
  32. import Vphone from '@/components/v-phone/v-phone.vue';
  33. // #ifdef MP-ALIPAY
  34. // const {
  35. // requestSubscribeMessage
  36. // } = requirePlugin('subscribeMsg');
  37. // #endif
  38. export default {
  39. data() {
  40. return {
  41. getPhonePop: false
  42. }
  43. },
  44. components: {
  45. Vphone
  46. },
  47. computed: {
  48. ...mapState(['systemInfo', 'setColor', 'store_id', 'userInfo', 'teen_index', 'address'])
  49. },
  50. methods: {
  51. onGetphoneNumber(e) {
  52. if (this.userInfo.mobile) {
  53. uni.showToast({
  54. title: "您已经完善过会员信息了,无需重复操作!",
  55. icon: 'none'
  56. })
  57. return
  58. }
  59. // #ifdef MP-WEIXIN
  60. if (e.detail.errMsg == "getPhoneNumber:ok") {
  61. this.$http.request('xcx/Jiemi', {
  62. id: this.userInfo.id,
  63. data: e.detail.encryptedData,
  64. iv: e.detail.iv,
  65. sessionKey: uni.getStorageSync('user_xcx_info').session_key,
  66. store_id: this.store_id,
  67. }, "", "", hideLoading).then(res => {
  68. this.phoneNumber = res.data.phoneNumber;
  69. uni.setStorageSync('phone', res.data.phoneNumber);
  70. uni.showModal({
  71. title: '授权成功',
  72. content: '享受更多优惠!',
  73. showCancel: false,
  74. cancelText: '',
  75. confirmText: '确定',
  76. success: res => {
  77. let subscribe = uni.getStorageSync('balance_subscribe');
  78. uni.requestSubscribeMessage({
  79. tmplIds: [subscribe.member_tid],
  80. success: (r) => {},
  81. complete: (r) => {
  82. var pages = getCurrentPages();
  83. this.$http.request('xcx/userinfo', {
  84. id: this.userInfo.id,
  85. }, "", "", hideLoading).then(res => {
  86. if (res.code == "200") {
  87. this.$store.commit('SET_USER_INFO',
  88. res.data)
  89. if (pages[pages.length-1].route ==
  90. "pages/creatOrder/creatOrder"
  91. ) {
  92. uni.redirectTo({
  93. url: '/pages/creatOrder/creatOrder'
  94. })
  95. }
  96. }
  97. }).catch((res) => {
  98. uni.showToast({
  99. title: res.message,
  100. icon: 'none'
  101. })
  102. });
  103. }
  104. })
  105. },
  106. fail: () => {},
  107. complete: () => {}
  108. });
  109. })
  110. } else {
  111. uni.showToast({
  112. title: "授权失败,请重新授权",
  113. icon: 'none'
  114. })
  115. }
  116. // #endif
  117. },
  118. // 子组件传参
  119. setClose(e) {
  120. this.getPhonePop = e;
  121. },
  122. // 开启会员弹窗
  123. onGetphone(e) {
  124. if (this.userInfo.mobile) {
  125. uni.showToast({
  126. title: "您已经完善过会员信息了,无需重复操作!",
  127. icon: 'none'
  128. })
  129. return
  130. }
  131. this.getPhonePop = true;
  132. },
  133. }
  134. }
  135. </script>
  136. <style>
  137. </style>