From 0d4c393c1afa90a9e6f209c0995976a07133bfbe Mon Sep 17 00:00:00 2001
From: gaoshp <291585735@qq.com>
Date: 星期六, 05 十月 2024 21:11:46 +0800
Subject: [PATCH] 工位数据点

---
 /dev/null                                    |   21 ----
 src/views/console/workstation/CollTable.vue  |   74 ++++++++++++++
 src/views/console/workstation/index.vue      |   79 +++------------
 src/views/console/workstation/CollDialog.vue |   94 +++++++++++++-----
 4 files changed, 160 insertions(+), 108 deletions(-)

diff --git a/src/views/console/workstation/Coll.vue b/src/views/console/workstation/Coll.vue
deleted file mode 100644
index 1e94570..0000000
--- a/src/views/console/workstation/Coll.vue
+++ /dev/null
@@ -1,21 +0,0 @@
-<!--
- * @Date: 2024-10-05 09:51:45
- * @LastEditors: gaoshp
- * @LastEditTime: 2024-10-05 09:53:47
- * @FilePath: /cps-web/src/views/console/workstation/Coll.vue
--->
-<template>
-    <div>
-
-    </div>
-</template>
-
-<script>
-    export default {
-        
-    }
-</script>
-
-<style lang="scss" scoped>
-
-</style>
\ No newline at end of file
diff --git a/src/views/console/workstation/CollDialog.vue b/src/views/console/workstation/CollDialog.vue
index ef32a4c..2b6bdd5 100644
--- a/src/views/console/workstation/CollDialog.vue
+++ b/src/views/console/workstation/CollDialog.vue
@@ -1,11 +1,19 @@
 <template>
-    <el-dialog title="鏁版嵁鐐�" v-model="visible" :width="'100%'" destroy-on-close @closed="$emit('closed')">
-        <el-select v-model="type" placeholder="Select" size="small" style="width: 240px" @change="changeType">
-            <el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id" />
-        </el-select>
+    <el-dialog title="鏁版嵁鐐�" v-model="visible" :width="'80%'" destroy-on-close @closed="$emit('closed')">
+        <p style="margin-bottom: 14px;">
+            <span style="margin-right: 8px;">绫诲瀷</span>
+            <el-select v-model="type" placeholder="Select" size="small" style="width: 240px" @change="changeType">
+                <el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id" />
+            </el-select>
+        </p>
+
         <scFormTable v-show="type" ref="table1" v-model="tabledata" stripe hideDelete :hideAdd="!type"
             :addTemplate="addTemplate">
             <el-table-column v-for="item in cols" :key="item.prop" :prop="item.prop" :label="item.label">
+                <template #header="scope">
+                    <span v-show="item.isRequired" style="color: red;">*</span>
+                    <span>{{ scope.column.label }}</span>
+                </template>
                 <template #default="scope">
                     <el-select v-model="scope.row[item.prop]" placeholder="Select" size="small"
                         v-if="scope.row.status && item.type === 'option'">
@@ -19,12 +27,12 @@
                 </template>
             </el-table-column>
 
-            <el-table-column label="鎿嶄綔" prop="state" width="120">
+            <el-table-column label="鎿嶄綔" prop="state" width="200">
                 <template #default="scope">
                     <el-button-group>
-                        <el-button text type="primary" size="small">缂栬緫</el-button>
-                        <el-button text type="primary">澶嶅埗</el-button>
-                        <el-popconfirm width="220" title="纭畾灏嗛�夋嫨鐨勬暟鎹垹闄�" @confirm="del(scope.row)">
+                        <el-button text type="primary" size="small" @click="table_edit(scope.row)">缂栬緫</el-button>
+                        <!-- <el-button text type="primary" size="small">澶嶅埗</el-button> -->
+                        <el-popconfirm width="220" title="纭畾灏嗛�夋嫨鐨勬暟鎹垹闄�" @confirm="del(scope.$index)">
                             <template #reference>
                                 <el-button text type="primary" size="small">鍒犻櫎</el-button>
                             </template>
@@ -42,8 +50,6 @@
 </template>
 
 <script>
