<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-07-22 19:43:22
 * @LastEditors: 无尘
 * @LastEditTime: 2020-09-23 16:14:12
 -->
<template>
  <div class="api-body-content border-box">
    <div class="common-nav">
      <nav-bread :nav-path="navPath" />
    </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
            v-model="searchValue"
            clearable
            class="w-320"
            placeholder="请输入版本号/API名称"
            @keyup.native="value => searchData(value)"
            @clear="clearInput">
            <i
              slot="prefix"
              class="el-input__icon el-icon-search" />
          </el-input>
        </div>
        <div class="table-wrap">
          <el-table
            v-loading="loading"
            :data="tableData"
            style="width: 100%">
            <el-table-column
              prop="publishRecordId"
              label="发布版本"
              show-overflow-tooltip />
            <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
                  type="text"
                  @click="handleShow(scope.$index, scope.row)">
                  查看
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div
            v-if="!!totalCount"
            class="pagination text-right m-t-14">
            <dm-pagination
              small
              :page-size="pageSize"
              :current-page="currentPage"
              layout="prev, pager, next"
              :total="totalCount"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange" />
          </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: '',
      loading: true,
      tableData: [
        /* {
          publishId: '1',
          publishName: '测试',
          apiName: '测试',
          publishVersion: 'V1.0.1',
          env: '测试',
          describe: '描述内容',
          createDate: 1564455643252
        } */
      ],
      pageSize: 20,
      currentPage: 1,
      totalCount: 0
    };
  },
  /* 接收数据 */
  mounted() {
    const that = this;
    that.$emit('showTab', 4);
    that.getData();
  },
  methods: {
    /**
     * @description: 搜索
     * @author: 无尘
     */
    searchData: _debounce(function() {
      const that = this;
      that.currentPage == 1;
      that.getData();
    }, 500),

    /**
     * @description: 搜索清除
     * @author: 无尘
     */
    clearInput() {
      this.currentPage = 1;
      this.getData();
    },
    /**
     * @description: 分页
     * @param {Number} val
     * @author: 无尘
     */
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getData();
    },
    /**
     * @description: 查看定义详情页
     * @param {Number} index
     * @param {Object} row
     * @author: 无尘
     */
    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}`);
    },
    /**
     * @description: 获取数据
     * @author: 无尘
     */
    getData() {
      const that = this;
      that.loading = true;
      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;
          that.loading = false;
          if (resData.code == '0000') {
            that.tableData = resData.result.result || [];
            that.totalCount = resData.result.totalCount;
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.loading = false;
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {
    $route: {
      handler: function(val, oldVal) {},
      // 深度观察监听
      deep: true
    }
  },

};
</script>

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