<template>
  <Search :tag="tag" :type="'SCENE'" ref="searchRef"></Search>
  <div style="background-color: #f0f2f5" class="dark:bg-dark-900">
    <div class="datacenter-right">
      <div class="resource_list" id="map_list">
        <div v-for="(i, n) in list" v-if="list.length" :key="n" data-permission="true" class="resource_item"
          data-checking="false" data-searching="1" data-ispub="1">
          <div class="mapItem-top-box">
            <div class="item-top">
              <div class="img_container" data-num="1">
                <img class="tab-list-icon-img-MR00001936 img_mr MR00001936" :id="i.SERVICEID + n" :src="setHtmlImg(i, n)"
                  alt="场景预览图">
              </div>
            </div>
            <div class="item-title">
              <span class="r_name">{{ i.SERVICENAME }}</span>
              <!-- <span class="r-number" data-num="1" title="编目1次">1</span> -->
            </div>
            <div class="item-msg">
              <div class="item-msg-val">坐标系：<span>{{ i.CRS }}</span></div>
              <div class="item-msg-val">适用流程：<span>国家秘密和工作秘密数据成果申请,</span></div>
              <div class="item-msg-val">关键字：
                <span :id="'KEYWORDS' + i.SERVICEID + n">{{ getTag(i.KEYWORDS, `KEYWORDS${i.SERVICEID}${n}`) }}</span>
              </div>
              <div class="item-msg-val">服务类型：<span>{{ i.TYPENAME }}</span></div>
            </div>
          </div>
          <div class="operation-box">
            <div class="left">
              <div class="operation-item browse-item-btn browse-item-MR00001936">
                <a target="_blank" :href="`./mapview.html?${i.SERVICEID}`">
                  <span>浏览</span>
                </a>
              </div>
              <div class="operation-item" @click="handleQuery(i, n)">
                <a href="javascript:void(0)" class="">
                  <span>详细</span>
                </a>
              </div>
            </div>
            <div class="right">
              <div class="operation-item" v-if="i.SFJRSQK === '未加入'" @click="applyWay(i)">
                <a href="javascript:void(0)" class="">
                  <span>加入申请库</span>
                </a>
              </div>
              <div class="operation-item" v-else style="cursor: not-allowed;background-color: #e8e8e8;">
                <a href="javascript:void(0)" style="cursor: not-allowed;">
                  <span>{{ i.SFJRSQK == '已加入' ? '已加入申请库' : i.SFJRSQK }}</span>
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <MyPage :total="total"></MyPage>
    <!-- 弹出框 -->
    <DetailModal v-if="showResDeatil" :type="'SCENE'" @closeModal="showResDeatil = false" :resId="detailResId" />
  </div>
</template>
<script>
import { defineComponent, nextTick, onMounted, ref, defineProps, watch } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { Popconfirm, Tooltip } from 'ant-design-vue';
import { Authority } from '/@/components/Authority';
// 加载自定义侧边弹出框 组件
import { useDrawer } from '/@/components/Drawer';
// 导入子页面【新增、修改】
import SceneDrawer from './SceneDrawer.vue';
import Search from './child/Search.vue';
import { platList, img, apply, tagAjax } from '/@/api/resource/plat';
import { session } from '/@/utils/Memory';
import { message } from 'ant-design-vue';
import MyPage from './child/MyPage.vue';
import DetailModal from './child/DetailModal.vue';
import { setHtmlImg } from '/@/views/minWidgets/CommonWay.js';



const props = {
  listData: {
    type: Object,
    default: () => {},
  }
}

