gongchunyi
2026-09-01 af9bd8d2f33bdac39400a94c46db45f48094d8cc
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
<template>
  <el-dialog v-model="visible" title="选择工序" width="800px" destroy-on-close :close-on-click-modal="false">
    <el-form :inline="true" :model="query" class="mb-2">
      <el-form-item label="工序名称">
        <el-input v-model="query.name" placeholder="输入工序名称" clearable @keyup.enter="onSearch" style="width: 180px" />
      </el-form-item>
      <el-form-item label="工序编码">
        <el-input v-model="query.no" placeholder="输入工序编码" clearable @keyup.enter="onSearch" style="width: 180px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSearch">搜索</el-button>
        <el-button @click="onReset">重置</el-button>
      </el-form-item>
    </el-form>
 
    <el-table ref="tableRef" v-loading="loading" :data="tableData" height="380" highlight-current-row row-key="id"
      @current-change="handleCurrentChange" @row-dblclick="onConfirm">
      <el-table-column type="index" label="序号" width="60" />
      <el-table-column prop="no" label="工序编码" min-width="130" />
      <el-table-column prop="name" label="工序名称" min-width="150" />
      <el-table-column prop="isQuality" label="是否质检" min-width="90">
        <template #default="{ row }">
          <el-tag size="small" :type="row.isQuality ? 'warning' : 'info'">{{ row.isQuality ? '是' : '否' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="isProduction" label="是否生产" min-width="90">
        <template #default="{ row }">
          <el-tag size="small" :type="row.isProduction ? 'success' : 'info'">{{ row.isProduction ? '是' : '否' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注" min-width="120" show-overflow-tooltip />
    </el-table>
 
    <div class="mt-3 flex justify-end">
      <el-pagination background layout="total, sizes, prev, pager, next, jumper" :total="total"
        v-model:page-size="page.pageSize" v-model:current-page="page.pageNum" :page-sizes="[10, 20, 50, 100]"
        @size-change="onPageChange" @current-change="onPageChange" />
    </div>
 
    <template #footer>
      <el-button type="primary" :disabled="!selectedRow" @click="onConfirm">确定</el-button>
      <el-button @click="close()">取消</el-button>
    </template>
  </el-dialog>
</template>
 
<script setup lang="ts">
  import { computed, reactive, ref, watch } from "vue";
  import { ElMessage } from "element-plus";
  import { listPage } from "@/api/productionManagement/productionProcess";
 
  export type ProcessRow = {
    id: number;
    no?: string;
    name: string;
    isQuality?: boolean;
    isProduction?: boolean;
    remark?: string;
  };
 
  const props = defineProps<{
    modelValue: boolean;
  }>();
 
  const emit = defineEmits(["update:modelValue", "confirm"]);
 
  const visible = computed({
    get: () => props.modelValue,
    set: v => emit("update:modelValue", v),
  });
 
  const query = reactive({
    name: "",
    no: "",
  });
 
  const page = reactive({
    pageNum: 1,
    pageSize: 10,
  });
 
  const loading = ref(false);
  const tableData = ref<ProcessRow[]>([]);
  const total = ref(0);
  const selectedRow = ref<ProcessRow | null>(null);
  const tableRef = ref();
 
  function close() {
    visible.value = false;
  }
 
  function handleCurrentChange(row: ProcessRow) {
    selectedRow.value = row;
  }
 
  function onSearch() {
    page.pageNum = 1;
    loadData();
  }
 
  function onReset() {
    query.name = "";
    query.no = "";
    onSearch();
  }
 
  function onPageChange() {
    loadData();
  }
 
  function onConfirm() {
    if (!selectedRow.value) {
      ElMessage.warning("请选择一个工序");
      return;
    }
    emit("confirm", selectedRow.value);
    close();
  }
 
  async function loadData() {
    loading.value = true;
    try {
      selectedRow.value = null;
      if (tableRef.value) {
        tableRef.value.setCurrentRow(null);
      }
      const { data } = await listPage({
        current: page.pageNum,
        size: page.pageSize,
        name: query.name.trim(),
        no: query.no.trim(),
      });
      const records = data?.records ?? (Array.isArray(data) ? data : []);
      tableData.value = Array.isArray(records) ? records : [];
      total.value = Number(data?.total ?? tableData.value.length);
    } catch (e) {
      console.error("加载工序列表失败", e);
      tableData.value = [];
      total.value = 0;
    } finally {
      loading.value = false;
    }
  }
 
  // 监听弹窗打开,重置查询条件和页码(immediate:组件创建时 modelValue 已为 true,也立即加载)
  watch(
    () => props.modelValue,
    visible => {
      if (visible) {
        selectedRow.value = null;
        query.name = "";
        query.no = "";
        page.pageNum = 1;
        loadData();
      }
    },
    { immediate: true }
  );
</script>