cuilei
5 天以前 dacf37deb3d53345024402016e9c4d19ac82e3aa
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
<template>
  <a-row :gutter="{ xs: 4, sm: 8, md: 16}">
    <a-col :span="12">
      <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :span="12">
                <a-form-item label="产线">
                  <j-tree-select dict="base_factory,factory_name,id" pid-field="parent_id"
                                 v-model="queryParam.factoryId"></j-tree-select>
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item label="起止日期">
                  <a-range-picker
                    style="width: 100%"
                    @change="dateRangeChange"
                    :value="dateRange"
                    :disabledDate="disabledDate"
                    @openChange="onOpenChange"
                  />
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="info" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button type="primary" @click="productionSchedule" icon="retweet"
                        style="margin-left: 8px">排产</a-button>
            </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
 
        <div class="table-operator">
          <a-dropdown v-if="selectedRowKeys.length > 0">
            <a-menu slot="overlay">
              <a-menu-item key="1" @click="batchDel">
                <a-icon type="delete" />
                删除
              </a-menu-item>
            </a-menu>
            <a-button style="margin-left: 8px"> 批量操作
              <a-icon type="down" />
            </a-button>
          </a-dropdown>
        </div>
        <div>
          <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
            <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
            style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
            <a style="margin-left: 24px" @click="onClearSelected">清空</a>
          </div>
 
          <a-table
            ref="table"
            size="middle"
            :scroll="{x:true}"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            class="j-table-force-nowrap"
            @change="handleTableChange">
 
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text,record">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
              <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
                   style="max-width:80px;font-size: 12px;font-style: italic;" />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
              <a-button
                v-else
                :ghost="true"
                type="primary"
                icon="download"
                size="small"
                @click="downloadFile(text)">
                下载
              </a-button>
            </template>
 
            <span slot="action" slot-scope="text, record">
              <span v-if="record.workOrderStatus === 'NEW'">
                <a-popconfirm title="确定发布吗?" @confirm="() => handlePublish(record.id)">
                  <a>发布</a>
                </a-popconfirm>
                <a-divider type="vertical" />
              </span>
              <span v-if="record.workOrderStatus === 'PUBLISHED'">
                <a @click="handleRePublish(record)">重发布</a>
                <a-divider type="vertical" />
              </span>
              <span>
                <a-dropdown v-if="record.workOrderStatus === 'NEW'">
                  <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                    <a-menu slot="overlay">
                    <a-menu-item>
                      <a @click="handleDetail(record)">详情</a>
                    </a-menu-item>
                    <a-menu-item>
                      <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                        <a>删除</a>
                      </a-popconfirm>
                    </a-menu-item>
                    </a-menu>
                </a-dropdown>
              </span>
              <span v-if="record.workOrderStatus !== 'NEW'">
                <a @click="handleDetail(record)">详情</a>
              </span>
        </span>
          </a-table>
        </div>
 
        <mes-production-work-order-list-modal ref="modal" @ok="modalFormOk"></mes-production-work-order-list-modal>
        <mes-production-work-order-modal ref="modalForm"></mes-production-work-order-modal>
        <mes-production-work-order-republish-modal ref="republishModal" @ok="modalFormOk"></mes-production-work-order-republish-modal>
      </a-card>
    </a-col>
    <a-col :span="12">
      <a-card>
        <MesProductionWeekCalendar
          ref="weekCalendar"
          :start-date="calendarStartDate"
          @select="onDateSelect"
          @change="onCalendarChange"
        >
          <!-- 使用插槽自定义日期单元格内容 -->
          <template #dateCell="{ date, isSelected, isToday }">
            <div class="custom-date-content">
              <!-- 示例:在日期单元格中显示工单信息 -->
              <div
                v-for="workOrder in getWorkOrdersForDate(date)"
                :key="workOrder.id"
                class="work-order-item"
                :class="{ 'urgent': isUrgent(workOrder) }"
              >
                <span class="work-order-shift">{{ workOrder.groupName }}</span>
                <span class="work-order-material">{{ workOrder.materialName }}</span>
                <span class="work-order-quantity">{{ workOrder.planQuantity }}</span>
              </div>
            </div>
          </template>
        </MesProductionWeekCalendar>
      </a-card>
    </a-col>
  </a-row>
</template>
 
<script>
 
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import MesProductionWorkOrderModal from './modules/MesProductionWorkOrderModal'
import MesProductionWeekCalendar from '@views/mes/modules/MesProductionWeekCalendar.vue'
import MesProductionWorkOrderListModal from '@views/mes/modules/MesProductionWorkOrderListModal.vue'
import MesProductionWorkOrderRepublishModal from '@views/mes/modules/MesProductionWorkOrderRepublishModal.vue'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import moment from 'moment'
import { getAction, postAction, requestPut } from '@api/manage'
 
