Commit 5b55955a by 张立顺

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

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