#
Junjie
8 小时以前 bf64e8016283b18c04d5392dd9c002b921021af2
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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
Vue.component("monitor-workbench", {
  template: `
    <div class="wb-root">
      <div class="wb-tabs" role="tablist">
        <button
          v-for="tab in tabs"
          :key="tab.key"
          type="button"
          :class="['wb-tab', { 'is-active': activeCard === tab.key }]"
          @click="changeTab(tab.key)"
        >{{ tab.label }}</button>
      </div>
 
      <div class="wb-toolbar">
        <input
          class="wb-input"
          :value="currentSearch"
          :placeholder="currentSearchPlaceholder()"
          @input="updateSearch($event.target.value)"
        />
        <div class="wb-toolbar-actions">
          <button type="button" class="wb-btn wb-btn-ghost" @click="refreshCurrent">刷新</button>
          <button type="button" class="wb-btn" @click="toggleControl">
            {{ currentShowControl ? '收起操作' : '展开操作' }}
          </button>
        </div>
      </div>
 
      <div class="wb-main">
        <div class="wb-side">
          <div class="wb-list-card">
            <div class="wb-side-title">设备选择</div>
            <div class="wb-list">
              <button
                v-for="item in filteredList"
                :key="activeCard + '-' + getItemId(activeCard, item)"
                type="button"
                :class="['wb-list-item', { 'is-active': isSelected(activeCard, item) }]"
                @click="selectItem(activeCard, item)"
              >
                <span :class="['wb-badge', 'is-' + getStatusTone(activeCard, item)]">{{ getStatusLabel(activeCard, item) }}</span>
                <div class="wb-list-main">
                  <div class="wb-list-title">{{ getItemTitle(activeCard, item) }}</div>
                  <div class="wb-list-meta">{{ getItemMeta(activeCard, item) }}</div>
                </div>
              </button>
              <div v-if="filteredList.length === 0" class="wb-empty">当前没有可展示的数据</div>
            </div>
          </div>
 
          <div v-if="currentShowControl" class="wb-control-card">
            <div class="wb-side-title">快捷操作</div>
            <div class="wb-control-target">{{ controlTargetText }}</div>
            <div class="wb-control-subtitle">{{ controlPanelHint }}</div>
 
            <div v-if="activeCard === 'crn'" class="wb-form-grid">
              <label class="wb-field">
                <span class="wb-field-label">堆垛机号</span>
                <input class="wb-input" v-model="controlForms.crn.crnNo" placeholder="1" />
              </label>
              <label class="wb-field">
                <span class="wb-field-label">源库位</span>
                <input class="wb-input" v-model="controlForms.crn.sourceLocNo" placeholder="源点" />
              </label>
              <label class="wb-field wb-field-span-2">
                <span class="wb-field-label">目标库位</span>
                <input class="wb-input" v-model="controlForms.crn.targetLocNo" placeholder="目标点" />
              </label>
              <div class="wb-action-row">
                <button type="button" class="wb-btn wb-btn-primary" @click="submitControl('transport')">取放货</button>
                <button type="button" class="wb-btn wb-btn-ghost" @click="submitControl('move')">移动</button>
                <button type="button" class="wb-btn wb-btn-soft" @click="submitControl('taskComplete')">完成</button>
              </div>
            </div>
 
            <div v-else-if="activeCard === 'dualCrn'" class="wb-form-grid">
              <label class="wb-field">
                <span class="wb-field-label">堆垛机号</span>
                <input class="wb-input" v-model="controlForms.dualCrn.crnNo" placeholder="2" />
              </label>
              <label class="wb-field">
                <span class="wb-field-label">工位</span>
                <select class="wb-select" v-model="controlForms.dualCrn.station">
                  <option :value="1">工位1</option>
                  <option :value="2">工位2</option>
                </select>
              </label>
              <label class="wb-field">
                <span class="wb-field-label">源库位</span>
                <input class="wb-input" v-model="controlForms.dualCrn.sourceLocNo" placeholder="源点" />
              </label>
              <label class="wb-field">
                <span class="wb-field-label">目标库位</span>
                <input class="wb-input" v-model="controlForms.dualCrn.targetLocNo" placeholder="目标点" />
              </label>
              <div class="wb-action-row">
                <button type="button" class="wb-btn wb-btn-primary" @click="submitControl('transport')">取放货</button>
                <button type="button" class="wb-btn wb-btn-ghost" @click="submitControl('pickup')">取货</button>
                <button type="button" class="wb-btn wb-btn-ghost" @click="submitControl('putdown')">放货</button>
                <button type="button" class="wb-btn wb-btn-ghost" @click="submitControl('move')">移动</button>
                <button type="button" class="wb-btn wb-btn-soft" @click="submitControl('taskComplete')">完成</button>
              </div>
            </div>
 
            <div v-else-if="activeCard === 'devp'" class="wb-form-grid">
              <label class="wb-field">
                <span class="wb-field-label">站号</span>
                <input class="wb-input" v-model="controlForms.devp.stationId" placeholder="101" />
              </label>
              <label class="wb-field">
                <span class="wb-field-label">工作号</span>
                <input class="wb-input" v-model="controlForms.devp.taskNo" placeholder="工作号" />
              </label>
              <label class="wb-field wb-field-span-2">
                <span class="wb-field-label">目标站</span>
                <input class="wb-input" v-model="controlForms.devp.targetStationId" placeholder="目标站号" />
              </label>
              <div class="wb-action-row">
                <button type="button" class="wb-btn wb-btn-primary" @click="submitControl('move')">下发</button>
                <button type="button" class="wb-btn wb-btn-soft" @click="submitControl('reset')">复位</button>
                <button
                  v-if="selectedItem"
                  type="button"
                  class="wb-btn wb-btn-ghost"
                  @click="editBarcode"
                >条码</button>
              </div>
            </div>
 
            <div v-else-if="activeCard === 'rgv'" class="wb-form-grid">
              <label class="wb-field">
                <span class="wb-field-label">RGV号</span>
                <input class="wb-input" v-model="controlForms.rgv.rgvNo" placeholder="1" />
              </label>
              <label class="wb-field">
                <span class="wb-field-label">源点</span>
                <input class="wb-input" v-model="controlForms.rgv.sourcePos" placeholder="源点" />
              </label>
              <label class="wb-field wb-field-span-2">
                <span class="wb-field-label">目标点</span>
                <input class="wb-input" v-model="controlForms.rgv.targetPos" placeholder="目标点" />
              </label>
              <div class="wb-action-row">
                <button type="button" class="wb-btn wb-btn-primary" @click="submitControl('transport')">取放货</button>
                <button type="button" class="wb-btn wb-btn-ghost" @click="submitControl('move')">移动</button>
                <button type="button" class="wb-btn wb-btn-soft" @click="submitControl('taskComplete')">完成</button>
              </div>
            </div>
          </div>
        </div>
 
        <div class="wb-detail-panel">
          <div class="wb-detail" v-if="selectedItem">
            <div class="wb-detail-header">
              <div>
                <div class="wb-section-title">{{ getItemTitle(activeCard, selectedItem) }}</div>
                <div class="wb-detail-subtitle">{{ getItemMeta(activeCard, selectedItem) }}</div>
              </div>
              <div class="wb-detail-actions">
                <button
                  v-if="activeCard === 'dualCrn'"
                  type="button"
                  class="wb-link"
                  @click="editDualTask(1)"
                >工位1任务号</button>
                <button
                  v-if="activeCard === 'dualCrn'"
                  type="button"
                  class="wb-link"
                  @click="editDualTask(2)"
                >工位2任务号</button>
              </div>
            </div>
 
            <div class="wb-detail-grid">
              <div v-for="entry in detailEntries" :key="entry.label" class="wb-detail-cell">
                <div class="wb-detail-label">{{ entry.label }}</div>
                <div class="wb-detail-value">{{ entry.value }}</div>
              </div>
            </div>
          </div>
          <div class="wb-detail wb-detail-empty" v-else>
            <div class="wb-empty">请先从左侧选择一个设备</div>
          </div>
        </div>
      </div>
 
      <div v-if="noticeMessage" :class="['wb-notice', 'is-' + noticeType]">{{ noticeMessage }}</div>
    </div>
  `,
  props: {
    activeCard: { type: String, default: "crn" },
    crnParam: { type: Object, default: function () { return {}; } },
    dualCrnParam: { type: Object, default: function () { return {}; } },
    devpParam: { type: Object, default: function () { return {}; } },
    rgvParam: { type: Object, default: function () { return {}; } },
    crnList: { type: Array, default: function () { return []; } },
    dualCrnList: { type: Array, default: function () { return []; } },
    stationList: { type: Array, default: function () { return []; } },
    rgvList: { type: Array, default: function () { return []; } }
  },
  data() {
    return {
      tabs: [
        { key: "crn", label: "堆垛机" },
        { key: "dualCrn", label: "双工位" },
        { key: "devp", label: "输送站" },
        { key: "rgv", label: "RGV" }
      ],
      searchMap: {
        crn: "",
        dualCrn: "",
        devp: "",
        rgv: ""
      },
      selectedIdMap: {
        crn: null,
        dualCrn: null,
        devp: null,
        rgv: null
      },
      showControlMap: {
        crn: false,
        dualCrn: false,
        devp: false,
        rgv: false
      },
      controlForms: {
        crn: { crnNo: "", sourceLocNo: "", targetLocNo: "" },
        dualCrn: { crnNo: "", sourceLocNo: "", targetLocNo: "", station: 1 },
        devp: { stationId: "", taskNo: "", targetStationId: "" },
        rgv: { rgvNo: "", sourcePos: "", targetPos: "" }
      },
      noticeMessage: "",
      noticeType: "info",
      noticeTimer: null
    };
  },
  computed: {
    currentSearch() {
      return this.searchMap[this.activeCard] || "";
    },
    currentShowControl() {
      return !!this.showControlMap[this.activeCard];
    },
    currentList() {
      return this.getListByType(this.activeCard);
    },
    filteredList() {
      const keyword = String(this.currentSearch || "").trim().toLowerCase();
      if (!keyword) { return this.currentList; }
      return this.currentList.filter((item) => this.matchesKeyword(this.activeCard, item, keyword));
    },
    selectedItem() {
      return this.getSelectedItem(this.activeCard);
    },
    detailEntries() {
      return this.buildDetailEntries(this.activeCard, this.selectedItem);
    },
    controlPanelTitle() {
      if (this.activeCard === "crn") { return "堆垛机控制"; }
      if (this.activeCard === "dualCrn") { return "双工位控制"; }
      if (this.activeCard === "devp") { return "输送站控制"; }
      if (this.activeCard === "rgv") { return "RGV控制"; }
      return "控制操作";
    },
    controlPanelHint() {
      if (this.activeCard === "crn") { return "先确认设备号,再填写源库位和目标库位。"; }
      if (this.activeCard === "dualCrn") { return "先选择工位,再下发取货、放货或移动指令。"; }
      if (this.activeCard === "devp") { return "用于站点下发、复位和条码维护。"; }
      if (this.activeCard === "rgv") { return "用于轨道车取放货、移动和任务完成。"; }
      return "";
    },
    controlTargetText() {
      if (!this.selectedItem) { return "未选中设备"; }
      return "当前目标: " + this.getItemTitle(this.activeCard, this.selectedItem);
    }
  },
  watch: {
    activeCard: {
      immediate: true,
      handler(type) {
        this.ensureSelection(type);
      }
    },
    crnList() { this.ensureSelection("crn"); },
    dualCrnList() { this.ensureSelection("dualCrn"); },
    stationList() { this.ensureSelection("devp"); },
    rgvList() { this.ensureSelection("rgv"); },
    crnParam: {
      deep: true,
      handler(v) { this.applyExternalFocus("crn", v && v.crnNo); }
    },
    dualCrnParam: {
      deep: true,
      handler(v) { this.applyExternalFocus("dualCrn", v && v.crnNo); }
    },
    devpParam: {
      deep: true,
      handler(v) { this.applyExternalFocus("devp", v && v.stationId); }
    },
    rgvParam: {
      deep: true,
      handler(v) { this.applyExternalFocus("rgv", v && v.rgvNo); }
    }
  },
  beforeDestroy() {
    if (this.noticeTimer) {
      clearTimeout(this.noticeTimer);
      this.noticeTimer = null;
    }
  },
  methods: {
    changeTab(type) {
      if (type === this.activeCard) { return; }
      this.$emit("change-tab", type);
    },
    updateSearch(value) {
      this.$set(this.searchMap, this.activeCard, value);
      this.ensureSelection(this.activeCard);
    },
    refreshCurrent() {
      this.$emit("refresh-request", this.activeCard);
    },
    toggleControl() {
      this.$set(this.showControlMap, this.activeCard, !this.currentShowControl);
      if (this.currentShowControl && this.selectedItem) {
        this.hydrateControlForm(this.activeCard, this.selectedItem);
      }
    },
    getListByType(type) {
      if (type === "crn") { return this.crnList || []; }
      if (type === "dualCrn") { return this.dualCrnList || []; }
      if (type === "devp") { return this.stationList || []; }
      if (type === "rgv") { return this.rgvList || []; }
      return [];
    },
    getItemId(type, item) {
      if (!item) { return null; }
      if (type === "crn" || type === "dualCrn") { return item.crnNo; }
      if (type === "devp") { return item.stationId; }
      if (type === "rgv") { return item.rgvNo; }
      return null;
    },
    getSelectedItem(type) {
      const list = this.filteredListForType(type);
      if (!list.length) { return null; }
      const selectedId = this.selectedIdMap[type];
      for (let i = 0; i < list.length; i++) {
        if (String(this.getItemId(type, list[i])) === String(selectedId)) {
          return list[i];
        }
      }
      return list[0];
    },
    filteredListForType(type) {
      const keyword = String(this.searchMap[type] || "").trim().toLowerCase();
      const list = this.getListByType(type);
      if (!keyword) { return list; }
      return list.filter((item) => this.matchesKeyword(type, item, keyword));
    },
    ensureSelection(type) {
      const list = this.filteredListForType(type);
      if (!list.length) {
        this.$set(this.selectedIdMap, type, null);
        return;
      }
      const currentId = this.selectedIdMap[type];
      const exists = list.some((item) => String(this.getItemId(type, item)) === String(currentId));
      if (!exists) {
        this.$set(this.selectedIdMap, type, this.getItemId(type, list[0]));
      }
    },
    applyExternalFocus(type, rawId) {
      if (rawId == null || rawId === "" || rawId === 0) { return; }
      this.$set(this.selectedIdMap, type, rawId);
      if (this.activeCard === type) {
        const item = this.getSelectedItem(type);
        if (item) { this.hydrateControlForm(type, item); }
      }
    },
    selectItem(type, item) {
      this.$set(this.selectedIdMap, type, this.getItemId(type, item));
      this.hydrateControlForm(type, item);
    },
    hydrateControlForm(type, item) {
      if (!item) { return; }
      if (type === "crn") {
        this.controlForms.crn.crnNo = this.orEmpty(item.crnNo);
      } else if (type === "dualCrn") {
        this.controlForms.dualCrn.crnNo = this.orEmpty(item.crnNo);
      } else if (type === "devp") {
        this.controlForms.devp.stationId = this.orEmpty(item.stationId);
        this.controlForms.devp.taskNo = this.orEmpty(item.taskNo);
        this.controlForms.devp.targetStationId = this.orEmpty(item.targetStaNo);
      } else if (type === "rgv") {
        this.controlForms.rgv.rgvNo = this.orEmpty(item.rgvNo);
      }
    },
    matchesKeyword(type, item, keyword) {
      const fields = [];
      if (type === "crn" || type === "dualCrn") {
        fields.push(item.crnNo, item.taskNo, item.taskNoTwo, item.locNo, item.sourceLocNo, item.status, item.mode);
      } else if (type === "devp") {
        fields.push(item.stationId, item.taskNo, item.targetStaNo, item.barcode, item.errorMsg, item.extend);
      } else if (type === "rgv") {
        fields.push(item.rgvNo, item.taskNo, item.trackSiteNo, item.status, item.mode, item.alarm);
      }
      return fields.some((field) => String(field == null ? "" : field).toLowerCase().indexOf(keyword) !== -1);
    },
    currentSearchPlaceholder() {
      if (this.activeCard === "crn") { return "搜索堆垛机号"; }
      if (this.activeCard === "dualCrn") { return "搜索双工位堆垛机号"; }
      if (this.activeCard === "devp") { return "搜索站号 / 条码"; }
      if (this.activeCard === "rgv") { return "搜索RGV号"; }
      return "搜索";
    },
    getItemTitle(type, item) {
      if (!item) { return "-"; }
      if (type === "crn") { return item.crnNo + "号堆垛机"; }
      if (type === "dualCrn") { return item.crnNo + "号双工位堆垛机"; }
      if (type === "devp") { return item.stationId + "号站点"; }
      if (type === "rgv") { return item.rgvNo + "号RGV"; }
      return "-";
    },
    getItemMeta(type, item) {
      if (!item) { return "-"; }
      if (type === "crn") { return "任务 " + this.orDash(item.workNo) + " | 目标 " + this.orDash(item.locNo); }
      if (type === "dualCrn") { return "工位1 " + this.orDash(item.taskNo) + " | 工位2 " + this.orDash(item.taskNoTwo); }
      if (type === "devp") { return "任务 " + this.orDash(item.taskNo) + " | 目标站 " + this.orDash(item.targetStaNo); }
      if (type === "rgv") { return "轨道位 " + this.orDash(item.trackSiteNo) + " | 任务 " + this.orDash(item.taskNo); }
      return "-";
    },
    getStatusLabel(type, item) {
      if (!item) { return "未知"; }
      if (type === "devp") { return item.autoing ? "自动" : "手动"; }
      const status = String(item.deviceStatus || "").toUpperCase();
      if (status === "AUTO") { return "自动"; }
      if (status === "WORKING") { return "作业中"; }
      if (status === "ERROR") { return "故障"; }
      return "离线";
    },
    getStatusTone(type, item) {
      const label = this.getStatusLabel(type, item);
      if (label === "自动") { return "success"; }
      if (label === "作业中") { return "working"; }
      if (label === "手动") { return "warning"; }
      if (label === "故障") { return "danger"; }
      return "muted";
    },
    isSelected(type, item) {
      return String(this.getItemId(type, item)) === String(this.selectedIdMap[type]);
    },
    buildDetailEntries(type, item) {
      if (!item) { return []; }
      if (type === "crn") {
        return [
          { label: "编号", value: this.orDash(item.crnNo) },
          { label: "工作号", value: this.orDash(item.workNo) },
          { label: "模式", value: this.orDash(item.mode) },
          { label: "状态", value: this.orDash(item.status) },
          { label: "源库位", value: this.orDash(item.sourceLocNo) },
          { label: "目标库位", value: this.orDash(item.locNo) },
          { label: "是否有物", value: this.yesNo(item.loading) },
          { label: "任务接收", value: this.orDash(item.taskReceive) },
          { label: "列", value: this.orDash(item.bay) },
          { label: "层", value: this.orDash(item.lev) },
          { label: "货叉定位", value: this.orDash(item.forkOffset) },
          { label: "载货台定位", value: this.orDash(item.liftPos) },
          { label: "走行定位", value: this.orDash(item.walkPos) },
          { label: "走行速度", value: this.orDash(item.xspeed) },
          { label: "升降速度", value: this.orDash(item.yspeed) },
          { label: "叉牙速度", value: this.orDash(item.zspeed) },
          { label: "称重数据", value: this.orDash(item.weight) },
          { label: "条码数据", value: this.orDash(item.barcode) },
          { label: "故障代码", value: this.orDash(item.warnCode) },
          { label: "故障描述", value: this.orDash(item.alarm) }
        ];
      }
      if (type === "dualCrn") {
        return [
          { label: "模式", value: this.orDash(item.mode) },
          { label: "异常码", value: this.orDash(item.warnCode) },
          { label: "工位1任务号", value: this.orDash(item.taskNo) },
          { label: "工位2任务号", value: this.orDash(item.taskNoTwo) },
          { label: "工位1状态", value: this.orDash(item.status) },
          { label: "工位2状态", value: this.orDash(item.statusTwo) },
          { label: "工位1有物", value: this.yesNo(item.loading) },
          { label: "工位2有物", value: this.yesNo(item.loadingTwo) },
          { label: "列", value: this.orDash(item.bay) },
          { label: "层", value: this.orDash(item.lev) },
          { label: "载货台定位", value: this.orDash(item.liftPos) },
          { label: "走行定位", value: this.orDash(item.walkPos) },
          { label: "走行速度", value: this.orDash(item.xspeed) },
          { label: "升降速度", value: this.orDash(item.yspeed) },
          { label: "叉牙速度", value: this.orDash(item.zspeed) },
          { label: "扩展数据", value: this.orDash(item.extend) }
        ];
      }
      if (type === "devp") {
        return [
          { label: "编号", value: this.orDash(item.stationId) },
          { label: "工作号", value: this.orDash(item.taskNo) },
          { label: "目标站", value: this.orDash(item.targetStaNo) },
          { label: "模式", value: item.autoing ? "自动" : "手动" },
          { label: "有物", value: this.yesNo(item.loading) },
          { label: "可入", value: this.yesNo(item.inEnable) },
          { label: "可出", value: this.yesNo(item.outEnable) },
          { label: "空板信号", value: this.yesNo(item.emptyMk) },
          { label: "满板信号", value: this.yesNo(item.fullPlt) },
          { label: "运行阻塞", value: this.yesNo(item.runBlock) },
          { label: "启动入库", value: this.yesNo(item.enableIn) },
          { label: "托盘高度", value: this.orDash(item.palletHeight) },
          { label: "条码", value: this.orDash(item.barcode) },
          { label: "重量", value: this.orDash(item.weight) },
          { label: "任务可写区", value: this.orDash(item.taskWriteIdx) },
          { label: "故障代码", value: this.orDash(item.error) },
          { label: "故障信息", value: this.orDash(item.errorMsg) }
        ];
      }
      if (type === "rgv") {
        return [
          { label: "编号", value: this.orDash(item.rgvNo) },
          { label: "工作号", value: this.orDash(item.taskNo) },
          { label: "模式", value: this.orDash(item.mode) },
          { label: "状态", value: this.orDash(item.status) },
          { label: "轨道位", value: this.orDash(item.trackSiteNo) },
          { label: "是否有物", value: this.yesNo(item.loading) },
          { label: "故障代码", value: this.orDash(item.warnCode) },
          { label: "故障描述", value: this.orDash(item.alarm) },
          { label: "扩展数据", value: this.orDash(item.extend) }
        ];
      }
      return [];
    },
    submitControl(action) {
      const config = this.getControlConfig(this.activeCard, action);
      if (!config) { return; }
      $.ajax({
        url: baseUrl + config.url,
        headers: { token: localStorage.getItem("token") },
        contentType: "application/json",
        method: "post",
        data: JSON.stringify(config.payload),
        success: (res) => {
          if (res && res.code === 200) {
            this.showNotice(res.msg || "操作成功", "success");
            this.$emit("refresh-request", this.activeCard);
          } else {
            this.showNotice((res && res.msg) || "操作失败", "warning");
          }
        },
        error: () => {
          this.showNotice("请求失败", "danger");
        }
      });
    },
    getControlConfig(type, action) {
      if (type === "crn") {
        return {
          url: { transport: "/crn/command/take", move: "/crn/command/move", taskComplete: "/crn/command/taskComplete" }[action],
          payload: this.controlForms.crn
        };
      }
      if (type === "dualCrn") {
        return {
          url: {
            transport: "/dualcrn/command/take",
            pickup: "/dualcrn/command/pick",
            putdown: "/dualcrn/command/put",
            move: "/dualcrn/command/move",
            taskComplete: "/dualcrn/command/taskComplete"
          }[action],
          payload: this.controlForms.dualCrn
        };
      }
      if (type === "devp") {
        return {
          url: { move: "/station/command/move", reset: "/station/command/reset" }[action],
          payload: this.controlForms.devp
        };
      }
      if (type === "rgv") {
        return {
          url: { transport: "/rgv/command/transport", move: "/rgv/command/move", taskComplete: "/rgv/command/taskComplete" }[action],
          payload: this.controlForms.rgv
        };
      }
      return null;
    },
    editBarcode() {
      const item = this.selectedItem;
      if (!item || item.stationId == null) { return; }
      const barcode = window.prompt("请输入新的条码值(可留空清空)", item.barcode || "");
      if (barcode === null) { return; }
      $.ajax({
        url: baseUrl + "/station/command/barcode",
        headers: { token: localStorage.getItem("token") },
        contentType: "application/json",
        method: "post",
        data: JSON.stringify({ stationId: item.stationId, barcode: String(barcode).trim() }),
        success: (res) => {
          if (res && res.code === 200) {
            this.showNotice("条码修改成功", "success");
            this.$emit("refresh-request", "devp");
          } else {
            this.showNotice((res && res.msg) || "条码修改失败", "warning");
          }
        },
        error: () => { this.showNotice("条码修改失败", "danger"); }
      });
    },
    editDualTask(station) {
      const item = this.selectedItem;
      if (!item || item.crnNo == null) { return; }
      const currentValue = station === 1 ? item.taskNo : item.taskNoTwo;
      const value = window.prompt("请输入工位" + station + "任务号", currentValue == null ? "" : String(currentValue));
      if (value === null) { return; }
      if (!/^\d+$/.test(String(value).trim())) {
        this.showNotice("任务号必须是非负整数", "warning");
        return;
      }
      $.ajax({
        url: baseUrl + "/dualcrn/command/updateTaskNo",
        headers: { token: localStorage.getItem("token") },
        contentType: "application/json",
        method: "post",
        data: JSON.stringify({ crnNo: item.crnNo, station: station, taskNo: Number(value) }),
        success: (res) => {
          if (res && res.code === 200) {
            this.showNotice("任务号更新成功", "success");
            this.$emit("refresh-request", "dualCrn");
          } else {
            this.showNotice((res && res.msg) || "任务号更新失败", "warning");
          }
        },
        error: () => { this.showNotice("任务号更新失败", "danger"); }
      });
    },
    showNotice(message, type) {
      this.noticeMessage = message;
      this.noticeType = type || "info";
      if (this.noticeTimer) { clearTimeout(this.noticeTimer); }
      this.noticeTimer = setTimeout(() => {
        this.noticeMessage = "";
        this.noticeTimer = null;
      }, 2200);
    },
    yesNo(value) {
      if (value === true || value === "Y" || value === "y" || value === 1 || value === "1") { return "Y"; }
      if (value === false || value === 0 || value === "0") { return "N"; }
      return value ? "Y" : "N";
    },
    orDash(value) {
      return value == null || value === "" ? "-" : String(value);
    },
    orEmpty(value) {
      return value == null ? "" : String(value);
    }
  }
});