金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
4.0 KiB

  1. <template>
  2. <view id="phone">
  3. <view class="phone__warning">
  4. <i class="iconfont icon-anquanjinggao"></i>
  5. </view>
  6. <view class="phone__text">
  7. 为确保您账户的安全及正常使用网络安全法相关要求6月1日起会员账户需绑定手机如您还未绑定请尽快完成感谢您的理解及支持
  8. </view>
  9. <!-- #ifdef MP-WEIXIN -->
  10. <button class="wechat-phoneBtn phone__btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  11. <i class="iconfont icon-hudong"></i>
  12. <view class="btn__text">使用注册微信手机号码</view>
  13. </button>
  14. <!-- #endif -->
  15. <view class="again-phoneBtn phone__btn" @tap="jumpPhone">
  16. <i class="iconfont icon-hudong"></i>
  17. <view class="btn__text">绑定新手机号码</view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  23. export default {
  24. data() {
  25. return {
  26. code: '',
  27. url: ''
  28. };
  29. },
  30. onLoad(e) {
  31. if (e.url) {
  32. this.setData({
  33. url: e.url
  34. });
  35. }
  36. },
  37. components: {},
  38. props: {},
  39. methods: {
  40. getCode() {},
  41. jumpPhone() {
  42. if (this.url) {
  43. wx.navigateTo({
  44. url: '/pages/user/bindingphone/bindingphone?url=' + this.url
  45. });
  46. } else {
  47. wx.navigateTo({
  48. url: '/pages/user/bindingphone/bindingphone'
  49. });
  50. }
  51. },
  52. getPhoneNumber(e) {
  53. if (e.detail.encryptedData) {
  54. wx.login({
  55. success: res => {
  56. if (res.code) {
  57. this.setData({
  58. code: res.code
  59. }, res => {
  60. this.phone(e);
  61. });
  62. } else {
  63. wx.showModal({
  64. content: " 获取code失败",
  65. showCancel: false
  66. });
  67. }
  68. }
  69. });
  70. console.log(this.code);
  71. return;
  72. } else {
  73. this.jumpPhone();
  74. }
  75. },
  76. phone(e) {
  77. this.$http.post({
  78. api: 'api/users/MiniProgramBindMobile',
  79. data: {
  80. code: this.code,
  81. encryptedData: e.detail.encryptedData,
  82. iv: e.detail.iv
  83. },
  84. header: {
  85. Authorization: this.$cookieStorage.get('user_token')
  86. }
  87. }).then(res => {
  88. if (res.statusCode == 200) {
  89. res = res.data;
  90. if (res.status) {
  91. wx.showModal({
  92. content: '绑定成功',
  93. showCancel: false,
  94. success: res => {
  95. if (res.confirm || !res.cancel && !res.confirm) {
  96. if (this.url) {
  97. wx.redirectTo({
  98. url: '/' + decodeURIComponent(this.url)
  99. });
  100. } else {
  101. wx.switchTab({
  102. url: '/pages/user/personal/personal'
  103. });
  104. }
  105. }
  106. }
  107. });
  108. } else {
  109. wx.showModal({
  110. content: res.message || '绑定失败',
  111. showCancel: false
  112. });
  113. }
  114. } else {
  115. wx.showModal({
  116. content: '请求失败,请重试',
  117. showCancel: false
  118. });
  119. }
  120. }).catch(rej => {
  121. wx.showModal({
  122. content: '请求失败,请重试',
  123. showCancel: false
  124. });
  125. });
  126. },
  127. setData: function (obj) {
  128. let that = this;
  129. let keys = [];
  130. let val, data;
  131. Object.keys(obj).forEach(function (key) {
  132. keys = key.split('.');
  133. val = obj[key];
  134. data = that.$data;
  135. keys.forEach(function (key2, index) {
  136. if (index + 1 == keys.length) {
  137. that.$set(data, key2, val);
  138. } else {
  139. if (!data[key2]) {
  140. that.$set(data, key2, {});
  141. }
  142. }
  143. data = data[key2];
  144. });
  145. });
  146. }
  147. },
  148. computed: {},
  149. watch: {}
  150. };
  151. </script>
  152. <style rel="stylesheet/less" lang="less">
  153. @import "phone";
  154. </style>