切换公司逻辑完善
This commit is contained in:
@@ -2,14 +2,14 @@
|
||||
<view class='u-flex-column'>
|
||||
<swiper class='swiper' :indicator-dots='true' :autoplay='true' :interval='3000' :duration='1000'
|
||||
@change='swiperChange'>
|
||||
<swiper-item v-for='(item, index) in bannerList' :key='index'>
|
||||
<image :src='item' mode='aspectFill' />
|
||||
<swiper-item v-for='(item, index) in companyConfigInfo?.bannerinx' :key='index'>
|
||||
<image :src='item.src' mode='aspectFill' />
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
|
||||
<view class='basic-view'>
|
||||
<view class='indicator-view'>
|
||||
<view v-for='(item,index) in bannerList' :key='item' class='normal'
|
||||
<view v-for='(item,index) in companyConfigInfo?.bannerinx' :key='item' class='normal'
|
||||
:class="{'active': index === currentBannerIndex}">
|
||||
</view>
|
||||
</view>
|
||||
@@ -26,6 +26,10 @@
|
||||
<text class='accent-text-color'>{{ userInfo?.balance || 0 }}</text>
|
||||
<text>余额(元)</text>
|
||||
</view>
|
||||
<view class='divider' style='height: 83rpx' />
|
||||
<view class='switch-view' @click.stop='switchCompany'>
|
||||
<image :src='assetsUrl("ic_switch_company.png")' />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class='menu-view'>
|
||||
@@ -53,8 +57,8 @@
|
||||
|
||||
<view class='bottom-banner-view'>
|
||||
<swiper :indicator-dots='true' :autoplay='true' :interval='3000' :duration='1000'>
|
||||
<swiper-item v-for='(item, index) in recommendBannerList' :key='index'>
|
||||
<image :src='item' mode='aspectFill' />
|
||||
<swiper-item v-for='(item, index) in companyConfigInfo.bannerhot' :key='index'>
|
||||
<image :src='item.src' mode='aspectFill' />
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
@@ -63,17 +67,15 @@
|
||||
</template>
|
||||
|
||||
<script setup lang='ts'>
|
||||
import { getCompanyInfo, getCompanyList } from '@/api/company';
|
||||
import { getCompanyList } from '@/api/company';
|
||||
import { useUserStore } from '@/store';
|
||||
import { assetsUrl, defaultAvatar } from '@/utils/assets';
|
||||
import { getCompanyId, goPath, isLogin, setCompanyId } from '@/utils';
|
||||
import { getCompanyId, goPath, isLogin } from '@/utils';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
const userStore = useUserStore();
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
const bannerList = ref<string[]>([]);
|
||||
const { userInfo, companyConfigInfo } = storeToRefs(userStore);
|
||||
const currentBannerIndex = ref(0);
|
||||
const recommendBannerList = ref<string[]>([]);
|
||||
|
||||
const submenuList = [
|
||||
{
|
||||
@@ -99,31 +101,31 @@ onLoad((e) => {
|
||||
|
||||
onShow(async () => {
|
||||
if(isLogin()) {
|
||||
const data = await getCompanyInfo(userInfo.value.companyId);
|
||||
bannerList.value = data.bannerinx?.map((res: { src: string }) => res.src);
|
||||
recommendBannerList.value = data.bannerhot?.map((res: { src: string }) => res.src);
|
||||
|
||||
if(userInfo.value.maOpenId) {
|
||||
getCompanyList(userInfo.value.maOpenId).then(res => {
|
||||
const companyList = res.map((res: { company: any }) => res.company);
|
||||
const userList = res.map((res: { user: any }) => res.user);
|
||||
// if(!getCompanyId()) {
|
||||
uni.showActionSheet({
|
||||
itemList: companyList.map((res: { companyName: string }) => res.companyName),
|
||||
success: (res) => {
|
||||
setCompanyId(companyList[res.tapIndex].id);
|
||||
userStore.setUserInfo(userList[res.tapIndex]);
|
||||
userStore.fetchTerminal();
|
||||
}
|
||||
});
|
||||
// }
|
||||
});
|
||||
if(getCompanyId() === '') {
|
||||
switchCompany();
|
||||
}
|
||||
} else {
|
||||
await userStore.getProfile();
|
||||
}
|
||||
} else {
|
||||
// setToken('42ae187265fb4688804fd294cbcf99f1')
|
||||
}
|
||||
});
|
||||
|
||||
const switchCompany = () => {
|
||||
getCompanyList(userInfo.value.maOpenId).then(res => {
|
||||
const companyList = res.map((res: { company: any }) => res.company);
|
||||
const userList = res.map((res: { user: any }) => res.user);
|
||||
uni.showActionSheet({
|
||||
itemList: companyList.map((res: { companyName: string }) => res.companyName),
|
||||
success: (res) => {
|
||||
userStore.setUserInfo(userList[res.tapIndex]);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const swiperChange = (e: any) => {
|
||||
currentBannerIndex.value = e.detail.current;
|
||||
};
|
||||
@@ -223,6 +225,13 @@ const swiperChange = (e: any) => {
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
.switch-view {
|
||||
image {
|
||||
width: 50rpx;
|
||||
height: 50rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.divider {
|
||||
|
Reference in New Issue
Block a user