app-user-phone.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <view class='phone-modal main-center cross-center' :class="showPhone"
  3. v-if="_app_config.mall.setting.is_mobile_auth == 1">
  4. <view class='phone-modal-content'>
  5. <view class='phone-modal-header t-large'>授权获取手机号</view>
  6. <view class='phone-modal-body dir-top-nowrap cross-center'>
  7. <image :src="img" class="img"></image>
  8. <view class='main-center text'>申请获取您绑定的手机号</view>
  9. <view class='main-center'>
  10. <view>
  11. <!-- #ifndef MP-ALIPAY -->
  12. <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="btn new-modal-btn"
  13. hover-class="none">确认
  14. </button>
  15. <!-- #endif -->
  16. <!-- #ifdef MP-ALIPAY -->
  17. <button open-type="getAuthorize"
  18. class="btn new-modal-btn"
  19. @getAuthorize="onGetAuthorize"
  20. scope='phoneNumber'
  21. >点击授权</button>
  22. <!-- #endif -->
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import {mapState} from "vuex";
  31. export default {
  32. name: "app-user-phone",
  33. computed: {
  34. ...mapState({
  35. _app_config: state => state.mallConfig,
  36. }),
  37. showPhone() {
  38. let userInfo = this.$store.state.user.info;
  39. let showClass = '';
  40. // #ifndef MP_BAIDU
  41. if (userInfo && userInfo.mobile == '') {
  42. showClass = 'showPhone';
  43. }
  44. // #endif
  45. return showClass;
  46. },
  47. img() {
  48. let img = '';
  49. if (this.$platform == 'wxapp') {
  50. img = this._app_config.__wxapp_img.mall.icon_wechat;
  51. } else if (this.$platform == 'aliapp') {
  52. img = this._app_config.__wxapp_img.mall.icon_alipay;
  53. } else if (this.$platform == 'ttapp') {
  54. img = this._app_config.__wxapp_img.mall.icon_ttapp;
  55. }
  56. return img;
  57. }
  58. },
  59. data() {
  60. return {
  61. code: null,
  62. };
  63. },
  64. created() {
  65. // #ifndef MP-ALIPAY
  66. let _this= this;
  67. uni.login({
  68. scopes: 'auth_base',
  69. success(res) {
  70. if (res.errMsg === 'login:ok') {
  71. _this.code = res.code;
  72. }
  73. }
  74. })
  75. // #endif
  76. },
  77. methods: {
  78. // #ifndef MP-ALIPAY
  79. getPhoneNumber(e) {
  80. if (e.detail.errMsg === 'getPhoneNumber:fail user deny') return;
  81. let _this = this;
  82. _this.$request({
  83. method: 'post',
  84. url: _this.$api.phone.binding,
  85. data: {
  86. encryptedData: e.detail.encryptedData,
  87. iv: e.detail.iv,
  88. code: _this.code,
  89. }
  90. }).then(() => {
  91. _this.$store.dispatch('user/refreshInfo');
  92. })
  93. },
  94. // #endif
  95. // #ifdef MP-ALIPAY
  96. onGetAuthorize() {
  97. let _this = this;
  98. my.getPhoneNumber({
  99. success: (res) => {
  100. this.$request({
  101. method: 'post',
  102. url: _this.$api.phone.binding,
  103. data: {
  104. data: JSON.parse(res.response).response,
  105. }
  106. }).then(() => {
  107. _this.$store.dispatch('user/refreshInfo');
  108. });
  109. },
  110. fail: () => {
  111. }
  112. });
  113. },
  114. // #endif
  115. }
  116. }
  117. </script>
  118. <style scoped lang="scss">
  119. .phone-modal {
  120. width: 100%;
  121. height: 100%;
  122. position: fixed;
  123. left: 0;
  124. top: 0;
  125. background-color: rgba(0, 0, 0, 0.5);
  126. z-index: 1601;
  127. visibility: hidden;
  128. .phone-modal-content {
  129. width: #{630rpx};
  130. height: auto;
  131. background-color: #ffffff;
  132. border-radius: #{16rpx};
  133. position: relative;
  134. }
  135. .phone-modal-header {
  136. text-align: center;
  137. padding: #{30rpx 0};
  138. line-height: #{60rpx};
  139. border-bottom: #{1rpx} solid #eeeefee;
  140. }
  141. .phone-modal-body {
  142. padding: #{0 24rpx};
  143. color: #666666;
  144. max-height: #{700rpx};
  145. overflow-y: auto;
  146. min-height: 0;
  147. margin-bottom: 0;
  148. .img {
  149. width: #{88rpx};
  150. height: #{88rpx};
  151. text-align: center;
  152. margin: #{32rpx 0 40rpx};
  153. }
  154. .text {
  155. margin-bottom: #{40rpx};
  156. font-size: $uni-font-size-general-two;
  157. }
  158. }
  159. &.showPhone {
  160. visibility: visible;
  161. }
  162. .new-modal-btn {
  163. background-color: #04be01;
  164. width: #{500rpx};
  165. height: #{80rpx};
  166. border-radius: #{80rpx};
  167. color: #ffffff;
  168. margin-bottom: #{40rpx};
  169. padding: 0;
  170. box-sizing: border-box;
  171. border: none;
  172. }
  173. }
  174. </style>