<template>
<a-spin :spinning="loading">
  <div class="modal-content">
    <div class="subject" v-for="subject in imageList">
      <div class="subject-name">{{ subject.zname }}</div>
      <div class="show-image-div">
        <div class="image-item" v-for="(item, index) in subject.val">
          <a-image
            style="width:100px;height:100px;"
            :src="`${props.server}/${item.FilePath}`"
          ></a-image>
          <div class="select-div" @click="changeSelect(selectImage.some(obj => obj === item.FilePath)? 1: 2,item.FilePath)">
            <Icon v-if="selectImage.some(obj => obj === item.FilePath)" icon="material-symbols-light:check-circle" :size="25" style="color: #18a058;"/>
            <Icon v-else icon="material-symbols-light:check-circle-outline" :size="25" style="color: #cacdcd;"/>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="button-div">
    <a-button type="primary" @click="save">保存</a-button>
  </div>
</a-spin>
</template>

<script setup lang="ts">
import { defineProps, onMounted, ref, defineEmits } from "vue"
import { rebackzhuantipic, CopyImg } from '@/api/tiankongdi/index'
import Icon from '@/components/Icon/Icon.vue';
import { message } from "ant-design-vue";
  import { getZhuantiName } from '@/utils/global'

const props = defineProps(['caseid','server','zhuanti'])
const emits = defineEmits(['save'])
const imageList = ref<string[]>([])
const selectImage = ref<string[]>([])
const loading = ref(false)
onMounted(() => {
  loading.value = true
  let caseid = sessionStorage.getItem('SelectOtherId')
  rebackzhuantipic({CaseId:caseid,zhuanti:getZhuantiName()}).then(res => {
    imageList.value = res
  }).finally(() => {
    loading.value = false
  })
})

const changeSelect = (type,item) => {
  switch(type){
    case 1: 
    selectImage.value = selectImage.value.filter(useItem => useItem !== item);
      break;
    case 2:
    selectImage.value.push(item)
      break
  }
}
const save = () => {
  if(selectImage.value.length <= 0){
    message.warning('至少选择一张图片')
    return
  }
  loading.value = true
  let params = {
    caseid: sessionStorage.getItem('SelectOtherId'),
    images: selectImage.value
  }
  CopyImg(params).then(res => {
    emits('save', res)
  }).finally(() => {
    loading.value = false
  })
}
</script>

<style lang="scss" scoped>
.modal-content{
  min-height: 500px;
  padding: 0px 20px;
  max-height: 678px;
  overflow: auto;
  scrollbar-width: none; 
  ::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
  .subject{
    margin-bottom: 10px;
    .subject-name{
      height: 30px;
      background-color: #8b8b8b;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #fff;
      font-size: 20px;
      font-weight: 500;
      margin-bottom: 10px;
    }
    .show-image-div{
      width: 100%;
      // height: 100%;
      display: flex;
      flex-wrap: wrap;
      align-content: flex-start;
      .image-item{
        position: relative;
        width: 100px;
        height: 100px;
        margin-right: 12px;
        margin-bottom: 10px;
        .select-div{
          position: absolute;
          bottom: 0px;
          height: 20px;
          width: 100%;
          height: 30px;
          background-color: #00000075;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
        }
      }
    }
  }

}
.button-div{
  display: flex;
  justify-content: end;
  padding: 20px;
}
</style>
