releaseRulesDialog.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <template>
  2. <ele-modal
  3. width="80%"
  4. :visible="visible"
  5. append-to-body
  6. custom-class="ele-dialog-form"
  7. :title="title"
  8. :close-on-click-modal="false"
  9. :before-close="handleBeforeClose"
  10. maxable
  11. >
  12. <header-title title="基本信息"></header-title>
  13. <el-form
  14. :model="addForm"
  15. :rules="formRules"
  16. ref="ruleFormRef"
  17. label-width="150px"
  18. v-loading="loading"
  19. >
  20. <el-row>
  21. <el-col :span="8">
  22. <el-form-item label="记录规则名称" required>
  23. <el-input
  24. v-model="addForm.ruleName"
  25. placeholder="自动带出"
  26. disabled
  27. ></el-input>
  28. </el-form-item>
  29. </el-col>
  30. <el-col :span="8">
  31. <el-form-item label="记录规则分类" required>
  32. <DictSelection
  33. dictName="记录规则类型"
  34. clearable
  35. v-model="addForm.recordRulesClassify"
  36. disabled
  37. >
  38. </DictSelection>
  39. </el-form-item>
  40. </el-col>
  41. <el-col :span="8">
  42. <el-form-item
  43. v-if="ruleInfo && ruleInfo.classify == 3"
  44. label="关联设备"
  45. >
  46. <el-input
  47. v-model="addForm.deviceName"
  48. placeholder="自动带出"
  49. disabled
  50. ></el-input>
  51. </el-form-item>
  52. <el-form-item v-else label="车间区域" prop="workshopArea">
  53. <el-input
  54. v-model="addForm.workshopArea"
  55. placeholder="请输入"
  56. ></el-input>
  57. </el-form-item>
  58. </el-col>
  59. </el-row>
  60. <el-row>
  61. <el-col :span="8">
  62. <el-form-item label="检查完成时间" required prop="checkFinishTime">
  63. <el-date-picker
  64. v-model="addForm.checkFinishTime"
  65. type="datetime"
  66. format="yyyy-MM-dd HH:mm:ss"
  67. value-format="yyyy-MM-dd HH:mm:ss"
  68. placeholder="选择日期"
  69. style="width: 100%"
  70. >
  71. </el-date-picker>
  72. </el-form-item>
  73. </el-col>
  74. <el-col :span="8">
  75. <el-form-item label="检查有效期" required prop="checkValidity">
  76. <el-input
  77. placeholder="请输入"
  78. v-model="addForm.checkValidity"
  79. type="text"
  80. >
  81. <template slot="append">
  82. <div style="width: 40px; box-sizing: border-box">
  83. <el-form-item required prop="checkValidityUnit">
  84. <DictSelection
  85. dictName="检查有效期单位"
  86. clearable
  87. v-model="addForm.checkValidityUnit"
  88. placeholder="单位"
  89. style="width: auto"
  90. >
  91. </DictSelection>
  92. </el-form-item>
  93. </div>
  94. </template>
  95. </el-input>
  96. </el-form-item>
  97. </el-col>
  98. <el-col :span="8">
  99. <el-form-item label="结论" required prop="conclution">
  100. <el-radio-group v-model="addForm.conclution">
  101. <el-radio :label="1">合格</el-radio>
  102. <el-radio :label="2">不合格</el-radio>
  103. </el-radio-group>
  104. </el-form-item>
  105. </el-col>
  106. </el-row>
  107. </el-form>
  108. <header-title title="检查项目"></header-title>
  109. <!-- 表格 -->
  110. <el-table v-loading="loading" :data="addForm.details" style="width: 100%">
  111. <el-table-column type="index" label="序号" width="50"> </el-table-column>
  112. <el-table-column label="检查内容">
  113. <template slot-scope="scope">
  114. <div v-if="addForm.recordRulesClassify == 4">
  115. {{ scope.row.productName || scope.row.name }}
  116. </div>
  117. <div v-else>
  118. {{ scope.row.paramValue }}
  119. </div>
  120. </template>
  121. </el-table-column>
  122. <el-table-column label="检查工具">
  123. <template slot-scope="{ row }">
  124. <el-link :underline="false" style="cursor: pointer">
  125. <div class="ele-cell">
  126. <div @click="handleAdd(row)">
  127. {{ row.toolNames ? row.toolNames : '请选择' }}
  128. </div>
  129. <i
  130. v-if="!row.toolNames"
  131. class="el-icon-arrow-down"
  132. @click="handleAdd(row)"
  133. ></i>
  134. <i v-else class="el-icon-close" @click="clearTool(row)"></i>
  135. </div>
  136. </el-link>
  137. </template>
  138. </el-table-column>
  139. <el-table-column label="检查人">
  140. <template slot-scope="scope">
  141. <div
  142. @click="openSelectUser(scope.row)"
  143. style="display: flex; align-items: center; cursor: pointer"
  144. >
  145. <div>{{ showCheckUserNames(scope.row.checkUsers) }}</div
  146. ><i class="el-icon-caret-bottom"></i>
  147. </div>
  148. </template>
  149. </el-table-column>
  150. <el-table-column label="检查情况">
  151. <template slot-scope="scope">
  152. <div>
  153. <el-radio-group v-model="scope.row.checkStatus">
  154. <el-radio :label="1">已检查</el-radio>
  155. <el-radio :label="0">未检查</el-radio>
  156. </el-radio-group>
  157. </div>
  158. </template>
  159. </el-table-column>
  160. <el-table-column label="描述">
  161. <template slot-scope="scope">
  162. <div>
  163. <el-input
  164. type="text"
  165. :rows="1"
  166. placeholder="请输入"
  167. v-model="scope.row.errorMsg"
  168. >
  169. <template v-if="scope.row.unitName" slot="append">
  170. <div>{{ scope.row.unitName }}</div>
  171. </template>
  172. </el-input>
  173. </div>
  174. </template>
  175. </el-table-column>
  176. <el-table-column label="检查结果">
  177. <template slot-scope="scope">
  178. <div>
  179. <el-radio-group v-model="scope.row.checkResult">
  180. <el-radio :label="1">合格</el-radio>
  181. <el-radio :label="0">不合格</el-radio>
  182. </el-radio-group>
  183. </div>
  184. </template>
  185. </el-table-column>
  186. </el-table>
  187. <!-- 底部按钮 -->
  188. <template #footer>
  189. <div class="modal-footer">
  190. <el-button
  191. v-if="$hasPermission('mes:producetaskrecordrulesrecord:sus')"
  192. :loading="butLoading"
  193. type="primary"
  194. @click="submit('submit')"
  195. :disabled="productionInfo && productionInfo.executeStatus == 2"
  196. >
  197. 一键报工
  198. </el-button>
  199. <template
  200. v-if="$hasPermission('mes:producetaskrecordrulesrecord:logicdelete')"
  201. >
  202. <el-popconfirm
  203. v-if="
  204. productionInfo &&
  205. productionInfo.recordId != null &&
  206. productionInfo.executeStatus == 1
  207. "
  208. title="您确定要清空缓存吗?"
  209. @confirm="clearCache"
  210. >
  211. <el-button slot="reference" :loading="butLoading" type="primary">
  212. 清空缓存
  213. </el-button>
  214. </el-popconfirm>
  215. </template>
  216. <el-button
  217. v-if="$hasPermission('mes:producetaskrecordrulesrecord:saveorupdate')"
  218. :loading="butLoading"
  219. type="primary"
  220. @click="submit('cache')"
  221. :disabled="productionInfo && productionInfo.executeStatus == 2"
  222. >
  223. 缓存
  224. </el-button>
  225. <el-button
  226. v-if="productionInfo && productionInfo.executeStatus == 2"
  227. @click="handleBeforeClose"
  228. >
  229. 关闭
  230. </el-button>
  231. </div>
  232. </template>
  233. <!-- 选择用户 -->
  234. <SelectUser
  235. ref="SelectUserRef"
  236. v-model="showSelectUser"
  237. multipleSelect
  238. @selectUserFinished="selectUserFinished"
  239. ></SelectUser>
  240. <toolModal ref="toolModalRef" @chooseModal="chooseModal" />
  241. </ele-modal>
  242. </template>
  243. <script>
  244. import { submit } from '@/api/entrust';
  245. import {
  246. recordRulesDetailPage,
  247. getRecordRulesDetail
  248. } from '@/api/recordRules/index.js';
  249. import DictSelection from '@/components/Dict/DictSelection.vue';
  250. import SelectUser from '@/components/select/SelectUser/index.vue';
  251. import {
  252. saveOrUpdateAndSubmit,
  253. saveOrUpdate,
  254. logicDelete,
  255. getById
  256. } from '@/api/producetaskrecordrulesrecord/index';
  257. import toolModal from '@/views/batchRecord/components/toolModal.vue';
  258. export default {
  259. components: { SelectUser, toolModal },
  260. emits: ['reload'],
  261. props: {
  262. isTempRecord: {
  263. type: Number,
  264. default: 0
  265. }
  266. },
  267. data() {
  268. const formDate = {
  269. id: null,
  270. workshopArea: '',
  271. checkFinishTime: '',
  272. checkValidity: null,
  273. checkValidityUnit: '',
  274. conclution: null,
  275. isTempRecord: this.isTempRecord,
  276. details: [],
  277. deviceId: 0,
  278. deviceName: '',
  279. batchNo: '',
  280. executeMethod: 0,
  281. formingNum: 0,
  282. itemType: 0,
  283. produceRoutingId: 0,
  284. produceRoutingName: '',
  285. produceTaskConfigId: 0,
  286. produceTaskId: 0,
  287. produceTaskName: '',
  288. productCode: '',
  289. productModel: '',
  290. productName: '',
  291. recordRulesClassify: null,
  292. ruleId: 0,
  293. ruleName: '',
  294. reportWorkType: 0,
  295. specification: '',
  296. workOrderCode: '',
  297. workOrderId: 0,
  298. itemTaskName: '',
  299. brandNo: ''
  300. };
  301. return {
  302. visible: false,
  303. formDate,
  304. addForm: JSON.parse(JSON.stringify(formDate)),
  305. formRules: {
  306. checkFinishTime: [
  307. { required: true, message: '请选择检查完成时间', trigger: 'blur' },
  308. { required: true, message: '请选择检查完成时间', trigger: 'change' }
  309. ],
  310. conclution: [
  311. { required: true, message: '请选择结论', trigger: 'blur' },
  312. { required: true, message: '请选择结论', trigger: 'change' }
  313. ],
  314. checkValidity: [
  315. { required: true, message: '请输入检查有效期', trigger: 'blur' },
  316. { required: true, message: '请输入检查有效期', trigger: 'change' }
  317. ],
  318. checkValidityUnit: [
  319. {
  320. required: true,
  321. message: '请选择检查有效期单位',
  322. trigger: 'blur'
  323. },
  324. {
  325. required: true,
  326. message: '请选择检查有效期单位',
  327. trigger: 'change'
  328. }
  329. ]
  330. },
  331. productionInfo: null,
  332. list: [],
  333. ruleInfo: null,
  334. showSelectUser: false,
  335. currentRow: null,
  336. butLoading: false,
  337. // 工艺路线
  338. workOrderInfo: null,
  339. // 加载中 loading
  340. loading: false
  341. };
  342. },
  343. computed: {
  344. title() {
  345. if (this.ruleInfo) {
  346. switch (this.ruleInfo.classify) {
  347. case 1:
  348. return '清场清洁类记录表';
  349. case 2:
  350. return '车间环境类记录表';
  351. default:
  352. return '设备检测类记录表';
  353. }
  354. }
  355. return '类记录表';
  356. }
  357. },
  358. methods: {
  359. open(productionInfo, workOrderInfo) {
  360. console.log(
  361. 'productionInfo, workOrderInfo',
  362. productionInfo,
  363. workOrderInfo
  364. );
  365. this.visible = true;
  366. this.productionInfo = productionInfo;
  367. this.workOrderInfo = workOrderInfo;
  368. // 存在缓存记录
  369. if (this.productionInfo.recordId != null) {
  370. // 查询详情
  371. this.getCacheInfo();
  372. } else {
  373. this.addForm.batchNo = workOrderInfo.batchNo;
  374. this.addForm.executeMethod = productionInfo.executeMethod;
  375. this.addForm.formingNum = workOrderInfo.formingNum;
  376. this.addForm.itemType = productionInfo.itemType;
  377. this.addForm.produceRoutingId = workOrderInfo.produceRoutingId;
  378. this.addForm.produceRoutingName = workOrderInfo.produceRoutingName;
  379. this.addForm.produceTaskConfigId = productionInfo.produceTaskConfigId;
  380. this.addForm.produceTaskId = productionInfo.produceTaskId;
  381. this.addForm.produceTaskName = productionInfo.produceTaskName;
  382. this.addForm.productCode = workOrderInfo.productCode;
  383. this.addForm.productModel = workOrderInfo.model;
  384. this.addForm.productName = workOrderInfo.productName;
  385. this.addForm.reportWorkType = productionInfo.reportWorkType;
  386. this.addForm.specification = workOrderInfo.specification;
  387. this.addForm.workOrderCode = workOrderInfo.code;
  388. this.addForm.workOrderId = workOrderInfo.id;
  389. this.addForm.brandNo = productionInfo.brandNo;
  390. // 临时添加存在规则详情
  391. if (
  392. this.productionInfo.details &&
  393. this.productionInfo.details.length > 0
  394. ) {
  395. this.addForm.details = this.productionInfo.details.map((i) => {
  396. i.toolNames = i.tools.map((j) => j.toolName).join(',');
  397. return i;
  398. });
  399. } else {
  400. this.getRuleList();
  401. }
  402. }
  403. console.log('this.productionInfo', this.productionInfo);
  404. console.log('this.addForm', this.addForm);
  405. this.getRuleInfo();
  406. },
  407. // 获取详情
  408. async getCacheInfo() {
  409. this.loading = true;
  410. try {
  411. const data = await getById(this.productionInfo.recordId);
  412. console.log('dat 缓存', data);
  413. data.details = data.details.map((i) => {
  414. i.toolNames = i.tools.map((j) => j.toolName).join(',');
  415. return i;
  416. });
  417. this.$util.assignObject(this.addForm, data);
  418. this.addForm.recordRulesClassify += '';
  419. if (this.addForm.details?.length == 0) {
  420. this.getRuleList();
  421. }
  422. this.loading = false;
  423. } catch (error) {
  424. this.loading = false;
  425. }
  426. },
  427. // 规则信息
  428. async getRuleInfo() {
  429. const data = await getRecordRulesDetail(this.productionInfo.ruleId);
  430. this.ruleInfo = data;
  431. console.log('this.ruleInfo', this.ruleInfo);
  432. if (this.productionInfo.recordId == null) {
  433. // 赋值表单信息
  434. this.addForm.recordRulesClassify = this.ruleInfo.classify + '';
  435. this.addForm.ruleId = this.ruleInfo.id;
  436. this.addForm.ruleName = this.ruleInfo.name;
  437. this.addForm.deviceId = this.ruleInfo.deviceId;
  438. this.addForm.deviceName = this.ruleInfo.deviceName;
  439. }
  440. },
  441. // 查询记录规则 事项列表
  442. async getRuleList() {
  443. const { list } = await recordRulesDetailPage({
  444. rulesId: this.productionInfo.ruleId,
  445. pageNum: 1,
  446. size: 9999
  447. });
  448. // 添加必要参数
  449. this.addForm.details = list.map((i) => {
  450. return {
  451. ...i,
  452. id: null,
  453. checkResult: null,
  454. checkStatus: null,
  455. checkStatusDesc: i.defaultValue || '',
  456. errorMsg: '',
  457. checkUsers: [],
  458. paramValue: i.paramValue,
  459. toolNames: i.tools.map((i) => i.toolName).join(',')
  460. };
  461. });
  462. console.log('this.addForm 添加规则', this.addForm, list);
  463. },
  464. openSelectUser(row) {
  465. this.currentRow = row;
  466. console.log('row', row);
  467. this.showSelectUser = true;
  468. },
  469. handleBeforeClose() {
  470. this.addForm = JSON.parse(JSON.stringify(this.formDate));
  471. console.log('this.$refs.ruleFormRef', this.addForm);
  472. this.$refs.ruleFormRef?.clearValidate();
  473. this.$nextTick(() => {
  474. this.visible = false;
  475. });
  476. },
  477. selectUserFinished(userInfo) {
  478. console.log('userInfo', userInfo);
  479. this.currentRow.checkUsers = userInfo.map((i) => {
  480. // 构建参数和接口的对应上
  481. return { ...i, userName: i.name, userId: i.id };
  482. });
  483. },
  484. showCheckUserNames(userList) {
  485. if (userList.length == 0) return '请选择部门-选择员工';
  486. return userList
  487. .map((i) => {
  488. return i.groupName + '-' + i.userName;
  489. })
  490. .join(',');
  491. },
  492. // 提交
  493. submit(type) {
  494. // 验证表单
  495. this.$refs.ruleFormRef.validate(async (valid) => {
  496. if (!valid) {
  497. return;
  498. }
  499. // 报工需要验证 缓存不验证
  500. if (type == 'submit') {
  501. // 验证检查项目
  502. const detailRequired = this.addForm.details.some((i) => {
  503. let qk = false;
  504. if (this.ruleInfo.classify == 3) {
  505. qk = Boolean(i.checkStatusDesc);
  506. } else {
  507. qk = i.checkStatus != null;
  508. }
  509. return i.checkResult == null || !qk || i.checkUsers?.length == 0;
  510. });
  511. if (detailRequired) {
  512. return this.$message.warning(
  513. '请先完善 检查人、检查情况、检查结果 内容!'
  514. );
  515. }
  516. }
  517. console.log('this.addForm', this.addForm);
  518. // 提交
  519. this.butLoading = true;
  520. try {
  521. if (type == 'submit') {
  522. await saveOrUpdateAndSubmit(this.addForm);
  523. this.$message.success('报工成功!');
  524. } else {
  525. const id = await saveOrUpdate(this.addForm);
  526. this.addForm.id = id;
  527. this.$message.success('缓存成功!');
  528. }
  529. this.butLoading = false;
  530. // 返回
  531. this.$emit('reload');
  532. this.handleBeforeClose();
  533. } catch (error) {
  534. this.butLoading = false;
  535. }
  536. });
  537. },
  538. async clearCache() {
  539. try {
  540. this.butLoading = true;
  541. await logicDelete(this.productionInfo.recordId);
  542. this.butLoading = false;
  543. this.productionInfo.recordId == null;
  544. this.addForm.workshopArea = '';
  545. this.addForm.checkFinishTime = null;
  546. this.addForm.checkValidity = null;
  547. this.addForm.checkValidityUnit = null;
  548. this.addForm.conclution = null;
  549. this.addForm.id = null;
  550. this.getRuleList();
  551. this.$message.success('缓存清空成功!');
  552. this.productionInfo.executeStatus = 0;
  553. if (this.addForm.isTempRecord) {
  554. this.handleBeforeClose();
  555. }
  556. this.$emit('reload');
  557. } catch (error) {
  558. this.butLoading = false;
  559. }
  560. },
  561. // 选择工具
  562. handleAdd(row) {
  563. this.currentRow = row;
  564. this.$refs.toolModalRef.open(row.tools.map((i) => i.toolCode));
  565. },
  566. chooseModal(data) {
  567. console.log('data', data);
  568. this.currentRow.tools = data.map((i) => {
  569. return {
  570. toolCode: i.code,
  571. toolName: i.name
  572. };
  573. });
  574. this.currentRow.toolNames = this.currentRow.tools
  575. .map((i) => i.toolName)
  576. .join(',');
  577. },
  578. clearTool(row) {
  579. row.tools = [];
  580. row.toolNames = '';
  581. }
  582. }
  583. };
  584. </script>
  585. <style scoped lang="scss">
  586. .modal-body {
  587. padding: 16px;
  588. min-height: 100px;
  589. }
  590. .modal-footer {
  591. display: flex;
  592. align-items: center;
  593. gap: 10px;
  594. justify-content: flex-end;
  595. }
  596. .el-form-item .el-form-item {
  597. margin-bottom: -5px;
  598. }
  599. </style>