<template>
<div style="height:95%">
  <el-button v-if="$local.isRoot()" size="small" @click="exportData()" plain>导出数据</el-button>
  <div style="float:right;">
    <el-date-picker
      v-model="search_month"
      type="daterange"
      align="right"
      size="small"
      style="margin-right:5px;width: 200px;"
      start-placeholder="申请日期"
      end-placeholder="申请日期">
    </el-date-picker>
    <el-select style="width:150px;" v-model="search_info.SellerNick" size='small' clearable placeholder="请选择淘宝店铺">
      <el-option
        v-for="item in SellerNicks"
        :key="item.value"
        :label="item.label"
        :value="item.value">
      </el-option>
    </el-select>
    <el-select style="width:150px;" v-model="search_info.status" size='small' clearable placeholder="请选择处理状态">
      <el-option
        v-for="item in search_status"
        :key="item.value"
        :label="item.label"
        :value="item.value">
      </el-option>
    </el-select>
    <el-input
      placeholder="请输入操作人员登陆名称"
      style="width:200px;"
      size='small'
      v-model="search_info.handle_user">
      <i slot="prefix" class="el-input__icon el-icon-search"></i>
    </el-input>
    <el-input
      placeholder="请输入会员号"
      style="width:200px;"
      size='small'
      v-model="search_info.Phone">
      <i slot="prefix" class="el-input__icon el-icon-search"></i>
    </el-input>
    <el-button size='small' @click="search()" type="primary" icon="el-icon-search">搜索</el-button>
  </div>
  <el-table :row-class-name="tableRowClassName" :show-overflow-tooltip="true" :data="tableData" height="calc(100% - 120px)" style="width: 100%">
    <el-table-column prop="BuyerNick" label="淘宝会员名" > </el-table-column>
    <el-table-column prop="Phone" label="会员号" > </el-table-column>
    <el-table-column prop="Tid" label="交易编号"> </el-table-column>
    <el-table-column prop="Oid" label="子订单编号"> </el-table-column>
    <el-table-column prop="SellerNick" label="商品"> </el-table-column>
    <el-table-column prop="Modified" label="申请时间"  width="150"> </el-table-column>
    <el-table-column prop="handle_time" label="处理时间" width="150"> </el-table-column>
    <el-table-column prop="handle_user" label="处理人"> </el-table-column>
    <el-table-column prop="status"  label="状态"> </el-table-column>
    <el-table-column prop="account"  label="用户现有余额"> </el-table-column>
    <el-table-column prop="RefundFee" label="退款金额"> </el-table-column>
    <el-table-column prop="f_balance" label="扣除后余额"> </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button v-show="!scope.row.f_balance" @click="handleClick(scope.row)" type="text" size="small">处理</el-button>
        <el-button v-show="scope.row.f_balance"  type="text" size="small">已处理</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    background
    v-if="count !== 0"
    :current-page="pageNum"
    style="top:91%"
    layout="prev, pager, next"
    :page-size = "50"
    @prev-click="prev_page"
    @next-click="next_page"
    @current-change="handleCurrentChange"
    :total="count">
  </el-pagination>
</div>
</template>

<script>
export default {
  data () {
    return {
      tableData: [],
      count: 0,
      pageNum: 1,
      search_info: {
        Phone: null,
        SellerNick: null,
        handle_user: null,
        status: null,
        Modified: {
          st: null,
          et: null
        }
      },
      SellerNicks: [{
        value: '强子pptp动态',
        label: '强子pptp动态'
      }, {
        value: '可乐开发商',
        label: '可乐开发商'
      }, {
        value: '老鹰动态pptp',
        label: '老鹰动态pptp'
      }],
      search_status: [{
        value: '0',
        label: '申请中'
      }, {
        value: '1',
        label: '已同意'
      }, {
        value: '2',
        label: '已拒绝'
      }, {
        value: '3',
        label: '已关闭'
      }],
      form: {},
      search_month: ''
    }
  },

  created () {
    this.$store.commit('setCurrentNav', '订单管理>>淘宝退款')
    this.getData()
  },
  methods: {
    handleClick (row) {
      this.$api.get(this.$api.phpURL + 'order/TbRefund/getOneInfo', {id: row.Id}).then(res => {
        this.form = res.data
      })
      this.$confirm('此操作只可进行一次, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$api.post(this.$api.phpURL + 'order/TbRefund/handle', {row}).then(res => {
            row.f_balance = res.balance
          // alert()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    getData () {
      this.$api.get(this.$api.phpURL + 'order/TbRefund/refundList').then(res => {
        this.tableData = res.data
        this.count = parseInt(res.count)
      })
    },
    prev_page () {
      this.$api.get(this.$api.phpURL + 'order/TbRefund/pageList', {page: this.pageNum}).then(res => {
        this.tableData = res.data
      })
    },
    next_page () {
      this.$api.get(this.$api.phpURL + 'order/TbRefund/pageList', {page: this.pageNum}).then(res => {
        this.tableData = res.data
      })
    },
    handleCurrentChange: function (currentPage) {
      this.pageNum = currentPage
      this.$api.get(this.$api.phpURL + 'order/TbRefund/pageList', {page: this.pageNum}).then(res => {
        this.tableData = res.data
      })
    },
    search () {
      if (this.search_month && this.search_month.length === 2) {
        this.search_info.Modified.st = this.search_month[0]
        this.search_info.Modified.et = this.search_month[1]
      }
      this.$api.post(this.$api.phpURL + 'order/TbRefund/search', {data: this.search_info}).then(res => {
        this.tableData = res.data
        this.count = parseInt(res.count)
      })
    },
    submit (info) {
      this.$api.post(this.$api.phpURL + 'order/TbRefund/handle', {info}).then(res => {})
      this.dialogFormVisible = false
    },
    exportData () {
      if (this.search_month && this.search_month.length === 2) {
        this.search_info.Modified.st = this.search_month[0]
        this.search_info.Modified.et = this.search_month[1]
      }
      this.$api.getDownloadFile(this.$api.phpURL + 'order/TbRefund/export', {data: this.search_info}, '淘宝退款.csv')
    }
  }
}
</script>
