<template>
  <el-card shadow="never"
           class="aui-card--fill">
    <div class="mod-heart__actuserclocklog}">
      <el-form :inline="true"
               :model="dataForm"
               @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-button type="primary"
                     @click="backToActList">返回</el-button>
        </el-form-item>
        <div>
          <el-form-item label="状态">
            <el-select v-model="dataForm.status"
                       placeholder="状态"
                       clearable>
              <el-option label="审核通过"
                         :value="1"></el-option>
              <el-option label="打卡"
                         :value="2"></el-option>
              <el-option label="确认加积分"
                         :value="5"></el-option>
              <el-option label="拒绝加积分"
                         :value="6"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="dataForm.realName"
                      placeholder="请输入"
                      clearable></el-input>
          </el-form-item>
          <el-form-item label="手机号">
            <el-input v-model="dataForm.mobile"
                      placeholder="请输入"
                      clearable></el-input>
          </el-form-item>
        </div>
        <div class="block">
          <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>&nbsp;
          <el-form-item>
            <el-button @click="getDataList()">{{ $t('query') }}</el-button>
          </el-form-item>
        </div>
      </el-form>
      <el-table v-loading="dataListLoading"
                :data="dataList"
                border
                @selection-change="dataListSelectionChangeHandle"
                style="width: 100%;">
        <el-table-column label="序号"
                         type="index"
                         show-overflow-tooltip
                         align="center"
                         width="50"></el-table-column>
        <el-table-column prop="realName"
                         label="报名人"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="sex"
                         label="性别"
                         :formatter="formatSex"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="age"
                         label="年龄"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="mobile"
                         label="联系电话"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="clockAddress"
                         label="打卡地点"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="clockCount"
                         label="打卡次数"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="status"
                         label="打卡状态"
                         :formatter="formatState"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="checkPoint"
                         :formatter="isCheckPoint"
                         label="是否发放积分"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="point"
                         label="积分"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column :label="$t('handle')"
                         fixed="right"
                         header-align="center"
                         align="center"
                         width="150">
          <template slot-scope="scope">
            <!--            <el-button  type="text" size="small" :disabled="scope.row.status ==='0'? false :true" @click="addOrUpdateHandle(scope.row.id)">审核</el-button>-->
            <el-button v-if="$hasPermission('heart:actinfo:look')"
                       type="text"
                       size="small"
                       @click="detailHandle(scope.row.id)">查看</el-button>
          </template>
        </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>
      <!-- 弹窗, 新增 / 修改 -->
      <actuserclock-detai v-if="detailVisible"
                          ref="actuserrelationDetail"
                          @refreshDataList="getDataList"></actuserclock-detai>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import ActUserClockDetail from './actuserclock-detail'
export default {
  name: 'ActUserClockLog',
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/heart/actuserclocklog/clockPage',
        getDataListIsPage: true
      },
      dataForm: {
        id: '',
        actId: '',
        startTime: '',
        endTime: ''
      },
      detailVisible: false,
      time: ''
    }
  },
  mounted () {
    this.dataForm.actId = this.$route.query.id
    this.getDataList()
  },
  methods: {
    backToActList () {
      this.$emit('refreshDataList')
      this.$parent.selectComponent = 'ActInfoList'
      this.$router.push({ path: '/heart-actinfo' })
    },
    detailHandle (id) {
      this.$parent.selectComponent = 'ActUserClockDetail'
      this.$router.push({ path: '/heart-actinfo', query: { id: id, actId: this.dataForm.actId } })
    },
    setRegistTime () {
      if (this.time === null) {
        this.dataForm.startTime = ''
        this.dataForm.endTime = ''
      }
      this.dataForm.startTime = this.time[0]
      this.dataForm.endTime = this.time[1]
    },
    formatState: function (row, column) {
      let state = row.status
      if (state === '0') {
        return '报名'
      } else if (state === '1') {
        return '审核通过'
      } else if (state === '2') {
        return '打卡'
      } else if (state === '3') {
        return '取消报名'
      } else if (state === '4') {
        return '审核不通过'
      } else if (state === '5') {
        return '确认加积分'
      } else if (state === '6') {
        return '拒绝加积分'
      }
    },
    formatSex: function (row, column) {
      let state = row.sex
      if (state === '0') {
        return '女'
      } else if (state === '1') {
        return '男'
      }
    },
    // 是否发放积分转义
    isCheckPoint: function (row, column) {
      let state = row.checkPoint
      if (state === '0') {
        return '否'
      } else if (state === '1') {
        return '是'
      }
    }
  },
  components: {
    ActUserClockDetail
  }
}
</script>
