<template>
  <div v-loading="loading">
    <div class="white-box">
      <el-tabs v-model="filterStatus" @tab-click="handleFilterStatusClick">
        <el-tab-pane label="全部" name="-1" :lazy="true"></el-tab-pane>
        <el-tab-pane label="待申请补发" name="0" :lazy="true"></el-tab-pane>
        <el-tab-pane label="已申请补发" name="1" :lazy="true"></el-tab-pane>
      </el-tabs>
      <div class="filter-box">
        <filter-user ref="filterUser" :filter-types.sync="filterTypes" @select-value="handleFilterUser"></filter-user>
      </div>
      <el-table class="table-box" ref="multipleTable" :data="tableData" stripe style="width: 100%;" @selection-change="handleSelectionChange" :height="tool.getTableHeight(true)">
        <el-table-column type="selection" width="55" v-if="tableHeaders"></el-table-column>
        <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-column fixed="right" label="操作" width="180" v-if="tableHeaders">
          <template slot-scope="scope">
            <el-dropdown size="small" trigger="click" v-if="scope.row.RESEND_STATUS==='0' && permission.hasPermission(`bonus/resend-qy`)">
              <el-button type="primary" size="small" @click.stop="">
                Action<i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleResend(scope.row.ID)"
                                  v-show="scope.row.RESEND_STATUS==='0'">申请补发
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <div class="white-box-footer">
        <el-dropdown size="small" trigger="click" v-if="(filterStatus==='0') && permission.hasPermission(`bonus/resend-qy`)">
          <el-button type="primary" size="small">
            Selected data<!--所选数据--><i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="del" @click.native="handleResend()">批量补发</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <el-button type="success" size="small" @click="handleExport" v-show="permission.hasPermission(`bonus/resend-qy-list-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 TraceDownYcFilter from './trace-down-yc-filter'
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: 'bonus_resend-qy-audit-list',
  components: {TraceDownYcFilter,FilterUser,Pagination},
  mounted () {
    this.getData()
  },
  data () {
    return {
      tableHeaders: null,
      tableData: null,
      loading: true,
      multipleSelection: [],
      currentPage: 1,
      totalPages: 1,
      totalCount: 1,
      pageSize: 20,
      tool: tool,
      permission: permission,
      filterTypes: null,
      filterModel: {},
      baseDecLevels: baseInfo.decLevels(),
      baseEmpLevels: baseInfo.empLevels(),
      filterStatus:'0',
      auditStatus: ['待申请补发', '已申请补发'],
    }
  },
  methods: {
    handleCurrentChange (page) {
      this.getData(page, this.pageSize)
    },
    handleSizeChange (pageSize) {
      this.getData(this.currentPage, pageSize)
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleResend(id = null) {
      if (id === null && this.multipleSelection.length < 1) {
        this.$message({
          message: '请勾选要申请发放的会员',
          type: 'warning'
        })
        return false
      }
      let obj = this
      this.$prompt('确定为所选数据申请补发区域津贴？请填写备注', 'Notice', {
        confirmButtonText: 'confirm', // 确定
        cancelButtonText: 'cancel', // 取消
        inputValue: '',
        type: 'warning'
      }).then(({value}) => {
        let selectedIds = []
        if (id === null) {
          for (let val of obj.multipleSelection) {
            selectedIds.push(val.ID)
          }
        } else {
          selectedIds.push(id)
        }
        return network.postData(`bonus/resend-qy`, {
          selectedIds: selectedIds,
          remark: value,
        })
      }).then(response => {
        this.$message({
          message: response,
          type: 'success'
        })
        obj.getData(obj.currentPage, obj.pageSize)
      }).catch(response => {

      })
    },
    handleFilterStatusClick(tab, event) {
      filterHelper.clearFilterOption(this)
      this.getData()
    },
    handleFilterUser(filterData) {
      filterHelper.handleFilterUser(this, filterData)
    },
    handleFilter() {
      this.getData()
    },
    getData(page, pageSize) {
      let filterData = this.filterModel
      filterData.filterStatus = this.filterStatus != '-1' ? `=,${this.filterStatus}` : ''
      let vueObj = this
      network.getPageData(this, 'bonus/resend-qy-list', page, pageSize, filterData, function (response) {
        vueObj.filterTypes = response.filterTypes
        vueObj.allData = response
      })
    },
    handleExport(){
      this.$confirm(`Are you sure you want to export the current data？`, 'Notice', {
        confirmButtonText: 'confirm', // 确定
        cancelButtonText: 'cancel', // 取消
        type: 'warning'
      }).then(() => {
        return network.getData(`bonus/resend-qy-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>
