haoxuan
2023-12-08 bf7b5516246e58e955d67a3c97ab14727e75b6be
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
<template>
  <div class="base-modal">
    <el-dialog v-model="modelData" :close-on-click-modal="false" :show-close="false" width="80%">
      <template #header>
        <div class="modal-title">
          <div class="modal-title-text">报工记录</div>
          <div class="modal-title-close" @click="closeModal">
            <el-icon :size="22" color="#fff"><CloseBold /></el-icon>
          </div>
        </div>
      </template>
      <div class="table-content">
        <el-table class="table" :data="reportingRecordList" border style="width: 100%" :scrollbar-always-on="true">
          <template #empty> 无数据 </template>
          <el-table-column type="index" label="序号" width="56" align="center" :resizable="false"></el-table-column>
          <el-table-column prop="deviceId" label="报工来源" align="center" :resizable="false">
            <template #default="scope">
              {{ scope?.row?.workerName ?? '--' }}/{{ scope?.row?.deviceName ?? '--' }}
            </template>
          </el-table-column>
          <el-table-column prop="barCode" label="条码" align="center" :resizable="false">条码</el-table-column>
          <el-table-column prop="reportAmount" label="报工数量" align="center" :resizable="false" />
          <el-table-column prop="finishAmount" label="完成数量" align="center" :resizable="false" />
          <el-table-column prop="startTime" label="开始时间" align="center" :resizable="false">
            <template #default="scope">
              {{ formatDate(scope.row.startTime) }}
            </template>
          </el-table-column>
          <el-table-column prop="endTime" label="结束时间" align="center" :resizable="false">
            <template #default="scope">
              {{ formatDate(scope.row.endTime) }}
            </template>
          </el-table-column>
          <el-table-column prop="workerTime" label="工时" align="center" :resizable="false">
            <template #default="scope">
              {{ formatDuration(scope.row.workerTime) }}
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>
<script setup lang="ts">
import { useDateFormat, useVModel } from '@vueuse/core'
import { CloseBold } from '@element-plus/icons-vue'
import { ref, watch } from 'vue'
import { apiGetReportingRecordList } from '@/api'
import type { ReportingRecord } from '@/api/reporting'
import { useTasksStore } from '@/stores/tasks'
import { isNumber } from 'lodash-es'
 
export interface BaseModalProps {
  /** 是否展示模态框 */
  modelValue: boolean
}
const props = withDefaults(defineProps<BaseModalProps>(), {
  modelValue: false
})
const emit = defineEmits<{
  'update:modelValue': [show: boolean]
  close: []
}>()
const modelData = useVModel(props, 'modelValue', emit)
function closeModal() {
  emit('update:modelValue', false)
  emit('close')
}
 
const taskStore = useTasksStore()
 
// 报工记录列表
const reportingRecordList = ref<ReportingRecord[]>([])
function getReportingList() {
  const procedureId = taskStore.activeTask?.Procedure.ID
  if (!procedureId) {
    return
  }
  apiGetReportingRecordList({
    procedureId: procedureId
  })
    .then((res) => {
      if (res.code === 200) {
        reportingRecordList.value = res?.data ?? []
      } else {
        reportingRecordList.value = []
      }
    })
    .catch((err) => {
      console.error(err)
      reportingRecordList.value = []
    })
}
// 打开弹窗时获取报工记录
watch(modelData, (show) => {
  if (show) {
    getReportingList()
  }
})
 
/**
 * 格式化时间戳
 * @param timestamp 后端返的10位时间戳
 */
function formatDate(timestamp?: number) {
  if (!timestamp) {
    return '--'
  }
  const time = useDateFormat(timestamp * 1000, 'YYYY-MM-DD HH:mm:ss', { locales: 'zh-cn' })
  return time.value
}
 
/**
 * 接受秒数,返回格式化后的 时分秒字符串
 * @param duration 秒数
 * @returns {string} 格式化后的 时分秒字符串
 */
function formatDuration(duration: number): string {
  if (duration < 0 || !isNumber(duration)) {
    return '--'
  }
  const h = Math.floor(duration / 3600)
  const m = Math.floor((duration % 3600) / 60)
  const s = Math.floor(duration % 60)
  return `${h > 0 ? h + '时' : ''}${m > 0 ? m + '分钟' : ''}${s}秒`
}
</script>
 
<style scoped lang="scss">
:deep(.el-dialog) {
  background-color: #1d3081;
}
 
.modal-title {
  position: relative;
  display: flex;
  align-items: center;
  &-text {
    padding-left: 12px;
    font-size: 26px;
    font-weight: 600;
  }
  &-close {
    cursor: pointer;
    height: 36px;
    width: 36px;
    border-radius: 50%;
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    top: -16px;
    right: -30px;
  }
}
$bgc: #1d3081;
.table-content {
  :deep(.el-table .el-table__cell) {
    background-color: $bgc;
    color: #dcdfec;
  }
  :deep(.el-table__body tr) {
    background-color: $bgc;
    color: #dcdfec;
  }
  :deep(.el-table__body tr:hover > td) {
    background-color: $bgc;
  }
  :deep(.el-scrollbar__wrap) {
    background-color: $bgc;
  }
  height: calc(70vh - 80px);
}
.table {
  height: 100%;
}
</style>