2
schangxiang@126.com
2025-05-12 6177ed5cb88df34f2a67d9d0610e3e0dc7030e70
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
<template>
  <div class="container">
    <div class="head">
      <div class="head-left">
        <el-date-picker
          v-model="timeValue"
          type="daterange"
          range-separator="-"
          :start-placeholder="_t('开始时间')"
          :end-placeholder="_t('结束时间')"
          value-format="YYYY-MM-DD HH:mm:ss"
          :default-time="[
            new Date(2000, 1, 1, 0, 0, 0),
            new Date(2000, 2, 1, 23, 59, 59),
          ]"
          @change="initTableData"
          class="fix-input-style fix-datetime-picker"
          popper-class="light-datetime-picker"
          :style="{ marginRight: '5px' }"
        />
        <IconButton icon="export" :onClick="onExport">
          {{ _t('导出') }}
        </IconButton>
      </div>
      <div class="head-right">
        <Search
          v-model="searchValue"
          @Confirm="initTableData"
          :style="{ marginLeft: '5px' }"
        />
      </div>
    </div>
    <!-- -->
    <!-- url="/api/v1/ordermanagement/order"
    :params="{
      Filter: '',
      StartTime: head(backtrackingCondition.timeValue),
      FinishTime: last(backtrackingCondition.timeValue),
      Status: FIXED_STATUS, // 固定传5 为工单记录->4
      Sorting: '',
    }" -->
    <BaseTable
      v-model:dataSource="tableData"
      v-model:total="paginationConfig.total"
      @page="onPage"
      :pageSize="paginationConfig.pageSize"
      id="id_key"
      :isSeq="true"
      :columns="tableHead"
    >
      <template #formulaName="{ row }">
        {{ row.formula.name }}
      </template>
 
      <template #productModel="{ row }">
        {{ row.product.model }}
      </template>
 
      <template #statusDescription="{ row }">
        {{ row.status.description }}
      </template>
      <template #segments="{ row }">
        <Text :truncated="true" :title="currentSegment(row)">{{
          currentSegment(row)
        }}</Text>
      </template>
    </BaseTable>
  </div>
</template>
 
<script lang="ts">
import {
  defineComponent,
  ref,
  reactive,
  onActivated,
  onMounted,
  watch,
  computed,
} from 'vue'
import { head, last, get, cloneDeep } from 'lodash'
import dayjs from 'dayjs'
import sdk from 'sdk'
import api from '../../api/product-setting'
import { ElMessageBox, ElMessage } from 'element-plus'
import type { IProductTableItem } from '../../api/product'
import Pagination from '../../components/pagination/index.vue'
import IconButton from '@/components/IconButton/IconButton'
import Search from '@/components/Search/Search'
import { createInjector } from '../../hooks/use-permission'
import Text from '@/components/Text/Text'
import { _t } from '../../app'
//import { downloadFile } from '@/utils/client'
const FIXED_STATUS = '4'
import BaseTable from '@/components/Table/Table'
 
