微信小店联盟带货小程序

index.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. // pages/user/index.js
  2. const app = getApp()
  3. import { checkNeedLogin, doLogin, getLoginInfo, checkNeedBindInstitution } from '../../utils/login'
  4. import { request } from '../../utils/request'
  5. Page({
  6. data: {
  7. userInfo: null,
  8. isLogin: false,
  9. needBind: false,
  10. earnings: {
  11. today: '0.00',
  12. month: '0.00',
  13. total: '0.00'
  14. }
  15. },
  16. onLoad() {
  17. this.checkLoginStatus()
  18. this.getEarnings()
  19. },
  20. onShow() {
  21. this.checkLoginStatus()
  22. this.getEarnings()
  23. },
  24. // 检查登录状态
  25. async checkLoginStatus() {
  26. console.log('检查登录状态')
  27. if (checkNeedLogin()) {
  28. try {
  29. await doLogin()
  30. this.setData({ isLogin: true })
  31. this.getUserInfo()
  32. } catch (err) {
  33. console.error('登录失败:', err)
  34. this.setData({ isLogin: false })
  35. }
  36. } else {
  37. this.setData({ isLogin: true })
  38. this.getUserInfo()
  39. }
  40. // 检查是否需要绑定机构
  41. const bindStatus = wx.getStorageSync('bindStatus')
  42. console.log('当前bindStatus:', bindStatus)
  43. const needBind = checkNeedBindInstitution()
  44. console.log('是否需要绑定机构:', needBind)
  45. this.setData({ needBind })
  46. },
  47. // 获取用户信息
  48. async getUserInfo() {
  49. try {
  50. const userInfo = wx.getStorageSync('userInfo')
  51. console.log('当前userInfo:', userInfo)
  52. this.setData({ userInfo })
  53. } catch (err) {
  54. console.error('获取用户信息失败:', err)
  55. }
  56. },
  57. // 绑定机构
  58. bindInstitution() {
  59. if (!this.data.isLogin) {
  60. wx.showToast({
  61. title: '请先登录',
  62. icon: 'none'
  63. })
  64. return
  65. }
  66. const userInfo = wx.getStorageSync('userInfo')
  67. const businessType = userInfo.bind_business_type
  68. const queryString = userInfo.bind_query_string
  69. const commissionType = userInfo.commission_type
  70. const commissionRatio = userInfo.commission_ratio
  71. const headSupplierAppid = userInfo.head_supplier_appid
  72. wx.openBusinessView({
  73. businessType: businessType,
  74. queryString: queryString,
  75. extraData: {
  76. commissionType: commissionType,
  77. commissionRatio: commissionRatio,
  78. headSupplierAppid: headSupplierAppid
  79. },
  80. success: (res) => {
  81. console.log('绑定机构成功', res)
  82. wx.setStorageSync('bindStatus', 1)
  83. this.setData({ needBind: false })
  84. // 重新获取用户信息
  85. this.getUserInfo()
  86. },
  87. fail: (err) => {
  88. console.error('绑定机构失败', err)
  89. wx.showToast({
  90. title: '绑定失败',
  91. icon: 'none'
  92. })
  93. }
  94. })
  95. },
  96. // 获取收益信息
  97. async getEarnings() {
  98. if (!this.data.isLogin) return
  99. try {
  100. // const res = await request({
  101. // url: '/api/promoter/earnings',
  102. // method: 'GET'
  103. // })
  104. this.setData({
  105. // earnings: res.data || {
  106. earnings: {
  107. today: '0.00',
  108. month: '0.00',
  109. total: '0.00'
  110. }
  111. })
  112. } catch (error) {
  113. console.error('获取收益信息失败:', error)
  114. }
  115. },
  116. // 导航到分销中心
  117. navigateToDistribution() {
  118. wx.navigateTo({
  119. url: '/pages/distribution/index'
  120. })
  121. },
  122. // 导航到推广订单
  123. navigateToOrder() {
  124. wx.navigateTo({
  125. url: '/pages/order/list'
  126. })
  127. },
  128. // 导航到我的团队
  129. navigateToTeam() {
  130. wx.navigateTo({
  131. url: '/pages/team/index'
  132. })
  133. },
  134. // 导航到提现管理
  135. navigateToWithdraw() {
  136. wx.navigateTo({
  137. url: '/pages/income/withdraw'
  138. })
  139. },
  140. // 导航到收款账户
  141. navigateToBank() {
  142. wx.navigateTo({
  143. url: '/pages/bank/list'
  144. })
  145. },
  146. // 导航到邀请好友
  147. navigateToInvite() {
  148. wx.navigateTo({
  149. url: '/pages/invite/index'
  150. })
  151. },
  152. // 导航到推广海报
  153. navigateToPromotion() {
  154. wx.navigateTo({
  155. url: '/pages/promotion/poster'
  156. })
  157. },
  158. // 导航到推广二维码
  159. navigateToQrcode() {
  160. wx.navigateTo({
  161. url: '/pages/promotion/qrcode'
  162. })
  163. },
  164. // 导航到收益明细
  165. navigateToIncome() {
  166. wx.navigateTo({
  167. url: '/pages/income/index'
  168. })
  169. },
  170. // 联系客服
  171. contactService() {
  172. // 可以使用微信自带的客服功能
  173. wx.openCustomerServiceChat({
  174. extInfo: { url: '' }, // 客服页面路径
  175. corpId: '', // 企业ID
  176. success(res) {
  177. console.log('打开客服会话成功')
  178. },
  179. fail(err) {
  180. wx.showToast({
  181. title: '打开客服会话失败',
  182. icon: 'none'
  183. })
  184. }
  185. })
  186. },
  187. // 导航到系统设置
  188. navigateToSettings() {
  189. wx.navigateTo({
  190. url: '/pages/settings/index'
  191. })
  192. },
  193. })