<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent v-show="showSearch">
      <el-form-item label="充值企业" prop="companyName">
        <el-input v-model="queryParams.companyName" placeholder="请输入充值企业" @keyup.enter.native="handleQuery" clearable />
      </el-form-item>
      <el-form-item label="充值编号" prop="nums">
        <el-input v-model="queryParams.nums" 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-option value="2" 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="结束日期" :clearable="false"></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-row :gutter="10" class="mb8">
      <el-button type="success" icon="el-icon-edit" :disabled="ids.length != 1" @click="op('edit', ids)" v-hasPermi="['work:recharge:edit']">审核</el-button>
      <el-button type="primary" icon="el-icon-download" @click="handleExport" v-hasPermi="['work:recharge:export']">导出</el-button>
      <el-button type="danger" icon="el-icon-delete" :disabled="ids.length == 0" @click="del" v-hasPermi="['work:recharge:remove']">删除{{ ids.length > 0 ? '(' + ids.length + ')' : '' }}</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table :data="response.rows" border @selection-change="selects" height="calc(100vh - 270px)">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="充值企业" align="left" prop="companyName" />
      <el-table-column label="充值编号" align="center" prop="nums" width="170" />
      <el-table-column label="充值金额（元）" align="center" prop="money" width="130" />
      <el-table-column label="充值状态" align="center" width="110">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.state == 0">待充值</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" title="原因" width="200" trigger="hover" :content="scope.row.msg">
            <div slot="reference">
              <el-tag type="info">充值失败</el-tag>
              <i class="el-icon-warning"></i>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="申请人" align="center" prop="opBy" width="130" />
      <el-table-column label="申请日期" align="center" prop="createTime" width="170" />
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="op('detail', scope.row)" v-hasPermi="['work:recharge:list']">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="op('edit', scope.row)" v-hasPermi="['work:recharge:edit']" :disabled="scope.row.state != 0">审核</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="del(scope.row)" v-hasPermi="['work:recharge:remove']">删除</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 audit from './audit';
export default {
  name: 'Recharge',
  data() {
    return {
      ids: [],
      showSearch: true,
      response: {},
      dateRange: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyName: null,
        state: null,
        nums: null,
        orderByColumn: 'r.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/recharge/list', data: this.queryParams }).then((response) => {
        this.response = response;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm('queryForm');
      this.dateRange = [];
      this.handleQuery();
    },
    selects(rows) {
      this.ids = rows.map((item) => item.id);
    },
    op(tag, row) {
      if (tag == 'detail') {
        const id = row.id || this.ids[0];
        this.iframe({ obj: audit, param: { id: id, detail: true, companyName: row.companyName }, title: '充值详情', width: '40%', height: '70%' });
      }
      if (tag == 'edit') {
        const id = row.id || this.ids[0];
        this.iframe({ obj: audit, param: { id: id, companyName: row.companyName }, title: '充值确认', width: '40%', height: '70%' });
      }
    },
    del(row) {
      this.$confirm('是否确认删除选中数据?', '警告', { type: 'warning' }).then(() => {
        this.get({ url: '/work/recharge/remove/' + (row.id || this.ids) }).then((response) => {
          this.$modal.msgSuccess('删除成功');
          this.getList();
        });
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/work/recharge/export', { ...this.queryParams }, '充值明细.xlsx');
    }
  }
};
</script>
