releaseRulesDialog.vue 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  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="车间区域">
  53. <el-select
  54. v-model="addForm.workshopAreaId"
  55. placeholder="请选择车间区域"
  56. filterable
  57. clearable
  58. style="width: 100%"
  59. @change="workshopAreaIdChange"
  60. >
  61. <el-option
  62. v-for="item in workshopAreaList"
  63. :key="item.id"
  64. :label="item.name"
  65. :value="item.id"
  66. />
  67. </el-select>
  68. </el-form-item>
  69. </el-col>
  70. </el-row>
  71. <el-row>
  72. <el-col :span="8">
  73. <el-form-item label="当前工序">
  74. <el-input
  75. v-model="addForm.produceTaskName"
  76. placeholder="当前工序"
  77. disabled
  78. ></el-input>
  79. </el-form-item>
  80. </el-col>
  81. <el-col :span="8">
  82. <el-form-item label="检查开始时间" required prop="checkStartTime">
  83. <el-date-picker
  84. v-model="addForm.checkStartTime"
  85. type="datetime"
  86. format="yyyy-MM-dd HH:mm:ss"
  87. value-format="yyyy-MM-dd HH:mm:ss"
  88. placeholder="选择日期"
  89. style="width: 100%"
  90. @change="computedDuration"
  91. >
  92. </el-date-picker>
  93. </el-form-item>
  94. </el-col>
  95. <el-col :span="8">
  96. <el-form-item label="检查结束时间" required prop="checkFinishTime">
  97. <el-date-picker
  98. v-model="addForm.checkFinishTime"
  99. type="datetime"
  100. format="yyyy-MM-dd HH:mm:ss"
  101. value-format="yyyy-MM-dd HH:mm:ss"
  102. placeholder="选择日期"
  103. style="width: 100%"
  104. @change="computedDuration"
  105. >
  106. </el-date-picker>
  107. </el-form-item>
  108. </el-col>
  109. </el-row>
  110. <el-row>
  111. <el-col :span="8">
  112. <el-form-item label="执行人" required prop="teamId">
  113. <el-select
  114. v-model="addForm.teamId"
  115. placeholder="请选择班组"
  116. filterable
  117. style="width: 120px"
  118. @change="checkTeamList(addForm.teamId)"
  119. >
  120. <el-option
  121. v-for="item in teamList"
  122. :label="item.name"
  123. :value="item.id"
  124. :key="item.id"
  125. >
  126. </el-option>
  127. </el-select>
  128. <el-select
  129. v-model="addForm.executeUsersIds"
  130. placeholder="请选择执行人"
  131. filterable
  132. multiple
  133. @change="changeId"
  134. >
  135. <div class="checkboxWrapper">
  136. <el-checkbox v-model="checked" @change="checkChange">
  137. 全选
  138. </el-checkbox>
  139. </div>
  140. <el-option
  141. v-for="item in teamUserList"
  142. :label="item.name"
  143. :value="item.id"
  144. :key="item.id"
  145. >
  146. </el-option>
  147. </el-select>
  148. </el-form-item>
  149. </el-col>
  150. <el-col :span="8">
  151. <el-form-item label="工时" required prop="duration">
  152. <el-input
  153. placeholder="请输入"
  154. v-model="addForm.duration"
  155. type="number"
  156. min="0"
  157. step="0.1"
  158. @change="durationChagne"
  159. >
  160. <template slot="append">
  161. <div style="width: 40px; box-sizing: border-box">小时</div>
  162. </template>
  163. </el-input>
  164. </el-form-item>
  165. </el-col>
  166. <el-col :span="8">
  167. <el-form-item label="检查有效期">
  168. <el-input
  169. placeholder="请输入"
  170. v-model="addForm.checkValidity"
  171. type="text"
  172. >
  173. <template slot="append">
  174. <div style="width: 40px; box-sizing: border-box">
  175. <el-form-item>
  176. <DictSelection
  177. dictName="检查有效期单位"
  178. clearable
  179. v-model="addForm.checkValidityUnit"
  180. placeholder="单位"
  181. style="width: auto"
  182. >
  183. </DictSelection>
  184. </el-form-item>
  185. </div>
  186. </template>
  187. </el-input>
  188. </el-form-item>
  189. </el-col>
  190. </el-row>
  191. <el-row>
  192. <el-col v-if="addForm.recordRulesExecuteMethodName" :span="8">
  193. <el-form-item label="执行方式" required>
  194. <el-input
  195. v-model="addForm.recordRulesExecuteMethodName"
  196. placeholder="自动带出"
  197. disabled
  198. ></el-input>
  199. </el-form-item>
  200. </el-col>
  201. <el-col :span="8">
  202. <el-form-item label="结论" required prop="conclusion">
  203. <el-radio-group v-model="addForm.conclusion">
  204. <el-radio :label="1">合格</el-radio>
  205. <el-radio :label="2">不合格</el-radio>
  206. </el-radio-group>
  207. </el-form-item>
  208. </el-col>
  209. </el-row>
  210. </el-form>
  211. <material
  212. v-if="addForm.produceTaskId"
  213. :pickDetails.sync="addForm.pickDetails"
  214. :previousOutputDetails="previousOutputDetails"
  215. :workOrderId="addForm.workOrderId"
  216. :ruleId="addForm.ruleId"
  217. :produceTaskId="addForm.produceTaskId"
  218. ></material>
  219. <header-title
  220. title="检查项目"
  221. :style="`margin-top: ${
  222. addForm.reportWorkType == '2' && addForm.produceTaskId ? '20px' : '0px'
  223. }`"
  224. ></header-title>
  225. <ele-pro-table
  226. v-loading="loading"
  227. ref="table"
  228. row-key="id"
  229. :columns="detailsColumns"
  230. :datasource="addForm.details"
  231. cacheKey="mes-releaseRulesDialong-2510281408"
  232. :needPage="false"
  233. >
  234. <template v-slot:toolkit>
  235. <el-button
  236. v-if="addForm.recordRulesClassify != 4"
  237. type="primary"
  238. @click="batchCheck"
  239. >批量检查</el-button
  240. >
  241. <el-button
  242. v-if="addForm.recordRulesClassify != 4"
  243. type="primary"
  244. @click="batchQualified"
  245. >批量合格</el-button
  246. >
  247. </template>
  248. <template v-slot:paramValue="{ row }">
  249. <div v-if="addForm.recordRulesClassify == 4">
  250. {{ row.productName || row.name }}
  251. </div>
  252. <div v-else>
  253. {{ row.paramValue }}
  254. </div>
  255. </template>
  256. <template v-slot:toolNames="{ row }">
  257. <el-link :underline="false" style="cursor: pointer">
  258. <div class="ele-cell">
  259. <div @click="handleAdd(row)">
  260. {{ row.toolNames ? row.toolNames : '请选择' }}
  261. </div>
  262. <i
  263. v-if="!row.toolNames"
  264. class="el-icon-arrow-down"
  265. @click="handleAdd(row)"
  266. ></i>
  267. <i v-else class="el-icon-close" @click="clearTool(row)"></i>
  268. </div>
  269. </el-link>
  270. </template>
  271. <template v-slot:checkUsersIds="{ row }">
  272. <div>
  273. <el-select
  274. v-model="row.checkUsersIds"
  275. placeholder="请选择检查人"
  276. filterable
  277. multiple
  278. @change="checkUsersIdsChange(row)"
  279. >
  280. <el-option
  281. v-for="item in activeTeamUserList"
  282. :label="item.name"
  283. :value="item.id"
  284. :key="item.id"
  285. >
  286. </el-option>
  287. </el-select>
  288. </div>
  289. </template>
  290. <template v-slot:checkStatus="{ row }">
  291. <div>
  292. <el-radio-group v-model="row.checkStatus">
  293. <el-radio :label="1">已检查</el-radio>
  294. <el-radio :label="0">未检查</el-radio>
  295. </el-radio-group>
  296. </div>
  297. </template>
  298. <template v-slot:errorMsg="{ row }">
  299. <div>
  300. <el-input
  301. type="text"
  302. :rows="1"
  303. placeholder="请输入"
  304. v-model="row.errorMsg"
  305. >
  306. <template v-if="row.unitName" slot="append">
  307. <div>{{ row.unitName }}</div>
  308. </template>
  309. </el-input>
  310. </div></template
  311. >
  312. <template v-slot:checkResult="{ row }">
  313. <div>
  314. <el-radio-group v-model="row.checkResult">
  315. <el-radio :label="1">合格</el-radio>
  316. <el-radio :label="0">不合格</el-radio>
  317. </el-radio-group>
  318. </div>
  319. </template>
  320. </ele-pro-table>
  321. <!-- 底部按钮 -->
  322. <template #footer>
  323. <div class="modal-footer">
  324. <el-button
  325. v-if="$hasPermission('mes:producetaskrecordrulesrecord:sus')"
  326. :loading="butLoading"
  327. type="primary"
  328. @click="submit('submit')"
  329. :disabled="productionInfo && productionInfo.executeStatus == 2"
  330. >
  331. 一键报工
  332. </el-button>
  333. <template
  334. v-if="$hasPermission('mes:producetaskrecordrulesrecord:logicdelete')"
  335. >
  336. <el-popconfirm
  337. v-if="
  338. productionInfo &&
  339. productionInfo.recordId != null &&
  340. productionInfo.executeStatus == 1
  341. "
  342. title="您确定要清空缓存吗?"
  343. @confirm="clearCache"
  344. >
  345. <el-button slot="reference" :loading="butLoading" type="primary">
  346. 清空缓存
  347. </el-button>
  348. </el-popconfirm>
  349. </template>
  350. <el-button
  351. v-if="$hasPermission('mes:producetaskrecordrulesrecord:saveorupdate')"
  352. :loading="butLoading"
  353. type="primary"
  354. @click="submit('cache')"
  355. :disabled="productionInfo && productionInfo.executeStatus == 2"
  356. >
  357. 缓存
  358. </el-button>
  359. <el-button
  360. v-if="productionInfo && productionInfo.executeStatus == 2"
  361. @click="handleBeforeClose"
  362. >
  363. 关闭
  364. </el-button>
  365. </div>
  366. </template>
  367. <toolModal ref="toolModalRef" @chooseModal="chooseModal" />
  368. </ele-modal>
  369. </template>
  370. <script>
  371. import {
  372. recordRulesDetailPage,
  373. getRecordRulesDetail
  374. } from '@/api/recordRules/index.js';
  375. import DictSelection from '@/components/Dict/DictSelection.vue';
  376. import SelectUser from '@/components/select/SelectUser/index.vue';
  377. import {
  378. saveOrUpdateAndSubmit,
  379. saveOrUpdate,
  380. logicDelete,
  381. getById,
  382. queryListByWorkOrderId
  383. } from '@/api/producetaskrecordrulesrecord/index';
  384. import toolModal from '@/views/batchRecord/components/toolModal.vue';
  385. import { getTeam } from '@/api/produce/job.js';
  386. import { getFactoryarea } from '@/api/aps/index';
  387. import dictMixins from '@/mixins/dictMixins';
  388. import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  389. import material from './material.vue';
  390. export default {
  391. components: { SelectUser, toolModal, material },
  392. mixins: [dictMixins, tableColumnsMixin],
  393. emits: ['reload'],
  394. props: {
  395. isTempRecord: {
  396. type: Number,
  397. default: 0
  398. }
  399. },
  400. watch: {
  401. 'addForm.details': {
  402. handler(details) {
  403. const any = details.some((i) => i.checkResult === null);
  404. if (any || details.length === 0) return;
  405. const every = details.every((i) => i.checkResult == 1);
  406. this.addForm.conclusion = every ? 1 : 2;
  407. console.log('this.addForm.conclusion', this.addForm.conclusion);
  408. },
  409. deep: true
  410. }
  411. },
  412. data() {
  413. const formDate = {
  414. id: null,
  415. workshopArea: '',
  416. workshopAreaId: null,
  417. checkFinishTime: '',
  418. checkStartTime: '',
  419. checkValidity: null,
  420. checkValidityUnit: '',
  421. conclusion: null,
  422. isTempRecord: this.isTempRecord,
  423. details: [],
  424. deviceId: 0,
  425. deviceName: '',
  426. batchNo: '',
  427. executeMethod: 0,
  428. formingNum: 0,
  429. itemType: 0,
  430. produceRoutingId: 0,
  431. produceRoutingName: '',
  432. produceTaskConfigId: 0,
  433. produceTaskId: 0,
  434. produceTaskName: '',
  435. productCode: '',
  436. productModel: '',
  437. productName: '',
  438. recordRulesClassify: null,
  439. ruleId: 0,
  440. ruleName: '',
  441. reportWorkType: 0,
  442. specification: '',
  443. workOrderCode: '',
  444. workOrderId: 0,
  445. itemTaskName: '',
  446. brandNo: '',
  447. duration: null,
  448. // 执行人
  449. executeUsersIds: [],
  450. executeUsers: [
  451. // {
  452. // teamId: 0,
  453. // teamName: '',
  454. // userId: 0,
  455. // userName: ''
  456. // }
  457. ],
  458. // 班组id
  459. teamId: '',
  460. // 物料字段name
  461. pickDetails: [],
  462. recordRulesExecuteMethodId: null,
  463. recordRulesExecuteMethodName: ''
  464. };
  465. return {
  466. visible: false,
  467. formDate,
  468. addForm: JSON.parse(JSON.stringify(formDate)),
  469. formRules: {
  470. checkStartTime: [
  471. { required: true, message: '请选择检查开始时间', trigger: 'blur' },
  472. {
  473. required: true,
  474. message: '请选择检查开始时间',
  475. trigger: 'change'
  476. },
  477. {
  478. validator: (rule, value, callback) => {
  479. if (!value) return callback();
  480. const now = new Date();
  481. const start = new Date(value);
  482. callback();
  483. },
  484. trigger: 'blur'
  485. }
  486. ],
  487. checkFinishTime: [
  488. { required: true, message: '请选择检查完成时间', trigger: 'blur' },
  489. {
  490. required: true,
  491. message: '请选择检查完成时间',
  492. trigger: 'change'
  493. },
  494. {
  495. validator: (rule, value, callback) => {
  496. if (!value) return callback();
  497. const start = new Date(this.addForm.checkStartTime);
  498. const finish = new Date(value);
  499. if (finish <= start) {
  500. callback(new Error('结束时间必须大于开始时间'));
  501. } else {
  502. callback();
  503. }
  504. },
  505. trigger: 'blur'
  506. }
  507. ],
  508. conclusion: [
  509. { required: true, message: '请选择结论', trigger: 'blur' },
  510. { required: true, message: '请选择结论', trigger: 'change' }
  511. ],
  512. duration: [
  513. { required: true, message: '请输入工时', trigger: 'blur' },
  514. { required: true, message: '请输入工时', trigger: 'change' },
  515. {
  516. validator: (rule, value, callback) => {
  517. if (value === '' || value === null) {
  518. callback();
  519. } else if (Number(value) <= 0) {
  520. callback(new Error('工时必须大于0'));
  521. } else {
  522. callback();
  523. }
  524. },
  525. trigger: 'blur'
  526. }
  527. ],
  528. teamId: [
  529. { required: true, message: '请选择班组', trigger: 'blur' },
  530. { required: true, message: '请选择班组', trigger: 'change' }
  531. ]
  532. },
  533. productionInfo: null,
  534. list: [],
  535. ruleInfo: null,
  536. showSelectUser: false,
  537. currentRow: null,
  538. butLoading: false,
  539. // 工艺路线
  540. workOrderInfo: null,
  541. // 加载中 loading
  542. loading: false,
  543. checked: false,
  544. teamUserList: [],
  545. teamList: [],
  546. teamAllList: [],
  547. workshopAreaList: [],
  548. // 上到工序的 产出明细
  549. previousOutputDetails: []
  550. };
  551. },
  552. computed: {
  553. title() {
  554. if (this.addForm.recordRulesClassify) {
  555. const dictValue = this.getDictValue(
  556. '记录规则类型',
  557. this.addForm.recordRulesClassify
  558. );
  559. return dictValue + '记录表';
  560. }
  561. return '记录表';
  562. },
  563. activeTeamUserList() {
  564. return this.teamUserList.filter((user) =>
  565. this.addForm.executeUsersIds.includes(user.id)
  566. );
  567. },
  568. // 规则详情表头
  569. detailsColumns() {
  570. let list = [
  571. {
  572. width: 45,
  573. type: 'index',
  574. columnKey: 'index',
  575. align: 'center'
  576. },
  577. {
  578. label: '检查内容',
  579. prop: 'paramValue',
  580. minWidth: 120,
  581. slot: 'paramValue'
  582. }
  583. ];
  584. if (this.addForm.recordRulesClassify != '4') {
  585. list = [
  586. ...list,
  587. {
  588. label: '检查工具',
  589. prop: 'toolNames',
  590. minWidth: 120,
  591. slot: 'toolNames'
  592. },
  593. {
  594. label: '检查人',
  595. prop: 'checkUsersIds',
  596. minWidth: 120,
  597. slot: 'checkUsersIds'
  598. },
  599. {
  600. label: '检查情况',
  601. prop: 'checkStatus',
  602. minWidth: 120,
  603. slot: 'checkStatus'
  604. },
  605. {
  606. label: '描述',
  607. prop: 'errorMsg',
  608. minWidth: 120,
  609. slot: 'errorMsg'
  610. },
  611. {
  612. label: '检查结果',
  613. prop: 'checkResult',
  614. minWidth: 120,
  615. slot: 'checkResult'
  616. }
  617. ];
  618. } else {
  619. list.push({
  620. label: '描述',
  621. prop: 'errorMsg',
  622. minWidth: 120,
  623. slot: 'errorMsg'
  624. });
  625. }
  626. return list;
  627. }
  628. },
  629. mounted() {
  630. if (localStorage.getItem('singleUserInfo') == '1') {
  631. const data = JSON.parse(localStorage.getItem('chooseUserInfo'));
  632. this.getTeamList(data.teamId);
  633. } else {
  634. this.getTeamList(this.$store.state.user.info.teamId);
  635. }
  636. this.getWorkshopArea();
  637. },
  638. methods: {
  639. open(productionInfo, workOrderInfo) {
  640. console.log(
  641. 'productionInfo, workOrderInfo',
  642. productionInfo,
  643. workOrderInfo
  644. );
  645. this.visible = true;
  646. this.productionInfo = productionInfo;
  647. this.workOrderInfo = workOrderInfo;
  648. // 存在缓存记录
  649. if (this.productionInfo.recordId != null) {
  650. // 查询详情
  651. this.getCacheInfo();
  652. } else {
  653. this.addForm.batchNo = workOrderInfo.batchNo;
  654. this.addForm.executeMethod = productionInfo.executeMethod;
  655. this.addForm.formingNum = workOrderInfo.formingNum;
  656. this.addForm.itemType = productionInfo.itemType;
  657. this.addForm.produceRoutingId = workOrderInfo.produceRoutingId;
  658. this.addForm.produceRoutingName = workOrderInfo.produceRoutingName;
  659. this.addForm.produceTaskConfigId = productionInfo.produceTaskConfigId;
  660. this.addForm.produceTaskId = productionInfo.produceTaskId;
  661. this.addForm.produceTaskName =
  662. productionInfo.produceTaskName || workOrderInfo.taskName;
  663. this.addForm.productCode = workOrderInfo.productCode;
  664. this.addForm.productModel = workOrderInfo.model;
  665. this.addForm.productName = workOrderInfo.productName;
  666. this.addForm.reportWorkType = productionInfo.reportWorkType;
  667. this.addForm.specification = workOrderInfo.specification;
  668. this.addForm.workOrderCode = workOrderInfo.code;
  669. this.addForm.workOrderId = workOrderInfo.id;
  670. this.addForm.brandNo = productionInfo.brandNo;
  671. this.addForm.recordRulesExecuteMethodId =
  672. productionInfo.recordRulesExecuteMethodId;
  673. this.addForm.recordRulesExecuteMethodName =
  674. productionInfo.recordRulesExecuteMethodName;
  675. // 临时添加存在规则详情
  676. if (
  677. this.productionInfo.details &&
  678. this.productionInfo.details.length > 0
  679. ) {
  680. this.addForm.details = this.productionInfo.details.map((i) => {
  681. i.toolNames = i.tools.map((j) => j.toolName).join(',');
  682. return i;
  683. });
  684. } else {
  685. this.getRuleList();
  686. }
  687. }
  688. console.log('this.productionInfo', this.productionInfo);
  689. console.log('this.addForm', this.addForm);
  690. this.getRuleInfo();
  691. },
  692. // 获取详情
  693. async getCacheInfo() {
  694. this.loading = true;
  695. try {
  696. const data = await getById(this.productionInfo.recordId);
  697. console.log('dat 缓存', data);
  698. data.details = data.details.map((i) => {
  699. i.toolNames = i.tools.map((j) => j.toolName).join(',');
  700. i.checkUsersIds = i.checkUsers.map((j) => j.userId);
  701. return i;
  702. });
  703. this.$util.assignObject(this.addForm, data);
  704. // 工时毫秒转小时
  705. this.addForm.duration = (
  706. this.addForm.duration /
  707. (1000 * 60 * 60)
  708. ).toFixed(2);
  709. this.addForm.recordRulesClassify += '';
  710. if (this.addForm.details?.length == 0) {
  711. this.getRuleList();
  712. }
  713. this.addForm.executeUsersIds = this.addForm.executeUsers.map(
  714. (i) => i.userId
  715. );
  716. this.addForm.teamId =
  717. this.addForm.executeUsers.length > 0
  718. ? this.addForm.executeUsers[0].teamId
  719. : '';
  720. // 加载班组人员列表
  721. if (this.addForm.teamId) {
  722. const index = this.teamList.findIndex(
  723. (item) => item.id == this.addForm.teamId
  724. );
  725. this.teamUserList = this.teamAllList[index];
  726. }
  727. this.getListByWorkOrderId();
  728. this.loading = false;
  729. } catch (error) {
  730. this.loading = false;
  731. }
  732. },
  733. // 物料信息查询
  734. async getListByWorkOrderId() {
  735. if (!this.productionInfo.produceTaskId) return;
  736. // 查询物料信息
  737. const materialObject = await queryListByWorkOrderId({
  738. workOrderId: this.addForm.workOrderId,
  739. recordId: this.productionInfo.recordId,
  740. produceTaskId: this.productionInfo.produceTaskId,
  741. ruleId: this.addForm.ruleId
  742. });
  743. console.log('materialList 物料信息', materialObject);
  744. this.addForm.pickDetails = materialObject.pickDetails;
  745. this.previousOutputDetails = materialObject.outputDetails;
  746. },
  747. // 规则信息
  748. async getRuleInfo() {
  749. const data = await getRecordRulesDetail(this.productionInfo.ruleId);
  750. this.ruleInfo = data;
  751. console.log('this.ruleInfo', this.ruleInfo);
  752. if (this.productionInfo.recordId == null) {
  753. // 赋值表单信息
  754. this.addForm.recordRulesClassify = this.ruleInfo.classify + '';
  755. this.addForm.ruleId = this.ruleInfo.id;
  756. this.addForm.ruleName = this.ruleInfo.name;
  757. this.addForm.deviceId = this.ruleInfo.deviceId;
  758. this.addForm.deviceName = this.ruleInfo.deviceName;
  759. }
  760. },
  761. // 查询记录规则 事项列表
  762. async getRuleList() {
  763. const { list } = await recordRulesDetailPage({
  764. rulesId: this.productionInfo.ruleId,
  765. pageNum: 1,
  766. size: 9999
  767. });
  768. // 添加必要参数
  769. this.addForm.details = list.map((i) => {
  770. return {
  771. ...i,
  772. id: null,
  773. checkResult: null,
  774. checkStatus: null,
  775. checkStatusDesc: i.defaultValue || '',
  776. errorMsg: '',
  777. checkUsers: [],
  778. checkUsersIds: [],
  779. paramValue: i.paramValue,
  780. toolNames: i.tools.map((i) => i.toolName).join(',')
  781. };
  782. });
  783. console.log('this.addForm 添加规则', this.addForm, list);
  784. },
  785. handleBeforeClose() {
  786. this.addForm = JSON.parse(JSON.stringify(this.formDate));
  787. console.log('this.$refs.ruleFormRef', this.addForm);
  788. this.$nextTick(() => {
  789. this.$refs.ruleFormRef.clearValidate();
  790. this.visible = false;
  791. });
  792. },
  793. // 提交
  794. submit(type) {
  795. console.log('this.addForm', this.addForm);
  796. // 验证表单
  797. this.$refs.ruleFormRef.validate(async (valid) => {
  798. if (!valid) {
  799. return;
  800. }
  801. if (this.addForm.executeUsersIds.length == 0) {
  802. this.$message.warning('请选择执行人!');
  803. return;
  804. }
  805. if (this.addForm.duration <= 0) {
  806. this.$message.warning('工时必须大于0!');
  807. return;
  808. }
  809. // 报工需要验证 缓存不验证 排除 recordRulesClassify ==4 物料添加 的情况
  810. if (type == 'submit' && this.addForm.recordRulesClassify != '4') {
  811. // 验证检查项目
  812. const detailRequired = this.addForm.details.some((i) => {
  813. return (
  814. i.checkResult == null ||
  815. !i.checkStatus ||
  816. i.checkUsers?.length == 0
  817. );
  818. });
  819. if (detailRequired) {
  820. return this.$message.warning(
  821. '请先完善 检查人、检查情况、检查结果 内容!'
  822. );
  823. }
  824. }
  825. const body = JSON.parse(JSON.stringify(this.addForm));
  826. // 工时小时转毫秒
  827. body.duration = Number(body.duration);
  828. body.duration = body.duration * 60 * 60 * 1000;
  829. // 处理执行人
  830. // 提交
  831. this.butLoading = true;
  832. try {
  833. if (type == 'submit') {
  834. await saveOrUpdateAndSubmit(body);
  835. this.$message.success('报工成功!');
  836. } else {
  837. const id = await saveOrUpdate(body);
  838. this.addForm.id = id;
  839. this.$message.success('缓存成功!');
  840. }
  841. this.butLoading = false;
  842. // 返回
  843. this.$emit('reload');
  844. this.handleBeforeClose();
  845. } catch (error) {
  846. this.butLoading = false;
  847. }
  848. });
  849. },
  850. async clearCache() {
  851. try {
  852. this.butLoading = true;
  853. await logicDelete(this.productionInfo.recordId);
  854. this.butLoading = false;
  855. this.productionInfo.recordId == null;
  856. this.addForm.workshopArea = '';
  857. this.addForm.workshopAreaId = null;
  858. this.addForm.checkFinishTime = null;
  859. this.addForm.checkStartTime = null;
  860. this.addForm.checkValidity = null;
  861. this.addForm.checkValidityUnit = '';
  862. this.addForm.conclusion = null;
  863. this.addForm.id = null;
  864. this.addForm.pickDetails = [];
  865. this.addForm.duration = 0;
  866. this.addForm.executeUsers = [];
  867. thia.addForm.executeUsersIds = [];
  868. this.getRuleList();
  869. this.$message.success('缓存清空成功!');
  870. this.productionInfo.executeStatus = 0;
  871. if (this.addForm.isTempRecord) {
  872. this.handleBeforeClose();
  873. } else {
  874. this.$nextTick(() => {
  875. this.$refs.ruleFormRef.clearValidate();
  876. });
  877. }
  878. this.$emit('reload');
  879. } catch (error) {
  880. this.butLoading = false;
  881. }
  882. },
  883. // 选择工具
  884. handleAdd(row) {
  885. this.currentRow = row;
  886. this.$refs.toolModalRef.open(row.tools.map((i) => i.toolCode));
  887. },
  888. chooseModal(data) {
  889. console.log('data', data);
  890. this.currentRow.tools = data.map((i) => {
  891. return {
  892. toolCode: i.code,
  893. toolName: i.name
  894. };
  895. });
  896. this.currentRow.toolNames = this.currentRow.tools
  897. .map((i) => i.toolName)
  898. .join(',');
  899. },
  900. clearTool(row) {
  901. row.tools = [];
  902. row.toolNames = '';
  903. },
  904. checkTeamList(id) {
  905. this.addForm.executeUsersIds = [];
  906. const index = this.teamList.findIndex((item) => item.id == id);
  907. this.teamUserList = this.teamAllList[index];
  908. console.log('this.teamUserList', this.teamUserList);
  909. },
  910. async getTeamList(id) {
  911. const ids = id.split(',');
  912. this.teamList = [];
  913. this.teamUserList = [];
  914. const list = ids.map((item) => getTeam(item));
  915. const dataList = await Promise.all(list);
  916. dataList.forEach((item) => {
  917. this.teamList.push({
  918. name: item.name,
  919. id: item.id
  920. });
  921. this.teamAllList.push(item.userVOList);
  922. });
  923. },
  924. changeId() {
  925. if (this.addForm.executeUsersIds.length == this.teamUserList.length) {
  926. this.checked = true;
  927. } else {
  928. this.checked = false;
  929. }
  930. // 同步 executeUsers
  931. this.addForm.executeUsers = this.addForm.executeUsersIds
  932. .map((id) => {
  933. const user = this.teamUserList.find((item) => item.id === id);
  934. console.log('user', user);
  935. if (user) {
  936. return {
  937. teamId: this.addForm.teamId,
  938. teamName: this.teamList.find(
  939. (team) => team.id == this.addForm.teamId
  940. )?.name,
  941. userId: user.id,
  942. userName: user.name
  943. };
  944. } else {
  945. return null;
  946. }
  947. })
  948. .filter((item) => item !== null);
  949. console.log('this.addForm.executeUsers', this.addForm.executeUsers);
  950. this.computedDuration();
  951. // 同步详情执行人
  952. this.addForm.details.forEach((detail) => {
  953. detail.checkUsersIds = this.addForm.executeUsersIds;
  954. detail.checkUsers = this.addForm.executeUsers;
  955. });
  956. },
  957. checkChange() {
  958. this.addForm.executeUsersIds = [];
  959. if (this.checked) {
  960. this.addForm.executeUsersIds = this.teamUserList.map(
  961. (item) => item.id
  962. );
  963. } else {
  964. this.addForm.executeUsersIds = [];
  965. }
  966. },
  967. // 计算工时
  968. computedDuration() {
  969. if (
  970. this.addForm.checkStartTime &&
  971. this.addForm.checkFinishTime &&
  972. this.addForm.executeUsersIds.length > 0
  973. ) {
  974. const start = new Date(this.addForm.checkStartTime);
  975. const finish = new Date(this.addForm.checkFinishTime);
  976. const diff = finish - start; // 毫秒差值
  977. const hours = diff / (1000 * 60 * 60); // 转换为小时
  978. const totalDuration = hours * this.addForm.executeUsersIds.length;
  979. this.addForm.duration = totalDuration.toFixed(1);
  980. }
  981. },
  982. durationChagne() {
  983. // 保留小数后一位
  984. if (
  985. this.addForm.duration &&
  986. this.addForm.duration.toString().includes('.')
  987. ) {
  988. this.addForm.duration = Number(this.addForm.duration).toFixed(1);
  989. }
  990. },
  991. checkUsersIdsChange(row) {
  992. // 同步 checkUsers
  993. row.checkUsers = row.checkUsersIds.map((i) => {
  994. const user = this.activeTeamUserList.find((item) => item.id === i);
  995. return {
  996. teamId: this.addForm.teamId,
  997. teamName: this.teamList.find(
  998. (team) => team.id == this.addForm.teamId
  999. )?.name,
  1000. userId: user.id,
  1001. userName: user.name
  1002. };
  1003. });
  1004. console.log('row', row);
  1005. },
  1006. // qualifiedQuantityMax 最大合格数量
  1007. qualifiedQuantityMax(row) {
  1008. return row.reportQuantity - row.noQualifiedQuantity;
  1009. },
  1010. noQualifiedQuantityMax(row) {
  1011. return row.reportQuantity - row.qualifiedQuantity;
  1012. },
  1013. // 查询车间区域
  1014. async getWorkshopArea() {
  1015. const data = await getFactoryarea({
  1016. pageNum: 1,
  1017. size: 999,
  1018. type: 3
  1019. });
  1020. console.log('list', data.list);
  1021. this.workshopAreaList = data.list;
  1022. },
  1023. workshopAreaIdChange(e) {
  1024. const area = this.workshopAreaList.find((i) => i.id === e);
  1025. if (area) {
  1026. this.addForm.workshopArea = area.name;
  1027. } else {
  1028. this.addForm.workshopArea = '';
  1029. }
  1030. },
  1031. // 批量检查
  1032. batchCheck() {
  1033. this.addForm.details = this.addForm.details.map((i) => {
  1034. i.checkStatus = 1;
  1035. return i;
  1036. });
  1037. },
  1038. // 批量合格
  1039. batchQualified() {
  1040. this.addForm.details = this.addForm.details.map((i) => {
  1041. i.checkResult = 1;
  1042. return i;
  1043. });
  1044. }
  1045. }
  1046. };
  1047. </script>
  1048. <style scoped lang="scss">
  1049. .modal-body {
  1050. padding: 16px;
  1051. min-height: 100px;
  1052. }
  1053. .modal-footer {
  1054. display: flex;
  1055. align-items: center;
  1056. gap: 10px;
  1057. justify-content: flex-end;
  1058. }
  1059. .el-form-item .el-form-item {
  1060. margin-bottom: -5px;
  1061. }
  1062. .checkboxWrapper {
  1063. padding: 8px 20px;
  1064. border-bottom: 1px solid #ccc;
  1065. }
  1066. ::v-deep .el-select__tags {
  1067. flex-wrap: nowrap;
  1068. overflow: auto;
  1069. }
  1070. /* 输入框最大宽度*/
  1071. ::v-deep .el-select__tags-text {
  1072. max-width: 90px;
  1073. }
  1074. /* 底部滚动条的高度*/
  1075. ::v-deep .el-select__tags::-webkit-scrollbar {
  1076. height: 2px !important;
  1077. }
  1078. </style>