export default defineComponent({
  name: 'SceneData',
  components: { BasicTable, TableAction, Search, DetailModal, Authority, Popconfirm, Tooltip, SceneDrawer, MyPage },
  props,
  emits:['resAddToCar'],
  setup(props, { emit }) {
    const showResDeatil = ref(false)
    const detailResId = ref('')
    const searchRef = ref(null)
    const [registerModal, { openDrawer }] = useDrawer(); //使用右侧弹出框
    const list = ref([]);

    const total = ref(0);
    onMounted(() => getList(props.listData));

    const tag = ref('');
    async function getList(res) {
      console.log("场景传进来的文件资源:", res)
      total.value = res.count;
      tag.value = res.keywords;
      var res = res.items;
      var val = JSON.parse(JSON.stringify(res))
      list.value = val;
    }

    //获取资源标签
    function getTag(i, id) {
      //判断是不是数组
      i = i.indexOf('[') > -1 ? JSON.parse(i) : [i];
      if (i.length) {
        tagAjax().then(r => {
          var name = r.filter(j => i.includes(j.code)).map(j => j.name).toString();
          document.querySelector(`#${id}`).innerHTML = name;
        })
      } else {
        return ''
      }
    }

    watch(() => props.listData, (val) => getList(val), {
      deep: true,
      immediate: true
    })

    function handleQuery(record, n) {
      console.log("11111:", record)
      // openDrawer(true, {
      //   record,
      // });
      //打开详情弹窗
      session.setItem('thumbnail2', document.getElementById(record.SERVICEID + n).src);
      detailResId.value = record.SERVICEID
      showResDeatil.value = true
    }
    function applyWay(i) {
      console.log(i)
      apply({
        addRes: [{
          resDataType: "1",
          resId: i.SERVICEID,
          resName: `${i.SERVICENAME}(${i.CRS})`,
          resType: 0,
          workflowType: "SCENE",
        }],
        userId: session.getItem('userId'),
      }).then((r) => {
        if (r.datas && r.resp_code == 0) {
          message.success('申请成功');
          // searchRef.value.getResData();
          eventBus.emit('addResToCarEventBus')
          emit('resAddToCar')
        }
      })
    }

    return {
      setHtmlImg,
      getTag,
      detailResId,
      showResDeatil,
      tag,
      total,
      searchRef,
      // getDataList,
      registerModal,
      applyWay,
      list,
      handleQuery,
    };
  },
});
</script>

<style scoped>
.datacenter-right .resource_list .item-title .r_name {
  color: #5e5d5e;
  display: inline-block;
  width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: Source Han Sans CN;
  font-size: 16px;
  font-weight: bold;
  line-height: 16.38px;
  letter-spacing: 0px;
  color: #333333;
}

.datacenter-right .resource_list {
  box-sizing: border-box;
  width: 100%;
  float: left;
  clear: both;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.datacenter-right .resource_list>div:not(:nth-of-type(4n + 4)) {
  margin-right: 7px;
}

.resource_item {
  height: 318px;
  width: 224px;
  margin-bottom: 14px;
  border: 2px dashed transparent;

  width: 386px;
  height: 402px;
  border-radius: 4px;
  opacity: 1;
  background: #FFFFFF;
  border: 1px solid #DEDEDE;
}

.mapItem-top-box {
  height: 350px;
}

.datacenter-right .resource_list .operation-box {
  height: 42px;
  display: flex;
  margin-bottom: 10px;
  /* margin-left: 20px; */
  justify-content: space-between;
  padding: 0 24px;

  .left {
    display: flex;

    .operation-item {
      display: flex;
      align-items: center;
      justify-content: center;
      min-width: 50px;
      height: 34px;
      opacity: 1;
      margin-right: 22px;
      padding: 0 10px;
      background: #E8E8E8;

      a {
        font-size: 12px;
        width: 100%;
        text-align: center;
        color: #333333;
      }
    }
  }

  .right {
    .operation-item {
      display: flex;
      align-items: center;
      justify-content: center;
      min-width: 50px;
      height: 34px;
      opacity: 1;
      padding: 0 10px;
      background: #0671DD;

      a {
        font-size: 12px;
        width: 100%;
        text-align: center;
        color: #fff;
      }
    }
  }
}

.datacenter-right .resource_list .item-top {
  padding: 10px 16px 10px;
}

.datacenter-right .resource_list .item-top img {
  width: 360px;
  height: 190px;
  border: solid 1px #eeebeb;
}

.datacenter-right .resource_list .item-title {
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: bold;
  color: #5e5d5e;
  line-height: 16px;
  padding: 0 0 0 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.datacenter-right .resource_list .item-msg {
  padding: 0 13px 13px;
}

.img_container {
  text-align: center;
}

.img_container {
  width: 100%;
  height: 100%;
  background: #b7bed3;
  border-radius: 4px;
}

.datacenter-right .resource_list .item-msg-val {
  font-size: 12px;
  font-family: PingFang SC;
  font-weight: bold;
  color: #888888;
  line-height: 26px;
  /* opacity: 0.5; */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-msg-val>span {
  font-family: Source Han Sans CN;
  font-size: 14px;
  font-weight: normal;
  line-height: 16.38px;
  letter-spacing: 0px;
  color: #333333;
}
</style>
