<template>
  <div class="assembly-data">
    <Search></Search>
    <div class="datacenter-right-1">
      <div class="resource_list" id="map_list">
        <div v-for="(i, k) in list" :key="k" class="item">
          <div class="img-box"><img :src="interfaceImg" alt="" srcset=""></div>
          <div class="itemLetf">
            <div class="item-top">
              <div class="title">{{ i.name }}</div>
              <div class="opts-btn">
                <div class="add-library btn">加入申请库</div>
                <div class="interface-details btn" @click="showDrawer(i)">查看详情</div>
              </div>
            </div>
            <div class="describle">
              <div class="title">描述：</div>
              <div class="text" v-html="i.remark"></div>
            </div>
            <div class="split-line"></div>
            <div class="leftBut">
              <p><span>当前版本:</span><span>{{ i.version }}</span></p>
              <p><span>调用次数:</span><span>{{ i.is_open || 0 }}</span></p>
              <p><span>发布时间:</span><span>{{ i.publishTime }}</span></p>
              <p><span>更新时间:</span><span>{{ i.updateTime }}</span></p>
            </div>
          </div>
        </div>
      </div>
      <div class="pagination">
        <Pagination v-model:current="current" :page-size-options="pageSizeOptions" :total="total" show-size-changer
          :page-size="pageSize" @showSizeChange="onShowSizeChange">
          <template #buildOptionText="props">
            <span v-if="props.value !== '50'">{{ props.value }}条/页</span>
            <span v-else>全部</span>
          </template>
        </Pagination>
      </div>
    </div>
    <a-drawer title="接口详情" width="700px" placement="right" :closable="false" v-model:visible="visible"
      :after-visible-change="afterVisibleChange">
      <Details :action="action"></Details>
      <div class="footer">
        <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
      </div>
    </a-drawer>
    <AssemblyDrawer @register="registerModal" />
  </div>
</template>
<script lang="ts">
import { defineComponent, nextTick, onMounted, ref, defineProps, watch } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { columns, searchFormSchema } from './sms.data';
import { Popconfirm, Tooltip, Pagination } from 'ant-design-vue';
import { Authority } from '/@/components/Authority';
import { interfaceList, getGroupId } from '/@/api/interface/interface.ts';
import { message } from 'ant-design-vue';
// 加载自定义侧边弹出框 组件
import { useDrawer } from '/@/components/Drawer';
// 导入子页面【新增、修改】
import AssemblyDrawer from './AssemblyDrawer.vue';
import Search from './child/Search.vue';
import Details from './child/Details.vue';
import { session } from '/@/utils/Memory';
import interfaceImg from '/@/assets/images/count2.png';


export default defineComponent({
  name: 'SmsLog',
  components: { Pagination, BasicTable, TableAction, Authority, Search, Details, Popconfirm, Tooltip, AssemblyDrawer },
  setup() {
    const [registerModal, { openDrawer }] = useDrawer(); //使用右侧弹出框

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

    // setInterval(() => {
    //   console.log(props)
    // }, 2000)


    function handleQuery(record: Recordable) {
      console.log("11111:", record)
      openDrawer(true, {
        record,
      });
    }


    // var list = [
    //   { src: 'http://106.12.170.138:4001/examples/img/Earth.jpg', name: '地图加载', has: false, href: "onlineIde_a1_Hello_World_01" },
    //   { src: 'http://106.12.170.138:4001/examples/img/Earth.jpg', name: '地图加载', has: false, href: "onlineIde_a1_Hello_World_01" },
    //   { src: 'http://106.12.170.138:4001/examples/img/Earth.jpg', name: '地图加载', has: false, href: "onlineIde_a1_Hello_World_01" }
    // ]

    var list = ref([]);

    // onMounted(() => getList())

    function getList() {
      interfaceList({
        page: current.value,
        rows: pageSize.value,
        keyword: keyword.value,
      }).then((e) => {
        console.log("e:", e)
        if (e.records.length) {
          eventBus.emit("interfaceNum", e);
          total.value = e.total;
          list.value = e.records;
        }
      })
    }

    const visible = ref<boolean>(false);
    const action = ref({});
    const afterVisibleChange = (bool: boolean) => {
      console.log('visible', bool);
    };

    const showDrawer = (i) => {
      console.log("i", i);
      action.value = i;
      visible.value = true;
    };
    const onClose = () => {
      visible.value = false;
    };

    function formatData(e) {
      var str = null;
      try {
        str = JSON.stringify(JSON.parse(action.request_headers), null, 4)
      } catch (error) {
        str = e;
      }
      return str;
    }

    const pageSizeOptions = ref(['10', '20', '30', '40', '50']);
    const current = ref(1);
    const pageSize = ref(6);
    const total = ref(50);
    const onShowSizeChange = (current, pageSize) => {
      console.log(pageSize);
      pageSize.value = pageSize;
      getGroupIdList()
    };
    watch(current, () => {
      getGroupIdList();
    });
    const keyword = ref("");
    eventBus.on("interfaceSearch", (e) => { keyword.value = e, getList() });
    eventBus.on("groupIdInterface", (e) => { groupId = e; getGroupIdList(groupId) });


    var groupId = null;
    function getGroupIdList(id) {
      getGroupId({
        page: current.value,
        rows: pageSize.value,
        groupId: groupId,
      }).then((e) => {
        eventBus.emit("interfaceNum", e);
        total.value = e.totalNum;
        list.value = e.list;
      })
    }


    return {
      pageSizeOptions,
      current,
      pageSize,
      total,
      onShowSizeChange,
      formatData,
      visible,
      action,
      afterVisibleChange,
      showDrawer,
      onClose,
      interfaceImg,
      registerModal,
      list,
      handleQuery,
    };
  },
});
</script>



