huminmin
3 天以前 303e0cb5fa6816dc10b77a284195d36b9e3787db
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
<template>
  <div>
    <el-dialog
        v-model="isShow"
        title="工艺路线项目"
        width="800"
        @close="closeModal"
    >
      <el-button type="primary" @click="isShowProductSelectDialog = true" class="mb5">选择产品</el-button>
      <el-table
          ref="multipleTable"
          v-loading="tableLoading"
          border
          :data="routeItems"
          :header-cell-style="{ background: '#F0F1F5', color: '#333333' }"
          row-key="id"
          tooltip-effect="dark"
          class="lims-table"
      >
        <el-table-column align="center" label="序号" type="index" width="60" />
 
        <el-table-column v-for="(item, index) in tableColumn" :key="index" :label="item.label" :width="item.width" show-overflow-tooltip>
          <template #default="scope" v-if="item.dataType === 'action'">
            <el-button
                v-for="(op, opIndex) in item.operation"
                :key="opIndex"
                :type="op.type"
                :link="op.link"
                size="small"
                @click="op.clickFun(scope.row)"
            >
              {{ op.name }}
            </el-button>
          </template>
 
          <template #default="scope" v-else>
            <template v-if="item.prop === 'processId'">
              <el-select v-model="scope.row[item.prop]" style="width: 100%">
                <el-option
                    v-for="process in processOptions"
                    :key="process.id"
                    :label="process.name"
                    :value="process.id"
                />
              </el-select>
            </template>
            <template v-else>
              {{ scope.row[item.prop] }}
            </template>
          </template>
 
        </el-table-column>
      </el-table>
 
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="handleSubmit">确认</el-button>
          <el-button @click="closeModal">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
 
  <ProductSelectDialog v-if="isShowProductSelectDialog" v-model:model-value="isShowProductSelectDialog" @confirm="handelSelectProducts" />
</template>
 
<script setup>
import {ref, computed, getCurrentInstance, onMounted} from "vue";
import ProductSelectDialog from "@/views/basicData/product/ProductSelectDialog.vue";
import {findProcessRouteItemList, addOrUpdateProcessRouteItem} from "@/api/productionManagement/processRouteItem.js";
import { processList } from "@/api/productionManagement/productionProcess.js";
 
const props = defineProps({
  visible: {
    type: Boolean,
    required: true,
  },
  record: {
    type: Object,
    required: true,
  }
});
 
const emit = defineEmits(['update:visible', 'completed']);
 
const processOptions = ref([]);
 
const isShow = computed({
  get() {
    return props.visible;
  },
  set(val) {
    emit('update:visible', val);
  },
});
 
const tableColumn = ref([
  {
    label: "产品名称",
    prop: "productName",
  },
  {
    label: "规格名称",
    prop: "model",
  },
  {
    label: "单位",
    prop: "unit",
  },
  {
    label: "工序名称",
    prop: "processId",
  },
  {
    dataType: "action",
    label: "操作",
    align: "center",
    fixed: "right",
    operation: [
      {
        name: "删除",
        type: "danger",
        link: true,
        clickFun: (row) => {
          const index = routeItems.value.indexOf(row);
          if (index !== -1) {
            routeItems.value.splice(index, 1);
          }
        }
      },
    ]
  }
])
 
const tableLoading = ref(false);
 
const isShowProductSelectDialog = ref(false)
const routeItems = ref([])
 
let { proxy } = getCurrentInstance()
 
const closeModal = () => {
  isShow.value = false;
};
 
const handelSelectProducts = (products) => {
  const data = products.map(({ id, ...product }) => ({
    ...product,
    productModelId: id,
    routeId: props.record.id
  }));
 
  routeItems.value.push(...data);
}
 
const findProcessRouteItems = () => {
  tableLoading.value = true;
 
  findProcessRouteItemList({routeId: props.record.id}).then(res => {
    tableLoading.value = false;
    routeItems.value = res.data.map(item => ({
      ...item,
      processId: item.processId === 0 ? undefined : item.processId
    }))
  }).catch(err => {
    tableLoading.value = false;
  })
};
 
const findProcessList = () => {
  processList({}).then(res => {
    processOptions.value = res.data
  })
}
 
const handleSubmit = () => {
  if (routeItems.value.length === 0) {
    proxy.$modal.msgError("请添加路线项目");
    return;
  }
 
  // 是否有未选择的工序
  const hasUnselectedProcess = routeItems.value.some(item => !item.processId);
  if (hasUnselectedProcess) {
    proxy.$modal.msgError("请选择工序");
    return;
  }
 
  addOrUpdateProcessRouteItem({routeId: props.record.id, processRouteItem: routeItems.value}).then(res => {
    // 关闭模态框
    isShow.value = false;
    // 告知父组件已完成
    emit('completed');
    proxy.$modal.msgSuccess("提交成功");
  })
};
 
 
defineExpose({
  closeModal,
  handleSubmit,
  isShow,
});
 
onMounted(() => {
  findProcessRouteItems()
  findProcessList()
})
</script>