<template>
  <view class="content-box">
    <uv-navbar title="切换店铺" placeholder leftIcon="" />
    <SearchBox class="SearchBox" @search="handleSearch" />

    <template v-for="item in RowsList">
      <StoreItem
        :item="item.businessVo"
        @click="handleSwitchStores(item.businessVo.businessId)"
      />
    </template>
    <uv-load-more :status="LoadStatus" />
  </view>
</template>

<script lang="ts" setup>
import { ref, onMounted, getCurrentInstance } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { userBusinessRolePage_Api } from "@/api/userInfo";
import StoreItem from "./components/StoreItem.vue";
import { usePageData } from "@/hooks/usePageData.ts";

const { RowsList, LoadStatus, initData } = usePageData(
  userBusinessRolePage_Api
);
initData();

const eventChannel = ref(null);
onMounted(() => {
  const instance = getCurrentInstance().proxy;
  eventChannel.value = instance.getOpenerEventChannel();
});

const businessId = ref(null);
const handleSwitchStores = (id) => {
  //   return;
  if (id == businessId.value) {
    return uni.$uv.toast("已是当前店铺");
  }
  try {
	eventChannel.value.emit("SwitchStore", { businessId: id });
  } catch (error) {
	
  }
  uni.navigateBack();
};

// 搜索
const handleSearch = (value) => {
  // console.log(value);
  initData({ businessName: value });
};

onLoad((options) => {
  console.log(options);
  if (options.businessId) businessId.value = options.businessId;
});
</script>

<style lang="scss" scoped>
.content-box {
  background-color: $my-pages-bg;
  min-height: 100vh;
  padding: 0 30rpx 30rpx;

  :deep(.store-item) {
    margin-bottom: 30rpx;
  }

  // .search{
  // 	width: 100%;
  // 	height: 130rpx;
  // 	background-color: $my-pages-bg;;
  // }
}
</style>
