<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <div class="filter-container">
      <div class="filter-control">
        <span>图片标题:</span>
        <el-input v-model="listQuery.imageTitle" placeholder="图片标题" @keyup.enter.native="getList" />
      </div>
      <div class="filter-control">
        <span>审核状态:</span>
        <el-select v-model="listQuery.auditStatus" placeholder="审核状态" clearable @change="getList">
          <el-option label="全部" value="" />
          <el-option label="待审核" :value="2" />
          <el-option label="审核通过" :value="1" />
          <el-option label="审核未通过" :value="0" />
        </el-select>
      </div>
      <div class="filter-control">
        <el-button type="primary" @click="getList">查询</el-button>
      </div>
    </div>
    <!-- 搜索区域END -->
    <!-- 表格区域 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      style="width: 100%"
      border
      fit
      highlight-current-row
      cell-class-name="table-cell"
      header-row-class-name="tableHeader"
    >
      <el-table-column label="序号" type="index" :index="indexMethod" width="80" align="center" />
      <el-table-column label="图片标题" prop="imageTitle" align="center" />
      <el-table-column label="审核状态" width="120px" align="center">
        <template slot-scope="{ row }">
          <audit-status :status="row.auditStatus" :reason="row.invalidReason" />
        </template>
      </el-table-column>
      <el-table-column label="审核时间" width="160px" align="center">
        <template slot-scope="{ row }">
          <span v-if="row.auditStatus !== 2">{{ row.auditTime | formatTime }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>

      <el-table-column label="审核人" align="center" width="280px">
        <template slot-scope="{ row }">
          <span v-if="row.auditStatus !== 2">{{ row.auditBy }}</span>
          <span v-else>—</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150px" align="center">
        <template slot-scope="{ row }">
          <!-- <el-button
            v-if="row.auditStatus !== 1"
            type="primary"
            size="mini"
            @click="navigationTo(`/audit/material/image-detail?imageId=${row.imageId}`)"
          >审核</el-button>
          <span v-else class="status success el-icon-check">&nbsp;已审核</span> -->
          <audit-button-group type="audit" :is-dot="true" :margin-right="false" @click="onClick(row, $event)" />
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格区域END -->
    <!-- 页码 -->
    <pagination
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getList(listQuery)"
    />
  </div>
</template>

<script>
import { getImageList } from '@/api/doc'
export default {
  data() {
    return {
      listLoading: false, // 列表加载
      total: 0, // 图片总条数
      listQuery: {
        authUserId: '', // 机构id
        auditStatus: '', // 审核状态
        imageTitle: '', // 图片标题
        listType: 2, // 列表类型
        pageNum: 1, // 页码
        pageSize: 10, // 分页大小
        status: '' // 文章状态：0已下线，1已上线，2待上线
      },
      list: []
    }
  },
  created() {
    this.listQuery.authUserId = this.$route.query.authUserId
    this.getList()
  },
  methods: {
    // 按钮组点击事件
    onClick(row, type) {
      const actions = {
        review: this.onReview,
        result: this.onResult,
        audit: this.onAudit
      }
      actions[type](row)
    },

    // 预览
    onReview(row) {
      console.log('预览')
      this.$router.push(`/audit/material/image-detail?imageId=${row.imageId}&type=review`)
    },
    // 驳回
    onResult(row) {
      console.log('驳回')
    },
    // 审核
    onAudit(row) {
      this.$router.push(`/audit/material/image-detail?imageId=${row.imageId}&type=audit`)
    },
    // 获取列表数据
    getList() {
      this.listLoading = true
      getImageList(this.listQuery)
        .then(res => {
          if (res.code !== 0) return
          this.list = res.data.list
          this.total = res.data.total
          console.log(res)
        })
        .finally(() => {
          this.listLoading = false
        })
    },
    indexMethod(index) {
      return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
    }
  }
}
</script>

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