<!--
 * @Author: kangkang
 * @Date: 2020-10-13 19:45:55
 * @LastEditors: kangkang
 * @LastEditTime: 2020-10-16 11:11:41
-->
<template>
<div style="height:95%">
  <el-input
    placeholder="请输入会员号"
    style="width:18%;"
    size='small'
    v-model="search_info">
    <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>
  <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: '',
      form: {}
    }
  },

  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 => {
          if (res.balance) {
            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 () {
      this.$api.post(this.$api.phpURL + 'order/TbRefund/search', {Phone: 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
    }
  }
}
</script>