export default defineComponent({
  name: 'OrderRecords',
  components: {
    Pagination,
    BaseTable,
    IconButton,
    Search,
    Text,
  },
  setup(props) {
    const { curTab } = createInjector()
    watch(curTab, (val: any) => {
      if (val == 'OrderRecords') {
        init()
      }
    })
 
    const searchValue = ref('')
    const timeValue = ref([
      dayjs().subtract(7, 'day').startOf('day').format('YYYY-MM-DD 00:00:00'),
      dayjs().startOf('day').format('YYYY-MM-DD 23:59:59'),
    ])
    const MaxResultCount = 20
    // 保留initTableData 请求时的参数
    const backtrackingCondition = ref({
      timeValue: [],
      SkipCount: '',
      MaxResultCount,
    })
    const tableData = ref<IProductTableItem[]>([])
    const tableSelectList = ref<IProductTableItem[]>([])
    const tableHead = computed(() => [
      {
        field: 'seq',
        title: _t('序号'),
        type: 'seq',
      },
      {
        field: 'code',
        title: _t('工单号'),
      },
      {
        field: 'source',
        title: _t('工单来源'),
      },
      {
        field: 'planStartTime',
        title: _t('计划开始时间'),
      },
      {
        field: 'planFinishTime',
        title: _t('计划结束时间'),
      },
      {
        field: 'productModel',
        title: _t('产品型号'),
      },
      {
        field: 'formulaName',
        title: _t('工艺配方'),
      },
      {
        field: 'segments',
        title: _t('产线段'),
      },
      {
        field: 'planQty',
        title: _t('计划数量'),
      },
      {
        field: 'produceQty',
        title: _t('投产数量'),
      },
      {
        field: 'qualifiedQty',
        title: _t('合格数'),
      },
      {
        field: 'shift',
        title: _t('班次'),
      },
      {
        field: 'startTime',
        title: _t('实际开始时间'),
      },
      {
        field: 'finishTime',
        title: _t('实际结束时间'),
      },
      {
        field: 'statusDescription',
        title: _t('工单状态'),
      },
      {
        field: 'finishReason',
        title: _t('订单结束原因'),
      },
    ])
    // 分页配置
    const paginationConfig = reactive<{
      pageSize: number
      currentPage: number
      total: number
    }>({
      pageSize: MaxResultCount, // X条/页
      currentPage: 1, // 当前第X页
      total: 0, // 总共X页
    })
    const currentSegment = computed(() => {
      return (row: Record<string, any>) => {
        const text = row?.segments
          ?.map((v: { segmentName: string; segmentId: string }) => {
            return v.segmentName
          })
          .join(',')
        return text
      }
    })
    const handleSelectionChange = (val: IProductTableItem[]) => {
      tableSelectList.value = val
    }
 
    const onExport = async () => {
      // if (!isHasPermission('OrderRecords-actions-export')) {
      //   return
      // }
 
      const StartTime =
        head(backtrackingCondition.value.timeValue) || timeValue.value[0]
      const FinishTime =
        last(backtrackingCondition.value.timeValue) || timeValue.value[1]
      const params = {
        Filter: '',
        StartTime,
        FinishTime,
        Status: FIXED_STATUS, // 固定传5 为工单记录->4
        Sorting: '',
        SkipCount: backtrackingCondition.value.SkipCount,
        MaxResultCount: backtrackingCondition.value.MaxResultCount,
      }
 
      // const result = await api.exportOrder(params)
      // console.log(result, 'result >>>')
 
      // downloadFile(
      //   result,
      //   `${_t('工单记录')}${
      //     '' +
      //     new Date().getFullYear() +
      //     Number(new Date().getMonth() + 1) +
      //     new Date().getDate() +
      //     new Date().getTime()
      //   }.xlsx`
      // )
 
      await downloadFile({
        fileUrl: '/api/v1/ordermanagement/order/export',
        fileName: `${_t('工单记录')}${
          '' +
          new Date().getFullYear() +
          Number(new Date().getMonth() + 1) +
          new Date().getDate() +
          new Date().getTime()
        }.xlsx`,
        params,
      })
    }
 
    const onPage = async (current: number) => {
      paginationConfig.currentPage = current
 
      const StartTime = head(backtrackingCondition.value.timeValue)
      const FinishTime = last(backtrackingCondition.value.timeValue)
      const params = {
        Filter: '',
        StartTime,
        FinishTime,
        Status: FIXED_STATUS, // 固定传5 为工单记录->4
        Sorting: '',
        SkipCount: (current - 1) * paginationConfig.pageSize,
        MaxResultCount: backtrackingCondition.value.MaxResultCount,
      }
 
      const result = await api.getTable(params)
      tableData.value = get(result, 'items', [])
 
      paginationConfig.total = get(result, 'totalCount', 0)
    }
    async function initTableData() {
      const StartTime = head(timeValue.value)
      const FinishTime = last(timeValue.value)
 
      const params = {
        Filter: searchValue.value,
        StartTime,
        FinishTime,
        Status: FIXED_STATUS, // 固定传5 为工单记录->4
        Sorting: '',
        SkipCount:
          (paginationConfig.currentPage - 1) * paginationConfig.pageSize,
        MaxResultCount: paginationConfig.pageSize + '',
      }
      // console.log(params, paginationConfig.currentPage, current, 'params')
 
      const result = await api.getTable(params)
      tableData.value = get(result, 'items', [])
      paginationConfig.total = get(result, 'totalCount', 0)
 
      backtrackingCondition.value = {
        // @ts-ignore
        timeValue: cloneDeep(timeValue.value),
        SkipCount:
          (paginationConfig.currentPage - 1) * paginationConfig.pageSize + '',
        MaxResultCount: paginationConfig.pageSize + '',
      }
    }
    function init() {
      initTableData()
    }
 
    // @ts-ignore
    // function downloadFile(file, fileName) {
    //   const blob = new Blob([file])
    //   // 兼容不同浏览器的URL对象
    //   // const url:any = window.URL || window.webkitURL || window.moxURL
    //   const url = window.URL || window.webkitURL
    //   // 创建下载链接
    //   const downloadHref = url.createObjectURL(blob)
    //   // 创建a标签并为其添加属性
    //   let downloadLink = document.createElement('a')
    //   downloadLink.href = downloadHref
    //   downloadLink.download = fileName
    //   // 触发点击事件执行下载
    //   downloadLink.click()
    //   // @ts-ignore
    //   window.URL.revokeObjectURL(url)
    // }
      // @ts-ignore
    function downloadFile(file, fileName) {
      const blob = new Blob([file])
      // 兼容不同浏览器的URL对象
      // const url:any = window.URL || window.webkitURL || window.moxURL
      const url = window.URL || window.webkitURL
      // 创建下载链接
      const downloadHref = url.createObjectURL(blob)
      // 创建a标签并为其添加属性
      let downloadLink = document.createElement('a')
      downloadLink.href = downloadHref
      downloadLink.download = fileName
      // 触发点击事件执行下载
      downloadLink.click()
      // @ts-ignore
      window.URL.revokeObjectURL(url)
    }
 
    init()
    return {
      timeValue,
      tableHead,
      tableData,
      paginationConfig,
      searchValue,
      FIXED_STATUS,
      backtrackingCondition,
      _t,
      currentSegment,
      initTableData,
      onExport,
      handleSelectionChange,
      onPage,
      head,
      last,
    }
  },
})
</script>
 
<style lang="scss" scoped>
@import url('../../styles/common.scss');
@import '../../styles/datePicker.scss';
 
.container {
  height: calc(100% - 80px);
}
 
.head {
  background-color: #f3f3f3;
  padding: 8px 10px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
 
  &-left {
    display: flex;
    align-items: center;
  }
 
  &-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
 
  :deep(.cs-input__wrapper) {
    height: 32px;
  }
}
 
.mt-12 {
  margin-top: 12px;
}
</style>
 
<style lang="scss" scoped>
@import url('../../styles/common.scss');
</style>