liuxiaolong
2019-05-06 770c069996e1d2979c1170c1639c18b02d07e72f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
<template>
  <b-modal ref="modalRef" centered hide-footer @hide="hiddenFn" size="lg">
    <div class="row">
      <div class="col-10">
        <div class>
          <h4 class="float-left">人员:{{attendanceInfo.employeeName?attendanceInfo.employeeName:''}}</h4>
          <div class="pb-4 flex-center">
            <el-date-picker
              v-model="yearValue"
              type="month"
              format="yyyy年MM月"
              value-format="yyyy-MM"
              :clearable="false"
              style="width:140px"
              placeholder="选择年月"
            ></el-date-picker>
          </div>
        </div>
        <vueCalendar
          ref="calendar"
          :events="calendarEvent"
          :lunar="false"
          :value="calendarDate"
          @select="calendarSelect"
          :isShowHeader="false"
          tdHeight="100px"
          @recordFn="recordFn"
          @leaveFn="leaveFn"
          @repairFn="repairFn"
        />
      </div>
      <!-- 统计数据 -->
      <div class="col-2">
        <div class="pt-4 pb-3 text-center">
          <b-button @click="setToday" size="sm" variant="primary" class="border-radius-25">返回今天</b-button>
          <fButton
            size="sm"
            type="primary"
            class="ml30 border-radius-25"
            @click.native="exportFile"
            authority="sys:attendance:export"
          >导出报表</fButton>
        </div>
        <!-- <b-list-group>
          <b-list-group-item href="javascript:void(0)" class="media ">
            <div class="media-body line-height-condenced text-center ">
              <h5 class="">签到天数<small class="text-secondary">(含补签)</small></h5>
              <div class="bg-primary text-white font-weight-bold attendance-count-num">
                18
              </div>
            </div>
          </b-list-group-item>
          <b-list-group-item href="javascript:void(0)" class="media ">
            <div class="media-body line-height-condenced text-center">
              <div class="text-dark">未签到</div>
              <div class="bg-warning text-white font-weight-bold attendance-count-num">
                2
              </div>
            </div>
          </b-list-group-item>
          <b-list-group-item href="javascript:void(0)" class="media ">
            <div class="media-body line-height-condenced text-center">
              <div class="text-dark">补签天数</div>
              <div class="bg-success text-white font-weight-bold attendance-count-num">
                2
              </div>
            </div>
          </b-list-group-item>
        </b-list-group>-->
        <div class="ml-4 mr-4" style="margin-top:150px">
          <div class="bg-primary text-white text-center pt-3 mt-4 mr-4 ml-4">
            <h5 class>
              签到天数
              <small class>(含补签)</small>
            </h5>
            <div
              class="text-white font-weight-bold attendance-count-num"
            >{{attendanceInfo.attendValue}}</div>
          </div>
          <div class="bg-warning text-white text-center pt-3 mt-4 mr-4 ml-4">
            <h5 class>未签到</h5>
            <div class="text-white font-weight-bold attendance-count-num">{{attendanceInfo.isLeave}}</div>
          </div>
          <!-- <div class="bg-success text-white text-center pt-3 mt-4 mr-4 ml-4">
            <h5 class="">补签天数</h5>
            <div class="text-white font-weight-bold attendance-count-num">
              {{attendanceInfo.isRepair}}
            </div>
          </div>-->
        </div>
      </div>
    </div>
    <el-dialog
      title="签到流水"
      :modal="false"
      width="80%"
      :show-close="false"
      :visible.sync="recordInfoModal"
    >
      <div slot="title" class="flex-row-between">
        <div class="flex-center">
          <h4 class="m-0">人员:{{attendanceInfo.employeeName}}</h4>
          <small class="pt-2 pl-4">{{yearValue + '-' + calendarValue}}</small>
        </div>
        <div>
          <!-- <b-button variant="primary" class="border-radius-25 pl20 pr20 mr10" @click="exportFileDay">导出报表</b-button> -->
          <fButton
            type="primary"
            @click.native="exportFileDay"
            authority="sys:attendance:export"
            class="border-radius-25 pl20 pr20 mr10"
          >导出报表</fButton>
          <b-button
            variant="outline-primary"
            class="border-radius-25 pl30 pr30"
            @click="recordInfoModal = false"
          >返回</b-button>
        </div>
      </div>
      <div style="height:58vh" class="overflow-auto px-2 pb-4">
        <Table :data="tableList" :border="true">
          <TableColumn type="index" prop="index" label="序号" :index="snMethod" width="50"/>
          <TableColumn label="抓拍图像" prop="deviceName" width="120">
            <template slot-scope="scope">
              <httpImgCopy :src="scope.row.Snapshotpath" height="80px" size="80px" alt/>
            </template>
          </TableColumn>
          <TableColumn label="进出入位置" prop="indevicename"/>
          <TableColumn label="时间" prop="onlinetime"/>
          <!-- <TableColumn
              label="是否补签"
              prop="updateTime"
              :span="3"
          />-->
        </Table>
      </div>
    </el-dialog>
    <el-dialog
      title="补签到"
      :modal="false"
      width="500px"
      @close="repairModalFn"
      :modal-append-to-body="false"
      :visible.sync="repairModal"
    >
      <div class="pl-5">
        <el-form :model="repairForm" :rules="rules" ref="repairForm" label-width="100px">
          <el-form-item label="活动区域" prop="inTime">
            <el-time-picker
              value-format="HH:mm:ss"
              v-model="repairForm.inTime"
              placeholder="选择首次时间"
            ></el-time-picker>
          </el-form-item>
          <el-form-item label="首次位置" prop="inDeviceName">
            <el-select v-model="repairForm.inDeviceName" placeholder="首次位置" style="width: 220px;">
              <el-option label="区域一" value="shanghai"></el-option>
              <el-option label="区域二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="末次时间" prop="outTime">
            <el-time-picker
              value-format="HH:mm:ss"
              v-model="repairForm.outTime"
              placeholder="选择末次时间"
            ></el-time-picker>
          </el-form-item>
          <el-form-item label="末次位置" prop="outDeviceName">
            <el-select
              v-model="repairForm.outDeviceName"
              placeholder="请选择末次位置"
              style="width: 220px;"
            >
              <el-option label="区域一" value="shanghai"></el-option>
              <el-option label="区域二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <hr class="p-0 m-0">
      <div slot="footer" class="dialog-footer">
        <b-button variant="primary" @click="submitForm('repairForm')">确 定</b-button>
        <b-button variant="default" @click="repairModal = false">取 消</b-button>
      </div>
    </el-dialog>
  </b-modal>
