u-authorized-iphone.vue 5.1 KB

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