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
<template>
  <div>
    <div class="bg-white border-bottom pt-4 pb-4 px-4">
      <!-- <h4 class="font-weight-bold py-2 mb-2">
          <router-link to="/">
            <span class="text-muted font-weight-light">考勤管理 /</span>
          </router-link>
          考勤报表
      </h4>-->
      <div class="flex-row-between title-box">
        <div class="flex-row-left">
          <div
            v-if="$route.query.isShow=== 'true'"
            class="grid-content bg-purple mr10"
            style="width: 100px;"
          >
            <Select v-model="gradesValue" @change="selectClass()" placeholder="年级">
              <Option
                v-for="item in gradeDate"
                :key="item.value"
                :label="item.name"
                :value="item.id"
              ></Option>
            </Select>
          </div>
          <div
            v-if="$route.query.isShow=== 'true'"
            class="grid-content bg-purple mr10"
            style="width: 100px;"
          >
            <Select
              v-model="classValue"
              :disabled="classDis"
              @change="queryList()"
              placeholder="班级"
            >
              <Option
                v-for="item in classDate"
                :key="item.value"
                :label="item.name"
                :value="item.id"
              ></Option>
            </Select>
          </div>
        </div>
        <div class="text-center">
          <el-date-picker
            style="width:120px"
            v-model="selectMonth"
            @change="queryList"
            :clearable="false"
            value-format="yyyy-MM"
            format="yyyy-MM"
            type="month"
            placeholder="选择年月"
          ></el-date-picker>
          <a style="color:#666;font-size:20px">考勤表</a>
        </div>
        <div>
          <fButton
            type="default"
            @click.native="exportExcel"
            authority="sys:attendance:export"
            class="pl-6 pr-6"
          >导出报表</fButton>
          <!-- <b-btn @click="exportExcel" class="pl-6 pr-6" variant="default">导出报表</b-btn> -->
          <b-button variant="default" class="pl-4 pr-4" @click="$router.push({path:'/'})">关闭</b-button>
        </div>
      </div>
    </div>
    <b-card class="mx-4 mt-4">
      <Table
        :data="tableDate"
        height="70vh"
        id="out-table"
        :border="true"
        :fit="true"
        style="width:100%;mso-number-format:'\@'"
      >
        <TableColumn type="index" width="50" label="序号"></TableColumn>
        <TableColumn label="姓名" width="70" property="perName" style="mso-number-format:'\@';">
          <!-- <template slot-scope="{row}">{{row.perName +' ' || '- -'}}</template> -->
          <template
            slot-scope="{row}"
          >{{isNaN(parseInt(row.perName))?row.perName:'身份证:'+row.perName}}</template>
        </TableColumn>
        <TableColumn
          v-for="item in countDays"
          :key="item"
          :label="item+''"
          width="50"
          property="total.label"
        >
          <template
            slot-scope="scope"
          >{{scope.row.totalList[item-1]&&scope.row.totalList[item-1].detail?scope.row.totalList[item-1].detail:''}}</template>
        </TableColumn>
        <TableColumn label="出勤" width="50" property="attendValue" id="attendance"></TableColumn>
        <TableColumn label="迟到" width="50" property="lateValue" id="late"></TableColumn>
        <TableColumn label="早退" width="50" property="leaveEarlyValue" id="leaveEarly"></TableColumn>
      </Table>
    </b-card>
  </div>
</template>
 
<script>
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
import { queryGrads } from '@/server/common.js'
import {
  Select,
  Col,
  Row,
  Option,
  Button,
  Table,
  TableColumn,
  DatePicker
} from 'element-ui'
 
import { getExportList } from '@/server/models/export.js'
export default {
  props: ['isTeacher'],
  data() {
    return {
      /** 班级禁用 */
      classDis: true,
      /** 查询班级年级的参数变量 */
      typeG: 600,
      typeC: 700,
      orgid: this.$store.getters.basicUserInfo.orgId,
      currentId: this.$store.getters.basicUserInfo.officeId,
      /** */
      gradeDate: [
        {
          id: 'all',
          name: '全部'
        }
      ],
      classDate: [
        {
          id: 'all',
          name: '全部'
        }
      ],
      tableDate: [],
      gradesValue: '',
      classValue: '',
      identity: '',
      selectMonth: this.$moment(new Date()).format('YYYY-MM'),
      countDays: 0
    }
  },
  methods: {
    exportExcel() {
      /* generate workbook object from table */
      var wb = XLSX.utils.table_to_book(document.querySelector('#out-table'))
      /* get binary string as output */
      var wbout = XLSX.write(wb, {
        bookType: 'xlsx',
        bookSST: true,
        type: 'array'
      })
      try {
        FileSaver.saveAs(
          new Blob([wbout], { type: 'application/octet-stream' }),
          '考勤.xlsx'
        )
      } catch (e) {
        if (typeof console !== 'undefined') console.log(e, wbout)
      }
      return wbout
    },
    async queryList() {
      // console.log(this.selectMonth + ' month')
      // console.log(this.$moment(this.selectMonth).month() + ' m')
      // console.log(this.$moment(this.selectMonth).year() + ' y')
 
      let month = this.$moment(this.selectMonth).month() + 1
      let year = this.$moment(this.selectMonth).year()
      this.countDays = this.getDaysInOneMonth(year, month)
      // console.log(this.countDays)
      // console.log(this.classValue)
      // console.log(this.gradeValue)
      let json = {
        mouthDate: this.selectMonth,
        gradeValue: this.gradesValue,
        classValue: this.classValue,
        identity: this.$route.query.identity,
        days: this.countDays
      }
      /* 保存拼接 */
      // json.authorizationSystem = ',' + json.authorizationSystem + ','
      let res = await getExportList(json)
      if (res && res.data) {
        console.log(res.data + ' res ')
        this.tableDate = res.data
      } else {
        this.$toast({
          message: res.msg ? res.msg : '报错了',
          type: 'error'
        })
      }
    },
    getDaysInOneMonth(year, month) {
      month = parseInt(month, 10)
      var d = new Date(year, month, 0)
      return d.getDate()
    },
    /** 选择年级,同时让班级根据年级获取数据 */
    selectGrad() {
      let json = {
        orgid: this.orgid,
        type: this.typeG,
        currentId: this.currentId
      }
      this.queryGrads(json)
    },
    async queryGrads(json) {
      let res = await queryGrads(json)
      this.gradeDate = this.gradeDate.concat(res)
      console.log(this.gradeDate, '学生考勤导出')
    },
    selectClass() {
      this.classDis = false
      this.classes = [
        {
          id: 'all',
          name: '全部'
        }
      ]
      this.classValue = ''
      let json = {
        type: this.typeC,
        orgid: this.orgid,
        currentId: this.gradesValue
      }
      this.queryClass(json)
      this.queryList()
    },
    async queryClass(json) {
      let res = await queryGrads(json)
      // console.log(res)
      this.classDate = this.classDate.concat(res)
    }
  },
  watch: {
    gradesValue(newVal, oldVal) {
      console.log(newVal, 'newVal', oldVal, 'oldVal')
      if (newVal !== oldVal) {
        if (newVal === 'all') {
          this.classDis = true
        } else {
          this.classDis = false
        }
      }
    }
  },
  created() {
    this.queryList()
    this.selectGrad()
  },
  components: {
    Select,
    Col,
    Row,
    Option,
    Button,
    Table,
    TableColumn,
    elDatePicker: DatePicker
  }
}
</script>
<style scope>
.has-gutter th {
  background: #f4fcff;
}
</style>