<template>
  <div class="branch">
    <el-table
      height="670"
      :data="dataList"
      style="width: 100%">
      <el-table-column
        prop="name"
        header-align="left"
        align="left"
        label="接口名称">
      </el-table-column>
      <el-table-column
        prop="for"
        header-align="left"
        align="left"
        label="用途">
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="操作">
        <template slot-scope="scope">
          <el-button v-if="isAuth('sys:user:update')" type="success" size="mini" @click="addOrUpdateHandle(scope.row)">测试</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 30, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalPage">
      </el-pagination>
    </div>
    <el-dialog
      title="测试"
      :close-on-click-modal="false"
      :visible.sync="visible"
      @close="cancel">
      <template v-if="row.type === 0">
        <el-form :model="form0" ref="form" @keyup.enter.native="formSubmit()" label-width="80px">
          <el-form-item label="耳标号" prop="pigEarTagNo">
            <el-input v-model="form0.pigEarTagNo" placeholder="年猪耳标号"></el-input>
          </el-form-item>
        </el-form>
      </template>
      <template v-else>
        <el-form :model="form1" ref="form" @keyup.enter.native="formSubmit()" label-width="80px">
          <el-form-item label="品种" prop="breedName">
            <el-input v-model="form1.breedName" placeholder="品种名称"></el-input>
          </el-form-item>
        </el-form>
      </template>
      
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="formSubmit()">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data () {
    return {
      dataForm: {
        key: ''
      },
      dataList: [
        {
          name: 'testGetPigInfo',
          for: '获取年猪信息',
          type: 0
        },
        {
          name: 'testGetImage',
          for: '获取年猪图片',
          type: 0
        },
        {
          name: 'testGetListByBreed',
          for: '根据品种获取年猪信息',
          type: 1
        },
        {
          name: 'testGetIndoorEnv',
          for: '获取室内环境',
          type: 0
        },
        {
          name: 'testAdopt',
          for: '获取认养情况',
          type: 0
        },
        {
          name: 'testOutFence',
          for: '获取出栏情况',
          type: 0
        }
      ],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      visible: false,
      form0: {
        pigEarTagNo: ''
      },
      form1: {
        breedName: '',
        currentPage: '',
        pageSize: ''
      },
      row: [],
      api: '',
    }
  },
  methods: {
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 新增 or 修改牧场
    addOrUpdateHandle (row) {
      this.visible = true
      this.form0 = {}
      this.form1 = {}
      this.row = row
    },
    formSubmit() {
      let form = {}
      this.row.type === 0? form = this.form0: form = this.form1
      this.$http({
        url: this.$http.adornUrl('/management/localTest/' + this.row.name),
        method: 'get',
        params: this.$http.adornParams(form)
      }).then(result => {
        this.$confirm(result.data.msg, '返回信息', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          console.log('接口测试');
          this.visible = false
        }).catch(() => {})
      })
    },
    // 清空form
    resetForm () {
      this.form = {}
      this.row = []
      this.api = ''
    },
    // 取消
    cancel () {
      this.visible = false
      this.resetForm()
    },
  }
}
</script>
<style scoped>
</style>