<template>
  <div>
    <el-card>
      <div>
        项目:
        <el-select v-model="selectProjectId" placeholder="请选择项目" @change="selectChange">
          <el-option v-for="item in projectList" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
        模块:
        <el-select v-model="interfaceDetailForm.moduleId" placeholder="请选择模块">
          <el-option v-for="item in modelList" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
        <el-input v-model="interfaceName" clearable placeholder="请输入接口名称" style="width: 300px;"></el-input>
        <el-button type="primary" style="margin-left:20px" @click="queryData">查询</el-button>
        <el-button type="primary" style="margin-left:20px" @click="addPage">新增</el-button>
      </div>
      <el-table :data="interfaceList" border style="width: 100%;margin-top:20px">
        <el-table-column type='index' width="50px"></el-table-column>
        <el-table-column prop="name" label="接口名称" width="200px"></el-table-column>
        <el-table-column prop="moduleName" label="所属模块" width="200px"></el-table-column>
        <el-table-column prop="url" label="接口路径" width="300px"></el-table-column>
        <el-table-column prop="method" label="请求方式" width="100px"></el-table-column>
        <el-table-column prop="paramType" label="参数类型" width="100px"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="200px"></el-table-column>
        <el-table-column prop="updateTime" label="修改时间" width="200px"></el-table-column>
        <el-table-column label="操作">
          <slot slot-scope="scope">
            <el-button type="success" @click="openEditDialog(scope.row)">编辑</el-button>
            <el-button type="danger" @click="delModelFrom(scope.row)">删除</el-button>
          </slot>
        </el-table-column>
      </el-table>
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="queryModuleInfo.pageNum" :page-size="queryModuleInfo.pageSize" layout="total, prev, pager, next"
        :total="totalNum"></el-pagination>
    </el-card>
  </div>
</template>

<script>
import {
  getModulList,
  getProjectList,
  interfaceDetailList
} from '@/api/getAotoInterface'
export default {
  data() {
    return {
      queryModuleInfo: {
        pageNum: 1,
        pageSize: 10,
        projectId: ''
      },
      totalNum: 0,
      projectList: [],
      modelList: [],
      // 下来项目id
      selectProjectId: '',
      interfaceName: '',
      interfaceList: [],
      interfaceDetailForm: {}
    }
  },
  created() {
    this.getProjectList()
    this.getInterfaceDetailList()
  },
  methods: {
    // 项目列表
    getProjectList() {
      getProjectList(this.queryModuleInfo).then((resp) => {
        this.projectList = resp.data.data.list
      })
    },

    // 下来框选中改变事件
    selectChange() {
      this.queryModuleInfo.projectId = this.selectProjectId
      getModulList(this.queryModuleInfo).then((resp) => {
        this.modelList = resp.data.data.list
      })
    },
    // 查询方法
    queryData() {},
    // 添加跳转页面
    addPage() {
      this.$router.push('AddInterface')
    },
    // 获取接口列表
    getInterfaceDetailList() {
      interfaceDetailList(this.queryModuleInfo).then((resp) => {
        this.interfaceList = resp.data.data.list
      })
    },
    handleSizeChange(newSize) {
      this.queryModuleInfo.pageSize = newSize
      this.getInterfaceDetailList()
    },
    handleCurrentChange(newPage) {
      this.queryModuleInfo.pageNum = newPage
      this.getInterfaceDetailList()
    }
  }
}
</script>
