wangyani 1 yıl önce
ebeveyn
işleme
754f6d84b0

+ 11 - 6
src/components/separationPoint/workshop.vue

@@ -89,12 +89,7 @@ export default {
         workShop: [],
         producLine: "",
       },
-      workShopOptions: [
-        { label: "士力架包装车间1号", value: "1" },
-        { label: "士力架包装车间2号", value: "2" },
-        { label: "士力架包装车间3号", value: "3" },
-        { label: "士力架包装车间4号", value: "4" },
-      ],
+      workShopOptions: [],
       producLineOptions: [],
     };
   },
@@ -113,6 +108,16 @@ export default {
           .catch((error) => {
             console.error("处理车间下拉失败", error);
           });
+           // 这里是为了拿到sop模板里默认的隔离点选中的数据
+        selectIsSopById(newVal[0].sopId).then((res) => {
+          console.log(res, "sop");
+          const selectSopPoints = res.data.pointDetailVOList.map((item) => {
+            return item.pointId;
+          });
+          // 调用 Vuex action 来存储 selectSopPoints
+          this.setSelectSopPoints(selectSopPoints);
+          console.log(selectSopPoints, "sop_selectePoints");
+        });
       },
       immediate: true, // 立即执行一次,确保在组件初始化时也能捕获到 jobProps 的值
     },

+ 168 - 10
src/views/mes/sop/sopm/NewSop.vue

@@ -253,21 +253,115 @@ export default {
     },
 
     // 详情数据
+    // getSopInfo() {
+    //   const sopId = this.$route.query.sopId;
+    //   console.log(this.$route.query.sopId, "接受路由参数");
+
+    //   selectIsSopById(sopId).then((response) => {
+    //     console.log(response, "详细内容");
+    //     this.form = response.data;
+    //     this.sopProps = [response.data];
+    //     this.tableData = response.data.pointDetailVOList;
+    //     // console.log(this.form, "data数据内容");
+    //     this.title = "修改隔离点信息";
+    //   });
+    // },
     getSopInfo() {
       const sopId = this.$route.query.sopId;
       console.log(this.$route.query.sopId, "接受路由参数");
 
-      selectIsSopById(sopId).then((response) => {
-        console.log(response, "详细内容");
-        this.form = response.data;
-        this.sopProps = [response.data];
-        this.tableData = response.data.pointDetailVOList;
-        // console.log(this.form, "data数据内容");
-        this.title = "修改隔离点信息";
-      });
+      if (sopId) {
+        selectIsSopById(sopId).then((response) => {
+          console.log(response, "详细内容");
+          this.form = response.data;
+          this.sopProps = [response.data];
+          this.tableData = response.data.pointDetailVOList;
+          this.title = "修改隔离点信息";
+        });
+      } else {
+        this.title = "新增隔离点信息";
+        this.form = {
+          spoint: [],
+          sopContent: "",
+          sopCode: "",
+          sopName: "",
+          sopType: "",
+          workareaId: "",
+          workshopId: "",
+        };
+      }
     },
+    // 检查 sopId 是否存在且不为 "null"。如果存在,则调用 getSopById 方法从后端获取数据,并将数据填充到 form 和其他相关字段中。
+
     // 新增sop确认按钮
