| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import { defineStore } from 'pinia'
- import type { apiResData } from '@/api/globals'
- interface SysState {
- opcity: number
- /**
- * 分类顶部激活id
- */
- topNavActive: string
- /**
- * 二级分类激活id
- */
- leftActive: string
- searchList: string[]
- /**
- * 回到顶部
- */
- backTop: boolean
- /**
- * 店铺名称
- */
- SelectShopInfo: Api.xsbShopList
- /**
- * 店铺列表
- */
- xsbShopList: Api.xsbShopList[]
- /**
- * 用户选中我的地址id
- */
- selectAddressId: number | undefined
- /**
- * 是否所有门店都有权限
- */
- allShopHasPermission: boolean
- /**
- * 优惠券到账弹窗是否显示
- */
- couponArrivalPopupVisible: boolean
- /**
- * 是否打开分类页面
- */
- isClassfiyPageOpen: boolean
- }
- export const useSysXsbStore = defineStore('system-xsb', {
- state: (): SysState => ({
- topNavActive: '',
- leftActive: '',
- searchList: [],
- backTop: false,
- SelectShopInfo: { shopId: 0 },
- xsbShopList: [],
- opcity: 0,
- selectAddressId: undefined,
- allShopHasPermission: false,
- couponArrivalPopupVisible: false,
- isClassfiyPageOpen: false,
- }),
- actions: {
- getTabbarItemValue(name: string) {
- if (name === 'xsb-cart') {
- const { getTotalNum } = storeToRefs(useSmqjhCartStore())
- return getTotalNum.value
- }
- },
- async getAllShopList() {
- return new Promise((resolve, reject) => {
- Apis.xsb.shopList({}).then(async (res) => {
- this.xsbShopList = res.data
- const hasPermission = res.data.every(it => !it.isPermiss)
- if (hasPermission) {
- // 所有门店都没有权限
- this.allShopHasPermission = true
- this.SelectShopInfo = { shopId: 0 }
- reject(new Error('所有门店都没有权限'))
- }
- else {
- this.allShopHasPermission = false
- const { Location } = storeToRefs(useAddressStore())
- await this.getnNearestShop(Location.value.latitude || 26.648327, Location.value.longitude || 106.620256)
- resolve(res)
- }
- }).catch((err) => { reject(err) })
- })
- },
- /**
- * 获取最近的门店
- * @param latitude 纬度
- * @param longitude 经度
- * @returns Promise<apiResData<{ nearestShopId: number }>>
- */
- async getnNearestShop(latitude: number, longitude: number): Promise<apiResData<{ nearestShopId: number }>> {
- return new Promise((resolve, reject) => {
- Apis.xsb.nearestShop({ data: { longitude, latitude } }).then((res) => {
- const newShop = this.xsbShopList.find(it => it.shopId === res.data.nearestShopId)
- if (newShop) {
- this.SelectShopInfo = this.SelectShopInfo.shopId ? this.SelectShopInfo : newShop
- }
- resolve(res)
- }).catch((err) => { reject(err) })
- })
- },
- },
- })
|