<template>
  <div class="m-container">
    <h2>
      <div class="squrt"></div>提现列表
    </h2>
    <div class="m-core">
      <!-- 搜索类型 -->
      <el-form :inline="true"
               class="searchForm"
               v-model.trim="searchForm">
        <el-form-item prop='organId'>
          <el-select class='multiple'
                     v-model.trim="searchForm.organId"
                     filterable
                     clearable
                     placeholder="请选择分部">
            <el-option v-for="(item,index) in organList"
                       :key="index"
                       :label="item.name"
                       :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="search"
                     type="danger">搜索</el-button>
          <!-- <el-button @click="onReSet"
                     type="primary">重置</el-button> -->
        </el-form-item>
      </el-form>
      <!-- 列表 -->
      <div class="tableWrap">
        <el-table :data='tableList'
                  :header-cell-style="{background:'#EDEEF0',color:'#444'}">
          <!-- <el-table-column align='center' prop="transNo"
                          label="提现交易流水号">
          </el-table-column> -->
          <el-table-column align='center'
                           prop="createTime"
                           label="申请时间">
            <template slot-scope="scope">
              <div>
                {{scope.row.createTime | dateForMinFormat}}
              </div>
            </template>
          </el-table-column>
          <el-table-column align='center'
                           prop="user.realName"
                           label="学员姓名">
          </el-table-column>
          <el-table-column align='center'
                           prop="amount"
                           label="提现金额">
            <template slot-scope="scope">
              <div>
                {{scope.row.amount| moneyFormat}}
              </div>
            </template>
          </el-table-column>
          <el-table-column align='center'
                           prop="detail.balance"
                           label="账户余额(元)">
            <template slot-scope="scope">
              <div>
                {{scope.row.detail.balance| moneyFormat}}
              </div>
            </template>
          </el-table-column>
          <el-table-column align='center'
                           prop="bankCardNo"
                           width="200"
                           label="提现账户">
          </el-table-column>
          <el-table-column align='center'
                           label="提现状态">
            <template slot-scope="scope">
              {{ scope.row.status | dealStatus }}
            </template>
          </el-table-column>
          <el-table-column align='center'
                           label="支付账号">
            <template slot-scope="scope">
              <el-input v-if="scope.row.status == 'ING'"
                        type="text"
                        v-model.trim="scope.row.detail.platformAccountNo"
                        placeholder="支付账号"></el-input>
              <span v-else>{{ scope.row.detail.platformAccountNo }}</span>
            </template>
          </el-table-column>
          <el-table-column align='center'
                           label="支付渠道">
            <template slot-scope="scope">
              <!-- <el-input type="text" v-model.trim="scope.row.channel" placeholder="支付渠道"></el-input> -->
              <el-select v-if="scope.row.status == 'ING'"
                         filterable
                         clearable
                         v-model.trim="scope.row.detail.transType"
                         placeholder="请选择"
                         style="width: 100% !important;">
                <el-option label="微信"
                           value="1"> </el-option>
                <el-option label="支付宝"
                           value="2"> </el-option>
                <el-option label="银联"
                           value="3"> </el-option>
              </el-select>
              <span v-else>{{ getTypes(scope.row.detail.transType) }}</span>
            </template>
          </el-table-column>
          <el-table-column align='center'
                           label="交易流水号">
            <template slot-scope="scope">
              <el-input v-if="scope.row.status == 'ING'"
                        type="text"
                        v-model.trim="scope.row.transNo"
                        placeholder="交易流水号"></el-input>
              <span v-else>{{ scope.row.transNo }}</span>
            </template>
          </el-table-column>
          <el-table-column align='center'
                           label="操作">
            <template slot-scope="scope"
                      v-if="scope.row.status == 'ING'">
              <el-button @click="onSure(scope.row, 'SUCCESS')"
                         v-permission="'studentWithdraw/confirm'"
                         type="text">确认</el-button>
              <el-button @click="onSure(scope.row, 'FAILED')"
                         v-permission="'studentWithdraw/confirm'"
                         type="text">拒绝</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination :total="pageInfo.total"
                    :page.sync="pageInfo.page"
                    :limit.sync="pageInfo.limit"
                    :page-sizes="pageInfo.page_size"
                    @pagination="getList" />
      </div>
    </div>
  </div>
</template>
<script>
import pagination from '@/components/Pagination/index'
import { studentWithdraw, studentWithdrawConfirm } from '@/api/orderManager'
import { getEmployeeOrgan } from '@/api/buildTeam'
import store from '@/store'
export default {
  components: { pagination },
  name: 'expend',
  data () {
    return {
      searchForm: {
        organId: null
      },
      tableList: [],
      organList: [],
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
    }
  },
  mounted () {
    getEmployeeOrgan().then(res => {
      if (res.code == 200) {
        this.organList = res.data;
      }
    })
    this.getList()
  },
  methods: {
    search () {
      this.pageInfo.page = 1;
      this.getList()
    },
    getList () {
      let params = this.searchForm
      params.rows = this.pageInfo.limit
      params.page = this.pageInfo.page
      studentWithdraw(params).then(res => {
        let result = res.data
        if (res.code == 200) {
          this.tableList = result.rows
          this.pageInfo.total = result.total
        }
      })
    },
    getTypes (index) {
      let template = {
        1: '微信',
        2: '支付宝',
        3: '银联'
      }
      return template[index]
    },
    onSure (row, type) {
      let contentText = ''
      if (type == 'SUCCESS') {
        contentText = '您确定提现吗？'
      } else if (type == 'FAILED') {
        contentText = '您确定拒绝吗？'
      }
      this.$confirm(contentText, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        studentWithdrawConfirm({
          id: row.id,
          platformAccountNo: row.detail.platformAccountNo,
          transType: row.detail.transType,
          status: type,
          transNo: row.transNo
        }).then(res => {
          if (res.code == 200) {
            this.$message.success('操作成功')
            this.getList()
          } else {
            this.$message.error(res.msg)
          }
        })

      }).catch(() => { })

    }
  }
}
</script>
<style lang="scss">
</style>