NewSop.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <div class="newOperations">
  3. <!-- newOperations盒子开始-->
  4. <div class="left">
  5. <!-- 车间 -->
  6. <SopLeft
  7. v-if="this.activeName == 'first'"
  8. @product-line-selected="handleProductLineSelected"
  9. @work-shop-selected="handleWorkshopSelected"
  10. :sopProps="sopProps"
  11. />
  12. <!-- 隔离点 -->
  13. <IsolationLeftVue
  14. v-else
  15. :points="points"
  16. @selection-changed="handleSelectPoint"
  17. />
  18. </div>
  19. <div class="right">
  20. <div class="right_top">
  21. <el-card class="box-card">
  22. <div slot="header" class="clearfix">
  23. <span style="font-size: 18px">{{ this.getSopTitle }}</span>
  24. <span
  25. style="
  26. float: right;
  27. padding: 1px 0;
  28. font-size: 22px;
  29. cursor: pointer;
  30. "
  31. type="text"
  32. @click="goBack"
  33. >×</span
  34. >
  35. </div>
  36. <div class="text item">
  37. <el-tabs v-model="activeName" @tab-click="handleClick">
  38. <el-tab-pane :label="this.getSopTitle" name="first">
  39. <!-- 新增作业票信息-->
  40. <el-form ref="form" :model="form" label-width="70px">
  41. <el-form-item label="SOP名称" prop="sopName">
  42. <el-input
  43. v-model="form.sopName"
  44. placeholder="请输入SOP名称"
  45. style="width: 100%"
  46. />
  47. </el-form-item>
  48. <el-row>
  49. <el-col :span="16">
  50. <el-form-item label="SOP编号" prop="sopCode">
  51. <el-input
  52. v-model="form.sopCode"
  53. placeholder="请输入SOP编号"
  54. style="width: 100%"
  55. />
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="8">
  59. <el-form-item label-width="80">
  60. <el-switch
  61. v-model="autoGenFlag"
  62. active-color="#13ce66"
  63. active-text="自动生成"
  64. @change="handleAutoGenChange(autoGenFlag)"
  65. >
  66. </el-switch>
  67. </el-form-item>
  68. </el-col>
  69. </el-row>
  70. <el-form-item label="SOP类型" prop="sopType">
  71. <el-select
  72. v-model="form.sopType"
  73. placeholder="请选择SOP类型"
  74. clearable
  75. style="width: 100%"
  76. >
  77. <el-option
  78. v-for="dict in dict.type.sop_type"
  79. :key="dict.value"
  80. :label="dict.label"
  81. :value="dict.value"
  82. />
  83. </el-select>
  84. </el-form-item>
  85. <el-form-item label="SOP内容" prop="sopContent">
  86. <el-input
  87. type="textarea"
  88. v-model="form.sopContent"
  89. :rows="5"
  90. ></el-input>
  91. </el-form-item>
  92. <el-form-item label="" prop="" style="margin-top: 95%">
  93. <el-button
  94. style="float: right; height: 30px; line-height: 10px"
  95. type="primary"
  96. @click="nextStep"
  97. >下一步</el-button
  98. >
  99. </el-form-item>
  100. </el-form>
  101. </el-tab-pane>
  102. <el-tab-pane label="选择隔离点" name="second">
  103. <!-- 隔离点信息-->
  104. <el-form ref="form" :model="form" label-width="90px">
  105. <el-form-item label="车间名称" prop="workshopName">
  106. <el-input
  107. v-model="form.workshopName"
  108. style="width: 100%"
  109. disabled
  110. />
  111. </el-form-item>
  112. <el-form-item label="生产线" prop="workline">
  113. <el-input
  114. v-model="form.workline"
  115. style="width: 100%"
  116. disabled
  117. />
  118. </el-form-item>
  119. <div class="text item">
  120. <p style="color:#606266;font-weight: 600;font-size: 16px">已选隔离点</p>
  121. <el-table
  122. :data="tableData"
  123. stripe
  124. height="480"
  125. style="width: 100%"
  126. >
  127. <el-table-column prop="pointId" label="序号" width="60">
  128. </el-table-column>
  129. <el-table-column prop="pointName" label="已选隔离点">
  130. <template slot-scope="scope">
  131. <span style="color: #2a87ff">{{
  132. scope.row.pointName
  133. }}</span>
  134. </template>
  135. </el-table-column>
  136. <el-table-column prop="pointType" label="隔离点类型">
  137. <template slot-scope="scope">
  138. <dict-tag
  139. :options="dict.type.point_type"
  140. :value="scope.row.pointType"
  141. />
  142. </template>
  143. </el-table-column>
  144. <el-table-column
  145. prop="powerType"
  146. label="危险能量类型"
  147. width="100"
  148. >
  149. <template slot-scope="scope">
  150. <dict-tag
  151. :options="dict.type.power_type"
  152. :value="scope.row.powerType"
  153. />
  154. </template>
  155. </el-table-column>
  156. </el-table>
  157. </div>
  158. <el-form-item label="" prop="">
  159. <el-button
  160. style="float: right; height: 30px; line-height: 10px"
  161. type="primary"
  162. @click="submit"
  163. >确 定</el-button
  164. >
  165. <el-button
  166. style="
  167. float: right;
  168. height: 30px;
  169. line-height: 10px;
  170. margin-right: 19%;
  171. "
  172. type="primary"
  173. @click="preStep"
  174. >上一步</el-button
  175. >
  176. </el-form-item>
  177. </el-form>
  178. </el-tab-pane>
  179. </el-tabs>
  180. </div>
  181. </el-card>
  182. </div>
  183. </div>
  184. <!-- newOperations盒子结束-->
  185. </div>
  186. </template>
  187. <script>
  188. import IsolationLeftVue from "@/components/separationPoint/index.vue";
  189. import SopLeft from "@/components/separationPoint/workshop.vue";
  190. import { genCode } from "@/api/system/autocode/rule";
  191. import {
  192. addinsertIsSop,
  193. updateIsSop,
  194. selectIsSopById,
  195. } from "@/api/mes/sop/sopindex";
  196. import { mapActions, mapGetters } from "vuex";
  197. export default {
  198. name: "addView",
  199. dicts: ["power_type", "point_type", "sop_type"],
  200. components: {
  201. SopLeft,
  202. IsolationLeftVue,
  203. },
  204. data() {
  205. return {
  206. //自动生成编码
  207. autoGenFlag: false,
  208. activeName: "first",
  209. form: {
  210. sopName: "",
  211. sopCode: "",
  212. SOPType: "",
  213. workshopName: "", //车间名称
  214. workline: "", //生产线
  215. workareaName: "",
  216. spoint: [], //已选隔离点
  217. },
  218. pickerOptions: {
  219. shortcuts: [
  220. {
  221. text: "今天",
  222. onClick(picker) {
  223. picker.$emit("pick", new Date());
  224. },
  225. },
  226. {
  227. text: "昨天",
  228. onClick(picker) {
  229. const date = new Date();
  230. date.setTime(date.getTime() - 3600 * 1000 * 24);
  231. picker.$emit("pick", date);
  232. },
  233. },
  234. {
  235. text: "一周前",
  236. onClick(picker) {
  237. const date = new Date();
  238. date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
  239. picker.$emit("pick", date);
  240. },
  241. },
  242. ],
  243. },
  244. // 右侧底部已选隔离点
  245. tableData: [],
  246. points: null, //车间逆向传递拿到的隔离点数据
  247. emitWorkShop: null, //车间逆向传递拿到车间相关数据
  248. sopProps: [], //正传递
  249. };
  250. },
  251. mounted() {
  252. if (this.$route.query.sopId !== "null") {
  253. // console.log(this.$route.query.sopId, "接受路由参数");
  254. this.getSopInfo();
  255. this.setSopTitle("编辑SOP");
  256. } else {
  257. this.setSelectSopPoints([]);
  258. this.setPointTableData([]);
  259. this.setSopTitle("新增SOP");
  260. }
  261. },
  262. computed: {
  263. ...mapGetters("sopSelectPoints", ["getSopTitle"]),
  264. },
  265. methods: {
  266. ...mapActions("sopSelectPoints", [
  267. "setSelectSopPoints",
  268. "setPointTableData",
  269. "setSopEdit",
  270. "setSopTitle",
  271. ]),
  272. handleClick(tab, event) {
  273. // console.log(tab, event);
  274. },
  275. preStep() {
  276. this.activeName = "first";
  277. this.tableData = [];
  278. console.log(this.form, "sopform");
  279. },
  280. nextStep() {
  281. this.activeName = "second";
  282. // console.log("我点击了下一步");
  283. console.log(
  284. this.form.workshopName,
  285. this.form.workline,
  286. "点击下一步拿到下拉框的数据"
  287. );
  288. },
  289. // 详情数据
  290. getSopInfo() {
  291. const sopId = this.$route.query.sopId;
  292. console.log(this.$route.query.sopId, "接受路由参数");
  293. if (sopId !== null) {
  294. selectIsSopById(sopId).then((response) => {
  295. console.log(response, "详细内容");
  296. this.form = response.data;
  297. this.sopProps = [response.data];
  298. this.tableData = response.data.pointDetailVOList;
  299. this.title = "修改隔离点信息";
  300. });
  301. } else {
  302. this.title = "新增隔离点信息";
  303. this.setSopEdit(true);
  304. this.setSelectSopPoints([]);
  305. this.setPointTableData([]);
  306. this.tableData = null;
  307. this.form = {
  308. spoint: [],
  309. sopContent: "",
  310. sopCode: "",
  311. sopName: "",
  312. sopType: "",
  313. workareaId: "",
  314. workshopId: "",
  315. };
  316. this.autoGenFlag = false;
  317. }
  318. },
  319. submit() {
  320. // 确保 this.form.spoint 是一个数组,如果为空则默认空数组
  321. if (!Array.isArray(this.form.spoint)) {
  322. this.form.spoint = [];
  323. }
  324. // 如果没有选中点,逆向传递为空时,使用当前表格数据中的点
  325. if (this.form.spoint.length === 0 && Array.isArray(this.tableData)) {
  326. this.form.spoint = this.tableData.map((point) => point.pointId);
  327. }
  328. const selectedpointIds = this.form.spoint.join(",");
  329. const data = {
  330. pointIds: selectedpointIds,
  331. sopContent: this.form.sopContent,
  332. sopCode: this.form.sopCode,
  333. sopName: this.form.sopName,
  334. sopType: this.form.sopType,
  335. workareaId: this.points.value,
  336. workshopId: this.emitWorkShop.value,
  337. };
  338. // 编辑模式
  339. if (this.$route.query.sopId !== "null") {
  340. console.log(this.$route.query.sopId, "sopIdaaa");
  341. // 确保 sopId 存在
  342. if (!this.form.sopId) {
  343. console.error("隔离点id不可为空!");
  344. this.$message.error("隔离点id不可为空!"); // 使用消息提示
  345. return;
  346. }
  347. data.sopId = this.form.sopId;
  348. updateIsSop(data).then((res) => {
  349. console.log(res, "修改接口");
  350. if (res.code == 200) {
  351. this.$router.push("/sop/sopm");
  352. this.$message.success("SOP修改成功");
  353. }
  354. });
  355. } else {
  356. // 新增模式
  357. addinsertIsSop(data).then((res) => {
  358. console.log(res, "新增接口");
  359. if (res.code == 200) {
  360. this.$router.push("/sop/sopm");
  361. this.$message.success("SOP新建成功");
  362. }
  363. });
  364. }
  365. },
  366. // 子组件选中的隔离点逆传递拿到的数据
  367. handleSelectPoint(points) {
  368. // console.log(points, "父组件接收逆向传递选中的隔离点");
  369. // 使用 Set 来存储传递过来的点值
  370. const newValues = new Set(points.map((point) => point.pointId));
  371. // 1. 删除取消选中的点
  372. this.tableData = this.tableData.filter((item) =>
  373. newValues.has(item.pointId)
  374. );
  375. // 2. 确保新增点不会重复
  376. const existingValues = new Set(
  377. this.tableData.map((item) => item.pointId)
  378. );
  379. points.forEach((point) => {
  380. // 如果当前传递的点不在已有的点集中,则添加
  381. if (!existingValues.has(point.pointId)) {
  382. this.tableData.push({
  383. pointName: point.pointName, // 显示的名称
  384. pointId: point.pointId, // 对应的值
  385. pointType: point.pointType,
  386. powerType: point.powerType,
  387. });
  388. // 将新点值添加到 Set 中
  389. existingValues.add(point.value);
  390. }
  391. });
  392. // 更新 form.spoint 为最新选中的隔离点数组
  393. this.form.spoint = points.map((point) => point.pointId);
  394. },
  395. // 车间你逆向传递拿到的隔离点数据产线
  396. handleProductLineSelected(selectedOption) {
  397. // console.log(selectedOption, '父组件接收到的 selectedOption');
  398. this.points = selectedOption;
  399. this.form.workline = selectedOption.label;
  400. },
  401. // 车间子组件逆传递车间相关数据车间
  402. handleWorkshopSelected(selectedOption) {
  403. console.log(selectedOption, "handleWorkshopSelected");
  404. this.emitWorkShop = selectedOption;
  405. this.form.workshopName = selectedOption.label;
  406. },
  407. //自动生成编码
  408. handleAutoGenChange(autoGenFlag) {
  409. if (autoGenFlag) {
  410. genCode("SOP_CODE").then((response) => {
  411. this.form.sopCode = response;
  412. });
  413. } else {
  414. this.form.sopCode = null;
  415. }
  416. },
  417. // 侧边X关闭
  418. goBack() {
  419. this.$router.push("/sop/sopm");
  420. },
  421. // methods结束
  422. },
  423. };
  424. </script>
  425. <style scoped lang="scss">
  426. .newOperations {
  427. width: 99%;
  428. height: 100%;
  429. // background: pink;
  430. margin: 10px;
  431. display: flex;
  432. .left {
  433. width: 75%;
  434. height: 830px;
  435. background: #eee;
  436. margin-right: 10px;
  437. }
  438. .right {
  439. flex: 1;
  440. .right_top {
  441. height: 540px;
  442. }
  443. }
  444. }
  445. //右侧卡片样式开始
  446. .text {
  447. font-size: 14px;
  448. }
  449. .item {
  450. margin-bottom: 18px;
  451. p {
  452. font-size: 18px;
  453. font-weight: bolder;
  454. font-family: SourceHanSansSC-bold;
  455. }
  456. }
  457. .clearfix:before,
  458. .clearfix:after {
  459. display: table;
  460. content: "";
  461. width: 320px;
  462. }
  463. .clearfix:after {
  464. clear: both;
  465. }
  466. .box-card {
  467. // width: 390px;
  468. width: 95%;
  469. height: 820px;
  470. }
  471. ::v-deeep .el-tabs--top .el-tabs__item.is-top:nth-child(2),
  472. .el-tabs--top .el-tabs__item.is-bottom:nth-child(2),
  473. .el-tabs--bottom .el-tabs__item.is-top:nth-child(2),
  474. .el-tabs--bottom .el-tabs__item.is-bottom:nth-child(2) {
  475. padding-left: 100px !important;
  476. }
  477. ::v-deep .el-tabs .el-tabs__item {
  478. padding: 0 50px !important;
  479. }
  480. //右侧卡片样式结束
  481. </style>
  482. <style>
  483. </style>