<template>
  <div class="assembly-data">
    <Search :totalNum="total" @interfaceSearch="interfaceSearch" ref="searchRef"></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" @click="applyWay(i)">加入申请库</div>
                <div class="interface-details btn" @click="showDrawer(i)">查看详情</div>
              </div>
            </div>
            <div class="describle">
              <div class="title">描述：</div>
              <div class="text">{{ i.name }}</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-modal wrapClassName="modal-wrap" title="接口详情" width="800px" v-model:visible="visible" @cancel="onClose" centered
      :footer="null">
      <div class="content">
        <Details :action="action"></Details>
      </div>
    </a-modal>
  </div>
</template>
<script>
import { defineComponent, nextTick, onMounted, ref, defineProps, watch } from 'vue';

import { interfaceList, getGroupId } from '/@/api/interface/interface.ts';
import { apply } from '/@/api/resource/plat';

import { message, Pagination } from 'ant-design-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';

const props = {
  groupId: {
    type: String,
    default: ""
  }
}

export default defineComponent({
  name: 'SmsLog',
  components: { Search, Details, Pagination },
  props,
  setup(props) {

    var list = ref([]);
    const visible = ref(false);
    const action = ref({});
    const pageSizeOptions = ref(['10', '20', '30', '40', '50']);
    const current = ref(1);
    const pageSize = ref(10);
    const total = ref(0);
    const groupId = ref("")

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


    const onShowSizeChange = (current, val) => {
      pageSize.value = val;
      getGroupIdList()
    };
    watch(current, () => {
      getGroupIdList()
    });

    // 根据组id查询接口列表
    const getGroupIdList = () => {
      getGroupId({
        page: current.value,
        rows: pageSize.value,
        groupId: groupId.value,
      }).then((e) => {
        // eventBus.emit("interfaceNum", e);
        total.value = e.totalNum;
        list.value = e.list;
      })
    }
    //根据关键字查询接口列表
    const getList = (keyword) => {
      interfaceList({
        page: current.value,
        rows: pageSize.value,
        keyword: keyword || "",
      }).then((e) => {
        console.log("e:", e)
        if (e.records.length) {
          total.value = e.total;
          list.value = e.records;
        }
      })
    }
    //关键字搜索
    const interfaceSearch = (e) => {
      console.log(e)
      if (e) {
        current.value = 1
        pageSize.value = 100000
        getList(e)
      } else {
        current.value = 1
        pageSize.value = 10
        getGroupIdList()
      }
    }

    onMounted(() => {
      groupId.value = props.groupId;
      getGroupIdList();
    })

    watch(
      () => props.groupId,
      (val) => {
        groupId.value = val;
        current.value = 1;
        pageSize.value = 10;
        getGroupIdList();
      }
    )
    const searchRef = ref(null)
    const applyWay = (i) => {
      console.log(i)
      apply({
        addRes: [{
          resDataType: "3",
          resId: i.id,
          resName: i.name,
          resType: 1,
          workflowType: "INTERFACE",
        }],
        userId: session.getItem('userId'),
      }).then((r) => {
        if (r.datas && r.resp_code == 0) {
          message.success('申请成功');
          searchRef.value.getResData();
        }
      })
    }

    return {
      searchRef,
      interfaceImg,
      list,
      visible,
      action,
      pageSizeOptions,
      current,
      pageSize,
      total,
      onShowSizeChange,
      onClose,
      interfaceSearch,
      showDrawer,
      applyWay
    };
  },
});
</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;
      }
    }
  }
}

.modal-wrap {
  .content {
    padding: 20px 10px 10px 20px;
    margin-top: 10px;
    max-height: 800px;
    overflow: auto;
  }
}
</style>
