releaseRulesDialog.vue 42 KB

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