<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent v-show="showSearch">
      <el-form-item label="充值编号" prop="nums">
        <el-input v-model="queryParams.nums" placeholder="充值编号" @keyup.enter.native="handleQuery" clearable />
      </el-form-item>
      <el-form-item label="充值人" prop="name">
        <el-input v-model="queryParams.name" placeholder="充值人姓名" @keyup.enter.native="handleQuery" class="inp" clearable />
      </el-form-item>
      <el-form-item label="充值状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="充值状态" clearable style="width: 117px">
          <el-option value="0" label="未支付"></el-option>
          <el-option value="1" label="充值成功"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="充值日期">
        <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="response.rows" border height="calc(100vh - 235px)">
      <el-table-column type="index" label="序号" align="center" width="80" />
      <el-table-column label="充值编号" align="center" prop="nums" />
      <el-table-column label="充值人" align="center" prop="money" width="110">
        <template slot-scope="scope">
          <span class="pon" @click="op('info', scope.row)">{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="充值金额" align="center" prop="money" width="130" />
      <el-table-column label="充值方式" align="center" width="130">
        <template slot-scope="scope">
          <span class="icon" v-if="scope.row.payWay == 0" style="color: #4caf50">&#xe620; 微信充值</span>
          <span class="icon" v-else style="color: #ff5722">&#xe66b; 转账充值</span>
        </template>
      </el-table-column>
      <el-table-column label="充值状态" align="center" prop="state" width="130">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.state == 0 && scope.row.payWay == 0">未支付</el-tag>
          <el-tag type="danger" v-if="scope.row.state == 0 && scope.row.payWay == 1">待确认</el-tag>
          <el-tag type="success" v-if="scope.row.state == 1">充值成功</el-tag>
          <el-popover placement="top-start" v-if="scope.row.state == 2 && scope.row.payWay == 1" title="原因" width="200" trigger="hover" :content="scope.row.msg">
            <div slot="reference">
              <el-tag type="danger">驳回</el-tag>
              <i class="el-icon-warning"></i>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="充值时间" align="center" prop="createTime" width="160" />
      <el-table-column label="操作" align="center" width="160">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="op('detail', scope.row)" v-hasPermi="['work:pay:list']">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="op('audit', scope.row)" v-hasPermi="['work:pay:audit']" v-if="scope.row.state == 0 && scope.row.payWay == 1">确认</el-button>
        </template>
      </el-table-column>
      <template slot="empty">
        <el-empty></el-empty>
      </template>
    </el-table>
    <pagination v-if="response.total > 0" :total="response.total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import detail from './detail.vue';
import info from '@/views/work/user/edit';
export default {
  name: 'Pay',
  data() {
    return {
      showSearch: true,
      response: {},
      dateRange: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nums: null,
        name: null,
        state: null,
        type: 0,
        orderByColumn: 'id',
        isAsc: 'desc'
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      if (this.dateRange) {
        this.queryParams.dateBegin = this.dateRange[0];
        this.queryParams.dateEnd = this.dateRange[1];
      }
      this.ajax({ url: '/work/pay/list', data: this.queryParams }).then((response) => {
        this.response = response;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm('queryForm');
      this.dateRange = [];
      this.handleQuery();
    },
    op(tag, row) {
      if (tag == 'info') {
        this.iframe({ obj: info, param: { id: row.userId, detail: true }, title: '用户详情', width: '55%', height: '65%' });
      }
      if (tag == 'detail') {
        this.iframe({ obj: detail, param: { id: row.id, detail: true }, title: '充值详情', width: '35%', height: '60%' });
      }
      if (tag == 'audit') {
        this.iframe({ obj: detail, param: { id: row.id }, title: '充值确认', width: '35%', height: '60%' });
      }
    }
  }
};
</script>
