<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-07-22 19:43:22
 * @LastEditors: 无尘
 * @LastEditTime: 2019-07-22 19:43:22
 -->
<template>
  <div class="api-body-content border-box">
    <div class="common-nav">
      <nav-bread :navPath="navPath"></nav-bread>
    </div>
    <div class="api-body-main common-body-main border-box">
      <div class="api-main-content border-box">
        <div class="search-wrap m-b-20">
          <el-input clearable class="w-320" placeholder="请输入版本号/API名称" v-model="searchValue" @keyup.native="value => searchData(value)" @clear="clearInput">
            <i slot="prefix" class="el-input__icon el-icon-search"></i>
          </el-input>
        </div>
        <div class="table-wrap">
          <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="publishRecordId" label="发布版本" show-overflow-tooltip> </el-table-column>
            <el-table-column label="API名称" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.interfaceName }}
              </template>
            </el-table-column>
            <el-table-column label="版本号" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.version }}
              </template>
            </el-table-column>
            <el-table-column label="环境" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.sceneName }}
              </template>
            </el-table-column>
            <el-table-column label="发布备注" show-overflow-tooltip>
              <template slot-scope="scope">
                {{ scope.row.remark }}
              </template>
            </el-table-column>
            <el-table-column label="创建时间" show-overflow-tooltip>
              <template slot-scope="scope">
                <div class="color-606266 line-18">{{ scope.row.createTime | timeStampToYmd }}</div>
                <div class="color-606266 line-18">{{ scope.row.createTime | timeStampToHms }}</div>
              </template>
            </el-table-column>
            <el-table-column label="操作" show-overflow-tooltip>
              <template slot-scope="scope">
                <el-button @click="handleShow(scope.$index, scope.row)" type="text">查看</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination text-right m-t-14" v-if="!!totalCount">
            <el-pagination small :page-size="pageSize" :current-page="currentPage" layout="prev, pager, next" :total="totalCount" @size-change="handleSizeChange" @current-change="handleCurrentChange"> </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import navBread from '@/components/nav/nav-bread.vue';
import { getRequest } from '@/api/api';
import { _debounce } from '@/assets/js/public';
import errMsg from '@/assets/js/error';
export default {
  name: 'releaseRecords',
  components: {
    navBread
  },
  data() {
    return {
      // 面包屑参数
      navPath: [
        {
          name: '发布记录',
          path: ''
        }
      ],
      searchValue: '',
      tableData: [
        /* {
          publishId: '1',
          publishName: '测试',
          apiName: '测试',
          publishVersion: 'V1.0.1',
          env: '测试',
          describe: '描述内容',
          createDate: 1564455643252
        } */
      ],
      pageSize: 20,
      currentPage: 1,
      totalCount: 0
    };
  },
  methods: {
    /**
     *  搜索
     */
    searchData: _debounce(function(value) {
      const that = this;
      that.currentPage == 1;
      that.getData();
    }, 500),

    /**
     *  搜索清除
     */
    clearInput() {
      this.currentPage = 1;
      this.getData();
    },
    /**
     *  分页
     */
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getData();
    },
    /**
     * 查看定义详情页
     */
    handleShow(index, row) {
      const that = this;
      that.$router.push(`/apiListManageShow?editFlag=0&interfaceId=${row.interfaceId}&interfaceName=${row.interfaceName}&interfaceVersionId=${row.interfaceVersionId}&publishRecordId=${row.publishRecordId}&projectId=${row.projectId}&projectName=${row.projectName}&interfaceGroupId=${row.interfaceGroupId}&interfaceGroupName=${row.interfaceGroupName}`);
    },
    /**
     *  获取数据
     */
    getData() {
      const that = this;
      let para = {
        search: that.searchValue,
        pageNum: that.currentPage,
        pageSize: that.pageSize
      };
      getRequest('/gateway-manage/page-api-publish-record', para)
        .then(res => {
          let resData = res.data;
          if (resData.code == '0000') {
            that.tableData = resData.result.result || [];
            that.totalCount = resData.result.totalCount;
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {
    $route: {
      handler: function(val, oldVal) {},
      // 深度观察监听
      deep: true
    }
  },

  /* 接收数据 */
  mounted() {
    const that = this;
    that.$emit('showTab', 4);
    that.getData();
  }
};
</script>

<style lang="less" scoped>
.w-320 {
  width: 320px;
}
.m-t-14 {
  margin-top: 14px;
}
</style>