</template>
 
<script>
import {
  DatePicker,
  Dialog,
  Button,
  Form,
  FormItem,
  TimePicker,
  Select,
  Option,
  Table,
  TableColumn
} from 'element-ui'
import vueCalendar from '@/components/vueCalendar'
import httpImgCopy from '@/components/common/httpImgCopy'
import { getPersonMouthData, getPersonById } from '@/server/attend.js'
export default {
  name: 'CalendarAttendanceModal',
  components: {
    vueCalendar,
    elDatePicker: DatePicker,
    elDialog: Dialog,
    elButton: Button,
    elForm: Form,
    elFormItem: FormItem,
    elSelect: Select,
    elOption: Option,
    elTimePicker: TimePicker,
    Table,
    TableColumn,
    httpImgCopy
  },
  // props: {
  //   modalData: {
  //     default: null,
  //     type: Object
  //   }
  // },
  data() {
    return {
      modalData: {},
      attendanceInfo: {},
      yearValue: this.$moment().format('YYYY-MM'),
      calendarValue: this.$moment().format('DD'),
 
      dataLsit: [],
      dayTime: '',
      recordInfoModal: false,
      tableList: [],
      repairModal: false,
      repairForm: {
        inTime: '',
        inDeviceName: '',
        outTime: '',
        outDeviceName: ''
      },
      rules: {
        inTime: [
          { required: true, message: '请选择末次时间', trigger: 'blur' }
        ],
        inDeviceName: [
          { required: true, message: '请选择首次位置', trigger: 'blur' }
        ],
        outTime: [
          { required: true, message: '请选择末次时间', trigger: 'blur' }
        ],
        outDeviceName: [
          { required: true, message: '请选择末次位置', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    calendarDate() {
      // 用于控制日历
      // console.log(this.dateValue(), 'this.dateValue')
      return this.dateValue().split('-')
    },
    calendarEvent() {
      let json = {}
      this.dataLsit.map(iteam => {
        json[iteam.signDate] = iteam
      })
      console.log(json, 'json')
      return json
    }
  },
  methods: {
    snMethod(index) {
      return this.activePage > 1
        ? this.pageSize * (this.activePage - 1) + index + 1
        : index + 1
    },
    // 计算日历中心val
    dateValue() {
      if (this.yearValue) {
        // console.log(this.calendarValue, 'this.calendarValue')
        const day = this.calendarValue
          ? this.calendarValue
          : this.$moment().format('DD')
        const dayNum = this.$moment(this.yearValue, 'YYYY-MM')
          .endOf('month')
          .format('DD') // 这个月最后一天
        if (dayNum < day) {
          this.calendarValue = dayNum
          return `${this.yearValue}-${dayNum}`
        }
        return `${this.yearValue}-${day}`
      }
      return this.$moment().format('YYYY-MM-DD')
    },
    showModal(data) {
      this.modalData = data
      this.queryperson({
        personId: data.pid ? data.pid : '',
        mouthDate: this.$moment().format('YYYY-MM')
      })
      this.$refs.modalRef.show()
    },
    hideModal() {
      this.$refs.modalRef.hide()
    },
    hiddenFn() {
      // console.log('关闭主要弹窗')
      this.recordInfoModal = false
      this.repairModal = false
    },
    calendarSelect(value) {
      this.calendarValue = this.$moment(value.join('-'), 'YYYY-M-D').format(
        'DD'
      )
      // console.log(this.calendarValue, 'value')
    },
    setToday() {
      this.yearValue = this.$moment().format('YYYY-MM')
      this.calendarValue = this.$moment().format('DD')
    },
    recordFn({ data, day }) {
      // console.log(data, '记录回调')
      let endTime = this.$moment(data.signDate).format('YYYY-MM-DD')
      let beginTime = this.$moment(data.signDate).format('YYYY-MM-DD')
      this.dayTime = endTime
      // console.log(endTime, 'endTime')
      let json = {
        id: data.employeeId,
        endTime: endTime,
        beginTime: beginTime
      }
      this.queryPersonById(json)
    },
    async queryPersonById(json) {
      let res = await getPersonById(json)
      if (res && res.data) {
        console.log(res.data, ' dayList ')
        this.tableList = res.data.dayList
        this.recordInfoModal = true
      } else {
        this.$toast({
          message: res.msg ? res.msg : '报错了',
          type: 'error'
        })
      }
    },
    async queryperson(json) {
      let res = await getPersonMouthData(json)
      if (res && res.data) {
        console.log(res.data, 'res.data---数据')
        this.attendanceInfo = res.data
        this.dataLsit = res.data.dayList ? res.data.dayList : []
        console.log(this.dataLsit, 'this.dataLsit')
      } else {
        this.$toast({
          message: res.msg ? res.msg : '报错了',
          type: 'error'
        })
      }
    },
    exportFile() {
      let access = JSON.parse(
        sessionStorage.getItem('loginedInfo')
      ).access_token.replace('bearer ', '')
      /* 创建form对象 */
      let oA = document.createElement('A')
      // oA.setAttribute('method', 'get')
      oA.setAttribute(
        'href',
        'data/api-a/att/poiPersonMouuthDataExcel?access_token=' +
          access +
          '&mouthDate=' +
          this.yearValue +
          '&personId=' +
          this.modalData.pid
      )
      // console.log(oA, 'oA')
      document.body.append(oA)
      oA.click()
      // window.location.href = 'data/api-a/att/poiPersonMouuthDataExcel?access_token=' + access + '&mouthDate=' + this.yearValue + '&personId=' + this.modalData.pid
      // window.open('data/api-a/att/excel?access_token=' + access, '_blank')
    },
    exportFileDay() {
      // console.log(this.dayTime, 'dayTime')
      let access = JSON.parse(
        sessionStorage.getItem('loginedInfo')
      ).access_token.replace('bearer ', '')
      /* 创建form对象 */
      let oA = document.createElement('A')
      // oA.setAttribute('method', 'get')
      oA.setAttribute(
        'href',
        'data/api-a/att/poiPersonDayDataExcel?access_token=' +
          access +
          '&id=' +
          this.modalData.pid +
          '&dayTime=' +
          this.dayTime
      )
      console.log(oA, 'oA')
      document.body.append(oA)
      oA.click()
      // window.location.href = 'data/api-a/att/poiPersonMouuthDataExcel?access_token=' + access + '&mouthDate=' + this.yearValue + '&personId=' + this.modalData.pid
      // window.open('data/api-a/att/excel?access_token=' + access, '_blank')
    },
    leaveFn({ data, day }) {
      console.log(data, '请假回调')
      alert('请假回调')
    },
 
    /* 补签开始 */
    repairFn({ data, day }) {
      console.log(data, '补签回到')
      console.log(data, 'data')
      this.repairModal = true
      if (data) {
        this.repairForm = data
      } else {
        this.repairForm = {
          inTime: '',
          inDeviceName: '',
          outTime: '',
          outDeviceName: ''
        }
      }
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert('submit!')
          this.repairModal = false
          this.resetForm('repairForm')
        } else {
          return false
        }
      })
    },
    /* 补签重置 */
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    repairModalFn() {
      this.resetForm('repairForm')
    }
  },
  watch: {
    yearValue(newVal, oldVal) {
      console.log(newVal, oldVal, 'newVal,oldVal')
      this.queryperson({
        personId: this.modalData.pid,
        mouthDate: newVal
      })
    }
  }
}
</script>
<style>
@media (min-width: 992px) {
  .modal-lg {
    max-width: 100rem;
  }
}
.attendance-count-num {
  border-radius: 5px;
  margin-top: 10px;
  font-size: 30px;
  line-height: 50px;
  height: 60px;
}
.border-radius-25 {
  border-radius: 25px;
}
</style>