NewSop.vue 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. <template>
  2. <div class="newOperations">
  3. <!-- newOperations盒子开始-->
  4. <div class="left">
  5. <!-- 车间 -->
  6. <keep-alive>
  7. <SopLeft
  8. v-show="this.activeName == 'first' || this.activeName == 'third'"
  9. @product-line-selected="handleProductLineSelected"
  10. @work-shop-selected="handleWorkshopSelected"
  11. :sopProps="sopProps"
  12. ></SopLeft>
  13. </keep-alive>
  14. <!-- 隔离点 style="position: relative;z-index:0"-->
  15. <IsolationLeftVue
  16. v-show="this.activeName == 'second'"
  17. :points="points"
  18. @selection-changed="handleSelectPoint"
  19. ></IsolationLeftVue>
  20. </div>
  21. <div class="right">
  22. <div class="right_top">
  23. <el-card class="box-card">
  24. <div slot="header" class="clearfix">
  25. <span style="font-size: 18px">{{ this.getSopTitle }}</span>
  26. <span
  27. style="
  28. float: right;
  29. padding: 1px 15px;
  30. font-size: 22px;
  31. cursor: pointer;
  32. "
  33. type="text"
  34. @click="goBack"
  35. >×</span
  36. >
  37. <el-tooltip content="开启人员配置" placement="top" style="float: right;margin-top: 3px">
  38. <el-switch v-model="openStaffing"
  39. active-color="#13ce66"
  40. active-text=""
  41. @change="handleOpenStaffing(openStaffing)"
  42. >
  43. </el-switch>
  44. </el-tooltip>
  45. </div>
  46. <div class="text item">
  47. <el-tabs v-model="activeName" @tab-click="handleClick">
  48. <el-tab-pane label="SOP信息" name="first">
  49. <!-- 新增作业票信息-->
  50. <el-form ref="form" :rules="rules" :model="form" label-width="80px">
  51. <el-form-item label="SOP名称" prop="sopName">
  52. <el-input
  53. :disabled="this.getSopLook"
  54. v-model="form.sopName"
  55. placeholder="请输入SOP名称"
  56. style="width: 100%"
  57. />
  58. </el-form-item>
  59. <el-row>
  60. <el-col :span="16">
  61. <el-form-item label="SOP编号" prop="sopCode">
  62. <el-input
  63. :disabled="this.getSopLook"
  64. v-model="form.sopCode"
  65. placeholder="请输入SOP编号"
  66. style="width: 100%"
  67. />
  68. </el-form-item>
  69. </el-col>
  70. <el-col :span="8">
  71. <el-form-item label-width="80">
  72. <el-switch
  73. :disabled="this.getSopLook"
  74. v-model="autoGenFlag"
  75. active-color="#13ce66"
  76. active-text="自动生成"
  77. @change="handleAutoGenChange(autoGenFlag)"
  78. >
  79. </el-switch>
  80. </el-form-item>
  81. </el-col>
  82. </el-row>
  83. <el-form-item label="SOP类型" prop="sopType">
  84. <el-select
  85. :disabled="this.getSopLook"
  86. v-model="form.sopType"
  87. placeholder="请选择SOP类型"
  88. clearable
  89. style="width: 100%"
  90. >
  91. <el-option
  92. v-for="dict in dict.type.sop_type"
  93. :key="dict.value"
  94. :label="dict.label"
  95. :value="dict.value"
  96. />
  97. </el-select>
  98. </el-form-item>
  99. <el-form-item label="SOP内容" prop="sopContent">
  100. <el-input
  101. :disabled="this.getSopLook"
  102. type="textarea"
  103. v-model="form.sopContent"
  104. :rows="5"
  105. ></el-input>
  106. </el-form-item>
  107. <el-form-item label="" prop="" style="margin-top: 95%">
  108. <el-button v-no-more-click
  109. style="float: right; height: 30px; line-height: 10px"
  110. type="primary"
  111. @click="nextStep('second')"
  112. >下一步
  113. </el-button
  114. >
  115. </el-form-item>
  116. </el-form>
  117. </el-tab-pane>
  118. <el-tab-pane label="隔离点信息" name="second">
  119. <!-- 隔离点信息-->
  120. <el-form ref="form" :model="form" label-width="90px">
  121. <!-- <el-form-item label="车间名称" prop="workshopName">-->
  122. <!-- <el-input-->
  123. <!-- v-model="form.workshopName"-->
  124. <!-- style="width: 100%"-->
  125. <!-- disabled-->
  126. <!-- />-->
  127. <!-- </el-form-item>-->
  128. <el-form-item label="作业区域" prop="workline">
  129. <el-input
  130. v-model="form.workline"
  131. style="width: 100%"
  132. disabled
  133. />
  134. </el-form-item>
  135. <div class="text item">
  136. <p
  137. style="color: #606266; font-weight: 600; font-size: 14px"
  138. >
  139. 已选隔离点
  140. </p>
  141. <el-table
  142. :data="tableData"
  143. stripe
  144. height="480"
  145. style="width: 100%"
  146. id="table-key"
  147. row-key="id"
  148. >
  149. <el-table-column prop="pointName" label="隔离点" width="80">
  150. <template slot-scope="scope">
  151. <span style="color: #2a87ff">{{
  152. scope.row.pointName
  153. }}</span>
  154. </template>
  155. </el-table-column>
  156. <el-table-column prop="pointType" label="隔离点类型">
  157. <template slot-scope="scope">
  158. {{ scope.row.pointType }}
  159. </template>
  160. </el-table-column>
  161. <el-table-column
  162. prop="powerType"
  163. label="危险能量类型"
  164. width="100"
  165. >
  166. <template slot-scope="scope">
  167. {{ scope.row.powerType }}
  168. </template>
  169. </el-table-column>
  170. <el-table-column
  171. prop="prePointId"
  172. label="前置隔离点"
  173. >
  174. <template slot-scope="scope">
  175. <el-select size="mini" v-model="scope.row.prePointId" @change="prePointIdChange(scope.row)"
  176. @visible-change="onDropdownVisibleChange(scope.row)" clearable
  177. >
  178. <el-option v-for="item in prePointIdOptions"
  179. :key="item.pointId"
  180. :label="item.pointName"
  181. :value="item.pointId"
  182. >
  183. </el-option>
  184. </el-select>
  185. </template>
  186. </el-table-column>
  187. </el-table>
  188. </div>
  189. <el-form-item label="" prop="">
  190. <!-- 这个确认是没有人员配置的时候-->
  191. <el-button v-no-more-click
  192. v-if="!openStaffing"
  193. :disabled="this.getSopLook"
  194. style="float: right; height: 30px; line-height: 10px"
  195. type="primary"
  196. @click="submit"
  197. >确 定
  198. </el-button
  199. >
  200. <el-button v-no-more-click
  201. v-if="openStaffing"
  202. :style="{float: 'right',
  203. height: '30px',
  204. lineHeight: '10px',
  205. marginRight: openStaffing?'0%':'0%'}
  206. "
  207. type="primary"
  208. @click="preStep('third')"
  209. >下一步
  210. </el-button
  211. >
  212. <el-button v-no-more-click
  213. :style="{float: 'right',
  214. height: '30px',
  215. lineHeight: '10px',
  216. marginRight: openStaffing?'19%':'19%'}
  217. "
  218. type="primary"
  219. @click="preStep('first')"
  220. >上一步
  221. </el-button
  222. >
  223. </el-form-item>
  224. </el-form>
  225. </el-tab-pane>
  226. <el-tab-pane label="人员选择" name="third" v-if="openStaffing ">
  227. <!--人员选择-->
  228. <el-form ref="form" :model="form" label-width="70px">
  229. <el-form-item label="上锁人" prop="locker">
  230. <el-select
  231. :disabled="this.getSopLook"
  232. v-model="form.locker"
  233. placeholder="上锁人"
  234. clearable
  235. style="width: 100%"
  236. @change="handlelockerChage"
  237. >
  238. <el-option
  239. v-for="dict in this.listLockerOption"
  240. :key="dict.value"
  241. :label="dict.label"
  242. :value="dict.value"
  243. />
  244. </el-select>
  245. </el-form-item>
  246. <el-form-item label="共锁人" prop="coLocker">
  247. <el-button v-no-more-click
  248. type="primary"
  249. @click="addInside"
  250. class="gsr"
  251. size="mini"
  252. >添加内部人员
  253. </el-button>
  254. <el-button v-no-more-click type="primary" @click="addOutside" size="mini"
  255. >添加外部人员
  256. </el-button>
  257. </el-form-item>
  258. <div class="text item">
  259. <el-table
  260. :data="sortedTicketUserDTOList"
  261. stripe
  262. height="400"
  263. style="width: 100%"
  264. >
  265. <el-table-column prop="userId" label="序号" width="50">
  266. </el-table-column>
  267. <el-table-column
  268. prop="userName"
  269. label="共锁人"
  270. width="120"
  271. >
  272. <template slot-scope="scope">
  273. <span style="color: #2a87ff">{{
  274. scope.row.userName
  275. }}</span>
  276. </template>
  277. </el-table-column>
  278. <el-table-column prop="userType" label="共锁人来源">
  279. <template slot-scope="scope">
  280. <span>{{
  281. scope.row.userType == '0' ? '内部' : '外部'
  282. }}</span>
  283. </template>
  284. </el-table-column>
  285. <el-table-column label="" width="80">
  286. <template slot-scope="scope">
  287. <el-button v-no-more-click
  288. @click.native.prevent="
  289. deleteRow(scope.$index, sortedTicketUserDTOList)
  290. "
  291. type="text"
  292. size="small"
  293. >
  294. 移除
  295. </el-button>
  296. </template>
  297. </el-table-column>
  298. </el-table>
  299. </div>
  300. <el-form-item label="" prop="">
  301. <!-- 这里是有人员配置的-->
  302. <el-button v-no-more-click
  303. v-if="openStaffing"
  304. :disabled="this.getSopLook"
  305. style="float: right; height: 30px; line-height: 10px"
  306. type="primary"
  307. @click="submit"
  308. >确 定
  309. </el-button
  310. >
  311. <el-button v-no-more-click
  312. style="
  313. float: right;
  314. height: 30px;
  315. line-height: 10px;
  316. margin-right: 19%;
  317. "
  318. type="primary"
  319. @click="preStep('second')"
  320. >上一步
  321. </el-button
  322. >
  323. </el-form-item>
  324. </el-form>
  325. </el-tab-pane>
  326. </el-tabs>
  327. </div>
  328. </el-card>
  329. </div>
  330. </div>
  331. <!-- newSop盒子结束-->
  332. <!-- 添加或修改设备维修单对话框 -->
  333. <el-dialog
  334. :visible.sync="open"
  335. width="450px"
  336. append-to-body
  337. style="margin-top: 13%"
  338. >
  339. <div slot="title" class="dialog-title">
  340. <i></i>
  341. <span class="title">{{ title }}</span>
  342. </div>
  343. <el-form
  344. ref="dialogForm"
  345. :model="dialogForm"
  346. label-width="70px"
  347. >
  348. <el-form-item label="选择人员" prop="nickName" v-if="insideMumber">
  349. <el-select
  350. v-model="dialogForm.nickName"
  351. placeholder="请选择人员"
  352. clearable
  353. style="width: 100%"
  354. multiple
  355. @change="changeInsideUser"
  356. >
  357. <el-option
  358. v-for="dict in this.listCoLockerOption"
  359. :key="dict.value"
  360. :label="dict.label"
  361. :value="dict.value"
  362. />
  363. </el-select>
  364. </el-form-item>
  365. <el-form-item label="人员ID" prop="username" v-if="outsideMumber">
  366. <el-row>
  367. <el-col :span="16">
  368. <el-input
  369. v-model="dialogForm.username"
  370. placeholder="请输入人员ID"
  371. clearable
  372. style="width: 80%"
  373. @change="outSideUserInput"
  374. />
  375. </el-col>
  376. <el-col :span="4">
  377. <el-button v-no-more-click type="primary" @click="insertOutSideTable">添加</el-button>
  378. </el-col>
  379. </el-row>
  380. </el-form-item>
  381. <el-row>
  382. <el-table :data="OutSideUserTableData"
  383. stripe
  384. height="200"
  385. v-if="outsideMumber"
  386. >
  387. <el-table-column prop="userId" label="序号">
  388. </el-table-column>
  389. <el-table-column
  390. prop="userName"
  391. label="人员ID"
  392. >
  393. <template slot-scope="scope">
  394. <span style="color: #2a87ff">{{
  395. scope.row.userName
  396. }}</span>
  397. </template>
  398. </el-table-column>
  399. <el-table-column label="操作" width="80">
  400. <template slot-scope="scope">
  401. <el-button v-no-more-click
  402. @click.native.prevent="
  403. deleteRow(scope.$index, OutSideUserTableData)
  404. "
  405. type="text"
  406. size="small"
  407. >
  408. 移除
  409. </el-button>
  410. </template>
  411. </el-table-column>
  412. </el-table>
  413. </el-row>
  414. </el-form>
  415. <div slot="footer" class="dialog-footer">
  416. <!-- 内部人员确认-->
  417. <el-button v-no-more-click type="primary" @click="cancel" v-if="insideMumber">确认</el-button>
  418. <!-- 外部人员确认-->
  419. <el-button v-no-more-click type="primary" @click="outSideDialogConfirm" v-if="outsideMumber">确认</el-button>
  420. <el-button v-no-more-click @click="cancel">取 消</el-button>
  421. </div>
  422. </el-dialog>
  423. </div>
  424. </template>
  425. <script>
  426. import IsolationLeftVue from '@/components/separationPoint/index.vue'
  427. import SopLeft from '@/components/separationPoint/workshop.vue'
  428. import { genCode } from '@/api/system/autocode/rule'
  429. import {
  430. addinsertIsSop,
  431. updateIsSop,
  432. selectIsSopById, SopUser
  433. } from '@/api/mes/sop/sopindex'
  434. import { mapActions, mapGetters } from 'vuex'
  435. export default {
  436. name: 'addView',
  437. dicts: ['power_type', 'point_type', 'sop_type', 'job_user_role'],
  438. components: {
  439. SopLeft,
  440. IsolationLeftVue
  441. },
  442. data() {
  443. return {
  444. //自动生成编码
  445. autoGenFlag: false,
  446. activeName: 'first',
  447. form: {
  448. sopName: '',
  449. sopCode: '',
  450. SOPType: '',
  451. workshopName: '', //车间名称
  452. workline: '', //区域
  453. workareaName: '',
  454. spoint: [], //已选隔离点
  455. prePointId: [],//已选隔离点的前置节点Id
  456. locker: '', //上锁人
  457. coLocker: '', //共锁人
  458. pointDetailVOList: [],//隔离点数据
  459. ticketUserDTOList: [
  460. // {
  461. // userId: '',
  462. // userName: '',
  463. // userRole: '',//作业票角色 角色code jtlocker(上锁人) jtcolocker(共锁人)
  464. // userType: ''//用户类型 0是内部 1是外部
  465. // }
  466. ] //所选择的用户
  467. },
  468. pickerOptions: {
  469. shortcuts: [
  470. {
  471. text: '今天',
  472. onClick(picker) {
  473. picker.$emit('pick', new Date())
  474. }
  475. },
  476. {
  477. text: '昨天',
  478. onClick(picker) {
  479. const date = new Date()
  480. date.setTime(date.getTime() - 3600 * 1000 * 24)
  481. picker.$emit('pick', date)
  482. }
  483. },
  484. {
  485. text: '一周前',
  486. onClick(picker) {
  487. const date = new Date()
  488. date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
  489. picker.$emit('pick', date)
  490. }
  491. }
  492. ]
  493. },
  494. // 右侧底部已选隔离点
  495. tableData: null,
  496. points: null, //车间逆向传递拿到的隔离点数据
  497. emitWorkShop: null, //车间逆向传递拿到车间相关数据
  498. emitworklineId: null,//生产线逆向传递拿到数据
  499. sopProps: [], //正传递
  500. worklineMap: '',
  501. prePointIdOptions: [],//前置节点的下拉选项
  502. initprePointIdOptions: [],//前置节点初始化数据选项
  503. prePointId: null,//回显选中的前置节点id
  504. relations: [],//维护父子关系的前置节点
  505. openStaffing: null,
  506. newticketUserDTOList: [], //为了上锁人单独传递数据
  507. // 弹框中显示的form表单内容
  508. insideMumber: false,
  509. outsideMumber: false,
  510. // 是否显示弹出层
  511. open: false,
  512. // 弹出层标题
  513. title: '',
  514. dialogForm: {
  515. nickName: '',
  516. username: ''
  517. },
  518. rules: {
  519. sopName: [
  520. { required: true, message: "sop名称不能为空", trigger: "blur" },
  521. ],
  522. sopCode: [
  523. { required: true, message: "sop编码不能为空", trigger: "blur" },
  524. ],
  525. },
  526. listLockerOption: null,//上锁人下拉数据
  527. listCoLockerOption: null,//共锁人下拉数据
  528. OutSideUserTableData: [],//添加外部人员多个表格
  529. nextUserId: 0//新增外部人员表格序号自定义
  530. }
  531. },
  532. mounted() {
  533. this.handleOpenStaffing()
  534. if (this.$route.query.sopId !== 'null') {
  535. // console.log(this.$route.query.sopId, "接受路由参数");
  536. this.getSopInfo()
  537. if (this.getSopLook) {
  538. this.setSopTitle('查看SOP')
  539. } else {
  540. this.setSopTitle('编辑SOP')
  541. }
  542. } else {
  543. this.setSelectSopPoints([])
  544. this.setPointTableData([])
  545. this.setSopTitle('新建SOP')
  546. }
  547. },
  548. computed: {
  549. ...mapGetters('sopSelectPoints', ['getSopTitle', 'getSopLook', 'getMapData']),
  550. // 排序 ticketUserDTOList,将 userRole 为 0 的选项放在前面
  551. sortedTicketUserDTOList() {
  552. return this.form.ticketUserDTOList.sort(
  553. (a, b) => Number(a.userRole) - Number(b.userRole)
  554. )
  555. }
  556. },
  557. methods: {
  558. ...mapActions('sopSelectPoints', [
  559. 'setSelectSopPoints',
  560. 'setPointTableData',
  561. 'setSopEdit',
  562. 'setSopTitle'
  563. ]),
  564. handleClick(tab, event) {
  565. },
  566. preStep(val) {
  567. this.activeName = val
  568. console.log(this.form, 'sopform')
  569. },
  570. nextStep(val) {
  571. if(val=='second'&&this.form.sopName==''){
  572. this.$message.error('SOP名称不能为空')
  573. return;
  574. }else if(val=='second'&&this.form.sopCode==''){
  575. this.$message.error('SOP编码不能为空')
  576. return;
  577. }
  578. this.activeName = val
  579. // console.log("我点击了下一步");
  580. },
  581. // 详情数据
  582. getSopInfo() {
  583. const sopId = this.$route.query.sopId
  584. console.log(this.$route.query.sopId, '接受路由参数')
  585. if (sopId !== null) {
  586. selectIsSopById(sopId).then((response) => {
  587. console.log(response, '详细内容 ')
  588. this.sopProps = [response.data]
  589. this.title = '修改隔离点信息'
  590. if (response.data.ticketUserDTOList) {
  591. this.openStaffing = true;
  592. }
  593. this.form = {
  594. ...response.data,
  595. workareaId: response.data.workareaId,
  596. sopId: response.data.sopId,
  597. spoint: response.data.pointDetailVOList,
  598. ticketUserDTOList: response.data.ticketUserDTOList
  599. ? response.data.ticketUserDTOList
  600. .filter((item) => item.userRole !== "jtlocker")
  601. .map((item) => ({
  602. userName: item.userName,
  603. userType: item.userType,
  604. userRole: item.userRole,
  605. userId: item.userId,
  606. }))
  607. : [],
  608. locker: response.data.ticketUserDTOList
  609. ? response.data.ticketUserDTOList
  610. .filter((item) => item.userRole === "jtlocker")
  611. .map((item) => item.userName)[0]
  612. : null,
  613. coLocker: response.data.ticketUserDTOList
  614. ? response.data.ticketUserDTOList.map((item) => {
  615. return item.userRole !== "jtlocker" ? item.userName : null;
  616. })
  617. : [],
  618. };
  619. this.newticketUserDTOList = response.data.ticketUserDTOList
  620. ? response.data.ticketUserDTOList
  621. .filter((item) => item.userRole === "jtlocker")
  622. .map((item) => ({
  623. userName: item.userName,
  624. userType: item.userType,
  625. userRole: item.userRole,
  626. userId: item.userId,
  627. }))
  628. : [];
  629. console.log(this.form,this.newticketUserDTOList,'编辑sop回显的数据',)
  630. })
  631. } else {
  632. this.title = '新增隔离点信息'
  633. this.setSopEdit(true)
  634. this.setSelectSopPoints([])
  635. this.setPointTableData([])
  636. this.tableData = null
  637. this.form = {
  638. spoint: [],
  639. sopContent: '',
  640. sopCode: '',
  641. sopName: '',
  642. sopType: '',
  643. workareaId: '',
  644. workshopId: ''
  645. }
  646. this.autoGenFlag = false
  647. }
  648. },
  649. submit() {
  650. console.log('我点击了确认')
  651. // 确保 this.form.spoint 是一个数组,如果为空则默认空数组
  652. if (!Array.isArray(this.form.spoint)) {
  653. this.form.spoint = []
  654. }
  655. console.log(this.form.spoint, 'spoint')
  656. // 如果没有选中点,逆向传递为空时,使用当前表格数据中的点
  657. if (this.form.spoint.length === 0 && Array.isArray(this.tableData)) {
  658. this.form.spoint = this.tableData.map((point) => point.pointId)
  659. }
  660. // 编辑模式
  661. if (this.$route.query.sopId !== 'null') {
  662. console.log(this.$route.query.sopId, 'sopIdaaa')
  663. // 确保 sopId 存在
  664. if (!this.form.sopId) {
  665. console.error('隔离点id不可为空!')
  666. this.$message.error('隔离点id不可为空!') // 使用消息提示
  667. return
  668. }
  669. const selectedpointIds = this.form.spoint.join(',')
  670. const UserList=[...(this.form.ticketUserDTOList|| []),...(this.newticketUserDTOList|| [])]
  671. // const pointsList=this.form.pointDetailVOList.map((item)=>{
  672. // return {
  673. // pointId:item.pointId,
  674. // prePointId:item.prePointId
  675. // }
  676. // })
  677. const pointsList=this.tableData.map((item)=>{
  678. return {
  679. pointId:item.pointId,
  680. prePointId:item.prePointId
  681. }
  682. })
  683. const data = {
  684. sopId:this.form.sopId,
  685. pointIds: selectedpointIds,
  686. sopContent: this.form.sopContent,
  687. sopCode: this.form.sopCode,
  688. sopName: this.form.sopName,
  689. sopType: this.form.sopType,
  690. workareaId: this.emitworklineId,
  691. ticketUserDTOList: UserList,
  692. pointsList: pointsList
  693. // workshopId: this.emitWorkShop.value
  694. }
  695. console.log(data,'编辑的参数')
  696. updateIsSop(data).then((res) => {
  697. console.log(res, '修改接口')
  698. if (res.code == 200) {
  699. this.$router.push('/sop/sopm')
  700. this.$message.success('SOP修改成功')
  701. }
  702. })
  703. } else {
  704. // 新增模式
  705. const selectedpointIds = this.form.spoint.join(',')
  706. const UserList=[...this.form.ticketUserDTOList,...this.newticketUserDTOList]
  707. const pointsList=this.tableData.map((item)=>{
  708. return {
  709. pointId:item.pointId,
  710. prePointId:item.prePointId
  711. }
  712. })
  713. const data = {
  714. pointIds: selectedpointIds,
  715. sopContent: this.form.sopContent,
  716. sopCode: this.form.sopCode,
  717. sopName: this.form.sopName,
  718. sopType: this.form.sopType,
  719. workareaId: this.emitworklineId,
  720. ticketUserDTOList: UserList,
  721. pointsList: pointsList
  722. }
  723. console.log(data, '新增参数')
  724. addinsertIsSop(data).then((res) => {
  725. console.log(res, '新增接口')
  726. if (res.code == 200) {
  727. this.$router.push('/sop/sopm')
  728. this.$message.success('SOP新建成功')
  729. }
  730. })
  731. }
  732. },
  733. // 选中隔离点 前置节点的change函数
  734. onDropdownVisibleChange(row) {
  735. console.log(row, '我执行这里拉')
  736. // 当前节点 ID
  737. const currentPointId = row.pointId
  738. // 获取当前行的 prePointId
  739. const currentPrePointId = row.prePointId
  740. // 已经被选为前置节点的 ID 集合
  741. const selectedPrePointIds = new Set(
  742. this.tableData
  743. .filter((item) => item.prePointId !== null)
  744. .map((item) => item.prePointId)
  745. )
  746. // console.log(selectedPrePointIds, 'selectedPrePointIds')
  747. // 构建 form.prePointId 数组对象
  748. this.form.prePointId = this.tableData.map((item) => ({
  749. pointId: item.pointId,
  750. prePointId: item.prePointId || null
  751. }))
  752. // 每次都从原始数据开始过滤
  753. let filteredOptions = [...this.initprePointIdOptions]
  754. // 过滤规则:
  755. // 1. 排除自身
  756. // 2. 排除已经被选为前置节点的隔离点
  757. // 3. 排除所有已经选为前置节点的节点及其前置节点
  758. const allExcludedPoints = new Set([currentPointId])
  759. this.getAllExcludedPoints(currentPointId, allExcludedPoints)
  760. filteredOptions = filteredOptions.filter((option) => {
  761. return !allExcludedPoints.has(option.pointId)
  762. })
  763. this.prePointIdOptions = filteredOptions
  764. console.log('过滤后的前置节点选项', this.prePointIdOptions)
  765. },
  766. // 递归获取所有需要排除的节点
  767. getAllExcludedPoints(pointId, excludedPoints) {
  768. const relatedRows = this.tableData.filter(item => item.prePointId === pointId)
  769. for (const row of relatedRows) {
  770. excludedPoints.add(row.pointId)
  771. this.getAllExcludedPoints(row.pointId, excludedPoints)
  772. }
  773. },
  774. // 前置节点改变时的处理函数
  775. prePointIdChange(row) {
  776. console.log(row, '前置节点改变')
  777. // 更新 tableData 中对应行的 prePointId
  778. const index = this.tableData.findIndex(item => item.pointId === row.pointId)
  779. if (index !== -1) {
  780. this.$set(this.tableData, index, row)
  781. }
  782. // 重新调用 onDropdownVisibleChange 确保其他节点的选项更新
  783. this.onDropdownVisibleChange(row)
  784. },
  785. // 子组件选中的隔离点逆传递拿到的数据
  786. handleSelectPoint(points) {
  787. console.log(points, "父组件接收逆向传递选中的隔离点");
  788. // 1. 去除重复的点,使用 Set 确保每个 pointId 唯一
  789. const uniquePoints = Array.from(
  790. new Set(points.map((point) => point.pointId))
  791. ).map((id) => points.find((point) => point.pointId === id));
  792. console.log(uniquePoints, "去重后的选中节点");
  793. this.tableData = uniquePoints; // 子组件传递过来的选中节点(去重后)
  794. // 使用 Set 来存储传递过来的点值
  795. const newValues = new Set(uniquePoints.map((point) => point.pointId));
  796. // 2. 删除取消选中的点
  797. const removedPoints = this.tableData
  798. .filter((item) => !newValues.has(item.pointId))
  799. .map((item) => item.pointId); // 记录被删除的点
  800. this.tableData = this.tableData.filter((item) =>
  801. newValues.has(item.pointId)
  802. );
  803. // 3. 确保新增点不会重复
  804. const existingValues = new Set(
  805. this.tableData.map((item) => item.pointId)
  806. );
  807. uniquePoints.forEach((point) => {
  808. // 如果当前传递的点不在已有的点集中,则添加
  809. if (!existingValues.has(point.pointId)) {
  810. this.tableData.push({
  811. pointName: point.pointName, // 显示的名称
  812. pointId: point.pointId, // 对应的值
  813. pointType: point.pointType,
  814. powerType: point.powerType,
  815. prePointId: null,
  816. });
  817. this.prePointIdOptions.push({
  818. pointName: point.pointName, // 显示的名称
  819. pointId: point.pointId, // 对应的值
  820. });
  821. this.initprePointIdOptions = [...this.prePointIdOptions];
  822. console.log(this.prePointIdOptions, "前置节点设置下拉");
  823. existingValues.add(point.pointId);
  824. }
  825. });
  826. // 4. 处理被删除的点,如果这些点作为父节点绑定,则将对应的 prePointId 设置为 null
  827. this.tableData.forEach((item) => {
  828. if (removedPoints.includes(item.prePointId)) {
  829. item.prePointId = null;
  830. }
  831. });
  832. // 5. 从下拉选项中移除被删除的点
  833. this.prePointIdOptions = this.prePointIdOptions.filter(
  834. (option) => !removedPoints.includes(option.pointId)
  835. );
  836. this.initprePointIdOptions = [...this.prePointIdOptions];
  837. // 6. 确保下拉选项中仍然保留所有未被删除的点
  838. const allPoints = uniquePoints.map((point) => ({
  839. pointName: point.pointName,
  840. pointId: point.pointId,
  841. }));
  842. this.prePointIdOptions = allPoints.filter(
  843. (option) => !removedPoints.includes(option.pointId)
  844. );
  845. this.initprePointIdOptions = [...this.prePointIdOptions];
  846. // 更新 form.spoint 为最新选中的隔离点数组
  847. this.form.spoint = uniquePoints.map((point) => point.pointId);
  848. },
  849. // 车间逆向传递拿到的隔离点数据产线
  850. handleProductLineSelected(selectedOption) {
  851. // console.log(selectedOption, "父组件接收到的 selectedOption");
  852. this.points = selectedOption
  853. this.form.workline = selectedOption.label
  854. // console.log(this.worklineMap.length, '父组件接收到的 worklineMap')
  855. },
  856. // 车间子组件逆传递车间相关数据车间
  857. handleWorkshopSelected(selectedOption) {
  858. console.log(selectedOption, 'handleWorkshopSelected')
  859. // this.emitWorkShop = selectedOption
  860. // this.form.workshopName = selectedOption.label;//这里是回显车间的 暂时不需要
  861. this.form.workline = selectedOption.label//这里是回显作业区域的
  862. this.emitworklineId = selectedOption.id
  863. this.worklineMap = selectedOption.map
  864. },
  865. // 添加内部人员
  866. addInside() {
  867. this.open = true
  868. this.title = '添加内部人员'
  869. this.insideMumber = true
  870. this.outsideMumber = false
  871. // this.form.ticketUserDTOList = [];
  872. this.dialogForm.nickName = ''
  873. },
  874. // 添加外部人员
  875. addOutside() {
  876. this.open = true
  877. this.title = '添加外部人员'
  878. this.insideMumber = false
  879. this.outsideMumber = true
  880. this.dialogForm.username = null
  881. },
  882. // 取消按钮
  883. cancel() {
  884. this.open = false
  885. },
  886. // 人员列表删除
  887. deleteRow(index, rows) {
  888. console.log(index, rows, '删除的行')
  889. const deletedItem = rows[index] // 获取要删除的项
  890. rows.splice(index, 1) // 从显示的列表中删除
  891. // const formIndex = this.form.ticketUserDTOList.findIndex(
  892. // (item) => item.userId === deletedItem.userId
  893. // )
  894. const formIndex = this.form.ticketUserDTOList.findIndex(
  895. (item) => item.userName == deletedItem.userName
  896. )
  897. if (formIndex !== -1) {
  898. this.form.ticketUserDTOList.splice(formIndex, 1) // 从 form.ticketUserDTOList 中删除
  899. }
  900. },
  901. // 上锁人下拉选择change事件
  902. handlelockerChage(val) {
  903. console.log(val, '上锁人chage')
  904. const user = this.listLockerOption.find((item) => item.value === val)
  905. if (user && this.form.locker !== '') {
  906. const existingUser = this.form.ticketUserDTOList.find(
  907. (u) => u.userName === user.label
  908. )
  909. if (!existingUser) {
  910. this.newticketUserDTOList.push({
  911. userName: user.label,
  912. userId: user.value,
  913. userType: 0,
  914. userRole: 'jtlocker'
  915. })
  916. console.log(this.newticketUserDTOList, '上锁人用户')
  917. } else {
  918. // console.log('用户已存在', user.label)
  919. }
  920. }
  921. },
  922. // 添加内部人员的用户新增到ticketUserDTOList这个数据里
  923. changeInsideUser(values) {
  924. const usersinside = values
  925. .map((value) =>
  926. this.listCoLockerOption.find((item) => item.value === value)
  927. )
  928. .filter(Boolean)
  929. usersinside.forEach((user) => {
  930. const existingUser = this.form.ticketUserDTOList.find(
  931. (u) => u.userName === user.label
  932. )
  933. // console.log(usersinside, 'usersinside----67')
  934. if (!existingUser) {
  935. this.form.ticketUserDTOList.push({
  936. userName: user.label,
  937. userId: user.value,
  938. userType: 0,
  939. userRole: 'jtcolocker'
  940. })
  941. console.log(this.form.ticketUserDTOList, '共锁人用户')
  942. } else {
  943. // console.log('用户已存在', user.label)
  944. }
  945. })
  946. this.updateCoLocker()
  947. // console.log(this.form.ticketUserDTOList, '用户')
  948. },
  949. // 添加外部人员 输入名称 userType==1是共锁人 0是上锁人 userId==0
  950. outSideUserInput(event) {
  951. this.dialogForm.username = event
  952. },
  953. // 添加外部人员弹窗 添加给表格数据的按钮事件
  954. insertOutSideTable() {
  955. const newUserName = this.dialogForm.username.trim();
  956. if (newUserName === '') {
  957. this.$message.warning('请输入用户名');
  958. return;
  959. }
  960. // 检查新用户是否已存在于表格中
  961. const existingUser = this.OutSideUserTableData.find(user => user.userName === newUserName);
  962. if (existingUser) {
  963. this.$message.warning('该用户已存在');
  964. return;
  965. }
  966. // 添加新用户
  967. this.OutSideUserTableData.push({
  968. userName: newUserName,
  969. userId: this.nextUserId++
  970. });
  971. // 清空对话框表单
  972. this.dialogForm.username = '';
  973. // 打印当前的外部人员表格数据
  974. console.log(this.OutSideUserTableData, 'OutSideUserTableData');
  975. },
  976. // 添加外部人员 确认弹窗
  977. outSideDialogConfirm() {
  978. this.updateCoLocker()
  979. this.open = false
  980. },
  981. // 更新界面中共锁人下拉框显示的内容
  982. updateCoLocker() {
  983. // 检查并补充 ticketUserDTOList 中缺少的用户
  984. this.OutSideUserTableData.forEach((item) => {
  985. const existingUser = this.form.ticketUserDTOList.find(
  986. (u) => u.userName === item.userName
  987. )
  988. if (!existingUser) {
  989. this.form.ticketUserDTOList.push({
  990. userName: item.userName,
  991. userId: 0,
  992. userType: 1,
  993. userRole: 'jtcolocker'
  994. })
  995. }
  996. })
  997. console.log(this.form.ticketUserDTOList, '最终的 ticketUserDTOList')
  998. },
  999. //自动生成编码
  1000. handleAutoGenChange(autoGenFlag) {
  1001. if (autoGenFlag) {
  1002. genCode('SOP_CODE').then((response) => {
  1003. this.form.sopCode = response
  1004. })
  1005. } else {
  1006. this.form.sopCode = null
  1007. }
  1008. },
  1009. //是否开启人员配置界面
  1010. handleOpenStaffing(openStaffing) {
  1011. // 定义一个函数来封装接口调用逻辑
  1012. const fetchUserData = (roleKey) => {
  1013. const data = {
  1014. pageNum: 1,
  1015. pageSize: 10000,
  1016. roleKey: roleKey
  1017. }
  1018. return SopUser(data).then((res) => {
  1019. // console.log(res, `上锁人 - ${roleKey}`);
  1020. return res // 返回结果以便后续处理
  1021. }).catch((err) => {
  1022. // console.error(err, `请求失败 - ${roleKey}`);
  1023. throw err // 抛出错误以便捕获
  1024. })
  1025. }
  1026. // 调用两次接口,分别传递不同的 roleKey
  1027. Promise.all([
  1028. fetchUserData('jtlocker'),
  1029. fetchUserData('jtcolocker')
  1030. ]).then((results) => {
  1031. // 处理两次调用的结果
  1032. const [jtlockerResult, jtcolockerResult] = results
  1033. console.log(jtlockerResult, jtcolockerResult, 'jtlocker 结果')
  1034. this.listLockerOption = jtlockerResult.rows.map((item) => {
  1035. return {
  1036. label: item.nickName,
  1037. value: item.userId
  1038. }
  1039. })
  1040. this.listCoLockerOption = jtcolockerResult.rows.map((item) => {
  1041. return {
  1042. label: item.nickName,
  1043. value: item.userId
  1044. }
  1045. })
  1046. }).catch((err) => {
  1047. console.error(err, '其中一个请求失败')
  1048. })
  1049. if (openStaffing) {
  1050. console.log(openStaffing, '开启人员配置')
  1051. this.openStaffing = openStaffing
  1052. } else {
  1053. console.log(openStaffing, '关闭人员配置')
  1054. this.openStaffing = openStaffing
  1055. this.activeName = 'first'
  1056. }
  1057. },
  1058. // 侧边X关闭
  1059. goBack() {
  1060. this.$router.push('/sop/sopm')
  1061. }
  1062. // methods结束
  1063. }
  1064. }
  1065. </script>
  1066. <style scoped lang="scss">
  1067. .newOperations {
  1068. width: 99%;
  1069. height: 100%;
  1070. // background: pink;
  1071. margin: 10px;
  1072. display: flex;
  1073. .left {
  1074. width: 75%;
  1075. height: 830px;
  1076. // background: #eee;
  1077. margin-right: 10px;
  1078. }
  1079. .right {
  1080. //width: 25%;
  1081. flex: 1;
  1082. height: 100%;
  1083. //background: #000;
  1084. .right_top {
  1085. height: 540px;
  1086. }
  1087. }
  1088. }
  1089. //右侧卡片样式开始
  1090. .text {
  1091. font-size: 14px;
  1092. }
  1093. .item {
  1094. margin-bottom: 18px;
  1095. p {
  1096. font-size: 18px;
  1097. font-weight: bolder;
  1098. font-family: SourceHanSansSC-bold;
  1099. }
  1100. }
  1101. .clearfix:before,
  1102. .clearfix:after {
  1103. display: table;
  1104. content: "";
  1105. width: 320px;
  1106. }
  1107. .clearfix:after {
  1108. clear: both;
  1109. }
  1110. .box-card {
  1111. // width: 390px;
  1112. width: 100%;
  1113. height: 850px;
  1114. //background: pink;
  1115. }
  1116. ::v-deeep .el-tabs--top .el-tabs__item.is-top:nth-child(2),
  1117. .el-tabs--top .el-tabs__item.is-bottom:nth-child(2),
  1118. .el-tabs--bottom .el-tabs__item.is-top:nth-child(2),
  1119. .el-tabs--bottom .el-tabs__item.is-bottom:nth-child(2) {
  1120. padding-left: 100px !important;
  1121. }
  1122. ::v-deep .el-tabs .el-tabs__item {
  1123. padding: 0 30px !important;
  1124. }
  1125. //右侧卡片样式结束
  1126. </style>
  1127. <style>
  1128. </style>