<template>
  <view class="content">
    <view class="head">
      <span class="title">项目列表</span>
      <span class="self">只看自己</span>
    </view>
    <view class="list">
      <view
        class="project"
        v-for="project in projectList"
        :key="project.id"
        @click="onClickProject(project)"
      >
        {{ `${project.project_name}(${project.project_full_code})` }}
      </view>
    </view>
  </view>
</template>

<script>
import { queryProject } from "@/services/project";
import { mapState } from "vuex";
export default {
  computed: {
    ...mapState(["currentProject"]),
  },
  data() {
    return { projectList: [] };
  },
  onShow() {
    this.getProject();
  },
  methods: {
    async getProject() {
      let res = {};
      res = await queryProject();
      this.projectList = res.data.list;
    },
    async onClickProject(project) {
      await this.$store.commit("setCurrentProject", project);
      uni.navigateTo({
        url: `./detail?id=${project.id}`,
      });
    },
  },
};
</script>

<style lang="less" scoped>
.content {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}
.head {
  width: 100%;
  padding: 0 20px 20px 20px;
  position: fixed;
  background: #f8f8f8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .title {
    font: 24px bold;
  }
  .self {
    font: 16px;
  }
}
.list {
  width: 90%;
  margin-top: 60px;
}
.project {
  border-top: 2px solid gray;
  padding: 20px 0px;
  font-size: 18px;
}
</style>