-import deepmerge from 'deepmerge'
-import http from "@/utils/request"
 export default {
     emits: ['success', 'closed'],
     props: {
@@ -75,13 +81,19 @@
     },
     methods: {
         changeType(val) {
-            console.log(val)
-            console.log(JSON.parse(this.typeList.find(v => v.id === val).dpHeadFull))
-            try {
-                this.cols = JSON.parse(this.typeList.find(v => v.id === val).dpHeadFull)
-            } catch (error) {
+            this.$confirm(`鍒囨崲绫诲瀷灏嗗垹闄ゆ墍鏈夊凡閰嶇疆鏁版嵁鐐筦, '鎻愮ず', {
+                type: 'warning'
+            }).then(() => {
+                try {
+                    this.cols = JSON.parse(this.typeList.find(v => v.id === val).dpHeadFull)
+                    this.table = []
+                } catch (error) {
+                    this.cols = []
+                }
+            }).catch(() => {
 
-            }
+            })
+
         },
         //鏄剧ず
         open(mode = 'add', params) {
@@ -106,22 +118,51 @@
         },
         getList(params) {
             this.$HTTP.get(`/api/blade-cps/workstation/listDatapointsByWorkstationId`, {}, { params }).then(res => {
-                // res.data.records = res?.data?.records.map(v => {
-                //     return {
-                //         ...v,
-                //         statusName: v.status ? '鍚敤' : '绂佺敤'
-                //     }
-                // })
+                try {
+                    this.cols = JSON.parse(res.data.dpHead)
+                    console.log(this.cols, 'cols')
+                } catch (error) {
+                    this.cols = []
+                }
+                try {
+                    this.tabledata = JSON.parse(res.data.dpConfig).map(v => {
+                        v.status = null
+                        return v
+                    }) || [];
+                } catch (error) {
+                    this.tabledata = []
+                }
                 this.type = res.data.type
-                this.tabledata = res.data.dpConfig || [];
+
                 // return res
             })
         },
+        table_edit(row) {
+            row.status = '1'
+        },
+        del(index) {
+            this.tabledata.splice(index, 1)
+        },
         //琛ㄥ崟鎻愪氦鏂规硶
         submit() {
-            console.log(this.tabledata)
+            let isRequiredKey = this.cols.filter(v => v.isRequired).map(v => v.prop)
+            let flag = this.tabledata.every(item => {
+                return isRequiredKey.every(v => {
+                    return item[v] !== undefined && item[v] !== null && item[v] !== ''
+                })
+            })
+            if (!flag) {
+                return this.$message.warning('璇锋牎楠屽繀濉」')
+            }
+            let len = [...new Set(this.tabledata.map(v => v.dpName))].length
+            if (len != this.tabledata.length) {
+                return this.$message.warning('鏁版嵁鐐瑰悕绉颁笉鑳介噸澶�')
+            }
             this.$HTTP.put('/api/blade-cps/workstation/saveDatapoints', {
-                dpConfig: JSON.stringify(this.tabledata),
+                dpConfig: JSON.stringify(this.tabledata.map(v => {
+                    delete v.status
+                    return v
+                })),
                 workstationId: this.params.id,
                 type: this.type
             }).then(res => {
@@ -130,6 +171,9 @@
                         workstationId: this.params.id,
                     })
                 }
+            }).finally(() => {
+                this.visible = false
+                this.$emit('success')
             })
         },
 
diff --git a/src/views/console/workstation/CollTable.vue b/src/views/console/workstation/CollTable.vue
new file mode 100644
index 0000000..400b45a
--- /dev/null
+++ b/src/views/console/workstation/CollTable.vue
@@ -0,0 +1,74 @@
+<!--
+ * @Date: 2024-10-05 09:51:45
+ * @LastEditors: gaoshp
+ * @LastEditTime: 2024-10-05 20:40:36
+ * @FilePath: /cps-web/src/views/console/workstation/CollTable.vue
+-->
+<template>
+    <div>
+        <el-table :data="tabledata" height="200px">
+            <el-table-column v-for="item in cols" :key="item.prop" :prop="item.prop" :label="item.label" width="120">
+                <template #default="scope">
+                    <span>{{ scope.row[item.prop] }}</span>
+                </template>
+            </el-table-column>
+        </el-table>
+    </div>
+</template>
+
+<script>
+
+export default {
+    props: {
+        info: {
+            type: Object,
+            default() {
+                return {}
+            }
+        }
+    },
+    watch: {
+        info: {
+            handler() {
+                this.getList({
+                    workstationId: this.info.id,
+                })
+            },
+            deep: true,
+            immediate: true
+        }
+    },
+    data() {
+        return {
+            cols: [],
+            tabledata: []
+        }
+    },
+    methods: {
+        refresh() {
+            this.getList({
+                workstationId: this.info.id,
+            })
+        },
+        getList(params) {
+            this.$HTTP.get(`/api/blade-cps/workstation/listDatapointsByWorkstationId`, {}, { params }).then(res => {
+                try {
+                    this.cols = JSON.parse(res.data.dpHead)
+                } catch (error) {
+                    this.cols = []
+                }
+                try {
+                    this.tabledata = JSON.parse(res.data.dpConfig).map(v => {
+                        v.status = null
+                        return v
+                    }) || [];
+                } catch (error) {
+                    this.tabledata = []
+                }
+            })
+        },
+    }
+}
+</script>
+
+<style lang="scss" scoped></style>
\ No newline at end of file
diff --git a/src/views/console/workstation/index.vue b/src/views/console/workstation/index.vue
index 724afd8..eb35a5f 100644
--- a/src/views/console/workstation/index.vue
+++ b/src/views/console/workstation/index.vue
@@ -153,65 +153,9 @@
 																size="small">鏁版嵁鐐圭紪杈�</el-button>
 														</el-header>
 														<el-main>
-															<el-table :data="list" height="200px"
-																@selection-change="handleSelectionChange">
-																<el-table-column type="selection" width="55"
-																	v-if="editFlag" />
-																<el-table-column label="閲囬泦鍙橀噺鍚嶇О" prop="name"
-																	width="120" />
-																<el-table-column label="宸ヤ綅鍙橀噺鍚嶇О" prop="dataItem"
-																	width="120">
-																	<template #default="scope">
-																		<el-input :disabled="!editFlag"
-																			v-model="scope.row.dataItem"></el-input>
-																	</template>
-																</el-table-column>
-																<el-table-column label="鏁版嵁鏍囩" prop="description"
-																	width="150">
-																	<template #default="scope">
-																		<el-select :disabled="!editFlag"
-																			v-model="scope.row.description">
-																			<el-option
-																				v-for="item in workstation_param_type"
-																				:key="item.dictKey"
-																				:label="item.dictValue"
-																				:value="item.dictKey - 0" />
-																		</el-select>
-																		<!-- {{ dmp_data_type.find(v => v.dictKey == scope.row.wcsDataType)?.dictValue }} -->
-																	</template>
-																</el-table-column>
-																<el-table-column label="鏁版嵁绫诲埆" prop="wcsDataType"
-																	width="150">
-																	<template #default="scope">
-																		<el-select disabled
-																			v-model="scope.row.wcsDataType">
-																			<el-option v-for="item in dmp_data_type"
-																				:key="item.dictKey"
-																				:label="item.dictValue"
-																				:value="item.dictKey - 0" />
-																		</el-select>
-																		<!-- {{ dmp_data_type.find(v => v.dictKey == scope.row.wcsDataType)?.dictValue }} -->
-																	</template>
-																</el-table-column>
-																<el-table-column label="澶у睆" prop="bigScreen">
-																	<template #default="scope">
-																		<el-checkbox :disabled="!editFlag"
-																			v-model="scope.row.bigScreen" />
-																	</template>
-																</el-table-column>
-																<el-table-column label="瀹炴椂鏁版嵁" prop="realTimeData">
-																	<template #default="scope">
-																		<el-checkbox :disabled="!editFlag"
-																			v-model="scope.row.realTimeData" />
-																	</template>
-																</el-table-column>
-																<el-table-column label="杩囩▼鍙傛暟" prop="processParameter">
-																	<template #default="scope">
-																		<el-checkbox :disabled="!editFlag"
-																			v-model="scope.row.processParameter" />
-																	</template>
-																</el-table-column>
-															</el-table>
+															<!-- <el-table :data="list" height="200px">
+															</el-table> -->
+															<CollTable ref="collTable" :info="previewData"></CollTable>
 														</el-main>
 													</el-container>
 												</el-tab-pane>
@@ -394,7 +338,7 @@
 			</el-tabs>
 		</el-card>
 		<Dialog ref="dialog" @success="success" :option="{ types, status, group }"></Dialog>
-		<CollDialog ref="CollDialog" @success="success" :option="{ previewData }"></CollDialog>
+		<CollDialog ref="CollDialog" @success="successColl" :option="{ previewData }"></CollDialog>
 	</el-main>
 </template>
 
@@ -402,12 +346,14 @@
 import pmsPng from '@/assets/pms.png'
 import Dialog from './Dialog.vue'
 import CollDialog from './CollDialog.vue'
+import CollTable from './CollTable.vue'
 import machinePng from '@/assets/machine.png'
 export default {
 	name: 'system',
 	components: {
 		Dialog,
-		CollDialog
+		CollDialog,
+		CollTable
 	},
 	data() {
 		return {
@@ -518,6 +464,9 @@
 		// 鏁版嵁鐐圭紪杈�
 		editCollection() {
 			this.$refs.CollDialog.open('edit', this.previewData)
+		},
+		successColl() {
+			this.$refs.collTable.refresh()
 		},
 		handleSelectionChange(val) {
 			val.forEach(v => {
@@ -671,7 +620,13 @@
 			}
 			console.log(data, '>>>>>>>>>>>')
 			this.$HTTP.get(`/api/blade-cps/workstation/listDmpVariablesByMachineId?machineId=${data.machineId}`).then(res => {
-				this.list = res?.data?.dmpVariablesVOList
+				this.list = res?.data
+				// Object.keys(this.basic).forEach(key => {
+				// 	this.basic[key] = res?.data?.[key] || '-'
+				// })
+			})
+			this.$HTTP.get(`/api/blade-cps/workstation/listDmpVariablesByWorkstationId?workstationId=${data.id}`).then(res => {
+				// this.list = res?.data?.dmpVariablesVOList
 				Object.keys(this.basic).forEach(key => {
 					this.basic[key] = res?.data?.[key] || '-'
 				})

--
Gitblit v1.9.3