<template>
  <div class="leo-dec-table" v-loading="loading">
    <div class="filter-box">
      <filter-user :filter-types="filterTypes" @select-value="handleFilterUser"></filter-user>
    </div>
    <el-table ref="multipleTable" :data="tableData" stripe style="width: 100%;" :height="tool.getTableHeight(true)">
      <el-table-column prop="DEC_SN" label="报单编号" width="180"></el-table-column>
      <el-table-column prop="ORDER_SN" label="订单编号" width="180"></el-table-column>
      <el-table-column label="会员编号">
        <template slot-scope="scope">
          {{scope.row.BASE_INFO.USER_NAME}}
        </template>
      </el-table-column>
      <el-table-column label="报单主体编号" width="150">
        <template slot-scope="scope">
          {{scope.row.BASE_INFO.DEC_USER_NAME}}
        </template>
      </el-table-column>
      <el-table-column label="报单类型">
        <template slot-scope="scope">
          {{scope.row.TYPE === 'ZG' && scope.row.IS_UPGRADE === '1' ? '升级单' : showType[scope.row.TYPE]}}
        </template>
      </el-table-column>
      <el-table-column label="是否管理员报单" width="120">
        <template slot-scope="scope">
          {{scope.row.IS_ADMIN === '1' ? '是' : '否'}}
        </template>
      </el-table-column>
      <el-table-column label="报单金额">
        <template slot-scope="scope">
          {{tool.formatPrice(scope.row.DEC_AMOUNT)}}
        </template>
      </el-table-column>
      <el-table-column label="报单PV">
        <template slot-scope="scope">
          {{tool.formatPrice(scope.row.DEC_PV)}}
        </template>
      </el-table-column>
      <el-table-column prop="PERIOD_NUM" label="期数" width="150"></el-table-column>
      <el-table-column label="报单时间" width="170">
        <template slot-scope="scope">
          {{tool.formatDate(scope.row.CREATED_AT)}}
        </template>
      </el-table-column>
    </el-table>
    <div class="white-box-footer">
      <el-button type="primary" size="small" @click="handleExport">导出Excel</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 Pagination from '@/components/Pagination'
import filterHelper from '../../utils/filterHelper'

const TYPE = {
  ZC: '首购',
  ZG: '增购',
  SJ: '升级',
  LS: '零售',
  FX: '复销',
}

export default {
  name: 'leo-dec-table',
  components: {FilterUser,Pagination},
  props: {
    type: {
      type: String,
      default: ''
    },
  },
  mounted () {
    this.getData()
  },
  data () {
    return {
      tableData: null,
      loading: true,
      multipleSelection: [],
      currentPage: 1,
      totalPages: 1,
      totalCount: 1,
      pageSize: 20,
      tool: tool,
      showType: TYPE,
      filterTypes: {
        'USER_NAME': {isUserTable: true, name: '会员编号'},
        'REAL_NAME': {isUserTable: true, name: '会员姓名'},
        'ID_CARD': {isUserTable: true, name: '身份证'},
        'MOBILE': {isUserTable: true, name: '手机号'},
      },
      filterModel: {},
    }
  },
  methods: {
    handleExport () {
      this.$confirm('确定要导出当前表格中的数据吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        return network.getData('report/dec-export', {type: this.type})
      }).then(response => {
        this.$message({
          message: response,
          type: 'success'
        })
      }).catch(response => {
      })
    },
    handleCurrentChange (page) {
      this.getData(page, this.pageSize)
    },
    handleSizeChange (pageSize) {
      this.getData(this.currentPage, pageSize)
    },
    handleFilterUser(filterData){
      filterHelper.handleFilterUser(this, filterData)
    },
    getData (page, pageSize) {
      let filterData = this.filterModel
      filterData.filterType = this.type != '' ? `=,${this.type}` : ''
      network.getPageData(this, 'report/dec', page, pageSize, filterData)
    },
  }
}
</script>

<style>
  .leo-withdrawTable .el-form-item__label {
    width: 100px;
    color: #99a9bf;
  }

  .leo-withdrawTable .el-form-item {
    width: 40%;
    margin-right: 0;
    margin-bottom: 0;
  }
</style>