+    // submit() {
+    //   const selectedpointIds = this.form.spoint.join(",");
+    //   const data = {
+    //     pointIds: selectedpointIds,
+    //     sopContent: this.form.sopContent,
+    //     sopCode: this.form.sopCode,
+    //     sopName: this.form.sopName,
+    //     sopType: this.form.sopType,
+    //     workareaId: this.points.value,
+    //     workshopId: this.emitWorkShop.value,
+    //   };
+    //   if (this.$route.query.sopId !== "null") {
+    //     // this.form.spoint = this.form.spoint.join(",");
+    //     updateIsSop(data).then((res) => {
+    //       console.log(res, "修改接口");
+    //       if (res.code == 200) {
+    //         this.$router.go(-1);
+    //       }
+    //     });
+    //   } else {
+    //     addinsertIsSop(data).then((res) => {
+    //       console.log(res, "新增接口");
+    //       if (res.code == 200) {
+    //         this.$router.go(-1);
+    //       }
+    //     });
+    //   }
+    // },
+
+    // submit() {
+    //   // 确保 this.form.spoint 是一个数组
+    //   if (!Array.isArray(this.form.spoint)) {
+    //     this.form.spoint = [];
+    //   }
+
+    //   const selectedpointIds = this.form.spoint.join(",");
+    //   const data = {
+    //     pointIds: selectedpointIds,
+    //     sopContent: this.form.sopContent,
+    //     sopCode: this.form.sopCode,
+    //     sopName: this.form.sopName,
+    //     sopType: this.form.sopType,
+    //     workareaId: this.points.value,
+    //     workshopId: this.emitWorkShop.value,
+    //   };
+
+    //   if (this.$route.query.sopId) {
+    //     updateIsSop(data).then((res) => {
+    //       console.log(res, "修改接口");
+    //       if (res.code == 200) {
+    //         this.$router.go(-1);
+    //       }
+    //     });
+    //   } else {
+    //     addinsertIsSop(data).then((res) => {
+    //       console.log(res, "新增接口");
+    //       if (res.code == 200) {
+    //         this.$router.go(-1);
+    //       }
+    //     });
+    //   }
+    // },
     submit() {
+      // 确保 this.form.spoint 是一个数组
+      if (!Array.isArray(this.form.spoint)) {
+        this.form.spoint = [];
+      }
+
       const selectedpointIds = this.form.spoint.join(",");
       const data = {
         pointIds: selectedpointIds,
@@ -278,8 +372,18 @@ export default {
         workareaId: this.points.value,
         workshopId: this.emitWorkShop.value,
       };
-      if (this.sopId != null) {
-        updateIsSop(this.form).then((res) => {
+
+      if (this.$route.query.sopId) {
+        // 确保 sopId 存在
+        if (!this.form.sopId) {
+          console.error("隔离点id不可为空!");
+          this.$message.error("隔离点id不可为空!"); // 假设你使用的是 Element UI 的消息提示
+          return;
+        }
+
+        data.sopId = this.form.sopId;
+
+        updateIsSop(data).then((res) => {
           console.log(res, "修改接口");
           if (res.code == 200) {
             this.$router.go(-1);
@@ -294,6 +398,60 @@ export default {
         });
       }
     },
+
+    submit() {
+      // 确保 this.form.spoint 是一个数组
+      if (!Array.isArray(this.form.spoint)) {
+        this.form.spoint = [this.form.spoint]; // 将其转换为数组
+      }
+
+      const selectedpointIds = this.form.spoint.join(",");
+
+      const data = {
+        pointIds: selectedpointIds,
+        sopContent: this.form.sopContent,
+        sopCode: this.form.sopCode,
+        sopName: this.form.sopName,
+        sopType: this.form.sopType,
+        workareaId: this.points.value,
+        workshopId: this.emitWorkShop.value,
+      };
+
+      if (this.$route.query.sopId) {
+        // 确保 sopId 存在
+        if (!this.form.sopId) {
+          this.$message.error("sopId不可为空!"); // 假设你使用的是 Element UI 的消息提示
+          return;
+        }
+
+        data.sopId = this.form.sopId; // 添加 sopId 到 data 对象
+
+        updateIsSop(data)
+          .then((res) => {
+            console.log(res, "修改接口");
+            if (res.code === 200) {
+              this.$router.go(-1);
+            }
+          })
+          .catch((error) => {
+            console.error("修改接口错误:", error);
+            this.$message.error("修改失败,请稍后再试!");
+          });
+      } else {
+        addinsertIsSop(data)
+          .then((res) => {
+            console.log(res, "新增接口");
+            if (res.code === 200) {
+              this.$router.go(-1);
+            }
+          })
+          .catch((error) => {
+            console.error("新增接口错误:", error);
+            this.$message.error("新增失败,请稍后再试!");
+          });
+      }
+    },
+
     // 子组件逆向传递选中的隔离点
     handleSelectPoint(points) {
       console.log(points, "父组件接收逆向传递选中的隔离点");

+ 3 - 2
src/views/mes/sop/sopm/index.vue

@@ -144,12 +144,13 @@
     >
       <el-table-column type="selection" width="55" align="center" />
       <!-- 此处sopId为了实现编辑 误删除 -->
-      <el-table-column
+      <!-- <el-table-column
         label="SOPID"
         align="center"
         prop="sopId"
         v-if="(showId = false)"
-      />
+      /> -->
+      <el-table-column label="SOPID" align="center" prop="sopId" />
       <el-table-column label="SOP编号" align="center" prop="sopCode">
         <!-- <template slot-scope="scope">
           <el-button