export default {
  name: 'MesProductionWorkOrderList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    MesProductionWorkOrderModal,
    MesProductionWeekCalendar,
    MesProductionWorkOrderListModal,
    MesProductionWorkOrderRepublishModal
  },
  data() {
    return {
      description: '排产工单管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '工单号(任务号)',
          align: 'center',
          dataIndex: 'workOrderCode'
        },
        {
          title: '物料编码',
          align: 'center',
          dataIndex: 'materialNumber'
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName'
        },
        {
          title: '计划生产数量',
          align: 'center',
          dataIndex: 'planQuantity'
        },
        {
          title: '产线',
          align: 'center',
          dataIndex: 'factoryId_dictText'
        },
        {
          title: '班组',
          align: 'center',
          dataIndex: 'groupId_dictText'
        },
        {
          title: '班次',
          align: 'center',
          dataIndex: 'shiftId_dictText'
        },
        {
          title: '排产日期',
          align: 'center',
          dataIndex: 'workOrderDate'
        },
        {
          title: '工单状态',
          align: 'center',
          dataIndex: 'workOrderStatus_dictText'
        },
        {
          title: '实际报工数量',
          align: 'center',
          dataIndex: 'actualQuantity'
        },
        {
          title: '发布人',
          align: 'center',
          dataIndex: 'publisher'
        },
        {
          title: '发布时间',
          align: 'center',
          dataIndex: 'publishTime'
        },
        {
          title: '重发布人',
          align: 'center',
          dataIndex: 'republisher'
        },
        {
          title: '重发布时间',
          align: 'center',
          dataIndex: 'republishTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/mesproductionworkorder/mesProductionWorkOrder/list',
        delete: '/mesproductionworkorder/mesProductionWorkOrder/delete',
        deleteBatch: '/mesproductionworkorder/mesProductionWorkOrder/deleteBatch',
        exportXlsUrl: '/mesproductionworkorder/mesProductionWorkOrder/exportXls',
        importExcelUrl: 'mesproductionworkorder/mesProductionWorkOrder/importExcel',
        listProductionLinesOption: '/base/factory/queryIdTree',
        schedule: '/mesproductionworkorder/mesProductionWorkOrder/schedule',
        publish: '/mesproductionworkorder/mesProductionWorkOrder/publish'
      },
      dictOptions: {},
      superFieldList: [],
      // 用于演示的工单数据
      workOrdersByDate: {},
      // 日历起始日期
      calendarStartDate: moment(),
      productionLineData: [],
      dateRange: [],
      tempStartDate: null, // 临时存储开始日期
      hoveredDate: null,    // 存储鼠标悬停的日期
    }
  },
  created() {
    this.getSuperFieldList()
    this.initDictConfig()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    modalFormOk() {
      this.onClearSelected()
      this.loadData(1).then(() => {
        if (this.queryParam.factoryId) {
          // 同时更新日历中的工单数据
          this.updateCalendarWorkOrders()
        }
      }).catch(error => {
        console.error('数据加载失败:', error)
      })
    },
    loadData(arg) {
      return new Promise((resolve, reject) => {
        if (!this.url.list) {
          this.$message.error("请设置url.list属性!")
          reject(new Error("请设置url.list属性!"))
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        console.log('params', params)
        if (!params) {
          reject(new Error("查询参数无效"))
          return false;
        }
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            // console.log(res)
            //update-begin---author:zhangyafei    Date:20201118  for:适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result;
            if (res.result.total) {
              this.ipagination.total = res.result.total;
            } else {
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for:适配不分页的数据列表------------
            resolve(res)
          } else {
            this.$message.warning(res.message)
            reject(new Error(res.message))
          }
        }).catch(error => {
          reject(error)
        }).finally(() => {
          this.loading = false
        })
      })
    },
    searchQuery() {
      this.queryParam = Object.assign(this.queryParam, this.dateRange)
      this.loadData(1).then(() => {
        if (this.queryParam.factoryId) {
          // 同时更新日历中的工单数据
          this.updateCalendarWorkOrders()
        }
      }).catch(error => {
        console.error('数据加载失败:', error)
      })
    },
    searchReset() {
      this.queryParam = {}
      this.dateRange = []
      this.workOrdersByDate = {}
      this.loadData(1);
    },
    handlePublish(id) {
      requestPut(this.url.publish, null, { ids: id }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData(1).then(() => {
            if (this.queryParam.factoryId) {
              // 同时更新日历中的工单数据
              this.updateCalendarWorkOrders()
            }
          }).catch(error => {
            console.error('数据加载失败:', error)
          })
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    handleRePublish(record) {
      this.$refs.republishModal.add(record)
    },
    initDictConfig() {
      getAction(this.url.listProductionLinesOption, null).then(res => {
        if (res.success) {
          this.productionLineData = res.result
        }
      })
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'int', value: 'delFlag', text: '删除标记', dictCode: '' })
      fieldList.push({ type: 'string', value: 'workOrderCode', text: '工单号(任务号)', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialNumber', text: '物料编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialName', text: '物料名称', dictCode: '' })
      fieldList.push({ type: 'double', value: 'planQuantity', text: '计划生产数量', dictCode: '' })
      fieldList.push({ type: 'string', value: 'factoryId', text: '产线ID(冗余)', dictCode: '' })
      fieldList.push({ type: 'string', value: 'groupId', text: '班组ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'shiftId', text: '班次ID(冗余)', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'workOrderDate', text: '排产日期' })
      fieldList.push({ type: 'string', value: 'workOrderStatus', text: '工单状态', dictCode: 'work_order_status' })
      fieldList.push({ type: 'double', value: 'actualQuantity', text: '实际报工数量', dictCode: '' })
      fieldList.push({ type: 'string', value: 'publisher', text: '发布人', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'publishTime', text: '发布时间' })
      fieldList.push({ type: 'string', value: 'republisher', text: '重发布人', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'republishTime', text: '重发布时间' })
      this.superFieldList = fieldList
    },
    productionSchedule() {
      if (!this.queryParam.factoryId || this.dateRange.length === 0) {
        this.$message.warning('请选择产线及排产日期范围!')
        return
      }
      getAction(this.url.schedule, {
        factoryId: this.queryParam.factoryId,
        startDate: this.dateRange[0].format('YYYY-MM-DD'),
        endDate: this.dateRange[1].format('YYYY-MM-DD')
      }).then(res => {
        if (res.success) {
          this.$refs.modal.edit(res.result, this.dateRange)
        }
      })
    },
    onOpenChange(open) {
      if (!open) {
        // 关闭选择器时重置状态
        this.tempStartDate = null
        this.hoveredDate = null
      }
    },
    disabledDate(current) {
      // 如果有临时开始日期,则限制结束日期范围
      if (this.tempStartDate) {
        const startDate = this.tempStartDate.clone().startOf('day')
        const maxDate = startDate.clone().add(6, 'days').endOf('day') // 7天包括起始日
        const minDate = startDate.clone().subtract(6, 'days').startOf('day') // 也可以向前选6天
        // 禁用超出7天范围的日期
        return current && (current < minDate || current > maxDate)
      }
      // 默认不禁用
      return false
    },
    dateRangeChange(dates, dateStrings) {
      this.dateRange = dates
      if (dates && dates.length > 0) {
        if (dates.length === 1) {
          // 选择了开始日期,保存到临时变量
          this.tempStartDate = dates[0]
          this.hoveredDate = dates[0]
        } else if (dates.length === 2) {
          // 选择了结束日期,验证范围
          const startDate = dates[0]
          const endDate = dates[1]
          const diffDays = endDate.diff(startDate, 'days') + 1
 
          if (diffDays > 7) {
            this.$message.warning('日期范围不能超过7天')
            // 自动调整为7天范围
            const adjustedEndDate = startDate.clone().add(6, 'days')
            this.dateRange = [startDate, adjustedEndDate]
            this.queryParam.startDate = startDate.format('YYYY-MM-DD')
            this.queryParam.endDate = adjustedEndDate.format('YYYY-MM-DD')
          } else {
            this.queryParam.startDate = dateStrings[0]
            this.queryParam.endDate = dateStrings[1]
          }
          // 重置临时状态
          this.tempStartDate = null
          this.hoveredDate = null
        }
      } else {
        // 清除了选择
        this.queryParam.startDate = null
        this.queryParam.endDate = null
        this.tempStartDate = null
        this.hoveredDate = null
      }
    },
    // 处理日期选择事件
    onDateSelect(date) {
      console.log('Selected date:', date.format('YYYY-MM-DD'))
    },
    // 处理日历周变化事件
    onCalendarChange(date) {
      console.log('Calendar week changed:', date.format('YYYY-MM-DD'))
    },
    // 更新日历中的工单数据
    updateCalendarWorkOrders() {
      // 将当前表格数据按日期分组显示在日历中
      const workOrdersByDate = {}
      this.dataSource.filter(workOrder => workOrder.workOrderStatus !== 'NEW').forEach(workOrder => {
        const workOrderDate = workOrder.workOrderDate
        if (workOrderDate) {
          if (!workOrdersByDate[workOrderDate]) {
            workOrdersByDate[workOrderDate] = []
          }
          workOrdersByDate[workOrderDate].push({
            id: workOrder.id,
            groupName: workOrder.groupId_dictText || '',
            materialName: workOrder.materialName || '',
            planQuantity: workOrder.planQuantity || 0
          })
        }
      })
      this.workOrdersByDate = workOrdersByDate
    },
    // 获取指定日期的工单
    getWorkOrdersForDate(date) {
      const dateStr = date.format('YYYY-MM-DD')
      console.log(dateStr)
      return this.workOrdersByDate[dateStr] || []
    },
    // 判断工单是否紧急
    isUrgent(workOrder) {
      return workOrder.status === 'urgent'
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
 
.work-order-item {
  font-size: 12px;
  padding: 2px 4px;
  margin-bottom: 2px;
  background-color: #f0f0f0;
  border-radius: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
 
.work-order-item.urgent {
  background-color: #ffccc7;
  border-left: 2px solid #ff4d4f;
}
 
.work-order-shift {
  font-weight: bold;
  margin-right: 4px;
}
 
.work-order-material {
  margin-right: 4px;
}
 
.work-order-quantity {
  float: right;
}
</style>