<template>
  <div class="page-box" v-loading="loading > 0">
    <Header :title="title"></Header>
    <div class="container">
      <div class="content">
        <!-- 表格 -->
        <div class="filter-box">
          <div class="filter">
            <div class="filter-item">
              <div class="label">变动类型：</div>
              <el-select
                v-model="filter.fundType"
                size="small"
                class="select"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in statusType"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>

            <div class="filter-item">
              <div class="label">奖励获得者ID：</div>
              <el-input
                class="input"
                v-model="filter.uid"
                placeholder="请输入内容"
                size="small"
              ></el-input>
            </div>

            <div class="filter-item">
              <div class="label">奖励发起者ID：</div>
              <el-input
                class="input"
                v-model="filter.fid"
                placeholder="请输入内容"
                size="small"
              ></el-input>
            </div>

            <div class="filter-item">
              <div class="label">创建时间：</div>
              <el-date-picker
                v-model="date"
                type="daterange"
                align="right"
                unlink-panels
                class="date-input"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                :default-time="['00:00:00', '23:59:59']"
                size="small"
              >
              </el-date-picker>
            </div>
          </div>
          <div class="btn-box">
            <button class="search" @click="search">筛选</button>
            <button class="reset" @click="reset">重置</button>
          </div>
        </div>
        <el-table
          :data="list"
          class="order-table table no-border-table"
          ref="orderTable"
          :header-cell-style="{
            border: 'none',
            color: '#333',
            background: '#f6f6f6',
            borderBottom: '1px solid #E8E8E8',
            height: '54px',
          }"
          :row-style="{
            height: '54px',
          }"
        >
          <el-table-column
            prop="created"
            align="center"
            label="创建时间"
          ></el-table-column>
          <el-table-column
            prop="describe"
            align="center"
            label="奖励类型"
          ></el-table-column>
          <el-table-column
            prop="amount"
            align="center"
            label="代金券数"
          ></el-table-column>
          <el-table-column
            prop="uid"
            align="center"
            label="奖励获得者ID"
          ></el-table-column>
          <el-table-column
            prop="fid"
            align="center"
            label="奖励发起者ID"
          ></el-table-column>
        </el-table>
      </div>
      <!-- 分页按钮 -->
      <div class="footer">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          background
          layout="total, prev, pager, next, jumper"
          :page-size="size"
          :total="total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import Header from '../../components/common/header';
export default {
  components: {
    Header
  },
  name: 'balanceRecord',
  data() {
    return {
      currentPage: 1, // 当前页码
      size: 20, // 每页条数
      total: 0, // 总页数
      loading: 0, // 加载中
      title: {
        // 页面标题
        firstTitile: '资金管理',
        secondTitle: '贡献值记录'
      },
      filter: {
        uid: null,
        fid: null,
        fundType: null,
      },

      statusMap: {},
      list: [], // 列表
      date: []
    };
  },

  mounted() {
    // 获取列表
    this.getFundTypeMap();
    this.getList();
  },
  computed: {},
  methods: {
    // 切换页码
    handleCurrentChange(page) {
      this.currentPage = page;
      this.getList();
    },
    getFundTypeMap() {
      this.loading++;
      this.httpGet(this.$root.getFundTypeMap, {}).then(
        (res) => {
          this.loading--;
          // this.statusType = res.balanceLog.score
          let list = [{
            name: '全部',
            value: null
          }];
          for(let key in res.balanceLog.score){
            list.push({
              name: res.balanceLog.score[key],
              value: key
            });
          }
          this.statusType = list;
        },
        (res) => {
          this.loading--;
          this.$message.error(res);
        })
    },
    // 获取列表
    getList() {
      this.filter.begin = this.date[0] || '';
      this.filter.end = this.date[1] || '';
      this.loading++;
      this.httpGet(this.$root.getScoreList, {
        page: this.currentPage,
        size: this.size,
        ...this.filter
      }).then(
        (res) => {
          this.loading--;
          this.list = res.list;
          this.total = res.total;
        },
        (res) => {
          this.loading--;
          this.$message.error(res);
        }
      );
    },
    // 过滤
    search() {
      this.currentPage = 1;
      this.getList();
    },
    // 重置过滤
    reset() {
      this.filter = {
        uid: null,
        fid: null,
        fundType: null,
      };
      this.date = [];
      this.getList();
    }
  }
};
</script>
<style lang="stylus" rel="stylesheet/stylus">
@import '~assets/public.styl';
</style>
<style lang="stylus" rel="stylesheet/stylus" scoped>
@import '~assets/main.styl';

.page-box {
  height: 100%;
  width: 100%;
  flex-y(flex-start, flex-start);
  overflow-y: hidden;
  background: bg-color;

  .container {
    box-sizing: border-box;
    height: 100%;
    width: 100%;
    overflow-y: auto;
    flex-y(flex-start, flex-start);
    padding: 10px;

    // content 表格
    .content {
      flex: 1;
      width: 100%;
      font-size: 14px;
      background: white;
      box-sizing: border-box;
      padding: 24px 32px;
      border-radius: 2px;

      // 按钮
      .btn {
        width: 100px;
        height: 32px;
        line-height: 32px;
        confirm-btn();
        font-size: 14px;
        margin: 16px 0;
      }

      // 表格按钮
      .table-btn {
        // width: 65px;
        height: 24px;
        line-height: 24px;
        color: gray3;
        font-size: 12px;
        margin-right: 8px;
        cancel-btn();
        padding: 0 8px;
      }

      .filter-item {
        margin-right: 12px;
      }

      .select, .input {
        width: 125px;
      }

      .date-input {
        width: 360px;
      }

      .btn-box {
        margin: 0;
      }

      .table {
        margin-top: 24px !important;
      }
    }
  }

  .footer {
    width: 100%;
    padding: 24px;
    box-sizing: border-box;
    flex-x(flex-end);
    background: white;
  }

  .dialog-content {
    flex-y();
  }

  .form {
    width: 100%;
    flex-center();
    margin: 8px 0;
  }
}
</style>
