<template>
  <div class="manage-container">
    <el-row :gutter="20">
      <el-col v-for="(val, key) in projectData" :key="key" :span="6">
        <div class="list">
          <div class="list-base">
            <h1 class="list-head">{{ val.name }}</h1>
            <el-image class="list-image"></el-image>
            <el-button
              type="primary"
              style="width: 100%"
              @click="projectDetail(val.id)"
            >
              项目管理
            </el-button>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getProjectsByUserId, getUserInfos } from '@/api/user';
export default {
  data() {
    return {
      projectData: [],
    };
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    async getUserProject(userId) {
      const { data } = await getProjectsByUserId({ userId: userId });
      this.projectData = data;
    },
    async getUserInfo() {
      const { data } = await getUserInfos();
      this.getUserProject(data.id);
    },
    projectDetail(projectId) {
      sessionStorage.setItem('projectId', projectId);
      this.$router.push({
        name: '监控地图',
        path: '/monitor',
        query: { projectId: projectId },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.el-input,
.el-select {
  width: 240px !important;
  margin-right: 20px !important;
}

.list {
  background-color: #f5f6fa;
  border-radius: 4px;
  margin-top: 20px;
  .list-base {
    padding: 20px;
    .list-head {
      margin: 0 !important;
      font-size: 14px !important;
      color: #444444 !important;
    }
    .list-image {
      width: 100%;
      height: 180px;
      background-color: #ffffff;
    }
  }
}
</style>
