planDotLine.vue 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. <template>
  2. <ele-modal
  3. v-if="visible"
  4. custom-class="ele-dialog-form long-dialog-form plan-dot-line-dialog"
  5. :centered="true"
  6. :append-to-body="true"
  7. :visible.sync="dialogVisible"
  8. :close-on-click-modal="false"
  9. width="70%"
  10. :maxable="true"
  11. :resizable="true"
  12. :fullscreen.sync="modalFullscreen"
  13. :title="title"
  14. @close="onModalClose"
  15. @opened="onModalOpened"
  16. >
  17. <div class="plan-dot-line">
  18. <div v-if="currentPlan" class="plan-time-bar">
  19. <span class="plan-time-item">
  20. <span class="plan-time-label">计划开始时间:</span>
  21. <span class="plan-time-value">{{ planStartDisplay }}</span>
  22. </span>
  23. <span class="plan-time-item">
  24. <span class="plan-time-label">计划结束时间:</span>
  25. <span class="plan-time-value">{{ planEndDisplay }}</span>
  26. </span>
  27. <span class="plan-time-item">
  28. <span class="plan-time-label">计划数量:</span>
  29. <span class="plan-time-value">{{ planNumDisplay }}</span>
  30. </span>
  31. </div>
  32. <div class="top-route">
  33. <div class="panel-title">工艺路线</div>
  34. <el-empty
  35. v-if="taskList.length === 0"
  36. description="暂无工艺路线"
  37. ></el-empty>
  38. <el-steps
  39. v-else
  40. :active="routeStepsActive"
  41. space="20px"
  42. align-center
  43. finish-status="success"
  44. class="route-steps"
  45. >
  46. <el-step
  47. v-for="(item, index) in taskList"
  48. :key="`route-step-${item._taskKey}`"
  49. :title="routeStepTitle(item, index)"
  50. :class="{ active: routeDesIndex === index }"
  51. v-bind="routeErrorIndex === index ? { status: 'error' } : {}"
  52. ></el-step>
  53. </el-steps>
  54. </div>
  55. <div class="config-panel">
  56. <div class="panel-title">工艺配置</div>
  57. <el-empty
  58. v-if="taskList.length === 0"
  59. description="暂无工艺"
  60. ></el-empty>
  61. <div v-else class="task-config-table-wrap">
  62. <el-table
  63. :key="modalFullscreen ? 'fs' : 'nm'"
  64. ref="configTable"
  65. :height="modalFullscreen ? tableMaxHeight : undefined"
  66. :max-height="modalFullscreen ? undefined : tableMaxHeight"
  67. :data="taskList"
  68. border
  69. size="small"
  70. row-key="_taskKey"
  71. class="config-table"
  72. >
  73. <el-table-column
  74. type="index"
  75. label="序号"
  76. width="60"
  77. align="center"
  78. class-name="config-table-index-col"
  79. />
  80. <el-table-column
  81. label="工序名称"
  82. min-width="100"
  83. show-overflow-tooltip
  84. class-name="task-name-cell"
  85. align="center"
  86. >
  87. <template slot-scope="{ row, $index }">
  88. <span class="task-name-text">{{
  89. row.taskName || row.name || `工艺${$index + 1}`
  90. }}</span>
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="工序并行" min-width="92" align="center">
  94. <template slot-scope="{ row }">
  95. <el-select
  96. v-model="row.isParallelism"
  97. placeholder="工序并行"
  98. class="config-table-control"
  99. @change="handleParallelismChange(row)"
  100. >
  101. <el-option label="否" :value="0" />
  102. <el-option label="是" :value="1" />
  103. </el-select>
  104. </template>
  105. </el-table-column>
  106. <el-table-column label="执行模式" min-width="100" align="center">
  107. <template slot-scope="{ row }">
  108. <el-select
  109. v-model="row.executionType"
  110. placeholder="执行模式"
  111. clearable
  112. class="config-table-control"
  113. @change="onExecutionTypeChange(row)"
  114. >
  115. <el-option
  116. v-for="opt in executionTypeOptions"
  117. :key="opt.value"
  118. :label="opt.label"
  119. :value="opt.value"
  120. />
  121. </el-select>
  122. </template>
  123. </el-table-column>
  124. <el-table-column label="执行对象" min-width="130" align="center">
  125. <template slot-scope="{ row }">
  126. <el-select
  127. v-if="execTypeNum(row) === EXEC_TYPE.HOMEMADE"
  128. v-model="row.executionTeamId"
  129. placeholder="请选择"
  130. clearable
  131. filterable
  132. class="config-table-control"
  133. @change="onExecutionObjectChange(row)"
  134. >
  135. <el-option
  136. v-for="team in teamOptions"
  137. :key="team.id"
  138. :label="team.name"
  139. :value="team.id"
  140. />
  141. </el-select>
  142. <el-select
  143. v-else-if="execTypeNum(row) === EXEC_TYPE.ENTRUST"
  144. v-model="row.executionFactoryId"
  145. placeholder="请选择"
  146. clearable
  147. filterable
  148. class="config-table-control"
  149. @change="onExecutionObjectChange(row)"
  150. >
  151. <el-option
  152. v-for="f in factoryList"
  153. :key="f.value"
  154. :label="f.label"
  155. :value="f.value"
  156. />
  157. </el-select>
  158. <el-select
  159. v-else-if="execTypeNum(row) === EXEC_TYPE.OUTSOURCE"
  160. :value="''"
  161. placeholder="委外无需选择"
  162. disabled
  163. class="config-table-control"
  164. />
  165. <el-select
  166. v-else
  167. :value="''"
  168. placeholder="请先选择执行模式"
  169. disabled
  170. class="config-table-control"
  171. />
  172. </template>
  173. </el-table-column>
  174. <el-table-column
  175. label="执行开始时间"
  176. min-width="168"
  177. align="center"
  178. >
  179. <template slot-scope="{ row }">
  180. <el-date-picker
  181. v-model="row.executionStartTime"
  182. type="datetime"
  183. value-format="yyyy-MM-dd HH:mm:ss"
  184. placeholder="执行开始时间"
  185. clearable
  186. class="config-table-control"
  187. @change="handleTimeChange(row, 'executionStartTime')"
  188. />
  189. </template>
  190. </el-table-column>
  191. <el-table-column
  192. label="执行结束时间"
  193. min-width="168"
  194. align="center"
  195. >
  196. <template slot-scope="{ row }">
  197. <div
  198. :class="{
  199. 'last-end-over-plan-wrap': isExecutionEndOverPlanEnd(row),
  200. 'end-over-delivery-wrap': isExecutionEndOverDelivery(row)
  201. }"
  202. >
  203. <el-date-picker
  204. v-model="row.executionEndTime"
  205. type="datetime"
  206. value-format="yyyy-MM-dd HH:mm:ss"
  207. placeholder="执行结束时间"
  208. clearable
  209. class="config-table-control"
  210. @change="handleTimeChange(row, 'executionEndTime')"
  211. />
  212. </div>
  213. </template>
  214. </el-table-column>
  215. </el-table>
  216. </div>
  217. </div>
  218. </div>
  219. <div slot="footer">
  220. <el-button size="mini" @click="onModalClose">取消</el-button>
  221. <el-button size="mini" type="warning" @click="handleClearAll"
  222. >一键清空</el-button
  223. >
  224. <el-button size="mini" type="success" @click="handleCache"
  225. >缓存</el-button
  226. >
  227. <el-button size="mini" type="primary" @click="handleSave">保存</el-button>
  228. </div>
  229. </ele-modal>
  230. </template>
  231. <script>
  232. import {
  233. getPlanDotLine,
  234. savePlanDotLine
  235. } from '@/api/productionPlan/planDotLine';
  236. import { getTaskListById } from '@/api/materialPlan';
  237. import { teamPage } from '@/api/mainData';
  238. import { getFactoryarea } from '@/api/saleOrder';
  239. const EXEC_TYPE = Object.freeze({ HOMEMADE: 0, ENTRUST: 1, OUTSOURCE: 2 });
  240. const EXEC_TYPE_OPTIONS = Object.freeze([
  241. { label: '自制', value: EXEC_TYPE.HOMEMADE },
  242. { label: '请托', value: EXEC_TYPE.ENTRUST },
  243. { label: '委外', value: EXEC_TYPE.OUTSOURCE }
  244. ]);
  245. function toSafeNumber(val) {
  246. if (val === '' || val == null) return undefined;
  247. const n = Number(val);
  248. return Number.isNaN(n) ? undefined : n;
  249. }
  250. function formatDateTime(val) {
  251. if (val == null || val === '') return '';
  252. const str = String(val).trim();
  253. if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(str)) return str;
  254. const d = new Date(val);
  255. if (Number.isNaN(d.getTime())) return '';
  256. const p = (n) => String(n).padStart(2, '0');
  257. return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(
  258. d.getHours()
  259. )}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
  260. }
  261. /** 比较两个时间字符串,结束 < 开始 则返回 true */
  262. function isEndBeforeStart(startStr, endStr) {
  263. if (!startStr || !endStr) return false;
  264. const s = new Date(startStr).getTime();
  265. const e = new Date(endStr).getTime();
  266. return !Number.isNaN(s) && !Number.isNaN(e) && e < s;
  267. }
  268. /** 工序结束时间是否晚于计划结束时间(用于最后一道工序标红与提醒) */
  269. function isEndAfterPlanEnd(executionEndStr, planEndStr) {
  270. if (!executionEndStr || !planEndStr) return false;
  271. const e = new Date(executionEndStr).getTime();
  272. const p = new Date(planEndStr).getTime();
  273. return !Number.isNaN(e) && !Number.isNaN(p) && e > p;
  274. }
  275. /** 计划交付时间是日期字段,比较时应以该日期当天结束为上限 */
  276. function isTimeAfterDeliveryDate(timeStr, deliveryDateStr) {
  277. if (!timeStr || !deliveryDateStr) return false;
  278. const time = new Date(timeStr).getTime();
  279. const deliveryDate = new Date(deliveryDateStr);
  280. if (Number.isNaN(time) || Number.isNaN(deliveryDate.getTime()))
  281. return false;
  282. deliveryDate.setHours(23, 59, 59, 999);
  283. return time > deliveryDate.getTime();
  284. }
  285. export default {
  286. data() {
  287. return {
  288. visible: false,
  289. dialogVisible: false,
  290. title: '计划布点',
  291. taskList: [],
  292. teamOptions: [],
  293. currentPlan: null,
  294. planRoutingPayload: null,
  295. executionTypeOptions: EXEC_TYPE_OPTIONS,
  296. /** 与 ele-modal 全屏按钮同步,用于表格高度适配 */
  297. modalFullscreen: false,
  298. /** 普通弹窗下动态限制表格最大高度,避免写死 420 */
  299. tableMaxHeight: 420,
  300. /** 工艺路线步骤 error 状态(-1 表示无) */
  301. routeErrorIndex: -1,
  302. factoryList: [],
  303. /** 模板中比对执行模式用 */
  304. EXEC_TYPE
  305. };
  306. },
  307. computed: {
  308. /** 当前激活步骤:首个未配置执行模式的工序;全部已配置则为步骤总数(全部 finish) */
  309. routeStepsActive() {
  310. const list = this.taskList;
  311. if (!list.length) return 0;
  312. for (let i = 0; i < list.length; i++) {
  313. if (!this.isRouteItemDone(list[i])) return i;
  314. }
  315. return list.length;
  316. },
  317. /** 用于 :class="active" 高亮,与 active 同步(全部完成时高亮最后一环) */
  318. routeDesIndex() {
  319. const list = this.taskList;
  320. if (!list.length) return -1;
  321. const a = this.routeStepsActive;
  322. return a >= list.length ? list.length - 1 : a;
  323. },
  324. /** 顶部展示:与列表行字段 startTime / endTime 一致(见 productionPlan/index.vue 列配置) */
  325. planStartDisplay() {
  326. const t = this.currentPlan?.startTime;
  327. return t ? formatDateTime(t) || String(t) : '—';
  328. },
  329. planEndDisplay() {
  330. const t = this.currentPlan?.endTime;
  331. return t ? formatDateTime(t) || String(t) : '—';
  332. },
  333. planNumDisplay() {
  334. const t =
  335. this.currentPlan?.productNum + this.currentPlan?.measuringUnit;
  336. return t ? t : '—';
  337. },
  338. /** 最后一道工序执行结束时间是否晚于计划结束时间 */
  339. lastProcessEndAfterPlanEnd() {
  340. const list = this.taskList;
  341. const planEnd = this.currentPlan?.endTime;
  342. if (!list.length || !planEnd) return false;
  343. const last = list[list.length - 1];
  344. if (!last?.executionEndTime) return false;
  345. return isEndAfterPlanEnd(last.executionEndTime, planEnd);
  346. }
  347. },
  348. watch: {
  349. modalFullscreen() {
  350. // 先算好高度,key 变化会重建 el-table,重建后再 doLayout
  351. this.calcTableHeight();
  352. this.$nextTick(() => {
  353. this.$refs.configTable?.doLayout?.();
  354. // 全屏动画结束后再修正一次
  355. setTimeout(() => {
  356. this.calcTableHeight();
  357. this.$nextTick(() => {
  358. this.$refs.configTable?.doLayout?.();
  359. });
  360. }, 400);
  361. });
  362. }
  363. },
  364. beforeDestroy() {
  365. window.removeEventListener('resize', this.calcTableHeight);
  366. },
  367. methods: {
  368. onModalOpened() {
  369. window.addEventListener('resize', this.calcTableHeight);
  370. this.$nextTick(() => {
  371. this.calcTableHeight();
  372. });
  373. },
  374. calcTableHeight() {
  375. if (this.modalFullscreen) {
  376. const tableEl = this.$refs.configTable?.$el;
  377. const footerEl = tableEl
  378. ?.closest('.el-dialog')
  379. ?.querySelector('.el-dialog__footer');
  380. const footerH = footerEl ? footerEl.offsetHeight : 52;
  381. const wrapEl = tableEl?.closest('.task-config-table-wrap');
  382. if (wrapEl) {
  383. const top = wrapEl.getBoundingClientRect().top;
  384. const vh = window.innerHeight;
  385. this.tableMaxHeight = Math.max(
  386. 200,
  387. Math.floor(vh - top - footerH - 16)
  388. );
  389. } else {
  390. const vh = window.innerHeight || 800;
  391. this.tableMaxHeight = Math.max(200, vh - 260);
  392. }
  393. } else {
  394. const vh = window.innerHeight || 800;
  395. this.tableMaxHeight = Math.max(320, Math.floor(vh * 0.52));
  396. }
  397. this.$nextTick(() => {
  398. this.$refs.configTable?.doLayout?.();
  399. });
  400. },
  401. async open(data) {
  402. this.currentPlan = data || null;
  403. this.planRoutingPayload = null;
  404. await this.loadTaskList()
  405. await Promise.all([
  406. this.loadTeamOptions(),
  407. this.loadFactoryList(),
  408. ]);
  409. this.visible = true;
  410. this.dialogVisible = true;
  411. },
  412. async loadFactoryList() {
  413. const par = { type: 1, size: 9999 };
  414. try {
  415. const res = await getFactoryarea(par);
  416. if (res.list?.length) {
  417. this.factoryList = res.list.map((el) => ({
  418. value: el.id,
  419. label: el.name
  420. }));
  421. } else {
  422. this.factoryList = [];
  423. }
  424. } catch {
  425. this.factoryList = [];
  426. }
  427. },
  428. async loadTaskList() {
  429. this.taskList = [];
  430. this.planRoutingPayload = null;
  431. if (!this.currentPlan?.id) return;
  432. let planData;
  433. try {
  434. planData = await getPlanDotLine({ planId: this.currentPlan.id });
  435. } catch (e) {
  436. this.$message.error(e.message || '获取工序布点信息失败');
  437. return;
  438. }
  439. this.planRoutingPayload = planData || {};
  440. const details = planData?.detailList;
  441. if (details?.length) {
  442. this.taskList = [...details]
  443. .sort((a, b) => (a.taskSort ?? 0) - (b.taskSort ?? 0))
  444. .map((item, i) => this.normalizeDetailRow(item, i));
  445. return;
  446. }
  447. if (!this.currentPlan.produceRoutingId) {
  448. this.$message.warning('暂无布点明细且缺少工艺路线,无法加载工序');
  449. return;
  450. }
  451. try {
  452. const list = await getTaskListById(this.currentPlan.produceRoutingId);
  453. this.taskList = (list || []).map((item, i) =>
  454. this.normalizeRoutingTaskRow(item, i)
  455. );
  456. } catch (e) {
  457. this.$message.error(e.message || '获取工序列表失败');
  458. }
  459. },
  460. normalizeDetailRow(item, index) {
  461. const execType = toSafeNumber(item.executionType) ?? EXEC_TYPE.HOMEMADE;
  462. const outsource = execType === EXEC_TYPE.OUTSOURCE;
  463. const entrust = execType === EXEC_TYPE.ENTRUST;
  464. const homemade = execType === EXEC_TYPE.HOMEMADE;
  465. return {
  466. ...item,
  467. _taskKey: item.id ?? `detail-${item.taskId ?? index}`,
  468. isParallelism: toSafeNumber(item.isParallelism) === 1 ? 1 : 0,
  469. executionStartTime: formatDateTime(item.executionStartTime),
  470. executionEndTime: formatDateTime(item.executionEndTime),
  471. executionType: execType,
  472. executionFactoryId: entrust
  473. ? item.executionFactoryId ?? item.executionTeamId ?? ''
  474. : '',
  475. executionFactoryName: entrust
  476. ? item.executionFactoryName ?? item.executionTeamName ?? ''
  477. : '',
  478. executionTeamId: homemade ? item.executionTeamId ?? '' : '',
  479. executionTeamLeader:
  480. outsource || entrust ? '' : item.executionTeamLeader ?? '',
  481. executionTeamLeaderId:
  482. outsource || entrust ? '' : item.executionTeamLeaderId ?? '',
  483. executionTeamName:
  484. outsource || entrust ? '' : item.executionTeamName ?? ''
  485. };
  486. },
  487. normalizeRoutingTaskRow(item, index) {
  488. const plan = this.currentPlan;
  489. const taskId = item.id;
  490. return {
  491. ...item,
  492. _taskKey: item.id ?? `new-${taskId ?? index}-${index}`,
  493. taskId: taskId ?? undefined,
  494. taskName: item.name ?? item.taskName,
  495. taskCode: item.code ?? item.taskCode,
  496. taskSort: item.taskSort ?? index + 1,
  497. type: item.type ?? undefined,
  498. sourceTaskId: item.sourceTaskId,
  499. planId: plan.id,
  500. planCode: plan.code,
  501. routingId: plan.produceRoutingId,
  502. routingName: plan.produceRoutingName ?? plan.routingName,
  503. isParallelism: item.isParallel ?? 0,
  504. executionType: EXEC_TYPE.HOMEMADE,
  505. executionTeamId: '',
  506. executionTeamLeader: '',
  507. executionTeamLeaderId: '',
  508. executionTeamName: '',
  509. executionStartTime: '',
  510. executionEndTime: '',
  511. executionFactoryId: '',
  512. executionFactoryName: ''
  513. };
  514. },
  515. execTypeNum(row) {
  516. return toSafeNumber(row.executionType);
  517. },
  518. clearExecutionTeamFields(row) {
  519. this.$set(row, 'executionTeamId', '');
  520. this.$set(row, 'executionTeamName', '');
  521. this.$set(row, 'executionTeamLeader', '');
  522. this.$set(row, 'executionTeamLeaderId', '');
  523. this.$set(row, 'executionFactoryId', '');
  524. this.$set(row, 'executionFactoryName', '');
  525. },
  526. onExecutionTypeChange(row) {
  527. this.clearExecutionTeamFields(row);
  528. },
  529. onExecutionObjectChange(row) {
  530. const t = this.execTypeNum(row);
  531. if (t === EXEC_TYPE.HOMEMADE) {
  532. const team = this.teamOptions.find(
  533. (x) => x.id === row.executionTeamId
  534. );
  535. row.executionTeamName = team?.name ?? '';
  536. row.executionTeamLeader = team?.leaderUserName ?? '';
  537. row.executionTeamLeaderId = team?.leaderUserId ?? '';
  538. row.executionFactoryId = '';
  539. row.executionFactoryName = '';
  540. } else if (t === EXEC_TYPE.ENTRUST) {
  541. const f = this.factoryList.find(
  542. (x) => x.value === row.executionFactoryId
  543. );
  544. row.executionFactoryName = f?.label ?? '';
  545. row.executionTeamId = '';
  546. row.executionTeamName = '';
  547. row.executionTeamLeader = '';
  548. row.executionTeamLeaderId = '';
  549. }
  550. },
  551. handleClearAll() {
  552. this.taskList.forEach((row) => {
  553. this.$set(row, 'executionType', EXEC_TYPE.HOMEMADE);
  554. this.$set(row, 'isParallelism', 0);
  555. this.clearExecutionTeamFields(row);
  556. this.$set(row, 'executionStartTime', '');
  557. this.$set(row, 'executionEndTime', '');
  558. });
  559. this.$message.success('已清空');
  560. },
  561. async loadTeamOptions() {
  562. try {
  563. const factoryId = this.$store.state.user.info.factoryId;
  564. const detailIds = this.planRoutingPayload?.detailList?.[0]?.workCenterIds?.join(',');
  565. const taskIds = this.taskList[0]?.workCenterIds?.join(',');
  566. const workCenterIds = detailIds || taskIds;
  567. const res = await teamPage({ pageNum: 1, size: -1, factoryId, workCenterIds });
  568. this.teamOptions = (res?.list || []).map(
  569. ({ id, name, leaderUserName, leaderUserId }) => ({
  570. id,
  571. name,
  572. leaderUserName,
  573. leaderUserId
  574. })
  575. );
  576. } catch {
  577. this.teamOptions = [];
  578. }
  579. },
  580. isRouteItemDone(row) {
  581. return row.executionType != null && row.executionType !== '';
  582. },
  583. routeStepTitle(item, index) {
  584. return (
  585. item.taskTypeName || item.taskName || item.name || `工艺${index + 1}`
  586. );
  587. },
  588. getTaskLabel(item, index) {
  589. return (
  590. item?.taskTypeName ||
  591. item?.taskName ||
  592. item?.name ||
  593. (typeof index === 'number' ? `工艺${index + 1}` : '当前工艺')
  594. );
  595. },
  596. compareTaskTime(start, end) {
  597. if (!start || !end) return false;
  598. const startTime = new Date(start).getTime();
  599. const endTime = new Date(end).getTime();
  600. return (
  601. !Number.isNaN(startTime) &&
  602. !Number.isNaN(endTime) &&
  603. startTime < endTime
  604. );
  605. },
  606. isTaskParallel(row) {
  607. return toSafeNumber(row?.isParallelism) === 1;
  608. },
  609. getCurrentPlanStartTime() {
  610. return (
  611. this.currentPlan?.startTime ||
  612. this.currentPlan?.planStartTime ||
  613. this.currentPlan?.executionStartTime ||
  614. ''
  615. );
  616. },
  617. isExecutionStartBeforePlanStart(executionStartTime) {
  618. if (!executionStartTime) {
  619. return false;
  620. }
  621. const planStartTime = this.getCurrentPlanStartTime();
  622. if (!planStartTime) {
  623. return false;
  624. }
  625. const executionStart = new Date(executionStartTime).getTime();
  626. const planStart = new Date(planStartTime).getTime();
  627. return (
  628. !Number.isNaN(executionStart) &&
  629. !Number.isNaN(planStart) &&
  630. executionStart < planStart
  631. );
  632. },
  633. validateTaskSequence(row, options = {}) {
  634. const index = this.taskList.findIndex((item) => item === row);
  635. if (index < 0) {
  636. return true;
  637. }
  638. const prev = this.taskList[index - 1];
  639. const next = this.taskList[index + 1];
  640. const resetKey = options.resetKey;
  641. const checkPrev =
  642. (!resetKey || resetKey === 'executionStartTime') &&
  643. !this.isTaskParallel(row);
  644. const checkNext =
  645. (!resetKey || resetKey === 'executionEndTime') &&
  646. !this.isTaskParallel(next);
  647. if (
  648. checkPrev &&
  649. prev?.executionEndTime &&
  650. row.executionStartTime &&
  651. this.compareTaskTime(row.executionStartTime, prev.executionEndTime)
  652. ) {
  653. this.routeErrorIndex = index;
  654. this.$message.warning(
  655. `${this.getTaskLabel(
  656. row,
  657. index
  658. )}执行开始时间不能小于上一道工序${this.getTaskLabel(
  659. prev,
  660. index - 1
  661. )}的执行结束时间`
  662. );
  663. if (resetKey) {
  664. this.$set(row, resetKey, '');
  665. }
  666. return false;
  667. }
  668. if (
  669. checkNext &&
  670. next?.executionStartTime &&
  671. row.executionEndTime &&
  672. this.compareTaskTime(next.executionStartTime, row.executionEndTime)
  673. ) {
  674. this.routeErrorIndex = index + 1;
  675. this.$message.warning(
  676. `下一道工序${this.getTaskLabel(
  677. next,
  678. index + 1
  679. )}的执行开始时间不能小于上一道工序${this.getTaskLabel(
  680. row,
  681. index
  682. )}的执行结束时间`
  683. );
  684. if (resetKey) {
  685. this.$set(row, resetKey, '');
  686. }
  687. return false;
  688. }
  689. return true;
  690. },
  691. handleTimeChange(row, changeKey) {
  692. if (isEndBeforeStart(row.executionStartTime, row.executionEndTime)) {
  693. this.$message.warning('执行结束时间不能小于执行开始时间');
  694. this.$set(row, changeKey, '');
  695. return;
  696. }
  697. if (
  698. changeKey === 'executionStartTime' &&
  699. this.isTaskParallel(row) &&
  700. this.isExecutionStartBeforePlanStart(row.executionStartTime)
  701. ) {
  702. this.$message.warning('执行开始时间不能小于计划开始时间');
  703. this.$set(row, changeKey, '');
  704. return;
  705. }
  706. if (!this.validateTaskSequence(row, { resetKey: changeKey })) {
  707. return;
  708. }
  709. this.routeErrorIndex = -1;
  710. const deadline = this.currentPlan?.planDeliveryTime;
  711. if (
  712. changeKey === 'executionStartTime' &&
  713. deadline &&
  714. row.executionStartTime
  715. ) {
  716. if (isTimeAfterDeliveryDate(row.executionStartTime, deadline)) {
  717. this.$message.warning('时间不能大于计划交付时间');
  718. this.$set(row, changeKey, '');
  719. return;
  720. }
  721. }
  722. if (changeKey === 'executionEndTime' && row.executionEndTime) {
  723. const planEnd = this.currentPlan?.endTime;
  724. const overDelivery =
  725. !!deadline &&
  726. isTimeAfterDeliveryDate(row.executionEndTime, deadline);
  727. const overPlanEnd =
  728. !!planEnd && isEndAfterPlanEnd(row.executionEndTime, planEnd);
  729. if (overDelivery && overPlanEnd) {
  730. this.$message.warning(
  731. '执行结束时间晚于计划交付时间及计划结束时间,已保留填写内容,请留意核对'
  732. );
  733. } else if (overDelivery) {
  734. this.$message.warning(
  735. '执行结束时间晚于计划交付时间,已保留填写内容,请留意核对'
  736. );
  737. } else if (overPlanEnd) {
  738. this.$message.warning(
  739. '执行结束时间晚于计划结束时间,已保留填写内容,请留意核对'
  740. );
  741. }
  742. }
  743. },
  744. handleParallelismChange(row) {
  745. if (!row?.executionStartTime) {
  746. return;
  747. }
  748. if (this.isTaskParallel(row)) {
  749. if (this.isExecutionStartBeforePlanStart(row.executionStartTime)) {
  750. this.$message.warning('执行开始时间不能小于计划开始时间');
  751. this.$set(row, 'executionStartTime', '');
  752. }
  753. return;
  754. }
  755. this.validateTaskSequence(row, { resetKey: 'executionStartTime' });
  756. },
  757. /** 执行结束时间晚于计划交付时间(选择框标红,可保存) */
  758. isExecutionEndOverDelivery(row) {
  759. const deadline = this.currentPlan?.planDeliveryTime;
  760. return (
  761. !!deadline &&
  762. !!row?.executionEndTime &&
  763. isTimeAfterDeliveryDate(row.executionEndTime, deadline)
  764. );
  765. },
  766. /** 仅最后一道工序执行结束时间晚于计划结束时间时标红(工序数量不固定) */
  767. isExecutionEndOverPlanEnd(row) {
  768. const planEnd = this.currentPlan?.endTime;
  769. const lastTask = this.taskList[this.taskList.length - 1];
  770. return (
  771. !!planEnd &&
  772. !!row?.executionEndTime &&
  773. row === lastTask &&
  774. isEndAfterPlanEnd(row.executionEndTime, planEnd)
  775. );
  776. },
  777. validateTaskList() {
  778. this.routeErrorIndex = -1;
  779. const label = (t) => this.getTaskLabel(t);
  780. for (const item of this.taskList) {
  781. const execType = toSafeNumber(item.executionType);
  782. if (execType === undefined) {
  783. this.$message.warning(`${label(item)}请选择执行模式`);
  784. return false;
  785. }
  786. if (execType === EXEC_TYPE.HOMEMADE) {
  787. if (
  788. !item.executionTeamId ||
  789. !item.executionStartTime ||
  790. !item.executionEndTime
  791. ) {
  792. this.$message.warning(
  793. `${label(
  794. item
  795. )}执行模式为自制时,需选择执行班组并填写执行开始和结束时间`
  796. );
  797. return false;
  798. }
  799. }
  800. if (execType === EXEC_TYPE.ENTRUST) {
  801. if (
  802. !item.executionFactoryId ||
  803. !item.executionStartTime ||
  804. !item.executionEndTime
  805. ) {
  806. this.$message.warning(
  807. `${label(
  808. item
  809. )}执行模式为请托时,需选择工厂并填写执行开始和结束时间`
  810. );
  811. return false;
  812. }
  813. }
  814. if (execType === EXEC_TYPE.OUTSOURCE) {
  815. if (!item.executionStartTime || !item.executionEndTime) {
  816. this.$message.warning(
  817. `${label(item)}执行模式为委外时,需填写执行开始和结束时间`
  818. );
  819. return false;
  820. }
  821. }
  822. if (
  823. isEndBeforeStart(item.executionStartTime, item.executionEndTime)
  824. ) {
  825. this.$message.warning(
  826. `${label(item)}执行结束时间不能小于执行开始时间`
  827. );
  828. return false;
  829. }
  830. if (
  831. this.isTaskParallel(item) &&
  832. this.isExecutionStartBeforePlanStart(item.executionStartTime)
  833. ) {
  834. this.$message.warning(
  835. `${label(item)}执行开始时间不能小于计划开始时间`
  836. );
  837. return false;
  838. }
  839. const deadline = this.currentPlan?.planDeliveryTime;
  840. if (deadline) {
  841. const checkStart = (val, name) => {
  842. if (!val) return true;
  843. if (!isTimeAfterDeliveryDate(val, deadline)) return true;
  844. this.$message.warning(
  845. `${label(item)}${name}不能大于计划交付时间`
  846. );
  847. return false;
  848. };
  849. if (!checkStart(item.executionStartTime, '执行开始时间'))
  850. return false;
  851. }
  852. }
  853. for (const item of this.taskList) {
  854. if (!this.validateTaskSequence(item)) {
  855. return false;
  856. }
  857. }
  858. return true;
  859. },
  860. /** @param {0|1} isCache 缓存传 1,保存传 0 */
  861. buildSavePayload(isCache = 0) {
  862. const plan = this.currentPlan;
  863. const head = this.planRoutingPayload || {};
  864. const detailList = this.taskList.map((row) => {
  865. const execType = toSafeNumber(row.executionType) ?? 0;
  866. const detail = {
  867. executionEndTime: row.executionEndTime || undefined,
  868. executionStartTime: row.executionStartTime || undefined,
  869. executionTeamId:
  870. execType === EXEC_TYPE.HOMEMADE
  871. ? row.executionTeamId || undefined
  872. : undefined,
  873. executionTeamLeader: row.executionTeamLeader || '',
  874. executionTeamLeaderId: row.executionTeamLeaderId || '',
  875. executionTeamName: row.executionTeamName || '',
  876. executionType: execType,
  877. isParallelism: this.isTaskParallel(row) ? 1 : 0,
  878. planCode: row.planCode || plan?.code,
  879. planId: row.planId ?? plan?.id,
  880. routingId:
  881. row.routingId ?? plan?.produceRoutingId ?? head.routingId,
  882. routingName:
  883. row.routingName || plan?.produceRoutingName || head.routingName,
  884. sourceTaskId: row.sourceTaskId ?? row.taskId,
  885. taskCode: row.taskCode,
  886. taskId: row.taskId,
  887. taskName: row.taskName,
  888. taskSort: row.taskSort,
  889. type: toSafeNumber(row.type)
  890. };
  891. if (execType === EXEC_TYPE.ENTRUST) {
  892. detail.executionFactoryId = row.executionFactoryId || undefined;
  893. detail.executionFactoryName = row.executionFactoryName || '';
  894. }
  895. if (row.id != null) detail.id = row.id;
  896. return detail;
  897. });
  898. return {
  899. detailList,
  900. fileParam: head.fileParam ?? [],
  901. id: head.id,
  902. isCache,
  903. planCode: plan?.code ?? head.planCode,
  904. planId: plan?.id ?? head.planId,
  905. produceVersionId: head.produceVersionId,
  906. produceVersionName: head.produceVersionName,
  907. releaseTime: head.releaseTime,
  908. routingCode: head.routingCode,
  909. routingId: head.routingId ?? plan?.produceRoutingId,
  910. routingName: head.routingName ?? plan?.produceRoutingName,
  911. routingVersion: head.routingVersion
  912. };
  913. },
  914. async handleCache() {
  915. if (!this.validateTaskList()) return;
  916. const payload = this.buildSavePayload(1);
  917. const loading = this.$loading({ lock: true, text: '缓存中...' });
  918. try {
  919. await savePlanDotLine(payload);
  920. this.$emit('save', {
  921. plan: this.currentPlan,
  922. taskList: this.taskList,
  923. payload
  924. });
  925. this.$message.success('缓存成功');
  926. this.onModalClose();
  927. } catch (e) {
  928. this.$message.error(e.message || '缓存失败');
  929. } finally {
  930. loading.close();
  931. }
  932. },
  933. async handleSave() {
  934. if (!this.validateTaskList()) return;
  935. const payload = this.buildSavePayload(0);
  936. const loading = this.$loading({ lock: true, text: '保存中...' });
  937. try {
  938. await savePlanDotLine(payload);
  939. this.$emit('save', {
  940. plan: this.currentPlan,
  941. taskList: this.taskList,
  942. payload
  943. });
  944. this.$message.success('保存成功');
  945. this.onModalClose();
  946. } catch (e) {
  947. this.$message.error(e.message || '保存失败');
  948. } finally {
  949. loading.close();
  950. }
  951. },
  952. onModalClose() {
  953. window.removeEventListener('resize', this.calcTableHeight);
  954. this.modalFullscreen = false;
  955. this.visible = false;
  956. this.dialogVisible = false;
  957. this.taskList = [];
  958. this.currentPlan = null;
  959. this.planRoutingPayload = null;
  960. this.routeErrorIndex = -1;
  961. this.$emit('success');
  962. }
  963. }
  964. };
  965. </script>
  966. <style lang="scss" scoped>
  967. .plan-dot-line,
  968. .top-route,
  969. .config-panel {
  970. width: 100%;
  971. max-width: 100%;
  972. min-width: 0;
  973. box-sizing: border-box;
  974. }
  975. .plan-dot-line {
  976. min-height: 360px;
  977. }
  978. .plan-time-bar {
  979. display: flex;
  980. flex-wrap: wrap;
  981. align-items: center;
  982. gap: 12px 28px;
  983. margin-bottom: 12px;
  984. padding: 10px 12px;
  985. border: 1px solid #ebeef5;
  986. border-radius: 4px;
  987. background: #fafafa;
  988. font-size: 14px;
  989. }
  990. .plan-time-item {
  991. display: inline-flex;
  992. align-items: baseline;
  993. gap: 4px;
  994. }
  995. .plan-time-label {
  996. color: #606266;
  997. white-space: nowrap;
  998. }
  999. .plan-time-value {
  1000. color: #303133;
  1001. font-weight: 500;
  1002. }
  1003. .last-end-over-plan-wrap,
  1004. .end-over-delivery-wrap {
  1005. width: 100%;
  1006. }
  1007. .last-end-over-plan-wrap ::v-deep .el-input__inner,
  1008. .end-over-delivery-wrap ::v-deep .el-input__inner {
  1009. color: #f56c6c;
  1010. border-color: #f56c6c;
  1011. }
  1012. .last-end-over-plan-wrap ::v-deep .el-input__inner:focus,
  1013. .end-over-delivery-wrap ::v-deep .el-input__inner:focus {
  1014. border-color: #f56c6c;
  1015. }
  1016. .top-route,
  1017. .config-panel {
  1018. border: 1px solid #ebeef5;
  1019. border-radius: 4px;
  1020. padding: 12px;
  1021. background: #fff;
  1022. }
  1023. /* 工艺路线区域随内容增高,不要出现纵向滚动条 */
  1024. .top-route {
  1025. overflow: visible;
  1026. }
  1027. .config-panel {
  1028. margin-top: 12px;
  1029. }
  1030. .panel-title {
  1031. font-size: 14px;
  1032. font-weight: 600;
  1033. margin-bottom: 10px;
  1034. }
  1035. .route-steps {
  1036. width: 100%;
  1037. overflow-x: auto;
  1038. overflow-y: hidden;
  1039. padding-bottom: 8px;
  1040. box-sizing: content-box;
  1041. }
  1042. .route-steps ::v-deep {
  1043. .el-steps {
  1044. display: flex;
  1045. flex-wrap: nowrap;
  1046. align-items: flex-start;
  1047. }
  1048. .el-step {
  1049. flex-shrink: 0;
  1050. }
  1051. .el-step__title {
  1052. font-size: clamp(16px, 2.2vw, 16px);
  1053. line-height: 1.35;
  1054. max-width: 8em;
  1055. margin-left: auto;
  1056. margin-right: auto;
  1057. white-space: normal;
  1058. word-break: break-all;
  1059. }
  1060. .el-step__title:not(.is-error) {
  1061. color: #157a2c;
  1062. }
  1063. .el-step.active .el-step__title:not(.is-error) {
  1064. font-weight: 600;
  1065. }
  1066. .el-step__line {
  1067. top: 14px;
  1068. }
  1069. /* 已完成步骤 success 色(默认绿)改为品牌绿 */
  1070. .el-step__head.is-success {
  1071. color: #157a2c;
  1072. border-color: #157a2c;
  1073. }
  1074. .el-step__head.is-success .el-step__line {
  1075. background-color: #157a2c;
  1076. }
  1077. .el-step__head.is-success .el-step__icon {
  1078. color: #157a2c;
  1079. border-color: #157a2c;
  1080. }
  1081. .el-step__head.is-success .el-step__line-inner {
  1082. background-color: #157a2c;
  1083. border-color: #157a2c;
  1084. }
  1085. /* 当前步骤 process:ele-admin 对 .is-text 使用主题色实心圆,需覆盖 background */
  1086. .el-step__head.is-process {
  1087. color: #157a2c;
  1088. border-color: #157a2c;
  1089. }
  1090. .el-step__head.is-process .el-step__icon {
  1091. color: #157a2c;
  1092. border-color: #157a2c;
  1093. }
  1094. .el-step__head.is-process .el-step__icon.is-text {
  1095. color: #fff;
  1096. border-color: #157a2c;
  1097. background: #157a2c;
  1098. }
  1099. .el-step__head.is-process .el-step__icon.is-text .el-step__icon-inner {
  1100. color: #fff;
  1101. }
  1102. .el-step__description.is-process {
  1103. color: #157a2c;
  1104. }
  1105. .el-step__icon {
  1106. width: 30px;
  1107. height: 30px;
  1108. }
  1109. .el-step__main {
  1110. padding-top: 8px;
  1111. margin-top: 0;
  1112. }
  1113. .el-step__description {
  1114. margin-top: 0;
  1115. padding-right: 0;
  1116. }
  1117. }
  1118. @media (max-width: 576px) {
  1119. .top-route,
  1120. .config-panel {
  1121. padding: 8px;
  1122. }
  1123. }
  1124. .task-config-table-wrap {
  1125. width: 100%;
  1126. }
  1127. .config-table ::v-deep {
  1128. /* 序号列:column 上的 style 无效,需 class-name + td 内 .cell */
  1129. td.config-table-index-col .cell {
  1130. font-size: 14px !important;
  1131. }
  1132. .el-table td > .cell {
  1133. font-size: 14px;
  1134. text-align: center;
  1135. }
  1136. .el-table__body .cell {
  1137. padding-left: 6px;
  1138. padding-right: 6px;
  1139. }
  1140. td.task-name-cell .task-name-text {
  1141. font-size: 14px;
  1142. line-height: 1.4;
  1143. }
  1144. /* 与工序名称一致:覆盖 el-select / date-editor 的 small 字号 */
  1145. .config-table-control .el-input__inner {
  1146. font-size: 14px;
  1147. }
  1148. .config-table-control {
  1149. width: 100% !important;
  1150. }
  1151. .config-table-control.el-date-editor {
  1152. max-width: 100%;
  1153. }
  1154. }
  1155. </style>
  1156. <!-- 弹窗 append-to-body 后表头不在带 scoped 的节点链上,需用弹窗 class 单独写表头 -->
  1157. <style lang="scss">
  1158. .plan-dot-line-dialog {
  1159. .task-config-table-wrap
  1160. .el-table__header-wrapper
  1161. th.el-table__cell
  1162. > .cell {
  1163. font-size: 15px !important;
  1164. line-height: 1.4 !important;
  1165. }
  1166. .top-route {
  1167. overflow: visible !important;
  1168. max-height: none !important;
  1169. }
  1170. .route-steps .el-step__head.is-success {
  1171. color: #157a2c;
  1172. border-color: #157a2c;
  1173. }
  1174. .route-steps .el-step__head.is-success .el-step__line {
  1175. background-color: #157a2c;
  1176. }
  1177. .route-steps .el-step__head.is-success .el-step__icon {
  1178. color: #157a2c;
  1179. border-color: #157a2c;
  1180. }
  1181. .route-steps .el-step__head.is-success .el-step__line-inner {
  1182. background-color: #157a2c;
  1183. border-color: #157a2c;
  1184. }
  1185. .route-steps .el-step__head.is-process {
  1186. color: #157a2c;
  1187. border-color: #157a2c;
  1188. }
  1189. .route-steps .el-step__head.is-process .el-step__icon {
  1190. color: #157a2c;
  1191. border-color: #157a2c;
  1192. }
  1193. .route-steps .el-step__head.is-process .el-step__icon.is-text {
  1194. color: #fff;
  1195. border-color: #157a2c;
  1196. background: #157a2c;
  1197. }
  1198. .route-steps
  1199. .el-step__head.is-process
  1200. .el-step__icon.is-text
  1201. .el-step__icon-inner {
  1202. color: #fff;
  1203. }
  1204. .route-steps .el-step__title:not(.is-error) {
  1205. color: #157a2c;
  1206. }
  1207. .route-steps .el-step__description.is-process {
  1208. color: #157a2c;
  1209. }
  1210. }
  1211. </style>