<script lang="ts" setup>
import { useCache } from '@/hooks/web/useCache'
import { useUserStoreWithOut } from '@/store/modules/user'
import { ShopApi } from '@/api/system/sale/shop'
defineOptions({ name: 'ScreenFull' })
// const userId = useUserStore().getUser.id // 当前登录的编号
let userStore = useUserStoreWithOut()
let shopCurrent = ref(0)
let shopList = ref({})
let { wsCache } = useCache()
let getShopCurrent = async () => {
  let CurrentShop = await ShopApi.getCurrentShop()
	shopCurrent.value = CurrentShop.shopId
	// 把商户id存入缓存
	wsCache.set('merId', CurrentShop.merId)
	wsCache.set('shopId', CurrentShop.shopId)
	userStore.setUserMerId()
}
let getShopList = async () => {
	shopList.value = await ShopApi.getAllShopByUserId()
}
// 店铺切换
const selectChange = async (val: any) => {
	wsCache.set('shopId', val)
	await ShopApi.ChangeShop(val)
}
//页面加载完毕查询当前用户的店铺和店铺列表
onMounted(async() => {
	
	await getShopCurrent()
	await getShopList()
})
</script>

<template>
	<el-select v-model="shopCurrent" placeholder="店铺" @change="selectChange">
		<el-option v-for="item in shopList" :key="item.id" :label="item.name" :value="item.id" />
	</el-select>

</template>