123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- // pages/user/index.js
- const app = getApp()
- import { checkNeedLogin, doLogin, getLoginInfo, checkNeedBindInstitution } from '../../utils/login'
- import { request } from '../../utils/request'
- Page({
- data: {
- userInfo: null,
- isLogin: false,
- needBind: false,
- earnings: {
- today: '0.00',
- month: '0.00',
- total: '0.00'
- }
- },
- onLoad() {
- this.checkLoginStatus()
- this.getEarnings()
- },
- onShow() {
- this.checkLoginStatus()
- this.getEarnings()
- },
- // 检查登录状态
- async checkLoginStatus() {
- console.log('检查登录状态')
- if (checkNeedLogin()) {
- try {
- await doLogin()
- this.setData({ isLogin: true })
- this.getUserInfo()
- } catch (err) {
- console.error('登录失败:', err)
- this.setData({ isLogin: false })
- }
- } else {
- this.setData({ isLogin: true })
- this.getUserInfo()
- }
- // 检查是否需要绑定机构
- const bindStatus = wx.getStorageSync('bindStatus')
- console.log('当前bindStatus:', bindStatus)
- const needBind = checkNeedBindInstitution()
- console.log('是否需要绑定机构:', needBind)
- this.setData({ needBind })
- },
- // 获取用户信息
- async getUserInfo() {
- try {
- const userInfo = wx.getStorageSync('userInfo')
- console.log('当前userInfo:', userInfo)
- this.setData({ userInfo })
- } catch (err) {
- console.error('获取用户信息失败:', err)
- }
- },
- // 绑定机构
- bindInstitution() {
- if (!this.data.isLogin) {
- wx.showToast({
- title: '请先登录',
- icon: 'none'
- })
- return
- }
- const userInfo = wx.getStorageSync('userInfo')
- const businessType = userInfo.bind_business_type
- const queryString = userInfo.bind_query_string
- const commissionType = userInfo.commission_type
- const commissionRatio = userInfo.commission_ratio
- const headSupplierAppid = userInfo.head_supplier_appid
- wx.openBusinessView({
- businessType: businessType,
- queryString: queryString,
- extraData: {
- commissionType: commissionType,
- commissionRatio: commissionRatio,
- headSupplierAppid: headSupplierAppid
- },
- success: (res) => {
- console.log('绑定机构成功', res)
- wx.setStorageSync('bindStatus', 1)
- this.setData({ needBind: false })
- // 重新获取用户信息
- this.getUserInfo()
- },
- fail: (err) => {
- console.error('绑定机构失败', err)
- wx.showToast({
- title: '绑定失败',
- icon: 'none'
- })
- }
- })
- },
- // 获取收益信息
- async getEarnings() {
- if (!this.data.isLogin) return
-
- try {
- // const res = await request({
- // url: '/api/promoter/earnings',
- // method: 'GET'
- // })
- this.setData({
- // earnings: res.data || {
- earnings: {
- today: '0.00',
- month: '0.00',
- total: '0.00'
- }
- })
- } catch (error) {
- console.error('获取收益信息失败:', error)
- }
- },
- // 导航到分销中心
- navigateToDistribution() {
- wx.navigateTo({
- url: '/pages/distribution/index'
- })
- },
- // 导航到推广订单
- navigateToOrder() {
- wx.navigateTo({
- url: '/pages/order/list'
- })
- },
- // 导航到我的团队
- navigateToTeam() {
- wx.navigateTo({
- url: '/pages/team/index'
- })
- },
- // 导航到提现管理
- navigateToWithdraw() {
- wx.navigateTo({
- url: '/pages/income/withdraw'
- })
- },
- // 导航到收款账户
- navigateToBank() {
- wx.navigateTo({
- url: '/pages/bank/list'
- })
- },
- // 导航到邀请好友
- navigateToInvite() {
- wx.navigateTo({
- url: '/pages/invite/index'
- })
- },
- // 导航到推广海报
- navigateToPromotion() {
- wx.navigateTo({
- url: '/pages/promotion/poster'
- })
- },
- // 导航到推广二维码
- navigateToQrcode() {
- wx.navigateTo({
- url: '/pages/promotion/qrcode'
- })
- },
- // 导航到收益明细
- navigateToIncome() {
- wx.navigateTo({
- url: '/pages/income/index'
- })
- },
- // 联系客服
- contactService() {
- // 可以使用微信自带的客服功能
- wx.openCustomerServiceChat({
- extInfo: { url: '' }, // 客服页面路径
- corpId: '', // 企业ID
- success(res) {
- console.log('打开客服会话成功')
- },
- fail(err) {
- wx.showToast({
- title: '打开客服会话失败',
- icon: 'none'
- })
- }
- })
- },
- // 导航到系统设置
- navigateToSettings() {
- wx.navigateTo({
- url: '/pages/settings/index'
- })
- },
- })
|