<template>
  <div class="root">
    <el-form :inline="true" :model="listQuery" class="form-listQuery">
      <el-form-item class="filter-item" label="举报人姓名" >
        <el-input v-model.trim="listQuery.taUserName" placeholder="举报人姓名" />
      </el-form-item>
      <el-form-item class="filter-item" label="举报人手机号" >
        <el-input v-model.trim="listQuery.reportPhone" placeholder="举报人手机号" />
      </el-form-item>
      <el-form-item>
        <el-button type="info" class="filter-item" @click="handleFilter">清空</el-button>
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="listLoading"
      ref="multipleTable"
      :data="transactionsList"
      border
      tooltip-effect="dark"
      style="width: 100%; margin-top: 20px;"
      @selection-change="handleSelectionChange">
      <el-table-column prop="reason" label="举报原因" align="center"/>
      <el-table-column prop="reportUserName" label="举报人姓名" align="center"/>
      <el-table-column prop="description" label="举报人身份" align="center"/>
      <el-table-column prop="reportPhone" label="举报人手机号" align="center"/>
      <el-table-column prop="createDate" label="举报时间" align="center"><template slot-scope="scope">{{ formatDate(scope.row.createDate) }}</template></el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        :current-page.sync="listQuery.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size.sync="listQuery.pageSize"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'

export default {
  data() {
    return {
      listQuery: {
        createDate: '',
        description: '',
        reason: '',
        reportPhone: '',
        reportReasonId: '',
        reportUserName: '',
        reporterId: '',
        transactionId: '',
        replyTaUserName:'', 
        pageNum: '1',
        pageSize: 10,
      },
      transactionsList:[],
      total: 0, // 数据总数
      deleteIds: [], // 选择的id集合
      listLoading: true // 加载圈
    }
  },
  mounted() {
    this.listQuery.transactionId = this.$route.query.id
    // 获取数据
    this.dataQuery()
  },
  methods: {
    ...mapActions('listAnnouncement', [
      'BserPassCertification'
    ]),
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.listQuery.pageSize = val
      this.dataQuery()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.listQuery.pageNum = val
      this.dataQuery()
    },
    padDate(value) {
      value = value < 10 ? '0' + value : value
      return value
    },
    dataQuery() { // 查询数据
      this.listLoading = true
      this.$store.dispatch('transaction/TransactionReportList', this.listQuery).then((res) => {
        const resData = res.data
        this.transactionsList = resData.list
        this.listQuery.pageNum = resData.pageNum
        this.listQuery.pageSize = resData.pageSize
        this.total = resData.total
        this.listLoading = false
      }).catch(() => {
        this.listLoading = false
        console.log('error TransactionsList')
      })
    },
    handleSelectionChange(data) {
      // 设置为 空
      this.deleteIds = []
      for (let i = 0; i < data.length; i++) {
        this.deleteIds.push(data[i].id)
      }
    },
	  search() {
      this.listQuery.pageNum = 1
      this.dataQuery()
    },
    handleFilter() {
      this.listQuery.pageNum = 1
      this.listQuery.pageSize = 10
      this.listQuery.taUserName = ''
       this.listQuery.reportPhone = ''
      this.dataQuery()
    },
    formatDate(val) {
      if (val === null) {
        return ''
      }
      var value = new Date(val)
      var year = value.getFullYear()
      var month = value.getMonth() + 1
      var day = value.getDate()
      return year + '-' + month + '-' + day
    }
  }
}
</script>

<style scoped>
.root{
  display: flex;
  flex-flow: column;
}
.form-listQuery{
  margin-top: 20px;
  margin-left: 30px;
}
.operation{
  display: flex;
  justify-content: space-between;
  margin-left: 20px;
  margin-right: 20px;
}
.block{
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}
.button {
  margin-left: 20px;
}
.textarea-inherit {
        width: 100%;
        overflow: auto;
        word-break: break-all; 
    }
</style>

