<template>
  <div>
    <div class="filter-box">
      <filter-user :filter-types="filterTypes" @select-value="handleFilterUser"></filter-user>
    </div>
    <el-table :data="tableData" stripe style="width: 100%;" @selection-change="handleSelectionChange" v-loading="loading" :height="tool.getTableHeight()">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="会员编号" width="">
        <template slot-scope="scope">
          <el-tag size="small" class="no-border">{{scope.row.BASE_INFO.USER_NAME}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="会员姓名" width="">
        <template slot-scope="scope">
          <el-tag type="success" size="small" class="no-border">{{scope.row.BASE_INFO.REAL_NAME}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="会员状态" width="">
        <template slot-scope="scope">
          {{(scope.row.BASE_INFO.STATUS_NAME)}}
        </template>
      </el-table-column>
      <el-table-column label="结算月" prop="CALC_MONTH" width="">
        <template slot-scope="scope">
          <el-tag type="danger" size="small" class="no-border">{{scope.row.CALC_MONTH}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-tag :type="tool.statusType(scope.row.AUDIT_STATUS)">{{scope.row.STATUS_NAME}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作管理员" width="">
        <template slot-scope="scope">
          {{scope.row.CREATE_ADMIN_NAME}}
        </template>
      </el-table-column>
      <el-table-column label="操作时间" width="">
        <template slot-scope="scope">
          {{tool.formatDate(scope.row.CREATED_AT)}}
        </template>
      </el-table-column>
      <el-table-column label="备注">
        <template slot-scope="scope">
          {{scope.row.CREATE_REMARK}}
        </template>
      </el-table-column>
    </el-table>
    <div class="white-box-footer">
      <el-button type="primary" size="small" @click="handleAdd" icon="el-icon-plus" v-show="permission.hasPermission(`reconsume/deduct-audit-add`)">申请扣除当月复销</el-button>
      <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
    </div>
  </div>
</template>

<script>
import network from '@/utils/network'
import tool from '@/utils/tool'
import FilterUser from '@/components/FilterUser'
import baseInfo from '@/utils/baseInfo'
import permission from '@/utils/permission'
import Pagination from '@/components/Pagination'
import filterHelper from '../../utils/filterHelper'

export default {
  name: 'reconsume_deduct-audit-list-table',
  components: {FilterUser,Pagination},
  mounted () {
    this.getData()
  },
  props: {
    status: {
      type: Number,
      default: 1,
    }
  },
  data () {
    return {
      allData: null,
      tableData: null,
      loading: true,
      multipleSelection: [],
      currentPage: 1,
      totalPages: 1,
      totalCount: 1,
      pageSize: 20,
      tool: tool,
      permission: permission,
      filterTypes: {
        'USER_NAME': {isUserTable: true, name: '会员编号'},
        'REAL_NAME': {isUserTable: true, name: '会员姓名'},
        'ID_CARD': {isUserTable: true, name: '身份证'},
        'MOBILE': {isUserTable: true, name: '手机号'},
      },
      filterModel: {},
      baseInfo: baseInfo,
    }
  },
  methods: {
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    handleCurrentChange (page) {
      this.getData(page, this.pageSize)
    },
    handleSizeChange (pageSize) {
      this.getData(this.currentPage, pageSize)
    },
    handleAdd () {
      this.$router.push({path: `/reconsume/deduct-audit-add`})
    },
    handleAudit (row, status) {
      let title = '确定要通过审核？请输入备注：'
      if(status === 'reject'){
        title = '确定要拒绝审核？请输入备注：'
      }
      this.$prompt(title, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        //type: 'warning',
        inputType: 'textarea',
        inputValue:row.CREATE_REMARK,
      }).then(({value}) => {
        return network.postData(`reconsume/deduct-audit/${row.ID}`, {remark: value, auditStatus: status})
      }).then(response => {
        this.$message({
          message: response,
          type: 'success'
        })
        this.getData(this.currentPage, this.pageSize)
      }).catch(response => {

      })
    },
    handleFilterUser(filterData){
      filterHelper.handleFilterUser(this, filterData)
    },
    getData (page, pageSize) {
      let filterData = this.filterModel
      filterData.filterStatus = this.status != -1 ? `=,${this.status}` : ''
      network.getPageData(this, 'reconsume/deduct-audit-list', page, pageSize, filterData)
    },
  },
}
</script>

<style scoped>

</style>
