<template>
  <div v-loading="loading">
    <div class="white-box">
      <el-tabs v-model="filterStatus" @tab-click="handleFilterStatusClick">
        <el-tab-pane label="全部" name="ALL" :lazy="true"></el-tab-pane>
        <el-tab-pane label="订货店补" name="ORDER" :lazy="true"></el-tab-pane>
        <el-tab-pane label="转账店补" name="TRANS" :lazy="true"></el-tab-pane>
        <el-tab-pane label="产品补贴" name="PROD" :lazy="true"></el-tab-pane>
        <el-tab-pane label="工具流补贴" name="TOOL" :lazy="true"></el-tab-pane>
      </el-tabs>
      <trace-bt-filter :filter="handleFilter"></trace-bt-filter>
      <el-table class="table-box" ref="multipleTable" :data="tableData" stripe style="width: 100%;" :height="tool.getTableHeight(true)">
        <el-table-column v-for="(tableHeader, key) in tableHeaders" :key="key" :label="tableHeader.header" :width="tableHeader.other.width ? tableHeader.other.width : ''" :prop="tableHeader.other.prop ? tableHeader.other.prop : null">
          <template slot-scope="scope">
            <template v-if="scope.row[tableHeader.index].other.tag" >
              <el-tag :type="scope.row[tableHeader.index].other.tag.type ? scope.row[tableHeader.index].other.tag.type : null" :size="scope.row[tableHeader.index].other.tag.size ? scope.row[tableHeader.index].other.tag.size : null" :class="scope.row[tableHeader.index].other.tag.class ? scope.row[tableHeader.index].other.tag.class : null" >{{scope.row[tableHeader.index].value}}</el-tag>
            </template>
            <template v-else>
              <div v-html="scope.row[tableHeader.index].value"></div>
            </template>
          </template>
        </el-table-column>
      </el-table>
      <div class="white-box-footer">
        <el-button type="success" size="small" @click="handleExport" v-show="permission.hasPermission(`bonus/trace-bt-export`)">Export Excel</el-button>
        <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
      </div>
    </div>
  </div>
</template>

<script>
  import network from '@/utils/network'
  import tool from '@/utils/tool'
  import baseInfo from '@/utils/baseInfo'
  import permission from '@/utils/permission'
  import TraceBtFilter from './trace-bt-filter'
  import Pagination from '@/components/Pagination'

  export default {
    name: 'bonus_trace-bt',
    components: {TraceBtFilter,Pagination},
    mounted() {
      this.loading = false
    },
    data() {
      return {
        tableHeaders: null,
        tableData: null,
        loading: true,
        multipleSelection: [],
        currentPage: 1,
        totalPages: 1,
        totalCount: 1,
        pageSize: 20,
        tool: tool,
        permission: permission,
        filterData: null,
        filterStatus: 'ALL',
        allType:{ORDER:'订货店补',TRANS:'转账店补',PROD:'产品补贴',TOOL:'工具流补贴'}
      }
    },
    methods: {
      getBtTypeName(type){
        console.log(type)
        return this.allType[type]
      },
      handleFilterStatusClick(tab, event) {
        if(!this.filterData) return
        this.filterData.filterStatus =this.filterStatus!=='ALL'?this.filterStatus:null
        this.getData()
      },
      handleCurrentChange(page) {
        this.getData(page, this.pageSize)
      },
      handleSizeChange(pageSize) {
        this.getData(this.currentPage, pageSize)
      },
      handleFilter(model) {
        this.filterData = model
        this.filterData.filterStatus =this.filterStatus!=='ALL'?this.filterStatus:null
        this.getData(1, this.pageSize)
      },
      getData(page, pageSize) {
        let vueObj = this
        network.getPageData(this, 'bonus/trace-bt', page, pageSize, this.filterData, function (response) {
          vueObj.tableData = response.list
        })
      },
      handleExport(){
        this.$confirm(`确定要导出当前数据吗？`, 'Notice', {
          confirmButtonText: 'confirm', // 确定
          cancelButtonText: 'cancel', // 取消
          type: 'warning'
        }).then(() => {
          return network.getData(`bonus/trace-bt-export`, this.filterData)
        }).then(response => {
          this.$message({
            message: response,
            type: 'success'
          })
        }).catch(response => {

        })
      },
    }
  }

</script>

<style scoped>
  .table-box .el-form-item__label {
    width: 100px;
    color: #99a9bf;
  }

  .table-box .el-form-item {
    width: 30%;
    margin-right: 0;
    margin-bottom: 0;
  }
</style>
