app-bind-info.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view>
  3. <tui-list-cell class="line-cell" :hover="false">
  4. <div class="tui-title required" style="width:120upx;">{{nameTetx}}</div>
  5. <view
  6. v-if="!$util.isEmpty(form.name)"
  7. style="width:400upx;padding-left: 90upx">{{form.name}}
  8. </view>
  9. <view
  10. v-else
  11. class="plart-tit"
  12. style="width:400upx; text-align:center;">
  13. 请点击右边按钮
  14. </view>
  15. <button
  16. class="admin-button-com blue mini-btn"
  17. @click="getWxAvatar"
  18. >帮我填</button>
  19. </tui-list-cell>
  20. <tui-list-cell class="line-cell" :hover="false">
  21. <div class="tui-title required" style="width:120upx;">手机号</div>
  22. <view
  23. v-if="!$util.isEmpty(form.mobile)"
  24. style="width:400upx;padding-left: 90upx">{{form.mobile}}</view>
  25. <view
  26. v-else
  27. class="plart-tit"
  28. style="width:400upx; text-align:center;">
  29. 请点击右边按钮
  30. </view>
  31. <button
  32. class="admin-button-com blue mini-btn"
  33. open-type="getPhoneNumber"
  34. @getphonenumber="getWxMobile"
  35. >帮我填</button>
  36. </tui-list-cell>
  37. </view>
  38. </template>
  39. <script>
  40. import TuiListCell from "@/components/plugin/list-cell";
  41. import { getWxInfo, getWxPhone } from "@/api/mini";
  42. export default {
  43. name:'AppBindInfo',
  44. props:{
  45. nameTetx:{
  46. type:String,
  47. default:'昵称'
  48. }
  49. },
  50. components:{
  51. TuiListCell
  52. },
  53. data(){
  54. return {
  55. form: {
  56. name: '',
  57. mobile: ''
  58. }
  59. }
  60. },
  61. methods:{
  62. // 获取微信信息
  63. getWxAvatar() {
  64. // uni.getUserInfo({
  65. // provider: "weixin",
  66. // success: res => {
  67. // },
  68. // fail: () => {
  69. // // this.loading = false
  70. // }
  71. // });
  72. uni.getUserProfile({
  73. desc:'登录',
  74. success:(res)=>{
  75. getWxInfo({ iv: res.iv, encryptedData: res.encryptedData }).then(
  76. subRes => {
  77. this.form.name = subRes.data.name
  78. this.$emit('bindInfo',this.form)
  79. uni.showToast({
  80. icon: "success"
  81. });
  82. }
  83. );
  84. },
  85. fail:(res)=>{
  86. }
  87. });
  88. },
  89. // 获取微信手机号
  90. getWxMobile(e) {
  91. if (e.detail.errMsg === "getPhoneNumber:ok") {
  92. getWxPhone({
  93. iv: e.detail.iv,
  94. encryptedData: e.detail.encryptedData
  95. }).then(res => {
  96. this.form.mobile = res.data.mobile;
  97. this.$emit('bindInfo',this.form)
  98. uni.showToast({
  99. icon: "success"
  100. });
  101. });
  102. } else {
  103. this.$msg("获取信息失败!");
  104. }
  105. },
  106. }
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. .plart-tit {
  111. color: #CCCCCC;
  112. font-size: 28upx;
  113. font-weight: 400;
  114. }
  115. .tui-title {
  116. color: #666666;
  117. font-size: 28upx;
  118. font-weight: 400;
  119. }
  120. </style>