index.vue 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. <template>
  2. <ele-modal
  3. :before-close="cancel"
  4. :close-on-click-modal="false"
  5. :maxable="true"
  6. :title="'派单'"
  7. :visible.sync="dispatchVisible"
  8. :width="modelWidth"
  9. append-to-body
  10. custom-class="ele-dialog-form"
  11. >
  12. <div class="form-wrapper">
  13. <el-form
  14. ref="form"
  15. :inline="true"
  16. :model="form"
  17. label-position="right"
  18. label-width="100px"
  19. >
  20. <el-row :gutter="10" class="basic" style="flex-wrap: wrap" type="flex">
  21. <el-col
  22. v-for="item in fieldList"
  23. :key="item.prop"
  24. :lg="8"
  25. :md="12"
  26. :sm="12"
  27. :xl="6"
  28. :xs="12"
  29. >
  30. <el-form-item :label="item.label">
  31. <!-- <div class="item_label">{{ current[item.prop] }}</div> -->
  32. <el-input v-model="current[item.prop]" disabled />
  33. </el-form-item>
  34. </el-col>
  35. </el-row>
  36. <el-row :gutter="10">
  37. <el-col :lg="8" :md="12" :sm="12" :xl="6" :xs="12">
  38. <el-form-item label="所属工厂:">
  39. <el-input v-model="form.factoryName" :disabled="true"></el-input>
  40. </el-form-item>
  41. </el-col>
  42. <el-col :lg="8" :md="12" :sm="12" :xl="6" :xs="12">
  43. <el-form-item label="所属工作中心:">
  44. <el-select
  45. v-model="form.workCenterId"
  46. placeholder="请选择"
  47. style="width: 100%"
  48. @change="changeWork"
  49. >
  50. <el-option
  51. v-for="item in workCenterList"
  52. :key="item.id"
  53. :label="item.name"
  54. :value="item.id"
  55. >
  56. </el-option>
  57. </el-select>
  58. </el-form-item>
  59. </el-col>
  60. <el-col :lg="8" :md="12" :sm="12" :xl="6" :xs="12">
  61. <el-form-item label="所属班组:" required>
  62. <el-select
  63. v-model="form.teamId"
  64. placeholder="请选择"
  65. style="width: 100%"
  66. @change="changeGroups"
  67. >
  68. <el-option
  69. v-for="item in teamList"
  70. :key="item.id"
  71. :label="item.name"
  72. :value="item.id"
  73. >
  74. </el-option>
  75. </el-select>
  76. </el-form-item>
  77. </el-col>
  78. </el-row>
  79. <!-- <el-row>-->
  80. <!-- <el-form-item label="报工类型:" required>-->
  81. <!-- <el-radio-group v-model="form.singleReport">-->
  82. <!-- &lt;!&ndash; v-if="clientEnvironmentId != 2" &ndash;&gt;-->
  83. <!-- <el-radio :label="1">单件报工</el-radio>-->
  84. <!-- <el-radio :label="0">批量报工</el-radio>-->
  85. <!-- </el-radio-group>-->
  86. <!-- </el-form-item>-->
  87. <!-- </el-row>-->
  88. <!-- <el-row>-->
  89. <!-- <el-form-item label="派单方式:" prop="taskAss">-->
  90. <!-- <el-radio-group v-model="form.taskAss">-->
  91. <!-- <el-radio :label="1">生产订单派单</el-radio>-->
  92. <!-- <el-radio :disabled="procTaskDis" :label="0"-->
  93. <!-- >工序任务派单-->
  94. <!-- </el-radio-->
  95. <!-- >-->
  96. <!-- </el-radio-group>-->
  97. <!-- </el-form-item>-->
  98. <!-- </el-row>-->
  99. <!-- <el-row v-if="form.taskAss == 1">-->
  100. <!-- <el-col :span="24">-->
  101. <!-- <el-form-item label="指派:" prop="assignType">-->
  102. <!-- <el-radio-group-->
  103. <!-- v-model="form.assignType"-->
  104. <!-- size="mini"-->
  105. <!-- @change="assignRadio"-->
  106. <!-- >-->
  107. <!-- <el-radio-button :label="1">工位</el-radio-button>-->
  108. <!-- <el-radio-button :label="2">人员</el-radio-button>-->
  109. <!-- &lt;!&ndash; <el-radio-button :label="3">产线</el-radio-button> &ndash;&gt;-->
  110. <!-- </el-radio-group>-->
  111. <!-- </el-form-item>-->
  112. <!-- </el-col>-->
  113. <!-- <el-form-item v-if="form.assignType == 1" label="工位:" required>-->
  114. <!-- <el-select-->
  115. <!-- v-model="form.workstationIds"-->
  116. <!-- class="ele-block"-->
  117. <!-- filterable-->
  118. <!-- multiple-->
  119. <!-- placeholder="请选择工位"-->
  120. <!-- size="mini"-->
  121. <!-- >-->
  122. <!-- <el-option-->
  123. <!-- v-for="item in stationList"-->
  124. <!-- :key="item.id"-->
  125. <!-- :label="item.name + '(' + item.code + ')'"-->
  126. <!-- :value="item.id"-->
  127. <!-- >-->
  128. <!-- </el-option>-->
  129. <!-- </el-select>-->
  130. <!-- </el-form-item>-->
  131. <!-- <el-form-item-->
  132. <!-- v-if="form.assignType == 2"-->
  133. <!-- label="人员:"-->
  134. <!-- prop="crewIds"-->
  135. <!-- >-->
  136. <!-- <el-select-->
  137. <!-- v-model="form.crewIds"-->
  138. <!-- class="ele-block"-->
  139. <!-- filterable-->
  140. <!-- multiple-->
  141. <!-- placeholder="请选择人员"-->
  142. <!-- size="mini"-->
  143. <!-- >-->
  144. <!-- <el-option-->
  145. <!-- v-for="item in crewList"-->
  146. <!-- :key="item.id"-->
  147. <!-- :label="item.name"-->
  148. <!-- :value="item.id"-->
  149. <!-- >-->
  150. <!-- </el-option>-->
  151. <!-- </el-select>-->
  152. <!-- </el-form-item>-->
  153. <!-- </el-row>-->
  154. <!-- v-show="form.taskAss == 0" -->
  155. <el-tabs
  156. v-model="processId"
  157. v-loading="tabsLoading"
  158. class="process_list"
  159. style="margin-bottom: 20px"
  160. type="border-card"
  161. @tab-click="handleClick"
  162. >
  163. <el-tab-pane
  164. v-for="(item, index) in processList"
  165. :key="item.id"
  166. :label="item.name"
  167. :name="item.id"
  168. >
  169. <ele-pro-table
  170. ref="tableRef"
  171. v-loading="tabLoading"
  172. :columns="columns"
  173. :datasource="item.list"
  174. :pageSize="20"
  175. :selection.sync="item.selection"
  176. cache-key="systemRoleTable"
  177. class="table"
  178. >
  179. <template v-slot:toolbar>
  180. <div style="display: inline-block" v-if="!item.isSpecialField">
  181. <el-button
  182. :loading="toolbarLoading"
  183. type="primary"
  184. @click="dispatch(item, 1)"
  185. >
  186. 派单
  187. </el-button>
  188. <el-button
  189. :loading="toolbarLoading"
  190. type="primary"
  191. @click="dispatch(item, 2)"
  192. >
  193. 撤回
  194. </el-button>
  195. <el-button
  196. :loading="toolbarLoading"
  197. type="primary"
  198. @click="dispatch(item, 3)"
  199. >
  200. 保存
  201. </el-button>
  202. </div>
  203. <div
  204. style="margin-left: 50px; display: inline-block"
  205. v-if="!item.isSpecialField"
  206. >
  207. <span
  208. class="text"
  209. style="
  210. font-weight: bold;
  211. font-size: 14px;
  212. margin-right: 8px;
  213. "
  214. >指派:</span
  215. >
  216. <el-radio-group
  217. v-model="item.assignType"
  218. size="mini"
  219. @change="(e) => changeRadio(e, index)"
  220. >
  221. <el-radio-button
  222. :disabled="radioBun(item, 'stationDis')"
  223. :label="1"
  224. >工位
  225. </el-radio-button>
  226. <el-radio-button
  227. :disabled="radioBun(item, 'staffDis')"
  228. :label="2"
  229. >人员
  230. </el-radio-button>
  231. <el-radio-button
  232. :disabled="radioBun(item, 'lineDis')"
  233. :label="3"
  234. >产线
  235. </el-radio-button>
  236. </el-radio-group>
  237. </div>
  238. <div
  239. v-if="item.isSpecialField"
  240. class="describe"
  241. style="color: #67c23a"
  242. >
  243. 该工序已完成派单!
  244. </div>
  245. </template>
  246. <template v-slot:quantity="{ row }">
  247. <el-input
  248. v-model="row.quantity"
  249. :disabled="permissions(row, item)"
  250. placeholder="请输入数量"
  251. type="number"
  252. @input="(e) => handleQuantityInput(e, row, item)"
  253. ></el-input>
  254. </template>
  255. <template v-slot:weight="{ row }">
  256. <el-input
  257. v-model="row.weight"
  258. :disabled="permissions(row, item)"
  259. placeholder="请输入重量"
  260. type="number"
  261. @input="(e) => handleWeightInput(e, row, item)"
  262. ></el-input>
  263. </template>
  264. <template v-slot:teamTimeDetailId="{ row }">
  265. <el-select
  266. v-model="row.teamTimeDetailId"
  267. placeholder="班次"
  268. :disabled="permissions(row, item)"
  269. @change="(e) => shiftSelection(e, row)"
  270. >
  271. <el-option
  272. v-for="item in shiftList"
  273. :key="item.id"
  274. :label="item.name"
  275. :value="item.id"
  276. >
  277. </el-option>
  278. </el-select>
  279. </template>
  280. <template v-slot:startTime="{ row }">
  281. <el-date-picker
  282. v-model="row.startTime"
  283. :disabled="permissions(row, item)"
  284. :picker-options="{
  285. disabledDate: (time) => {
  286. return (
  287. row.endTime && time.getTime() > new Date(row.endTime)
  288. );
  289. }
  290. }"
  291. class="w100"
  292. placeholder="开始时间"
  293. type="datetime"
  294. value-format="yyyy-MM-dd HH:mm:ss"
  295. ></el-date-picker>
  296. </template>
  297. <template v-slot:endTime="{ row }">
  298. <el-date-picker
  299. v-model="row.endTime"
  300. :disabled="permissions(row, item)"
  301. :picker-options="{
  302. disabledDate: (time) => {
  303. return (
  304. row.startTime &&
  305. time.getTime() < new Date(row.startTime)
  306. );
  307. }
  308. }"
  309. class="w100"
  310. placeholder="完成时间"
  311. type="datetime"
  312. value-format="yyyy-MM-dd HH:mm:ss"
  313. ></el-date-picker>
  314. </template>
  315. <template v-slot:action="{ row }">
  316. <!-- :disabled="resetBtnDis(row)" -->
  317. <el-popconfirm
  318. v-if="resetBtnDis(row)"
  319. title="确定要重置该条数据吗?"
  320. @confirm="resetData(row, item)"
  321. >
  322. <template v-slot:reference>
  323. <el-link :underline="false" type="primary"> 重置</el-link>
  324. </template>
  325. </el-popconfirm>
  326. </template>
  327. </ele-pro-table>
  328. </el-tab-pane>
  329. </el-tabs>
  330. </el-form>
  331. </div>
  332. <!-- <div slot="footer">-->
  333. <!-- <el-button plain @click="cancel">取消</el-button>-->
  334. <!-- <el-button :loading="toolbarLoading" type="primary" @click="confirm"-->
  335. <!-- >确定-->
  336. <!-- </el-button-->
  337. <!-- >-->
  338. <!-- </div>-->
  339. </ele-modal>
  340. </template>
  341. <script>
  342. import {
  343. lineByCurrentUser,
  344. listAssign,
  345. listByFirstTaskId,
  346. listByMesWorkOrder,
  347. listByRoutingIds,
  348. listUserByIds,
  349. listWorkCenter,
  350. resetAssignee,
  351. taskAssignment,
  352. taskRevoked,
  353. taskSave,
  354. listByFactoryId
  355. } from '@/api/mainData/index.js';
  356. export default {
  357. components: {},
  358. props: {
  359. current: {
  360. type: Object,
  361. default: () => {}
  362. },
  363. dispatchVisible: {
  364. type: Boolean,
  365. default: false
  366. }
  367. },
  368. data() {
  369. return {
  370. processId: '',
  371. tabLoading: false,
  372. dynamicName: '工位名称',
  373. form: {
  374. assignType: 1,
  375. crewIds: '',
  376. workstationIds: '',
  377. teamId: '',
  378. singleReport: '',
  379. workCenterId: '',
  380. taskAss: 1,
  381. factoryName: ''
  382. },
  383. toolbarLoading: false,
  384. processList: [],
  385. workCenterList: [],
  386. teamList: [],
  387. tabsLoading: false,
  388. stationList: [], // 工位的数据
  389. productionList: [], // 产线的数据
  390. crewList: [], // 人员的数据
  391. // procTaskDis: false, // 工序任务派单选择
  392. // firstTaskindex: '', // 首工序id 对应的工序列表数据下标
  393. fieldList: [
  394. { label: '生产订单号:', prop: 'code' },
  395. { label: '计划编号:', prop: 'productionPlanCode' },
  396. { label: '工艺路线:', prop: 'produceRoutingName' },
  397. // { label: '编码', prop: 'productCode' },
  398. { label: '名称:', prop: 'productName' },
  399. { label: '生产编号:', prop: 'productionCodes' },
  400. { label: '牌号:', prop: 'brandNo' },
  401. { label: '批次号:', prop: 'batchNo' },
  402. { label: '型号:', prop: 'model' },
  403. { label: '要求生产数量:', prop: 'formingNum' },
  404. { label: '要求生产重量:', prop: 'initialWeight' },
  405. { label: '计划开始时间:', prop: 'planStartTime' },
  406. { label: '计划结束时间:', prop: 'planCompleteTime' }
  407. ],
  408. shiftList: [],
  409. dateValue: ''
  410. };
  411. },
  412. computed: {
  413. clientEnvironmentId() {
  414. return this.$store.state.user.info.clientEnvironmentId;
  415. },
  416. userInfo() {
  417. return this.$store.state.user.info;
  418. },
  419. modelWidth() {
  420. // if(this.form.taskAss == 1){
  421. // return '1000px'
  422. // }
  423. return '75vw';
  424. },
  425. // 重置按钮 的置灰权限 没有进行操作跟派单的数据 置灰
  426. resetBtnDis() {
  427. return (row) => {
  428. if (!row.status) return false;
  429. let flag = row.status.code != 1;
  430. return flag;
  431. };
  432. },
  433. // 指派单选框操作 已派单的 其它两个按钮不能操作
  434. radioBun() {
  435. return (row, type) => {
  436. if (!row.radioBun) return false;
  437. let flag = row.radioBun[type];
  438. return flag;
  439. };
  440. },
  441. // 列表输入框操作 已派单的不能操作
  442. permissions() {
  443. return (row, item) => {
  444. if (item.isSpecialField) return true;
  445. if (!row.status) return false;
  446. if (row.status.code == 1) return true;
  447. };
  448. },
  449. columns() {
  450. return [
  451. {
  452. columnKey: 'index',
  453. label: '序号',
  454. type: 'index',
  455. width: 55,
  456. align: 'center',
  457. showOverflowTooltip: true,
  458. fixed: 'left'
  459. },
  460. {
  461. width: 45,
  462. type: 'selection',
  463. columnKey: 'selection',
  464. align: 'center',
  465. fixed: 'left'
  466. },
  467. {
  468. prop: 'name',
  469. label: this.dynamicName,
  470. align: 'center',
  471. showOverflowTooltip: true,
  472. width: 200
  473. },
  474. {
  475. prop: 'code',
  476. label: '编码',
  477. align: 'center',
  478. showOverflowTooltip: true,
  479. width: 200
  480. },
  481. {
  482. prop: 'status',
  483. label: '状态',
  484. align: 'center',
  485. showOverflowTooltip: true,
  486. width: 150,
  487. formatter: (row) => {
  488. if (!row.status) return '';
  489. return row.status.desc || '';
  490. }
  491. },
  492. {
  493. slot: 'quantity',
  494. prop: 'quantity',
  495. label: '数量',
  496. align: 'center',
  497. width: 140
  498. },
  499. {
  500. slot: 'weight',
  501. prop: 'weight',
  502. label: `重量(${this.current.weightUnit})`,
  503. align: 'center',
  504. width: 140
  505. },
  506. {
  507. slot: 'teamTimeDetailId',
  508. prop: 'teamTimeDetailId',
  509. label: '班次',
  510. align: 'center',
  511. minWidth: 140
  512. },
  513. {
  514. slot: 'startTime',
  515. prop: 'startTime',
  516. label: '计划开始时间',
  517. align: 'center',
  518. minWidth: 240
  519. },
  520. {
  521. slot: 'endTime',
  522. prop: 'endTime',
  523. label: '计划完成时间',
  524. align: 'center',
  525. minWidth: 240
  526. },
  527. {
  528. columnKey: 'action',
  529. label: '操作',
  530. width: 120,
  531. align: 'center',
  532. resizable: false,
  533. fixed: 'right',
  534. slot: 'action'
  535. }
  536. ];
  537. }
  538. },
  539. watch: {},
  540. created() {
  541. this.workCenterData();
  542. this.getClassesData();
  543. this.form.singleReport = this.clientEnvironmentId == 2 ? 0 : 1;
  544. this.dateValue = this.getFormattedDate();
  545. },
  546. methods: {
  547. // 查询班次
  548. getClassesData() {
  549. if (!this.current.factoriesId) return;
  550. listByFactoryId(this.current.factoriesId).then((res) => {
  551. if (!res) return;
  552. this.shiftList = res;
  553. });
  554. },
  555. // 选中班次
  556. shiftSelection(e, row) {
  557. let data = this.shiftList.find((item) => item.id == e);
  558. let startTime = `${this.dateValue} ${data.startTime}`;
  559. let endTime = `${this.dateValue} ${data.endTime}`;
  560. this.$set(row, 'startTime', startTime);
  561. this.$set(row, 'endTime', endTime);
  562. },
  563. // 获取当前年月日
  564. getFormattedDate() {
  565. const now = new Date();
  566. const year = now.getFullYear();
  567. const month = String(now.getMonth() + 1).padStart(2, '0');
  568. const date = String(now.getDate()).padStart(2, '0');
  569. return `${year}-${month}-${date}`;
  570. },
  571. // 查询工作中心
  572. async workCenterData() {
  573. const res = await listWorkCenter(this.current.taskInstanceId);
  574. this.workCenterList = res;
  575. if (res.length > 0) {
  576. this.form.factoryName = res[0].factoryName;
  577. this.form.workCenterId = res[0].id;
  578. // 查首工序
  579. this.changeWork(res[0].id); // 选择工作中心
  580. this.getProductionData(res[0].id); // 查询产线
  581. this.FirstTaskIdFn(); // 查询工位数据
  582. }
  583. },
  584. // 查询工序列表数据
  585. async changeDispatch(e) {
  586. this.tabsLoading = true;
  587. try {
  588. // /aps/assign/listByMesWorkOrder
  589. let allRes = await listByRoutingIds([this.current.produceRoutingId]); // 查询全部工序数据
  590. let params = {
  591. apsWorkOrderId: this.current.apsWorkOrderId,
  592. categoryId: this.current.categoryId,
  593. mesWorkOrderId: this.current.id,
  594. produceRoutingId: this.current.produceRoutingId
  595. };
  596. let existRes = await listByMesWorkOrder(params); // 存在的工序数据
  597. let res = [];
  598. if (!existRes || existRes.length === 0) {
  599. res = allRes;
  600. } else {
  601. // 先将 存在的工序数据 数组的 id 存入 Set
  602. const existIds = new Map(
  603. existRes.map((item) => [item.taskId, true])
  604. );
  605. // 过滤 全部工序数据 数组
  606. // res = allRes.map((aItem) => !existIds.has(aItem.sourceTaskId));
  607. res = allRes.map((aItem) => {
  608. return {
  609. ...aItem,
  610. isSpecialField: existIds.has(aItem.sourceTaskId)
  611. };
  612. });
  613. }
  614. // 如果没有首工序的数据 就不能选择工序任务派单
  615. if (!res || res.length === 0) {
  616. this.processList = [];
  617. // this.form.taskAss = 1;
  618. // this.procTaskDis = true;
  619. this.$message.warning('当前工单没有工序数据');
  620. return;
  621. }
  622. // this.procTaskDis = false;
  623. let list = [];
  624. res.forEach((item, index) => {
  625. let obj = {
  626. id: item.sourceTaskId, //工序 id
  627. name: item.name, //工序 名称
  628. assignType: 1, // 默认的指派数据
  629. assignName: '工位', // 默认指派数据名称
  630. list: [], // 当前工序下面的指派 绑定的表格
  631. selection: [], // 当前工序下面的指派 选中的数据
  632. code: item.code, // 工序 编码
  633. index: index, // 当前工序数据的下标
  634. isSpecialField: item.isSpecialField,
  635. radioBun: {
  636. // 指派按钮的操作状态 绑定 默认false(可操作)
  637. stationDis: false,
  638. staffDis: false,
  639. lineDis: false
  640. }
  641. };
  642. list.push(obj);
  643. });
  644. this.processList = list;
  645. this.handleClick({ name: res[0].sourceTaskId });
  646. } catch (err) {
  647. this.processList = [];
  648. this.$message.error(err.message);
  649. } finally {
  650. this.tabsLoading = false;
  651. }
  652. },
  653. // 选择工作中心
  654. changeWork(e) {
  655. this.form.workCenterId = e;
  656. // this.changeDispatch(); // 查询工序列表
  657. let data = this.workCenterList.find((item) => item.id == e);
  658. this.form.workCenterName = data.name;
  659. this.teamList = data.teamList || [];
  660. if (this.teamList.length > 0) {
  661. this.form.teamId = this.teamList[0].id;
  662. this.changeGroups(this.teamList[0].id);
  663. }
  664. },
  665. // 选择班组 查询人员的数据
  666. async changeGroups(e) {
  667. let data = this.teamList.find((item) => item.id == e);
  668. this.form.teamName = data.name;
  669. try {
  670. const res = await listUserByIds([e]);
  671. this.crewList = res || [];
  672. // 查看当前的工序数据是不是 选择的人员 是的话同步更改
  673. // if (this.form.taskAss == 1) {
  674. // return;
  675. // }
  676. if (!this.processId || this.processId == 0) {
  677. return;
  678. }
  679. let data = this.processList.find(
  680. (item) => item.id === this.processId
  681. );
  682. if (data.assignType == 2) {
  683. this.handleClick({ name: this.processId });
  684. // this.$set(data, 'list', res);
  685. }
  686. } catch {
  687. this.crewList = [];
  688. }
  689. },
  690. // 获取产线数据
  691. async getProductionData() {
  692. const res = await lineByCurrentUser(this.form.workCenterId);
  693. this.productionList = res || [];
  694. },
  695. // 查询工位数据
  696. FirstTaskIdFn() {
  697. listByFirstTaskId(this.current.taskInstanceId)
  698. .then((res) => {
  699. this.stationList = res;
  700. this.changeDispatch();
  701. })
  702. .catch((err) => {
  703. this.stationList = [];
  704. this.$message.error(err.message);
  705. });
  706. },
  707. // 重置(单个)
  708. resetData(row, item) {
  709. if (!row.changeId) {
  710. return this.$message.warning('只能对已撤回跟已保存的数据进行重置');
  711. }
  712. this.toolbarLoading = true;
  713. resetAssignee(row.changeId)
  714. .then((res) => {
  715. this.toolbarLoading = false;
  716. if (res) {
  717. this.$message.success('操作成功');
  718. // 更改当前表格数据
  719. this.setCurrentTab(item);
  720. }
  721. })
  722. .catch((err) => {
  723. this.toolbarLoading = false;
  724. this.$message.warning(err.message);
  725. });
  726. },
  727. // 撤回的逻辑
  728. getWithdrawT(row, type) {
  729. if (type != 2) {
  730. return true;
  731. }
  732. let isFlag = true;
  733. row.selection.forEach((item) => {
  734. if (!item.status) {
  735. isFlag = false;
  736. return;
  737. }
  738. if (!item.status.code) {
  739. isFlag = false;
  740. }
  741. });
  742. return isFlag;
  743. },
  744. // 派单
  745. dispatch(row, type) {
  746. if (row.selection.length == 0) {
  747. return this.$message.warning('请最少选择一条数据');
  748. }
  749. let isWithdraw = this.getWithdrawT(row, type);
  750. if (!isWithdraw) {
  751. this.$message.warning('只有状态为派单的数据才能进行撤回');
  752. return;
  753. }
  754. let assignees = [];
  755. let changeIds = [];
  756. let flag = true; // 是否填写 校验
  757. let digit = true; // 数字校验
  758. row.selection.forEach((item) => {
  759. if (!item.quantity || !item.startTime || !item.endTime) {
  760. flag = false;
  761. return;
  762. }
  763. if (item.quantity == 0) {
  764. this.$message.warning('请检查所选数据的数量不能为0');
  765. digit = false;
  766. return;
  767. }
  768. if (item.weight == 0) {
  769. this.$message.warning('请检查所选数据的重量不能为0');
  770. digit = false;
  771. return;
  772. }
  773. let Aobj = {
  774. assigneeId: item.id,
  775. quantity: item.quantity,
  776. weight: item.weight,
  777. startTime: item.startTime,
  778. endTime: item.endTime,
  779. assigneeType: row.assignType,
  780. assigneeName: item.name
  781. };
  782. if (item.teamTimeDetailId) {
  783. Aobj.teamTimeDetailId = item.teamTimeDetailId;
  784. }
  785. assignees.push(Aobj);
  786. changeIds.push(item.changeId);
  787. });
  788. // 校验没过 就不往下进行
  789. if (!digit) {
  790. return;
  791. }
  792. if (!flag) {
  793. this.$message.warning(
  794. '请将所选数据的 数量 ,开始时间,完成时间 填写完毕'
  795. );
  796. return;
  797. }
  798. let data = null;
  799. this.toolbarLoading = true;
  800. if (type == 2) {
  801. data = changeIds;
  802. } else {
  803. data = {
  804. taskId: this.processId,
  805. taskName: row.name,
  806. taskCode: row.code,
  807. teamName: this.form.teamName,
  808. teamId: this.form.teamId,
  809. workCenterId: this.form.workCenterId,
  810. workCenterName: this.form.workCenterName,
  811. workOrderId: this.current.apsWorkOrderId,
  812. sourceType: 2,
  813. assignees
  814. };
  815. }
  816. const api =
  817. type == 1 ? taskAssignment : type == 2 ? taskRevoked : taskSave;
  818. api(data)
  819. .then((res) => {
  820. this.toolbarLoading = false;
  821. if (res) {
  822. this.$message.success('操作成功');
  823. // 更改当前表格数据
  824. this.setCurrentTab(row);
  825. }
  826. })
  827. .catch((err) => {
  828. this.toolbarLoading = false;
  829. this.$message.warning(err.message);
  830. });
  831. },
  832. cancel() {
  833. this.$emit('update:dispatchVisible', false);
  834. },
  835. // 按钮操作成功后 更改当前的表格数据
  836. setCurrentTab(row) {
  837. let arr = [];
  838. if (row.assignType == 1) {
  839. arr = this.stationList;
  840. } else if (row.assignType == 2) {
  841. arr = this.crewList;
  842. } else {
  843. arr = this.productionList;
  844. }
  845. this.getAssignData(row.index, arr);
  846. },
  847. // 工序选择
  848. handleClick(tab) {
  849. let id = tab.name;
  850. this.processId = id;
  851. let data = this.processList.find((item) => item.id == this.processId);
  852. // if (data.list.length == 0) {
  853. this.changeRadio(data.assignType, data.index);
  854. // }
  855. },
  856. // 指派选择
  857. changeRadio(e, index) {
  858. let data = this.processList[index];
  859. if (e == 1) {
  860. this.dynamicName = '工位名称';
  861. data.assignName = '工位';
  862. this.getAssignData(index, this.stationList);
  863. } else if (e == 2) {
  864. this.dynamicName = '人员名称';
  865. data.assignName = '人员';
  866. this.getAssignData(index, this.crewList);
  867. } else {
  868. this.dynamicName = '产线名称';
  869. data.assignName = '产线';
  870. this.getAssignData(index, this.productionList);
  871. }
  872. },
  873. // 指派数据处理
  874. async getAssignData(index, arr) {
  875. let list = JSON.parse(JSON.stringify(arr));
  876. let dataRow = this.processList[index];
  877. let params = {
  878. workOrderId: this.current.apsWorkOrderId,
  879. workCenterId: this.form.workCenterId,
  880. teamId: this.form.teamId,
  881. taskId: this.processId
  882. };
  883. this.tabLoading = true;
  884. try {
  885. const res = await listAssign(params);
  886. this.tabLoading = false;
  887. // 如果 res 没有数据 说明未对数据进行操作 直接赋值
  888. if (res.length == 0) {
  889. this.$set(dataRow, 'list', list);
  890. return;
  891. }
  892. // 对有操作过的数据进行赋值
  893. this.operationalData(index, res, list);
  894. } catch (err) {
  895. this.tabLoading = false;
  896. this.$message.warning(err.message);
  897. }
  898. },
  899. // 操作过的数据 赋值
  900. operationalData(index, res, list) {
  901. const dataRow = this.processList[index];
  902. // 键值对存储 当前工序 操作的数据 指派的code(键) 数据(list:值)
  903. let arrMap = {};
  904. // 要先判断有没有操作的数据 如果有的话 其它的指派操作置灰
  905. let codeT = null; // 表示有已操作的数据(对应的 code)
  906. res[0].assignees.map((el) => {
  907. let code = el.assigneeType.code;
  908. if (arrMap[code]) {
  909. arrMap[code].arr.push(el);
  910. arrMap[code].bunDis = arrMap[code].bunDis
  911. ? arrMap[code].bunDis
  912. : el.status.desc
  913. ? true
  914. : false;
  915. } else {
  916. arrMap[code] = {
  917. arr: [el],
  918. bunDis: el.status.desc ? true : false
  919. };
  920. }
  921. codeT = codeT ? codeT : el.status.desc ? code : '';
  922. });
  923. let radioBun = {
  924. lineDis: false, // 产线 3
  925. staffDis: false, // 人员 2
  926. stationDis: false // 工位 1
  927. };
  928. // 默认是传递下来的 list 数据 但是如果 codeT有值 说明 工位 人员 产线 有派单数据
  929. // 需要自动切换过去
  930. let listArr = list;
  931. if (codeT) {
  932. if (codeT == 1) {
  933. radioBun.staffDis = true;
  934. radioBun.lineDis = true;
  935. radioBun.stationDis = false;
  936. listArr = JSON.parse(JSON.stringify(this.stationList));
  937. dataRow.assignType = 1;
  938. dataRow.assignName = '工位';
  939. } else if (codeT == 2) {
  940. radioBun.stationDis = true;
  941. radioBun.lineDis = true;
  942. radioBun.staffDis = false;
  943. listArr = JSON.parse(JSON.stringify(this.crewList));
  944. dataRow.assignType = 2;
  945. dataRow.assignName = '人员';
  946. } else {
  947. radioBun.stationDis = true;
  948. radioBun.staffDis = true;
  949. radioBun.lineDis = false;
  950. listArr = JSON.parse(JSON.stringify(this.productionList));
  951. dataRow.assignType = 3;
  952. dataRow.assignName = '产线';
  953. }
  954. }
  955. // 切换完后 对 指派的数组数据进行赋值
  956. let listMap = {};
  957. listArr.map((el, index) => (listMap[el.id] = index));
  958. let arrList = codeT ? arrMap[codeT].arr : res[0].assignees;
  959. arrList.map((item) => {
  960. if (item.assigneeType.code == dataRow.assignType) {
  961. let idx = listMap[item.assigneeId];
  962. listArr[idx].status = item.status;
  963. listArr[idx].startTime = item.startTime;
  964. listArr[idx].endTime = item.endTime;
  965. listArr[idx].quantity = item.quantity;
  966. listArr[idx].weight = item.weight;
  967. listArr[idx].changeId = item.id;
  968. listArr[idx].teamTimeDetailId = item.teamTimeDetailId;
  969. }
  970. });
  971. this.$set(dataRow, 'list', listArr);
  972. this.$set(dataRow, 'radioBun', radioBun);
  973. },
  974. assignRadio(e) {},
  975. // 数量正则 quantity
  976. handleQuantityInput(e, row, item) {
  977. // 过滤非数字字符(包括负号)
  978. let value = e.replace(/[^\d]/g, '');
  979. // 限制不能以 0 开头(除非是 0 本身)
  980. if (value.startsWith('0') && value.length > 1) {
  981. value = value.slice(1);
  982. }
  983. // 更新绑定值
  984. row.quantity = value;
  985. this.calculateQuantity(row, item);
  986. this.bringWeight(row.quantity, row);
  987. },
  988. // 自动算重量
  989. bringWeight(value, row) {
  990. if (!this.current.formingWeight) {
  991. this.$set(row, 'weight', 0);
  992. return;
  993. }
  994. let weight =
  995. (this.current.formingWeight / this.current.formingNum) * value;
  996. if (weight > 0) {
  997. weight = weight.toFixed(4) - 0;
  998. }
  999. this.$set(row, 'weight', weight);
  1000. },
  1001. calculateQuantity(row, item) {
  1002. // 如果没有该字段 就不做判断
  1003. if (!this.current.formingNum) {
  1004. return;
  1005. }
  1006. let total = 0;
  1007. item.list.forEach((el) => {
  1008. if (el.quantity) {
  1009. total = total + (el.quantity - 0);
  1010. }
  1011. });
  1012. if (total > this.current.formingNum - 0) {
  1013. this.$message.warning('列表数量相加不能大于目标要求生产数量');
  1014. row.quantity = 0;
  1015. }
  1016. },
  1017. // 计算重量
  1018. calculateWeight(row, item) {
  1019. // 如果没有该字段 就不做判断
  1020. if (!this.current.formingWeight) {
  1021. return;
  1022. }
  1023. let total = 0;
  1024. item.list.forEach((el) => {
  1025. if (el.weight) {
  1026. total = total + (el.weight - 0);
  1027. }
  1028. });
  1029. if (total > this.current.formingWeight - 0) {
  1030. this.$message.warning('列表数量相加不能大于目标要求生产数量');
  1031. row.weight = 0;
  1032. }
  1033. },
  1034. // 重量正则 weight
  1035. handleWeightInput(e, row, item) {
  1036. // 过滤非数字和非小数点字符(包括负号)
  1037. let value = e.replace(/[^\d.]/g, '');
  1038. // 限制只能有一个小数点
  1039. const dotCount = (value.match(/\./g) || []).length;
  1040. if (dotCount > 1) {
  1041. value = value.slice(0, value.lastIndexOf('.'));
  1042. }
  1043. // 限制不能以小数点开头
  1044. if (value.startsWith('.')) {
  1045. value = '0' + value;
  1046. }
  1047. // 更新绑定值
  1048. row.weight = value;
  1049. this.calculateWeight(row, item);
  1050. }
  1051. }
  1052. };
  1053. </script>
  1054. <style lang="scss" scoped>
  1055. .top-box {
  1056. display: flex;
  1057. margin-bottom: 10px;
  1058. .item-box {
  1059. flex: 1;
  1060. }
  1061. }
  1062. .radio-box {
  1063. margin: 10px 0;
  1064. }
  1065. .table {
  1066. margin-top: 20px;
  1067. }
  1068. ::v-deep .el-radio-button__orig-radio:checked + .el-radio-button__inner {
  1069. background-color: #10d070;
  1070. border-color: #10d070;
  1071. }
  1072. ::v-deep .el-radio-button__orig-radio:checked + .el-radio-button__inner {
  1073. box-shadow: none;
  1074. }
  1075. // ::v-deep .ele-block{
  1076. // width: 240px;
  1077. // }
  1078. // ::v-deep .basic {
  1079. // .el-form-item {
  1080. // width: 100%;
  1081. // }
  1082. // .form80 {
  1083. // .el-form-item__content {
  1084. // width: calc(100% - 80px);
  1085. // }
  1086. // }
  1087. // .form65 {
  1088. // .el-form-item__content {
  1089. // width: calc(100% - 65px);
  1090. // }
  1091. // }
  1092. // .el-form-item__label {
  1093. // padding: 0 4px 0 0;
  1094. // }
  1095. // .item_label {
  1096. // white-space: nowrap;
  1097. // overflow: hidden;
  1098. // text-overflow: ellipsis;
  1099. // width: 100%;
  1100. // }
  1101. // }
  1102. </style>