<style scoped lang="less">
.assembly-data {
  width: 100%;
  height: 100%;

  .datacenter-right-1 {
    width: 100%;
    position: relative;
    height: calc(100% - 64px);
    max-height: 810px;
    // height: 890px;



    .resource_list {
      width: 100%;
      height: calc(100% - 45px);
      max-height: 760px;
      overflow: auto;

      &::-webkit-scrollbar {
        width: 1px;
      }

      .item {
        margin-bottom: 20px;
        width: 100%;
        height: 110px;
        border-radius: 4px;
        background: #FFFFFF;
        border: 1px solid #DEDEDE;
        padding: 10px;
        display: flex;
        align-items: center;

        &:last-child {
          margin-bottom: 0;
        }

        .img-box {
          width: 140px;
          height: 90px;
          display: flex;
          align-items: center;
          justify-content: center;
          border: solid 1px #f1eded;
          box-sizing: border-box;

          img {
            width: 48px;
            height: 48px;
          }
        }

        .itemLetf {
          flex-grow: 1;
          margin-left: 20px;
          display: flex;
          flex-direction: column;
          justify-content: center;

          .item-top {
            display: flex;
            justify-content: space-between;
            align-items: center;

            .title {
              font-family: Source Han Sans CN;
              font-size: 16px;
              font-weight: bold;
              color: #333333;
            }

            .opts-btn {
              margin-right: 10px;
              display: flex;

              .add-library {
                margin-right: 9px;
                padding-right: 9px;
                border-right: 1px solid #0671DD;
              }

              .btn {
                font-family: '阿里巴巴普惠体 2.0';
                font-size: 14px;
                font-weight: normal;
                color: #0671DD;
                user-select: none;
                cursor: pointer;
              }
            }
          }

          .describle {
            margin-top: 7px;
            display: flex;

            .title {
              font-family: Source Han Sans CN;
              font-size: 14px;
              font-weight: normal;
              color: #888888;
            }

            .text {
              font-family: Source Han Sans CN;
              font-size: 14px;
              color: #333333;

              p {
                margin-bottom: 0 !important;
              }
            }
          }

          .split-line {
            margin-top: 7px;
            height: 1px;
            background-color: #DEDEDE;
          }

          .leftBut {
            margin-top: 7px;
            display: flex;
            justify-content: space-between;

            p {
              margin-bottom: 0;

              &:last-child {
                margin-right: 10px;
              }
            }
          }
        }

      }
    }

    .pagination {
      width: 100%;
      height: 40px;
      position: absolute;
      // z-index: 4;
      bottom: 0px;
      right: 0;
      // background: #fff;

      ul {
        float: right;
      }
    }
  }
}
</style>
