<template>
  <div class="app-container">
    <!-- 顶部操作区域 -->
    <div class="filter-container">
      <div class="filter-control">
        <span>合同编号:</span>
        <el-input
          v-model="listQuery.contractId"
          placeholder=""
          clearable
          @keyup.enter.native="getList"
          @clear="getList"
        />
      </div>
      <div class="filter-control">
        <span>授权起止日期:</span>
        <el-date-picker
          v-model="time"
          type="daterange"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          @change="getList"
        />
      </div>
      <div class="filter-control">
        <el-button type="primary" @click="getList">查询</el-button>
        <el-button type="primary" @click="$router.push('/service/settlement/contract/edit?providersId=' + providersId)">添加</el-button>
      </div>
    </div>
    <el-table
      ref="table"
      v-loading="isLoading"
      :data="list"
      border
      :default-sort="{ prop: 'frequency', order: 'descending' }"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        label="序号"
        type="index"
        sortable="custom"
        align="center"
        width="80"
      />
      <el-table-column prop="contractId" label="合同编号" align="center" />
      <el-table-column prop="contractStartDate" label="合同起始日期" align="center" />
      <el-table-column prop="contractEndDate" label="合同截止日期" align="center" />
      <el-table-column prop="updateTime" label="添加时间" align="center" />
      <el-table-column prop="createBy" label="创建人" align="center" />
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button
            v-if="scope.$index === 0"
            type="primary"
            size="mini"
            @click="checkout(scope)"
          >编辑</el-button>
          <el-button
            v-else
            type="primary"
            size="mini"
            @click="$router.push('/service/settlement/contract/edit?id=' + scope.row.id + '&providersId=' + providersId + '&isCheck=1')"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 页码 -->
    <pagination
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getContractList } from '@/api/serviceSettlement/contract'

export default {
  data() {
    return {
      listQuery: {
        pageNum: 1,
        pageSize: 30
      },
      time: '',
      list: [],
      indexMethod: 0,
      total: 10,
      isLoading: false
    }
  },
  computed: {
    providersId() {
      return this.$route.query.providersId || false
    }
  },
  mounted() {
    if (this.providersId) {
      this.getList()
    }
  },
  methods: {
    async getList(obj) {
      const form = Object.assign(this.listQuery, {
        contractStartDate: obj ? obj[0] : '',
        contractEndDate: obj ? obj[1] : '',
        providersId: this.providersId || ''
      })
      const { data } = await getContractList(form)
      this.list = data.results
    },
    handleSelectionChange() {},
    checkout(row) {
      console.log(row)
      this.$router.push('/service/settlement/contract/edit?id=' + row.row.id + '&providersId=' + this.providersId)
    }
  }
}
</script>

<style lang="scss" scoped></style>
