<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="人员">
              <a-input placeholder="请输入人员" v-model="queryParam.personName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="账号">
              <a-input placeholder="请输入账号" v-model="queryParam.personId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="日期">
              <a-month-picker valueFormat="YYYY-MM"  @change="onChange" placeholder="请输入日期" v-model="queryParam.monthTime"></a-month-picker>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>

            </span>
          </a-col>

        </a-row>

        <!-- <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="生成月报日期">
              <a-month-picker format="YYYY-MM" placeholder="请输入生成月报日期" v-model="queryParam.nowDate" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="monthReport" icon="reload" style="margin-left: 8px">生成当月考勤月报</a-button>
            </span>
          </a-col>
        </a-row> -->
      </a-form>
    </div>


    <!-- table区域-begin -->
    <div>

      <a-table class="j-table-force-nowrap" ref="table" size="middle" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="latetimeState" slot-scope="text, record, index">
          <a-tag color="pink" v-if="record.latetimeX > 0 || record.latetimeS > 0 ">异常</a-tag>
          <a-tag color="#87d068" v-if="record.latetimeX <= 0 && record.latetimeS <= 0 ">正常</a-tag>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <!-- <ViewClockIn-modal ref="modalForm" @ok="modalFormOk"></ViewClockIn-modal> -->
  </a-card>
</template>

<script>
  import {
    JeecgListMixin
  } from '@/mixins/JeecgListMixin'
  import JDictSelectTag from '@/components/dict/JDictSelectTag'
  import {
    monthReport
  } from '@/api/api'
  import moment from 'moment';
  import 'moment/locale/zh-cn';

  export default {
    name: 'ViewClockInList',
    mixins: [JeecgListMixin],
    components: {
      JDictSelectTag
    },
    data() {
      return {
        moment,
        description: '考勤月报',
        // 表头
        columns: [{
            title: '行号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            title: '日期',
            align: 'center',
            dataIndex: 'monthTime'
          },
          {
            title: '人员姓名',
            align: 'center',
            dataIndex: 'personName'
          },
          {
            title: '账号',
            align: 'center',
            dataIndex: 'personId'
          },
          {
            title: '本月迟到分钟数',
            align: 'center',
            dataIndex: 'latetimeS'
          },
          {
            title: '本月早退分钟数',
            align: 'center',
            dataIndex: 'latetimeX'
          },
          {
            title: '本月加班时长',
            align: 'center',
            dataIndex: 'duration'
          },
          {
            title: '本月请假时长',
            align: 'center',
            dataIndex: 'holidayTime'
          }
        ],
        url: {
          list: '/viewClockIn/bdClockinMonth/list'
        },
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      onChange(date, dateString) {
            console.log(date, dateString);
            // this.value = "2021-01-01"
      },
      monthReport() {
        let sqp1 = this.getQueryParams();
        if(sqp1['nowDate'] == 'undefined' || sqp1['nowDate'] == null || sqp1['nowDate'] == ''){
          this.$message.warning('请选择生成月报日期！');
          return false;
        }
        let nowDate = moment(sqp1['nowDate']).format('YYYY-MM');
        let that = this;
        that.$confirm({
           title: "确认操作",
           content: "是否生成" + nowDate + "月报?",
           onOk: function () {
             monthReport({nowDate:nowDate}).then((res) => {
               if (res) {
                 that.$message.success("已成功生成"+nowDate+"考勤月报");
                 that.loadData();
               } else {
                 that.$message.warning(res);
               }
             });
           }
        });
       
       
       
       

      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>
