<template>
  <Search></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, k) in list" :key="k" class="item">
          <div><img :src="interfaceImg" alt="" srcset=""></div>
          <div class="itemLetf">
            <span>
              <h1>{{ i.name }}</h1>
              <b>
                <span>加入申请库</span>
                <span @click="showDrawer(i)" style="cursor: pointer;">查看详情</span>
              </b>
            </span>
            <p class="remark" style="height: 32px;"><span>描述:</span>
            <p v-html="i.remark"></p>
            </p>
            <div class="leftBut">
              <p><span>当前版本:</span><span>{{ i.version }}</span></p>
              <p><span>调用次数:</span><span>{{ i.is_open || 0 }}</span></p>
              <p><span>{{ i.publish_time ? '发布时间' : '创建时间' }}</span><span>{{ i.publish_time || i.create_time }}</span></p>
              <p><span>更新时间:</span><span>{{ i.update_time }}</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="400px" placement="right" :closable="false" v-model:visible="visible"
      :after-visible-change="afterVisibleChange">
      <p><b>接口名称:</b>&nbsp;&nbsp;<span>{{ action.name }}</span></p>
      <p><b>系统名称:</b>&nbsp;&nbsp;<span>{{ action.system_name }}</span></p>
      <p><b>接口地址:</b>&nbsp;&nbsp;<span>{{ action.request_url }}</span></p>
      <p><b>接口类型:</b>&nbsp;&nbsp;<span>{{ action.request_method }}</span></p>
      <p><b>请求数据:</b>&nbsp;&nbsp;<span>{{ action.response_datatype }}</span></p>
      <p class="remark" style="height: 19px;"><b>资源描述:</b>&nbsp;&nbsp;<span>
          <p v-html="action.remark"></p>
        </span></p>
      <p>
      <p>请求头:</p> <textarea name="" id="" cols="45" rows="3">{{ formatData(action.request_headers) }}</textarea></p>
      <p>
      <p>请求参数:</p> <textarea name="" id="" cols="45" rows="3">{{ formatData(action.query_params) }}</textarea></p>
      <p>
      <p>返回参数:</p> <textarea name="" id="" cols="45" rows="10">{{ formatData(action.response_params) }}</textarea></p>
      <p>
      <p>返回案例:</p> <textarea name="" id="" cols="45" rows="10">{{ formatData(action.success_resp_example) }}</textarea>
      </p>
      <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 { session } from '/@/utils/Memory';
import interfaceImg from '/@/assets/images/count2.png';


export default defineComponent({
  name: 'SmsLog',
  components: { Pagination, BasicTable, TableAction, Authority, Search, 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(10);
    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() });


    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>
.datacenter-right {
  position: relative;
  height: auto;
}

.pagination {
  width: calc(100% - 320px);
  height: 40px;
  position: fixed;
  z-index: 4;
  bottom: 16px;
  background: #fff;
}

.pagination>ul {
  float: right;
}

.remark span,
.remark p {
  display: inline-block;
}

#map_list {
  overflow-y: scroll;
  height: calc(100vh - 194px);
  background: #fff;
}

#map_list::-webkit-scrollbar {
  width: 1px;
}

.leftBut>p {
  display: inline-block;
  font-size: 14px;
  font-weight: normal;
  line-height: 16.38px;
  letter-spacing: 0px;
  color: #888888;
  width: 25%;
}

.leftBut>p span:last-child {
  color: #333;
}

.item b {
  font-size: 16px;
  font-weight: bold;
  display: inline-block;
  margin: 10px 0;
}

.item {
  width: 100%;
  height: 110px;
  border-radius: 4px;
  background: #FFFFFF;
  border: 1px solid #DEDEDE;
  padding: 10px;
  float: left;
  margin: 0px 20px 20px 0px;
}

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

.item>div:first-child {
  float: left;
  width: 140px;
  height: 90px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: solid 1px #f1eded;
}

.item>div:last-child {
  float: left;
  width: calc(100vw - 503px);
  margin-left: 20px;
}

.itemLetf>span {
  display: block;
  height: 24px;
  line-height: 24px;
}

.itemLetf>span>h1 {
  font-size: 16px;
  font-weight: bold;
  line-height: 16px;
  color: #333333;
  float: left;
}

.itemLetf>span>b {
  float: right;
  margin: 0px;
  font-size: 14px;
  font-weight: normal;
  line-height: 16.38px;
  letter-spacing: 0px;
  color: #0671DD;
}

.itemLetf>span>b>span:first-child {
  border-right: solid 1px #999999;
  padding-right: 10px;
}

.itemLetf>span>b>span:last-child {
  padding-left: 10px;
}

.itemLetf>p {
  text-align: left;
  border-bottom: 1px solid #DEDEDE;
  padding-bottom: 10px;
}

.itemLetf>p>span {
  font-size: 14px;
  font-weight: normal;
  line-height: 16.38px;
  letter-spacing: 0px;
  color: #888888;
  margin-right: 20px;
}
</style>
