<template>
  <div class="choice-project com-search">
    <van-search placeholder="请输入搜索关键词" />
    <div class="choice-content">
      <div
        class="choice-item"
        :key="index"
        @click="goCheckSpace(item)"
        v-for="(item, index) in projects"
      >
        {{ item.localName }}
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, nextTick, onMounted, reactive, toRefs } from "vue";
import { useRoute, onBeforeRouteUpdate } from "vue-router";
import { Search } from "vant";
import router from "@/router";
import { getUsersInfo } from "@/apis/user";
import { store } from "@/store";
import { UserMutationTypes } from "@/store/modules/user/mutation-types";

export default defineComponent({
  components: {
    vanSearch: Search,
  },
  setup() {
    const route: any = useRoute();
    const projects: any = [];
    const proxyData = reactive({
      route: route,
      transitionName: "slide-right",
      showHeader: false,
      // 去选择空间
      goCheckSpace(item: any) {
        store.commit(UserMutationTypes.SET_PROJECT_ID, item.id);
        router.push({ path: "/choice-space", query: { id: item.id } });
      },
      projects: projects,
      getUsersInfo() {
        getUsersInfo().then((res) => {
          let resData: any = res;
          let projects: any = resData?.projects ?? [];
          proxyData.projects = projects;
        });
      },
    });
    onMounted(() => {
      proxyData.getUsersInfo();
    });
    return {
      ...toRefs(proxyData),
    };
  },
});
</script>
<style lang="scss" scoped>
.choice-project {
  width: 100%;
  // height: 100%;
  background: #fff;
  padding: 5px 20px;
}
</style>
<style lang="scss">
.choice-project {
  

  .choice-content {
    padding-top: 10px;
    .choice-item {
      padding: 20px 10px;
      font-family: "Noto Sans SC";
      font-style: normal;
      font-weight: 400;
      font-size: 16px;
      line-height: 26px;
      color: #1f2429;
      border-bottom: 1px solid #e4e6e7;
    }
  }
}
</style>
