invite.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view>
  3. <view style="margin: 0 0 30rpx 0;">
  4. <img :src="info.share_img" alt="" style="width: 100%;">
  5. </view>
  6. <view class="in_box">
  7. <view class="in_text">我的邀请码</view>
  8. <input class="in_input" type="number" disabled="true" v-model="info.code" @click="copy">
  9. </view>
  10. <view class="in_box" v-if="info.state == 1">
  11. <view class="in_text">我的邀请人</view>
  12. <input class="in_input" type="text" disabled="true" v-model="info.invite" >
  13. </view>
  14. <view class="in_box" v-else>
  15. <view class="in_text">输入邀请码</view>
  16. <input class="in_input" type="number" v-model='user_id' style="width: 46%;">
  17. <button style="height: 65rpx;line-height: 65rpx;font-size: 30rpx; margin: 0 0 0 18rpx;
  18. background-color: #4CAF50;
  19. color: #fff;" @click="bind">绑定</button>
  20. </view>
  21. <view class="in_info">
  22. <view style="margin: 20rpx 0;">活动规则: </view>
  23. <view>1. 邀请人成功邀请到用户后会赠送课程优惠券</view>
  24. <view>2. 被邀请用户可以免费获得体验会员</view>
  25. <view>3. 每位用户限定绑定一次</view>
  26. <view>4. 用户之间无法互相绑定</view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. info: {},
  35. user_id: '',
  36. }
  37. },
  38. onLoad() {
  39. if (uni.getStorageSync('id')) {
  40. this.getInfo();
  41. this.show = true;
  42. } else {
  43. // #ifdef MP
  44. this.mpLogin()
  45. return
  46. uni.showToast({
  47. title: '请先登录'
  48. })
  49. // #endif
  50. }
  51. },
  52. methods: {
  53. copy() {
  54. uni.setClipboardData({
  55. data: this.info.code,
  56. success: function() {
  57. uni.showToast({
  58. title: '复制成功',
  59. icon: 'none',
  60. })
  61. }
  62. });
  63. },
  64. bind() {
  65. let user_id = uni.getStorageSync('id');
  66. let invite_id = this.user_id.substring(4);
  67. if (!invite_id) {
  68. uni.showToast({
  69. title: '请输入邀请码',
  70. icon: 'none',
  71. })
  72. return false;
  73. }
  74. if (user_id == invite_id) {
  75. uni.showToast({
  76. title: '无法绑定自己',
  77. icon: 'none',
  78. })
  79. return false;
  80. }
  81. uni.showModal({
  82. title: '提示',
  83. content: '每个账号只能绑定一个邀请人, 您确定绑定么',
  84. success: (res) => {
  85. this.$post({
  86. data: {
  87. do: 'UserInvite',
  88. data: {
  89. invite_id: invite_id,
  90. user_id: user_id,
  91. }
  92. }
  93. }).then(res => {
  94. if(res.data.status != 1){
  95. uni.showToast({
  96. title: '绑定失败',
  97. icon: 'none',
  98. })
  99. return false;
  100. }else{
  101. uni.showToast({
  102. title: '绑定成功',
  103. icon: 'none',
  104. })
  105. this.$post({
  106. data: {
  107. do: 'Vip',
  108. data: {
  109. user_id: user_id,
  110. }
  111. }
  112. }).then(res3 => {
  113. if(res3.data.is_vip == 1){
  114. uni.setStorageSync('is_vip',1);
  115. }
  116. }).catch(err => {})
  117. this.getInfo();
  118. return false;
  119. }
  120. }).catch(err => {})
  121. }
  122. })
  123. },
  124. getInfo() {
  125. let that = this;
  126. let user_id = uni.getStorageSync('id');
  127. this.$post({
  128. data: {
  129. do: 'GetShareInfo',
  130. data: {
  131. user_id: user_id,
  132. }
  133. }
  134. }).then(res => {
  135. that.info = res.data
  136. })
  137. },
  138. // 小程序登录
  139. mpLogin() {
  140. let that = this;
  141. uni.login({
  142. provider: 'weixin',
  143. success: (res) => {
  144. console.log(res, 'rrrrrr')
  145. const code = res.code
  146. this.$post({
  147. data: {
  148. do: 'Login',
  149. data: {
  150. code
  151. }
  152. }
  153. }).then(res => {
  154. this.logininfo = res.data
  155. uni.showModal({
  156. title: '提示',
  157. content: '是否进行头像和昵称授权',
  158. success: (res) => {
  159. if (res.confirm) {
  160. this.getnickImage()
  161. }
  162. }
  163. })
  164. })
  165. }
  166. })
  167. },
  168. getnickImage() {
  169. console.log(this.logininfo.id)
  170. uni.getUserProfile({
  171. desc: '用于昵称和头像的展示',
  172. success: res => {
  173. console.log(res, '++++')
  174. console.log({
  175. user_id: this.logininfo.id,
  176. nickName: res.userInfo.nickName,
  177. avatarUrl: res.userInfo.avatarUrl
  178. })
  179. this.$post({
  180. data: {
  181. do: 'UpdateUser',
  182. data: {
  183. user_id: this.logininfo.id,
  184. nickName: res.userInfo.nickName,
  185. avatarUrl: res.userInfo.avatarUrl
  186. }
  187. }
  188. }).then(res => {
  189. for (let i in this.logininfo) {
  190. uni.setStorageSync(i, this.logininfo[i])
  191. }
  192. this.type == 0;
  193. this.getInfo();
  194. })
  195. // this.nickName = res.userInfo.nickName
  196. // this.avatarUrl = res.userInfo.avatarUrl
  197. // this.country = res.userInfo.country
  198. // this.province = res.userInfo.province
  199. // this.city = res.userInfo.city
  200. // this.gender = res.userInfo.gender
  201. // uni.login({
  202. // provider: 'weixin',
  203. // success: (res) => {
  204. // this.loginCode = res.code
  205. // uni.hideLoading()
  206. // this.popShow = true
  207. // },
  208. // })
  209. },
  210. fail: (err) => {
  211. uni.hideLoading()
  212. }
  213. })
  214. },
  215. }
  216. }
  217. </script>
  218. <style>
  219. .in_input {
  220. margin: 0 0 0 30rpx;
  221. background-color: #f1f1f1;
  222. height: 65rpx;
  223. border-radius: 10rpx;
  224. width: 64%;
  225. padding: 0 15rpx;
  226. }
  227. .in_text {
  228. margin: 0 0 0 29rpx;
  229. }
  230. .in_box {
  231. display: flex;
  232. height: 85rpx;
  233. align-items: center;
  234. }
  235. .in_info{
  236. margin: 20rpx;
  237. padding: 10rpx;
  238. border-radius: 20rpx;
  239. background-color: #fff;
  240. }
  241. </style>