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
<template>
  <div>
    <div class="bg-white border-bottom pt-4 pb-4 px-4">
      <h5 class="font-weight-bold py-2">
        <router-link to="/">
          <i class="ion ion-ios-arrow-dropleft f20 text-dark pr5"></i>
          <span class="text-muted font-weight-light">考勤管理 /</span>
        </router-link>考勤报表
      </h5>
      <div class="flex-row-between title-box">
        <div class="flex-row-left">
          <div class="grid-content bg-purple mr10" style="width: 100px;">
            <Select
              class="mr10"
              v-model="identityVal"
              placeholder="身份"
              style="width:100%"
              @change="queryList"
            >
              <Option
                v-for="item in identity"
                :key="item.value"
                :label="item.lable"
                :value="item.value"
              ></Option>
            </Select>
          </div>
          <div class="grid-content bg-purple mr10" style="width: 200px;">
            <select-org-tree
              ref="tree"
              :data="treeList"
              :isOpenAll="false"
              :highlightCurrent="false"
              :showCheckbox="true"
              @hide-change="({ids})=>{checkIds=ids;queryList()}"
            />
          </div>
          <div class="grid-content bg-purple mr10 pt10" style="width: 150px;">
            <b-form-checkbox v-model="delFlag" @change="(val)=>{delFlag = val;queryList()}">已删除人员</b-form-checkbox>
          </div>
        </div>
        <div class="text-center pr50">
          <el-date-picker
            style="width:120px"
            v-model="selectMonth"
            @change="queryList"
            :clearable="false"
            value-format="yyyy-MM"
            format="yyyy-MM"
            type="month"
            placeholder="选择年月"
            class="mr10"
          ></el-date-picker>
          <a style="color:#666;font-size:20px" class="pr50 mr50">考勤表</a>
        </div>
        <div>
          <!-- <fButton
            type="default"
            @click.native="exportExcel"
            authority="sys:attendance:export"
            class="pl-6 pr-6"
          >导出</fButton>-->
          <fTemplate authority="sys:attendance:export">
            <span class="text-primary cursor-pointer font-weight-bolder" @click="exportExcel">
              <i class="ion ion-md-open pr5"></i>
              导出
            </span>
          </fTemplate>
          <!-- <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="65vh"
        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 { mapState } from 'vuex'
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
import {
  Select,
  Col,
  Row,
  Option,
  Button,
  Table,
  TableColumn,
  DatePicker
} from 'element-ui'
import selectOrgTree from '../Home/components/SelectOrgTree'
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: '',
      selectMonth: this.$moment(new Date()).format('YYYY-MM'),
      countDays: 0,
      /* 新增 变量 */
      identityVal: '',
      checkIds: [],
      delFlag: true
    }
  },
  computed: {
    ...mapState({
      treeList: 'dictOrgTree',
      identity: 'dictIdentity'
    })
  },
  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() {
      let month = this.$moment(this.selectMonth).month() + 1
      let year = this.$moment(this.selectMonth).year()
      this.countDays = this.getDaysInOneMonth(year, month)
      let json = {
        mouthDate: this.selectMonth,
        gradeValue: this.gradesValue,
        classValue: this.classValue,
        identity: this.identityVal,
        days: this.countDays,
        delFlag: this.delFlag,
        orgIds: this.checkIds.join(',')
      }
      /* 保存拼接 */
      // json.authorizationSystem = ',' + json.authorizationSystem + ','
      let res = await getExportList(json)
      if (res && res.data) {
        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.identityVal =
      this.identity[0] && this.identity[0].value ? this.identity[0].value : ''
 
    this.queryList()
  },
  components: {
    Select,
    Col,
    Row,
    Option,
    Button,
    Table,
    TableColumn,
    elDatePicker: DatePicker,
    selectOrgTree
  }
}
</script>
<style scope>
.has-gutter th {
  background: #f4fcff;
}
</style>