<template>
  <div class="cmain">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent>
      <el-form-item label="交易类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="交易类型" clearable style="width: 125px">
          <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-table :data="response.rows" border>
      <el-table-column type="index" label="序号" align="center" width="80" />
      <el-table-column label="交易类型" align="center" prop="type">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.type == 0">充值</el-tag>
          <el-tag type="warning" v-if="scope.row.type == 1">提现</el-tag>
          <el-tag type="primary" v-if="scope.row.type == 2">结算发放</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="交易金额(元)" align="center" prop="money">
        <template slot-scope="scope">
          <span v-if="scope.row.type == 0" style="color: orangered">+{{ scope.row.money }}</span>
          <span v-if="scope.row.type == 1">-{{ scope.row.money }}</span>
          <span v-if="scope.row.type == 2">-{{ scope.row.money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="交易日期" align="center" prop="createTime" />
      <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>
export default {
  name: 'Record',
  data() {
    return {
      dateRange: [],
      response: {},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyId: null,
        opId: null,
        type: null,
        money: null,
        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/record/list', data: this.queryParams }).then((response) => {
        this.response = response;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm('queryForm');
      this.dateRange = [];
      this.handleQuery();
    }
  }
};
</script>
