<template>
  <div class="project-list">
    <div class="title-div">
      <div class="title">
        <div class="title-icon"></div>
        <div class="title-span">项目列表</div>
      </div>
      <div class="add" @click="addProject"></div>
    </div>
    <div class="interval"></div>
    <div class="list">
      <div v-for="item in projectList">
        <div :class="`project-list-item ${activeProject == item.Id? 'active': ''}`" @click="selectProject(item)">
          <div style="display: flex;align-items: center;">
            <div class="list-item-icon"></div>
            <div class="list-item-content">{{ item.WorkspaceName }}</div>
            <div class="active-icon"></div>
          </div>
          <div class="button-div">
            <div class="edit-button" @click="editProject(item)"></div>
            <div class="button-interval"></div>
            <div class="del-button" @click="delProject(item)"></div>
          </div>
        </div>
        <div class="item-bottom-interval"></div>
      </div>
    </div>
    <!-- 添加项目组件 -->
    <AddProject v-model:addModal="addModal" :modalType="modalType" :map="props.map" :updateProject="updateProject" @getProjectList="getProjectList"/>
  </div>
</template>

<script setup lang="ts">
import AddProject from './AddProject/index.vue'
import { ref, defineProps, onMounted, createVNode } from "vue"
import { GetWorkspaceList, GetWorkSpaceById, DeleteWorkspace } from '@/api/demo/projecthome'
import { message, Modal } from 'ant-design-vue'
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'

onMounted(() => {
  getProjectList()
})

const props = defineProps(['map'])
const addModal = ref(false)
const modalType = ref('')
const projectList = ref([])
const activeProject = ref('')
const updateProject = ref({})
const addProject = () => {
  modalType.value = 'insert'
  addModal.value = true
}
const selectProject = (item) => {
  activeProject.value = item.Id
}
const getProjectList = () => {
  GetWorkspaceList().then(res => {
    projectList.value = res
  })
}
const editProject = (item) => {
  let params = {
    id: item.Id
  }
  modalType.value = 'update'
  GetWorkSpaceById(params).then(res => {
    console.log('res',res)
    updateProject.value = res
    addModal.value = true
  })
}
const delProject = (item) => {
   Modal.confirm({
    title: `确定要删除 " ${item.WorkspaceName} " 项目吗`,
    icon: createVNode(ExclamationCircleOutlined),
    onOk() {
      let params = {
        id: item.Id
      }
      return DeleteWorkspace(params).then(res => {
        console.log(res)
        message.success('项目删除成功')
        getProjectList()
      })
    },
    onCancel() {
    },
  });
}
</script>

<style lang="scss" scoped>
.project-list{
  position: absolute;
  top: 40px;
  left: 27px;
  width: 328px;
  height: 500px;
  background-image: url('/public/projecthome/background.png');
  background-size: 100% 100%;
  padding-top: 19px;
  .title-div{
    padding-left: 26px;
    padding-right: 24px;
    width: 100%;
    height: 33px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 13px;
    .title{
      display: flex;
      align-items: center;
      .title-icon{
        width: 24px;
        height: 24px;
        background-image: url('/public/projecthome/project_list_icon.png');
        background-size: 100% 100%;
        margin-right: 14px;
      }
      .title-span{
        font-family: 'PingFangSC-Medium';
        font-weight: 500;
        font-size: 22px;
        color: #FFFFFF;
        line-height: 33px;
        text-shadow: 0px 10px 30px rgba(0,0,6,0.15);
      }
    }
    .add{
      width: 24px;
      height: 24px;
      background-image: url('/public/projecthome/project_list_add.png');
      background-size: 100% 100%;
      cursor: pointer;
    }
  }
  .interval{
    width: 328px;
    height: 1px;
    box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
    border: 1px solid #4E5778;
    opacity: 0.2;
  }
  .list{
    user-select: none;
    .project-list-item{
      position: relative;
      padding-left: 25px;
      padding-right: 22px;
      width: 100%;
      height: 35px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      opacity: 0.7;
      .list-item-icon{
        width: 6px;
        height: 6px;
        background: #FFFFFF;
        box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
        margin-right: 18px;
      }
      .list-item-content{
        font-family: 'PingFangSC-Regular';
        font-weight: 400;
        font-size: 16px;
        color: #FFFFFF;
        line-height: 33px;
        text-shadow: 0px 10px 30px rgba(0,0,6,0.15);
      }
      .button-div{
        display: flex;
        align-items: center;
        .edit-button{
          width: 13px;
          height: 13px;
          background-image: url('/public/projecthome/active_project_edit.png');
          background-size: 100% 100%;
          cursor: pointer;
        }
        .button-interval{
          width: 1px;
          height: 13px;
          background: #FFFFFF;
          box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
          opacity: 0.48;
          margin: 0px 9px;
        }
        .del-button{
          width: 13px;
          height: 13px;
          background-image: url('/public/projecthome/active_project_del.png');
          background-size: 100% 100%;
          cursor: pointer;
        }
      }
    }
    .active{
      background: linear-gradient( 270deg, rgba(108,144,245,0) 0%, #3A57E8 100%);
      box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15), inset 0px 1px 3px 0px rgba(0,0,0,0.28);
      opacity: 1;
      .active-icon{
        position: absolute;
        top: 0px;
        left: 0px;
        width: 4px;
        height: 35px;
        background: #607AFF;
        box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15);
      }
    }
    .item-bottom-interval{
      margin-left: 25px;
      height: 2px;
      width: calc(100% - 25px);
      box-shadow: 0px 10px 30px 0px rgba(0, 0, 6, 0.15);
      background: #4E5778;
      opacity: 0.3;
    }
  }
}
</style>
