<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <div class="filter-container">
      <div class="filter-control">
        <span>设备名称:</span>
        <el-input v-model="listQuery.productName" placeholder="请输入设备名称" @keyup.enter.native="getList" />
      </div>
      <div class="filter-control">
        <span>设备SN码:</span>
        <el-input v-model="listQuery.snCode" placeholder="请输入设备SN码" @keyup.enter.native="getList" />
      </div>
      <div class="filter-control">
        <permission-button type="primary" @click="getList">查询</permission-button>
      </div>
    </div>
    <!-- 搜索区域END -->
    <!-- 表格区域 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      style="width: 100%"
      border
      fit
      highlight-current-row
      header-row-class-name="tableHeader"
      cell-class-name="table-cell"
    >
      <el-table-column :index="indexMethod" label="序号" type="index" width="80" align="center" />
      <el-table-column prop="productName" label="设备名称" align="center" />
      <el-table-column prop="snCode" label="设备SN码" align="center" />
      <el-table-column label="审核状态" width="120px" align="center">
        <template slot-scope="{ row }">
          <audit-status :status="row.shopAuditStatus" :reason="row.invalidReason" />
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.shopAuditStatus !== 2">{{ row.shopAuditBy }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" width="160px" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.shopAuditStatus !== 2">{{ row.shopAuditTime | formatTime }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>
      <el-table-column label="注册时间" width="160px" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.shopAuditStatus !== 2">{{ row.createTime | formatTime }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="240px" align="center">
        <template slot-scope="{ row }">
          <permission-button
            v-if="row.shopAuditStatus !== 1"
            type="primary"
            size="mini"
            @click="onClick(row, 'audit')"
          >审核</permission-button>
          <permission-button v-else type="primary" size="mini" @click="onClick(row, 'review')">查看</permission-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格区域END -->
    <!-- 页码 -->
    <pagination :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { getProdList } from '@/api/product'
export default {
  props: {
    shopAuditStatus: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      listLoading: false,
      listQuery: {
        listType: 3,
        authId: '',
        productName: '',
        snCode: '',
        pageNum: 1,
        pageSize: 10,
        shopAuditStatus: 0
      },
      total: 0,
      list: []
    }
  },
  created() {
    this.listQuery.authId = this.$route.query.authId
    this.getList()
  },
  methods: {
    // 过滤列表
    handleFilter() {},
    // 获取列表信息
    getList() {
      this.listQuery.shopAuditStatus = this.shopAuditStatus
      this.listLoading = true
      getProdList(this.listQuery)
        .then((res) => {
          if (res.code !== 0) return
          this.total = res.data.total
          this.list = res.data.list
        })
        .finally(() => {
          this.listLoading = false
        })
    },
    onClick(row, type) {
      this.$router.push(
        `/supplier-audit/club/device-detail?id=${row.productId}&authId=${this.listQuery.authId}&type=${type}`
      )
    },
    indexMethod(index) {
      return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
    }
  }
}
</script>

<style lang="scss" scoped>
.el-table .cell {
  overflow: visible;
}
</style>
