<template>
  <div class="recharge">
    <!-- 头部细节部分 -->
      <div class="title">
        <el-row>
          <el-col :span="24">
            <div class="top">
              <el-input  placeholder="用户名称" class="input-demo" v-model="userName"></el-input>
              <el-input  placeholder="手机号" class="input-demo" v-model="userPhone"></el-input>
              <el-input  placeholder="用户所在公司" class="input-demo" v-model="userCompany"></el-input>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <div class="top">
              <el-button type="success" style="margin-left: 1%;" @click="queryLook">查询</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
    <!-- 头部细节部分结束 -->
    <!-- 表格部分 -->
      <template>
        <el-table
          v-loading="loading"
          ref="multipleTable"
          :data="usertable"
          border
          tooltip-effect="dark">
          <el-table-column
            label="用户名"
            prop="userName"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="userPhone"
            label="手机号"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="userCompany"
            label="用户所在公司"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            label="创建时间"
            show-overflow-tooltip>
            <template slot-scope="scope" show-overflow-tooltip>
              <span>{{scope.row.createTime | fmtDate}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="充值前余额(元)"
            show-overflow-tooltip>
              <template slot-scope="scope" show-overflow-tooltip>
                <span>{{scope.row.beforeMoney / 100}}</span>
              </template>
          </el-table-column>
          <el-table-column
            label="充值金额(元)"
            show-overflow-tooltip>
              <template slot-scope="scope" show-overflow-tooltip>
                <span>{{scope.row.money / 100}}</span>
              </template>
          </el-table-column>
        </el-table>
      </template>

    <!-- 分页 -->
      <div class="block">
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current"
        :page-sizes="[6, 8, 10]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
        </el-pagination>
      </div>

  </div>
</template>

<script type="text/javascript">
import axios from 'axios';
export default{
  data() {
    return {
      loading: true,
      usertable: [],
      userName: "",
      userPhone: "",
      userCompany: "",
      current: 1,
      pagesize: 8,
      // 总共有多少条数据
      total: 0,
    }
  },
  created() {
    this.loadData();
  },
  methods: {
    // 列表展示
    async loadData() {

      const formData = new FormData();
      formData.append('current', this.current);
      formData.append('size', this.pagesize);
      const response = await this.$http.post(`recharge/list`, formData);
      if (response.data.code === 0) {
        this.loading = false;
        this.usertable = response.data.data.records;
        this.total = response.data.data.total;
      }
    },
    //查询
    async queryLook() {
      const formData = new FormData();
      formData.append('current', this.current);
      formData.append('size', this.pagesize);
      formData.append('userName', this.userName);
      formData.append('userPhone', this.userPhone);
      formData.append('userCompany', this.userCompany);
      const response = await this.$http.post(`recharge/list`, formData);
      if (response.data.code === 0) {
        this.loading = false;
        this.usertable = response.data.data.records;
        this.total = response.data.data.total;
      }
    },
    // 分页方法
    handleSizeChange(val) {
      this.pagesize = val;
      if(this.userName !== '' || this.userPhone !== '' || this.userCompany !== '') {
        this.queryLook();
      }else{
        this.loadData();
      };
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.current = val;
      if(this.userName !== '' || this.userPhone !== '' || this.userCompany !== '') {
        this.queryLook();
      }else{
        this.loadData();
      };
      console.log(`当前页: ${val}`);
    },

  }
};
</script>

<style>
.recharge {
  border: 1px solid #d9d9d9;
  border-radius: 10px;
}
.recharge .title {
  font-size: 5px;
  margin-bottom: 20px;
}
.recharge .top {
  padding-top: 20px;
  padding-left: 20px;
}
.recharge .text {
  display: inline-block;
  color: #000;
  font-size: 16px ;
  margin-left: 1%;
}
.recharge .input-demo {
  display: inline-block;
  width: 20%;
  margin-left: 1%;
}
.recharge .block {
  font-size: 5px;
  text-align: center;
  margin-top: 15px;
  margin-bottom: 20px;
}

.recharge .tou {
  font-size: 20px;
  height: 30px;
  line-height: 30px;
  padding-top: 15px;
}
.recharge .line {
  margin-top: 15px;
  margin-bottom: 15px;
  width: 100%;
  height: 2px;
  background-color: #d9d9d9;
}
.recharge .xinxi {
  text-align: center;
  margin: 15px auto;
  font-size: 18px;
}
</style>
