BUG
yaozc
2023-06-05 b58907aa082880c8812f3022151537f204b54cd2
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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <el-select v-model="query.userId" filterable clearable placeholder="申请人" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in users"
            :key="item.id"
            :label="item.nickName"
            :value="item.id"
          />
        </el-select>
        <el-select v-model="query.approvalUserId" filterable clearable placeholder="审批者" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in users"
            :key="item.id"
            :label="item.nickName"
            :value="item.id"
          />
        </el-select>
        <el-select v-model="query.approvalStatus" filterable clearable placeholder="审批状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[dictBussinessStatus]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-date-picker
          v-model="query.travelStartTime"
          type="date"
          clearable
          style="width: 185px;"
          class="filter-item"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="出差开始日期"
        />
        <el-date-picker
          v-model="query.travelEndTime"
          type="date"
          clearable
          style="width: 185px;"
          class="filter-item"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="出差结束日期"
        />
        <rrOperation />
      </div>
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">
          <el-form-item label="申请人" prop="userId">
            <el-select v-model="form.userId" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="disabledUser(form)">
              <el-option
                v-for="item in users"
                :key="item.id"
                :label="item.nickName"
                :value="item.id"
                :disabled="!item.enabled"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="审批者" prop="approvalUserId">
            <el-select v-model="form.approvalUserId" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn">
              <el-option
                v-for="item in approvalUsers"
                :key="item.id"
                :label="item.nickName"
                :value="item.id"
                :disabled="!item.enabled"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="出差开始日期" prop="travelStartTime">
            <el-date-picker
              v-model="form.travelStartTime"
              :type="'date'"
              placeholder="选择日期"
              value-format="yyyy-MM-dd"
              style="width: 340px;"
              align="right"
              :picker-options="{
                disabledDate(time) {
                  return form.travelEndTime ? time.getTime() > new Date(form.travelEndTime).getTime() - 8.64e7 : false;
                }
              }"
              :disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn"
              @change="checkTime"
            />
          </el-form-item>
          <el-form-item label="出差结束日期" prop="travelEndTime">
            <el-date-picker
              v-model="form.travelEndTime"
              :type="'date'"
              placeholder="选择日期"
              style="width: 340px;"
              value-format="yyyy-MM-dd"
              align="right"
              :picker-options="{
                disabledDate(time) {
                  return form.travelStartTime ? time.getTime() < new Date(form.travelStartTime).getTime() - 8.64e7 : false;
                }
              }"
              :disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn"
              @change="checkTime"
            />
          </el-form-item>
          <el-form-item label="出差时长" prop="travelDuration">
            <el-input v-model="form.travelDuration" disabled style="width: 340px;">
              <template slot="append">{{ dict.label[dictLeaveTimeType][form.durationUnit] }}</template>
            </el-input>
          </el-form-item>
          <el-form-item label="出差原因">
            <el-input v-model="form.travelReason" type="textarea" rows="3" style="width: 340px;" :disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn" />
          </el-form-item>
          <el-form-item label="出发城市">
            <el-input v-model="form.departureCity" style="width: 340px;" :disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn" />
          </el-form-item>
          <el-form-item label="到达城市">
            <el-input v-model="form.arrivalCity" style="width: 340px;" :disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn" />
          </el-form-item>
          <el-form-item label="审批说明">
            <el-input v-model="form.approvalDescription" type="textarea" rows="3" style="width: 340px;" disabled />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remarks" type="textarea" rows="3" style="width: 340px;" :disabled="form.approvalStatus == dictGoOutAgree || form.approvalStatus == dictGoOutReturn" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--审核表单-->
      <el-dialog :close-on-click-modal="false" :before-close="closeCard" :visible.sync="makeUpCardVisible" title="出差审批" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">
          <el-form-item label="申请人">
            {{ form.userName }}
          </el-form-item>
          <el-form-item label="出发城市">
            {{ form.departureCity }}
          </el-form-item>
          <el-form-item label="到达城市">
            {{ form.arrivalCity }}
          </el-form-item>
          <el-form-item label="出差开始时间">
            {{ crud.toDate(form.travelStartTime) }}
          </el-form-item>
          <el-form-item label="出差结束时间">
            {{ crud.toDate(form.travelEndTime) }}
          </el-form-item>
          <el-form-item label="出差时长">
            {{ form.travelDuration + '(' + dict.label[dictLeaveTimeType][form.durationUnit] + ')' }}
          </el-form-item>
          <el-form-item label="出差原因">
            {{ form.travelReason }}
          </el-form-item>
          <el-form-item v-if="form.approvalStatus === dictGoOutReturn" label="退回原因" prop="approvalDescription">
            <div style="color: red;">*审核退回需要填写退回原因,请填写后再次点击审核退回</div>
            <el-input v-model="form.approvalDescription" type="textarea" :rows="3" style="width: 340px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="danger" style="margin-right: 10px;" @click="approveFunction(1,form)">审核退回</el-button>
          <el-button v-if="form.approvalStatus !== dictGoOutReturn" :loading="successLoading" type="success" @click="approveFunction(2,form)">审核通过</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" row-key="id" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="userName" label="申请人" width="100" fixed="left" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag>{{ scope.row.userName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="appUserName" label="审批者" width="100" fixed="left" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag>{{ scope.row.appUserName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="travelStartTime" label="出差开始时间" width="140" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.travelStartTime) }}
          </template>
        </el-table-column>
        <el-table-column prop="travelEndTime" label="出差结束时间" width="140" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.travelEndTime) }}
          </template>
        </el-table-column>
        <el-table-column prop="travelDuration" label="出差时长" width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.travelDuration + '(' + dict.label[dictLeaveTimeType][scope.row.durationUnit] + ')' }}
          </template>
        </el-table-column>
        <el-table-column prop="travelReason" label="出差原因" width="140" show-overflow-tooltip />
        <el-table-column prop="departureCity" label="出发城市" width="80" show-overflow-tooltip />
        <el-table-column prop="arrivalCity" label="到达城市" width="80" show-overflow-tooltip />
        <el-table-column prop="approvalStatus" label="审批状态" width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.approvalStatus === dictGoOutAppRev" type="warning">{{ dict.label[dictBussinessStatus][scope.row.approvalStatus] }}</el-tag>
            <el-tag v-if="scope.row.approvalStatus === dictGoOutAgree" type="success">{{ dict.label[dictBussinessStatus][scope.row.approvalStatus] }}</el-tag>
            <el-tag v-if="scope.row.approvalStatus === dictGoOutReturn" type="danger">{{ dict.label[dictBussinessStatus][scope.row.approvalStatus] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="approvalDescription" label="审批说明" width="140" show-overflow-tooltip />
        <el-table-column prop="remarks" label="备注" width="140" show-overflow-tooltip />
        <el-table-column prop="createTime" label="创建时间" width="140" show-overflow-tooltip />
        <el-table-column v-if="checkPer(['admin','attendanceBusinessTravel:approve'])" label="审核操作" width="180px" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.approvalUserId === $store.state.user.user.id"
              v-permission="permission.approve"
              :loading="crud.status.cu === 2"
              size="mini"
              type="primary"
              icon="el-icon-s-check"
              :disabled="scope.row.approvalStatus === dictGoOutAppRev ? false : true"
              @click="toApprove(scope.row)"
            >审核
            </el-button>
            <el-popover
              :ref="`popover_${scope.row.id}`"
              width="200"
            >
              <p>确定撤销该记录?</p>
              <div style="text-align: right; margin: 0">
                <el-button size="mini" type="primary" @click="canel(scope.row)">取消</el-button>
                <el-button :loading="successLoading" type="primary" size="mini" @click="revoke(scope.row)">确定</el-button>
              </div>
              <el-button
                v-if="scope.row.approvalUserId === $store.state.user.user.id"
                slot="reference"
                v-permission="permission.approve"
                type="danger"
                icon="el-icon-edit-outline"
                size="mini"
                :disabled="scope.row.approvalStatus === dictGoOutAppRev ? true : false"
              >撤销
              </el-button>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column v-if="checkPer(['admin','attendanceBusinessTravel:edit','attendanceBusinessTravel:del'])" label="操作" width="150px" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
 
<script>
import crudAttendanceBusinessTravel from '@/api/attendance/attendanceBusinessTravel'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudUser from '@/api/system/user'
import { mapGetters } from 'vuex'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import constant from '../../../utils/constant'
 
const defaultForm = { id: null, userId: null, approvalUserId: null, travelStartTime: null, travelEndTime: null, travelDuration: null, durationUnit: null, travelReason: null, departureCity: null, arrivalCity: null, approvalStatus: null, approvalDescription: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
  name: 'AttendanceBusinessTravel',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '出差记录', url: 'api/attendanceBusinessTravel', idField: 'id', sort: 'travelStartTime,desc', crudMethod: { ...crudAttendanceBusinessTravel }})
  },
  // 数据字典constant
  dicts: [constant.BUSSINESS_APPROVE_STATUS, constant.LEAVE_TIME_TYPE],
  data() {
    return {
      permission: {
        add: ['admin', 'attendanceBusinessTravel:add'],
        edit: ['admin', 'attendanceBusinessTravel:edit'],
        del: ['admin', 'attendanceBusinessTravel:del'],
        download: ['admin', 'attendanceBusinessTravel:download'],
        approve: ['admin', 'attendanceBusinessTravel:approve']
      },
      rules: {
        userId: [
          { required: true, message: '申请人不能为空', trigger: 'change' }
        ],
        approvalUserId: [
          { required: true, message: '审批者不能为空', trigger: 'change' }
        ],
        travelStartTime: [
          { required: true, message: '出差开始日期不能为空', trigger: 'change' }
        ],
        travelEndTime: [
          { required: true, message: '出差结束日期不能为空', trigger: 'change' }
        ],
        travelDuration: [
          { required: true, message: '出差时长不能为空', trigger: 'blur' }
        ],
        durationUnit: [
          { required: true, message: '时长单位不能为空', trigger: 'change' }
        ],
        approvalDescription: [
          { required: true, message: '退回原因不能为空', trigger: 'blur' }
        ],
        approvalStatus: [
          { required: true, message: '审批状态不能为空', trigger: 'change' }
        ]
      },
      users: [],
      approvalUsers: [],
      dictBussinessStatus: constant.BUSSINESS_APPROVE_STATUS,
      dictGoOutAppRev: constant.BUSSINESS_APPROVE_STATUS_REVIEWED,
      dictGoOutAgree: constant.BUSSINESS_APPROVE_STATUS_AGREE,
      dictGoOutReturn: constant.BUSSINESS_APPROVE_STATUS_REFUSE,
      dictLeaveTimeTypeDay: constant.LEAVE_TIME_TYPE_DAY,
      dictLeaveTimeType: constant.LEAVE_TIME_TYPE,
      makeUpCardVisible: false,
      successLoading: false,
      userRolesLevelMin: null,
      // 角色级别:普通用户
      roleLevelOrdinary: constant.ROLE_LEVEL_ORDINARY,
      // 角色级别: 总经理
      roleLevelGenerl: constant.ROLE_LEVEL_GENERAL
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  created() {
    this.getUsers()
    this.getApprovalUsers()
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      // 用户角色级别数组
      const userRolesLevel = this.user.roles.map(({ level }) => level)
      // 用户最大角色级别
      this.userRolesLevelMin = Math.min(...userRolesLevel)
      return true
    },
    // 钩子:新建 - 之前
    [CRUD.HOOK.beforeToAdd]() {
      this.form.durationUnit = this.dictLeaveTimeTypeDay
      // 判断用户最大角色级别是否大于总经理角色:赋值
      if (this.userRolesLevelMin > this.roleLevelGenerl) {
        // 表单赋值
        this.form.userId = this.user.id
      }
    },
    // 禁用
    disabledUser(data) {
      if (this.userRolesLevelMin > this.roleLevelGenerl) {
        return true
      }
      if (data.approvalStatus !== null && data.approvalStatus === this.dictGoOutAgree || data.approvalStatus === this.dictGoOutReturn) {
        return true
      }
    },
    // 查询员工
    getUsers() {
      crudUser.getAll().then(res => {
        this.users = res
      })
    },
    // 查询审核人
    getApprovalUsers() {
      crudUser.getApprovalUsers().then(res => {
        this.approvalUsers = res
      })
    },
    // 计算时长
    checkTime() {
      var data = JSON.stringify({
        'travelStartTime': this.form.travelStartTime,
        'travelEndTime': this.form.travelEndTime
      })
      crudAttendanceBusinessTravel.getRemainingTime(data).then(res => {
        this.form.travelDuration = res
      })
    },
    // 审批页面赋值
    toApprove(data, Number) {
      if (Number !== '1') {
        this.makeUpCardVisible = true
      }
      this.form.id = data.id
      this.form.userId = data.userId
      this.form.userName = data.userName
      this.form.travelStartTime = data.travelStartTime
      this.form.travelEndTime = data.travelEndTime
      this.form.departureCity = data.departureCity
      this.form.arrivalCity = data.arrivalCity
      this.form.travelDuration = data.travelDuration
      this.form.durationUnit = data.durationUnit
      this.form.approvalStatus = data.approvalStatus
      this.form.travelReason = data.travelReason
      this.form.remarks = data.remarks
    },
    // 审核提交功能
    approveFunction(Number, data) {
      this.form.userId = data.userId
      const msg = Number === 2 ? '通过' : '拒绝'
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        // 判断通过状态
        if (Number === 2) {
          this.form.approvalStatus = this.dictGoOutAgree
        } else {
          // 退回改状态显示退回原因
          this.form.approvalStatus = this.dictGoOutReturn
          if (this.form.approvalDescription == null) {
            return
          }
        }
        this.successLoading = true
        crudAttendanceBusinessTravel.approve(this.form).then(res => {
          this.crud.refresh()
          this.makeUpCardVisible = false
          this.successLoading = false
          this.$message({
            type: 'success',
            message: '审核' + msg + '成功'
          })
        }).catch(() => {
          this.makeUpCardVisible = false
          this.successLoading = false
        })
        if (this.$refs['form']) {
          this.$refs['form'].resetFields()
        }
      })
    },
    // 撤消功能
    revoke(data) {
      this.toApprove(data, '1')
      this.form.approvalStatus = this.dictGoOutAppRev
      this.successLoading = true
      crudAttendanceBusinessTravel.approve(this.form).then(res => {
        this.crud.refresh()
        this.successLoading = false
        this.$message({ type: 'success', message: '撤销成功' })
        this.$refs[`popover_${data.id}`].showPopper = false
      }).catch((error) => {
        this.$message({ type: 'error', message: error.response.data.message })
      })
      if (this.$refs['form']) {
        this.$refs['form'].resetFields()
      }
      this.crud.cancelCU()
    },
    // 关闭
    closeCard() {
      if (this.$refs['form']) {
        this.$refs['form'].resetFields()
      }
      this.crud.cancelCU()
      this.makeUpCardVisible = false
    },
    // 取消
    canel(data) {
      this.$refs[`popover_${data.id}`].showPopper = false
    }
  }
}
</script>
 
<style scoped>
.form-item {
  width: 100%;
  display: flex;
  margin-bottom: 20px;
}
.form-item-label {
  width: 20%;
  display: flex;
  padding-left: 20px;
}
.form-item-value {
  width: 80%;
  display: flex;
  padding-left: 25px;
  padding-right: 25px;
}
</style>