Commit 5b55955a by 张立顺

other: 优化顶部切换账号逻辑

1 parent d873f734
......@@ -114,14 +114,76 @@ App({
})
})
},
// 获取园区店信息
getYQInfo(userInfo) {
console.log(userInfo)
// console.log(globalData)
// let merchantRange
console.log(this.globalData)
return new Promise((resolve, reject) => {
// 如果有 直接返回
if (this.globalData.yqdInfo.merchantRange) {
return resolve(this.globalData.yqdInfo)
}
// 判断是否是多账号用户
let subIndex = 0
if (!userInfo.isSuper && userInfo.merchantType && userInfo.userType == 2) {
this.globalData.yqdInfo = {
subIndex,
merchantRange: [{ merchantName: userInfo.merchantName }]
}
// this.setData({
// merchantRange: [{ merchantName: userInfo.merchantName }]
// })
// return
resolve(this.globalData.yqdInfo)
} else {
let all = {
merchantName: '全部'
}
api
.getYQList()
.then(res => {
console.log(res)
let { code, data } = res
if (code == 0) {
let arr = []
if (data.length > 1) {
if (userInfo.merchantId != userInfo.subLoginUser.merchantId) {
data.map((e, index) => {
if (e.merchantId == userInfo.subLoginUser.merchantId) subIndex = index + 1
})
}
arr = [all, ...data]
} else {
arr = [
{
merchantName: userInfo.merchantName
}
]
}
this.globalData.yqdInfo = {
merchantRange: arr,
subIndex
}
resolve(this.globalData.yqdInfo)
}
})
.catch(error => {
console.log(error)
})
}
})
},
globalData: {
loginUserInfo: {},
// loginUserInfo: {},
systemInfo: {},
// 头部导航栏的高度
statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
bottomLift: 0,
yqdInfo: {
refresh: false
}
yqdInfo: {}
// refresh: false
}
})
......@@ -64,7 +64,8 @@
"remark-popup": "/components/RemarkPopup/RemarkPopup",
"tab-bar": "/components/TabBar/TabBar",
"order-confirm": "/components/Confirm/Confirm",
"tipsPopup": "components/tipsPopup/Popup"
"tipsPopup": "components/tipsPopup/Popup",
"account-switch": "components/accountSwitch/accountSwitch"
},
"sitemapLocation": "sitemap.json",
"permission": {
......
// components/accountSwitch.js
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
},
/**
* 组件的方法列表
*/
methods: {
}
})
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
<!--components/accountSwitch.wxml-->
<text>components/accountSwitch.wxml</text>
/* components/accountSwitch.wxss */
\ No newline at end of file
......@@ -61,6 +61,7 @@ class Router {
if (!thisPage.data.firstOpen) {
thisPage.setData({
firstOpen: true,
// 插入用户信息
userInfo
})
if (thisPage.init) thisPage.init(userInfo)
......
// tabIndex/pages/index/index.js
import mixins from './index_mixins'
import api from '../../api.js'
// const app = getApp()
const app = getApp()
Page({
/**
* 页面的初始数据
......@@ -83,6 +83,8 @@ Page({
changePicker(e) {
let { value } = e.detail
let { merchantId } = this.data.merchantRange[value]
// 修改对应下标显示
app.globalData.yqdInfo.subIndex = value
let obj = {}
if (merchantId) obj.merchantId = merchantId
wx.$util.showLoading('加载中...')
......@@ -235,51 +237,62 @@ Page({
})
},
init(userInfo) {
// console.log(!userInfo.isSuper && userInfo.merchantType && userInfo.userType == 2)
if (!userInfo.isSuper && userInfo.merchantType && userInfo.userType == 2) {
this.setData({
merchantRange: [
{
merchantName: userInfo.merchantName
}
// 测试用 后面要取消
// {
// merchantName: '全部'
// }
]
})
return
}
let all = {
merchantName: '全部'
}
api.getYQList().then(res => {
console.log(res)
let { code, data } = res
if (code == 0) {
let subIndex = 0
let arr = []
if (data.length > 1) {
if (userInfo.merchantId != userInfo.subLoginUser.merchantId) {
data.map((e, index) => {
if (e.merchantId == userInfo.subLoginUser.merchantId) subIndex = index + 1
})
}
arr = [all, ...data]
} else {
arr = [
{
merchantName: userInfo.merchantName
}
]
}
app
.getYQInfo(userInfo)
.then(result => {
console.log(result)
this.setData({
merchantRange: arr,
subIndex
...result
})
}
})
})
.catch(err => {})
// console.log(!userInfo.isSuper && userInfo.merchantType && userInfo.userType == 2)
// if (!userInfo.isSuper && userInfo.merchantType && userInfo.userType == 2) {
// this.setData({
// merchantRange: [
// {
// merchantName: userInfo.merchantName
// }
// // 测试用 后面要取消
// // {
// // merchantName: '全部'
// // }
// ]
// })
// return
// }
// let all = {
// merchantName: '全部'
// }
// api.getYQList().then(res => {
// console.log(res)
// let { code, data } = res
// if (code == 0) {
// let subIndex = 0
// let arr = []
// if (data.length > 1) {
// if (userInfo.merchantId != userInfo.subLoginUser.merchantId) {
// data.map((e, index) => {
// if (e.merchantId == userInfo.subLoginUser.merchantId) subIndex = index + 1
// })
// }
// arr = [all, ...data]
// } else {
// arr = [
// {
// merchantName: userInfo.merchantName
// }
// ]
// }
// this.setData({
// merchantRange: arr,
// subIndex
// })
// }
// })
this.getPageData()
},
getPageData() {
......@@ -351,7 +364,8 @@ Page({
let userInfo = wx.$util.getUserInfo()
// console.log(userInfo)
// // console.log(app.globalData)
console.log(app.globalData)
if (userInfo) {
let { userInfo: newUserInfo } = this.data
......@@ -359,9 +373,10 @@ Page({
if (newUserInfo) {
let isChangeLogin = newUserInfo.subLoginUser.merchantId != userInfo.subLoginUser.merchantId
isChangeLogin && this.init(userInfo)
} else {
this.getPageData()
}
// else {
// this.getPageData()
// }
} else {
console.log('首页登录')
getApp().login(true)
......
......@@ -46,6 +46,8 @@ Page({
changePicker(e) {
console.log('changePicker')
let { value } = e.detail
// 修改对应下标显示
app.globalData.yqdInfo.subIndex = value
let { merchantId } = this.data.merchantRange[value]
let obj = {}
if (merchantId) obj.merchantId = merchantId
......@@ -56,8 +58,7 @@ Page({
if (code == 0) {
// debugger
wx.$util.setUserInfo(data)
this.init(data)
this.refresh()
this.refresh(data)
} else {
this.showToast(message)
}
......@@ -65,55 +66,67 @@ Page({
this.tapPicker()
},
init(userInfo) {
// console.log(userInfo)
// debugger
if (!userInfo.isSuper && userInfo.merchantType && userInfo.userType == 2) {
this.setData({
merchantRange: [
{
merchantName: userInfo.merchantName
}
],
subIndex: 0
})
return
}
let all = {
merchantName: '全部'
}
api.getYQList().then(res => {
console.log(res)
wx.hideLoading()
let { code, data } = res
if (code == 0) {
let subIndex = 0
let arr = []
if (data.length > 1) {
if (userInfo.merchantId != userInfo.subLoginUser.merchantId) {
data.map((e, index) => {
if (e.merchantId == userInfo.subLoginUser.merchantId) subIndex = index + 1
})
}
arr = [all, ...data]
} else {
arr = [
{
merchantName: userInfo.merchantName
}
]
}
app
.getYQInfo(userInfo)
.then(result => {
console.log(result)
this.setData({
merchantRange: arr,
subIndex,
canRemark: arr.length == 1
...result,
canRemark: result.merchantRange.length == 1
})
}
})
})
.catch(err => {})
// console.log(userInfo)
// debugger
// if (!userInfo.isSuper && userInfo.merchantType && userInfo.userType == 2) {
// this.setData({
// merchantRange: [
// {
// merchantName: userInfo.merchantName
// }
// ],
// subIndex: 0
// })
// return
// }
// let all = {
// merchantName: '全部'
// }
// api.getYQList().then(res => {
// console.log(res)
// wx.hideLoading()
// let { code, data } = res
// if (code == 0) {
// let subIndex = 0
// let arr = []
// if (data.length > 1) {
// if (userInfo.merchantId != userInfo.subLoginUser.merchantId) {
// data.map((e, index) => {
// if (e.merchantId == userInfo.subLoginUser.merchantId) subIndex = index + 1
// })
// }
// arr = [all, ...data]
// } else {
// arr = [
// {
// merchantName: userInfo.merchantName
// }
// ]
// }
// this.setData({
// merchantRange: arr,
// subIndex,
// canRemark: arr.length == 1
// })
// }
// })
// this.getPageData()
},
refresh() {
console.log('refresh')
refresh(data) {
// console.log('refresh')
this.getOrderNum()
this.init(data)
let { activeTab } = this.data
this.setData({
activeTab: -1
......@@ -221,7 +234,7 @@ Page({
} else {
this.setTimeList(dateObj.nextDay)
}
this.calendar.resetData(type == 'before'?dateObj.beforeDay:dateObj.nextDay)
this.calendar.resetData(type == 'before' ? dateObj.beforeDay : dateObj.nextDay)
},
// 获取选中天数
rangeSelect(e) {
......@@ -326,7 +339,7 @@ Page({
// console.log(newUserInfo)
if (newUserInfo) {
let isChangeLogin = newUserInfo.subLoginUser.merchantId != userInfo.subLoginUser.merchantId
isChangeLogin && this.init(userInfo)
isChangeLogin && this.refresh(userInfo)
}
},
......
......@@ -66,6 +66,8 @@ Page({
let { value } = e.detail
let { merchantId } = this.data.merchantRange[value]
// 修改对应下标显示
app.globalData.yqdInfo.subIndex = value
let obj = {}
if (merchantId) obj.merchantId = merchantId
wx.$util.showLoading('加载中...')
......@@ -104,47 +106,56 @@ Page({
})
},
init(userInfo) {
// return
if (!userInfo.isSuper && userInfo.merchantType && userInfo.userType == 2) {
this.setData({
merchantRange: [
{
merchantName: userInfo.merchantName
}
],
subIndex: 0
})
return
}
let all = {
merchantName: '全部'
}
api.getYQList().then(res => {
console.log(res)
let { code, data } = res
if (code == 0) {
let subIndex = 0
let arr = []
if (data.length > 1) {
if (userInfo.merchantId != userInfo.subLoginUser.merchantId) {
data.map((e, index) => {
if (e.merchantId == userInfo.subLoginUser.merchantId) subIndex = index + 1
})
}
arr = [all, ...data]
} else {
arr = [
{
merchantName: userInfo.merchantName
}
]
}
app
.getYQInfo(userInfo)
.then(result => {
console.log(result)
this.setData({
merchantRange: arr,
subIndex
...result
})
}
})
})
.catch(err => {})
// return
// if (!userInfo.isSuper && userInfo.merchantType && userInfo.userType == 2) {
// this.setData({
// merchantRange: [
// {
// merchantName: userInfo.merchantName
// }
// ],
// subIndex: 0
// })
// return
// }
// let all = {
// merchantName: '全部'
// }
// api.getYQList().then(res => {
// console.log(res)
// let { code, data } = res
// if (code == 0) {
// let subIndex = 0
// let arr = []
// if (data.length > 1) {
// if (userInfo.merchantId != userInfo.subLoginUser.merchantId) {
// data.map((e, index) => {
// if (e.merchantId == userInfo.subLoginUser.merchantId) subIndex = index + 1
// })
// }
// arr = [all, ...data]
// } else {
// arr = [
// {
// merchantName: userInfo.merchantName
// }
// ]
// }
// this.setData({
// merchantRange: arr,
// subIndex
// })
// }
// })
// this.getAccumulateList()
},
// 获取选中天数
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!