<template>
  <div v-loading="loading">
    <div class="white-box">
      <el-tabs v-model="filterStatus" @tab-click="handleFilterStatusClick">
        <el-tab-pane label="全部" name="0" :lazy="true"></el-tab-pane>
        <el-tab-pane label="复销池余额流水" name="1" :lazy="true"></el-tab-pane>
        <el-tab-pane label="复销池月数流水" name="2" :lazy="true"></el-tab-pane>
      </el-tabs>
      <div class="filter-box">
        <filter-user ref="filterUser" :filter-types="filterTypes" @select-value="handleFilterUser"></filter-user>
      </div>
      <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 : ''"
                         v-if="tableHeader.other.deductType?((tableHeader.other.deductType==='1'&&filterStatus!=='2')||(tableHeader.other.deductType==='2'&&filterStatus!=='1')):true">
          <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-if="scope.row[tableHeader.index].other.progress">
              <el-progress type="circle" :percentage="Number.parseInt(percentList['MOVE_PERCENT'][scope.row.ID])"
                           :width="50"
                           :stroke-width="3"></el-progress>
            </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(`reconsume/flow-list-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 FilterUser from '../../components/FilterUser'
  import Pagination from '@/components/Pagination'
  import permission from '@/utils/permission'
  import filterHelper from '../../utils/filterHelper'

  export default {
    name: 'reconsume_flow-list',
    components: {FilterUser, Pagination},
    mounted() {
      network.getData('reconsume/get-flow-deal-type').then(response => {
        this.dealTypes = response.dealTypes
        this.getData()
      })
    },
    data() {
      return {
        tableHeaders: null,
        tableData: null,
        loading: true,
        multipleSelection: [],
        currentPage: 1,
        totalPages: 1,
        totalCount: 1,
        pageSize: 20,
        tool: tool,
        permission: permission,
        filterTypes: {},
        filterModel: {},
        filterStatus: '0',
        dealTypes: [],
      }
    },
    methods: {
      handleCurrentChange(page) {
        this.getData(page, this.pageSize)
      },
      handleSizeChange(pageSize) {
        this.getData(this.currentPage, pageSize)
      },
      handleFilterStatusClick(tab, event) {
        filterHelper.clearFilterOption(this)
        this.getData()
      },
      handleFilterUser(filterData) {
        filterHelper.handleFilterUser(this, filterData)
      },
      getData(page, pageSize) {
        let filterData = this.filterModel
        filterData.filterStatus = this.filterStatus != '0' ? `=,${this.filterStatus}` : ''
        let vueObj = this
        network.getPageData(this, 'reconsume/flow-list', page, pageSize, filterData, function (response) {
          vueObj.allData = response
          vueObj.filterTypes = response.filterTypes
        })
      },
      handleExport() {
        this.$confirm(`确定要导出当前数据吗？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          return network.getData(`reconsume/flow-list-export`, this.filterModel)
        }).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>
