<template>
  <el-card shadow="never"
           class="aui-card--fill">
    <div class="mod-sys__user">
      <el-form :inline="true"
               :model="dataForm"
               @keyup.enter.native="getDataList()">
        <el-select v-model="dataForm.ruleCode"
                   placeholder="积分类别"
                   clearable>
          <el-option v-for="item in options"
                     :key="item.ruleCode"
                     :label="item.ruleDesc"
                     :value="item.ruleCode">
          </el-option>
        </el-select>
        &nbsp;&nbsp;
        <span class="demonstration">统计时间</span>&nbsp;&nbsp;
        <el-date-picker @change='setRegistTime'
                        v-model="time"
                        value-format="yyyy-MM-dd"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
        </el-date-picker>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>

      </el-form>
      <el-table v-loading="dataListLoading"
                :data="dataList"
                border
                @selection-change="dataListSelectionChangeHandle"
                @sort-change="dataListSortChangeHandle"
                style="width: 100%;">
        <el-table-column prop="operationDesc"
                         label="积分类别"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="allPoints"
                         label="总积分"
                         header-align="center"
                         align="center"></el-table-column>
      </el-table>
      <el-pagination :current-page="page"
                     :page-sizes="[10, 20, 50, 100]"
                     :page-size="limit"
                     :total="total"
                     layout="total, sizes, prev, pager, next, jumper"
                     @size-change="pageSizeChangeHandle"
                     @current-change="pageCurrentChangeHandle">
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: 'points/pointslogs/point/listPagePoints',
        getDataListIsPage: true
      },
      dataForm: {
        ruleCode: '',
        startTime: '',
        endTime: ''
      },
      time: '',
      options: []
    }
  },
  created () {
    this.$http
      .get(`/points/pointsrule/ruleList`)
      .then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.options = res.data
      })
      .catch(() => { })
  },
  watch: {
    'time': function (val) {
      if (this.time === null) {
        this.dataForm.startTime = ''
        this.dataForm.endTime = ''
      }
    }
  },
  methods: {
    realNameFormat (row, column) {
      if (row.realName) {
        return row.realName
      }
      return row.nickname
    },
    setRegistTime () {
      // console.log(this.time[0])
      this.dataForm.startTime = this.time[0]
      this.dataForm.endTime = this.time[1]
    }
  },
  components: {
  }
}
</script>
