<template>
  <Search 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"
                  :src="(i.info && i.info.length && i.info[0].thumbnail) || './static/img/default-dr3.jpg'" 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>测试数据</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="(i.info && i.info.length && i.info[0].thumbnail) || './static/img/default-dr3.jpg'">
                  <span>浏览</span>
                </a>
              </div>
              <div class="operation-item" @click="handleQuery(i)">
                <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)" class="" style="cursor: not-allowed;">
                  <span>已加入</span>
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 弹出框 -->
    <DetailModal v-if="showResDeatil" @closeModal="showResDeatil = false" :resId="detailResId" />
  </div>
</template>
<script>
import { defineComponent, nextTick, onMounted, ref, defineProps, watch } from 'vue';
// 导入子页面【详情】
import DetailModal from './child/DetailModal.vue';
import Search from './child/Search.vue';
import { platList, img, apply } from '/@/api/resource/plat';
import { session } from '/@/utils/Memory';
import { message } from 'ant-design-vue';

const props = {
  listData: {
    type: Array,
    default: () => [],
  }
}

export default defineComponent({
  name: 'SmsLog',
  components: { Search, DetailModal },
  props,
  setup(props, { emit }) {
    const showResDeatil = ref(false)
    const searchRef = ref(null)
    const list = ref([]);
    const detailResId = ref('')

    onMounted(() => {
      console.log("传进来的文件资源:", props.listData)
      list.value = props.listData
      list.value.map(async (i) => i.info = await img(i.SERVICEID))
    });

    watch(
      () => props.listData,
      (val) => {
        list.value = JSON.parse(JSON.stringify(val))
        list.value.map(async (i) => i.info = await img(i.SERVICEID))
      },
      {
        deep: true,
        immediate: true
      }
    )

    function applyWay(i) {
      console.log(i)
      apply({
        addRes: [{
          resDataType: "2",
          resId: i.SERVICEID,
          resName: `${i.SERVICENAME}(${i.CRS})`,
          resType: 0,
          workflowType: "FILE",
        }],
        userId: session.getItem('userId'),
      }).then((r) => {
        if (r.datas && r.resp_code == 0) {
          message.success('申请成功');
          // searchRef.value.getResData();
          eventBus.emit('addResToCarEventBus')
          emit('resAddToCar')
        }
      })
    }

    function handleQuery(record) {
      //打开详情弹窗
      detailResId.value = record.SERVICEID
      showResDeatil.value = true
    }

    return {
      showResDeatil,
      detailResId,
      searchRef,
      list,
      applyWay,
      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>
