releaseDialog.vue 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  1. <template>
  2. <ele-modal
  3. :width="modelWidth"
  4. :visible.sync="dispatchVisible"
  5. :close-on-click-modal="false"
  6. custom-class="ele-dialog-form"
  7. :maxable="true"
  8. :title="'派单'"
  9. append-to-body
  10. :before-close="cancel"
  11. >
  12. <div class="form-wrapper">
  13. <el-form
  14. ref="form"
  15. :model="form"
  16. :inline="true"
  17. label-position="right"
  18. label-width="100px"
  19. >
  20. <el-row :gutter="10" class="basic" type="flex" style="flex-wrap: wrap">
  21. <el-col
  22. :xs="12"
  23. :sm="12"
  24. :md="12"
  25. :lg="8"
  26. :xl="6"
  27. v-for="item in fieldList"
  28. :key="item.prop"
  29. >
  30. <el-form-item :label="item.label">
  31. <!-- <div class="item_label">{{ current[item.prop] }}</div> -->
  32. <el-input :value="fieldValue(item.prop)" disabled />
  33. </el-form-item>
  34. </el-col>
  35. </el-row>
  36. <el-row :gutter="10">
  37. <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
  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 :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
  43. <el-form-item label="所属工作中心:">
  44. <el-select
  45. style="width: 100%"
  46. v-model="form.workCenterId"
  47. placeholder="请选择"
  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 :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
  61. <el-form-item label="所属班组:" required>
  62. <el-select
  63. style="width: 100%"
  64. v-model="form.teamId"
  65. placeholder="请选择"
  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. <!-- v-if="clientEnvironmentId != 2" -->
  83. <el-radio :label="1" :disabled="singleDis">单件报工</el-radio>
  84. <el-radio :label="0" :disabled="batchDis">批量报工</el-radio>
  85. </el-radio-group>
  86. </el-form-item>
  87. </el-row>
  88. <el-row>
  89. <el-form-item label="派单方式:" prop="taskAss">
  90. <!-- @change="changeDispatch" -->
  91. <el-radio-group v-model="form.taskAss">
  92. <el-radio :label="1" :disabled="orderDis">生产订单派单</el-radio>
  93. <el-radio :label="0" :disabled="procTaskDis"
  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. <el-radio-button :label="3">产线</el-radio-button>
  110. </el-radio-group>
  111. </el-form-item>
  112. </el-col>
  113. <el-form-item required label="工位:" v-if="form.assignType == 1">
  114. <el-select
  115. class="ele-block"
  116. v-model="form.workstationIds"
  117. placeholder="请选择工位"
  118. size="mini"
  119. multiple
  120. filterable
  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 label="人员:" v-if="form.assignType == 2">
  132. <el-select
  133. class="ele-block"
  134. v-model="form.crewIds"
  135. placeholder="请选择人员"
  136. size="mini"
  137. filterable
  138. multiple
  139. >
  140. <el-option
  141. v-for="item in crewList"
  142. :key="item.id"
  143. :label="item.name"
  144. :value="item.id"
  145. >
  146. </el-option>
  147. </el-select>
  148. </el-form-item>
  149. <el-form-item label="产线:" v-if="form.assignType == 3" required>
  150. <el-select
  151. class="ele-block"
  152. v-model="form.factoryLineIds"
  153. placeholder="请选择产线"
  154. size="mini"
  155. filterable
  156. multiple
  157. >
  158. <el-option
  159. v-for="item in productionList"
  160. :key="item.id"
  161. :label="item.name"
  162. :value="item.id"
  163. >
  164. </el-option>
  165. </el-select>
  166. </el-form-item>
  167. </el-row>
  168. <el-tabs
  169. class="process_list"
  170. v-model="processId"
  171. type="border-card"
  172. @tab-click="handleClick"
  173. v-show="form.taskAss == 0"
  174. v-loading="tabsLoading"
  175. >
  176. <el-tab-pane
  177. v-for="(item, index) in processList"
  178. :key="item.id"
  179. :label="item.name"
  180. :name="item.id"
  181. >
  182. <ele-pro-table
  183. class="table"
  184. ref="tableRef"
  185. :columns="columns"
  186. :datasource="item.list"
  187. cache-key="systemRoleTable"
  188. :pageSize="20"
  189. v-loading="tabLoading"
  190. :selection.sync="item.selection"
  191. >
  192. <template v-slot:toolbar>
  193. <el-button
  194. type="primary"
  195. @click="dispatch(item, 1)"
  196. :loading="toolbarLoading"
  197. >
  198. 派单
  199. </el-button>
  200. <el-button
  201. type="primary"
  202. @click="dispatch(item, 2)"
  203. :loading="toolbarLoading"
  204. >
  205. 撤回
  206. </el-button>
  207. <el-button
  208. type="primary"
  209. @click="dispatch(item, 3)"
  210. :loading="toolbarLoading"
  211. >
  212. 保存
  213. </el-button>
  214. <div style="margin-left: 50px; display: inline-block">
  215. <span
  216. class="text"
  217. style="
  218. font-weight: bold;
  219. font-size: 14px;
  220. margin-right: 8px;
  221. "
  222. >指派:</span
  223. >
  224. <el-radio-group
  225. v-model="item.assignType"
  226. size="mini"
  227. @change="(e) => changeRadio(e, index)"
  228. >
  229. <el-radio-button
  230. :label="1"
  231. :disabled="radioBun(item, 'stationDis')"
  232. >工位</el-radio-button
  233. >
  234. <el-radio-button
  235. :label="2"
  236. :disabled="radioBun(item, 'staffDis')"
  237. >人员</el-radio-button
  238. >
  239. <el-radio-button
  240. :label="3"
  241. :disabled="radioBun(item, 'lineDis')"
  242. >产线</el-radio-button
  243. >
  244. </el-radio-group>
  245. </div>
  246. <div
  247. style="margin-left: 50px; display: inline-block"
  248. v-if="timeSlot(item)"
  249. >
  250. 时间段: {{ item.startDate }} ----- {{ item.endDate }}
  251. </div>
  252. </template>
  253. <template v-slot:quantity="{ row }">
  254. <el-input
  255. :disabled="permissions(row)"
  256. type="number"
  257. v-model="row.quantity"
  258. placeholder="请输入数量"
  259. @input="(e) => handleQuantityInput(e, row, item)"
  260. ></el-input>
  261. </template>
  262. <template v-slot:weight="{ row }">
  263. <el-input
  264. :disabled="permissions(row)"
  265. type="number"
  266. v-model="row.weight"
  267. placeholder="请输入重量"
  268. @input="(e) => handleWeightInput(e, row, item)"
  269. ></el-input>
  270. </template>
  271. <template v-slot:teamTimeDetailId="{ row }">
  272. <el-select
  273. :disabled="permissions(row)"
  274. v-model="row.teamTimeDetailId"
  275. placeholder="班次"
  276. @change="(e) => shiftSelection(e, row, item)"
  277. >
  278. <el-option
  279. v-for="item in shiftList"
  280. :key="item.id"
  281. :label="item.name"
  282. :value="item.id"
  283. >
  284. </el-option>
  285. </el-select>
  286. </template>
  287. <template v-slot:startTime="{ row }">
  288. <el-date-picker
  289. :disabled="permissions(row)"
  290. class="w100"
  291. v-model="row.startTime"
  292. type="datetime"
  293. value-format="yyyy-MM-dd HH:mm:ss"
  294. placeholder="开始时间"
  295. @change="handleStartTimeChange(row, item)"
  296. :picker-options="{
  297. disabledDate: (time) => {
  298. const end = row.endTime;
  299. if (!end) return false; // 无结束时间,不禁用
  300. // 将结束时间和当前时间都转换为“当天0点”,仅比较年月日
  301. const endDay = new Date(end);
  302. endDay.setHours(0, 0, 0, 0);
  303. const currentDay = new Date(time);
  304. currentDay.setHours(0, 0, 0, 0);
  305. return currentDay > endDay; // 仅当天0点更晚时禁用
  306. }
  307. }"
  308. ></el-date-picker>
  309. </template>
  310. <template v-slot:endTime="{ row }">
  311. <el-date-picker
  312. :disabled="permissions(row)"
  313. class="w100"
  314. v-model="row.endTime"
  315. type="datetime"
  316. value-format="yyyy-MM-dd HH:mm:ss"
  317. @change="handleEndTimeChange(row, item)"
  318. placeholder="完成时间"
  319. :picker-options="{
  320. disabledDate: (time) => {
  321. const start = row.startTime;
  322. if (!start) return false; // 无开始时间,不禁用
  323. // 将开始时间和当前时间都转换为“当天0点”,仅比较年月日
  324. const startDay = new Date(start);
  325. startDay.setHours(0, 0, 0, 0);
  326. const currentDay = new Date(time);
  327. currentDay.setHours(0, 0, 0, 0);
  328. return currentDay < startDay; // 仅当天0点更早时禁用
  329. },
  330. // 新增:限制同一天内的时间必须晚于开始时间
  331. disabledTime: (date) => {
  332. const start = row.startTime;
  333. if (!start) {
  334. return {
  335. disabledHours: () => [],
  336. disabledMinutes: () => [],
  337. disabledSeconds: () => []
  338. };
  339. }
  340. const startDate = new Date(start);
  341. const currentDate = new Date(date);
  342. // 判断是否是同一天
  343. if (
  344. currentDate.getFullYear() === startDate.getFullYear() &&
  345. currentDate.getMonth() === startDate.getMonth() &&
  346. currentDate.getDate() === startDate.getDate()
  347. ) {
  348. const startHour = startDate.getHours();
  349. const startMinute = startDate.getMinutes();
  350. const startSecond = startDate.getSeconds();
  351. return {
  352. // 禁用比 startHour 早的小时
  353. disabledHours: () =>
  354. Array.from({ length: startHour }, (_, i) => i),
  355. // 若小时相同,禁用比 startMinute 早的分钟
  356. disabledMinutes: (hour) =>
  357. hour === startHour
  358. ? Array.from({ length: startMinute }, (_, i) => i)
  359. : [],
  360. // 若小时和分钟都相同,禁用比 startSecond 早的秒
  361. disabledSeconds: (hour, minute) =>
  362. hour === startHour && minute === startMinute
  363. ? Array.from({ length: startSecond }, (_, i) => i)
  364. : []
  365. };
  366. } else {
  367. // 不同天,时间无限制
  368. return {
  369. disabledHours: () => [],
  370. disabledMinutes: () => [],
  371. disabledSeconds: () => []
  372. };
  373. }
  374. }
  375. }"
  376. ></el-date-picker>
  377. </template>
  378. <template v-slot:action="{ row }">
  379. <!-- :disabled="resetBtnDis(row)" -->
  380. <el-popconfirm
  381. title="确定要重置该条数据吗?"
  382. @confirm="resetData(row, item)"
  383. v-if="resetBtnDis(row)"
  384. >
  385. <template v-slot:reference>
  386. <el-link type="primary" :underline="false"> 重置 </el-link>
  387. </template>
  388. </el-popconfirm>
  389. </template>
  390. </ele-pro-table>
  391. </el-tab-pane>
  392. </el-tabs>
  393. </el-form>
  394. </div>
  395. <div slot="footer">
  396. <el-button plain @click="cancel">取消</el-button>
  397. <el-button type="primary" @click="confirm" :loading="toolbarLoading"
  398. >确定</el-button
  399. >
  400. </div>
  401. </ele-modal>
  402. </template>
  403. <script>
  404. import {
  405. listByFirstTaskId,
  406. listUserByIds,
  407. listWorkCenter,
  408. listByWorkCenter,
  409. lineByCurrentUser,
  410. taskSave,
  411. taskRevoked,
  412. taskAssignment,
  413. listAssign,
  414. checkAssignConfirm,
  415. resetAssignee,
  416. listByRoutingIds,
  417. listByFactoryId,
  418. checkExists
  419. } from '@/api/mainData/index.js';
  420. import { releaseWorkOrder } from '@/api/workOrder/index.js';
  421. export default {
  422. components: {},
  423. props: {
  424. current: {
  425. type: Object,
  426. default: () => {}
  427. },
  428. dispatchVisible: {
  429. type: Boolean,
  430. default: false
  431. }
  432. },
  433. data() {
  434. return {
  435. processId: '',
  436. tabLoading: false,
  437. dynamicName: '工位名称',
  438. form: {
  439. assignType: 1,
  440. crewIds: '',
  441. workstationIds: '',
  442. teamId: '',
  443. singleReport: '',
  444. workCenterId: '',
  445. taskAss: 1,
  446. factoryName: '',
  447. factoryLineIds: ''
  448. },
  449. toolbarLoading: false,
  450. processList: [],
  451. workCenterList: [],
  452. teamList: [],
  453. tabsLoading: false,
  454. stationList: [], // 工位的数据
  455. productionList: [], // 产线的数据
  456. crewList: [], // 人员的数据
  457. procTaskDis: false, // 工序任务派单选择
  458. firstTaskindex: '', // 首工序id 对应的工序列表数据下标
  459. fieldList: [
  460. { label: '生产订单号:', prop: 'code' },
  461. { label: '计划编号:', prop: 'productionPlanCode' },
  462. { label: '工艺路线:', prop: 'produceRoutingName' },
  463. // { label: '编码', prop: 'productCode' },
  464. { label: '名称:', prop: 'productName' },
  465. { label: '生产编号:', prop: 'productionCodes' },
  466. { label: '牌号:', prop: 'brandNo' },
  467. { label: '批次号:', prop: 'batchNo' },
  468. { label: '型号:', prop: 'model' },
  469. { label: '要求生产数量:', prop: 'formingNum' },
  470. { label: '要求生产重量:', prop: 'initialWeight' },
  471. { label: '计划开始时间:', prop: 'planStartTime' },
  472. { label: '计划结束时间:', prop: 'planCompleteTime' }
  473. ],
  474. shiftList: [],
  475. dateValue: '',
  476. orderDis: false, // 生产订单派单
  477. singleDis: false, // 单个报工
  478. batchDis: false, // 批量报工
  479. isDispatchRow: {}
  480. };
  481. },
  482. computed: {
  483. fieldValue() {
  484. return (field) => {
  485. return this.current[field];
  486. };
  487. },
  488. clientEnvironmentId() {
  489. return this.$store.state.user.info.clientEnvironmentId;
  490. },
  491. userInfo() {
  492. return this.$store.state.user.info;
  493. },
  494. modelWidth() {
  495. // if(this.form.taskAss == 1){
  496. // return '1000px'
  497. // }
  498. return '75vw';
  499. },
  500. // 重置按钮 的置灰权限 没有进行操作跟派单的数据 置灰
  501. resetBtnDis() {
  502. return (row) => {
  503. if (!row.status) return false;
  504. let flag = row.status.code != 1;
  505. return flag;
  506. };
  507. },
  508. // 指派单选框操作 已派单的 其它两个按钮不能操作
  509. radioBun() {
  510. return (row, type) => {
  511. if (!row.radioBun) return false;
  512. let flag = row.radioBun[type];
  513. return flag;
  514. };
  515. },
  516. // 列表输入框操作 已派单的不能操作
  517. permissions() {
  518. return (row) => {
  519. if (!row.status) return false;
  520. if (row.status.code == 1) return true;
  521. };
  522. },
  523. // 时间段显示
  524. timeSlot() {
  525. return (item) => {
  526. if (!item.startDate || !item.endDate) {
  527. return false;
  528. }
  529. return true;
  530. };
  531. },
  532. columns() {
  533. return [
  534. {
  535. columnKey: 'index',
  536. label: '序号',
  537. type: 'index',
  538. width: 55,
  539. align: 'center',
  540. fixed: 'left'
  541. },
  542. {
  543. width: 45,
  544. type: 'selection',
  545. columnKey: 'selection',
  546. align: 'center',
  547. fixed: 'left'
  548. },
  549. {
  550. prop: 'name',
  551. label: this.dynamicName,
  552. align: 'center',
  553. width: 200
  554. },
  555. {
  556. prop: 'code',
  557. label: '编码',
  558. align: 'center',
  559. width: 200
  560. },
  561. {
  562. prop: 'status',
  563. label: '状态',
  564. align: 'center',
  565. width: 150,
  566. formatter: (row) => {
  567. if (!row.status) return '';
  568. return row.status.desc || '';
  569. }
  570. },
  571. {
  572. slot: 'quantity',
  573. prop: 'quantity',
  574. label: '数量',
  575. align: 'center',
  576. width: 140
  577. },
  578. {
  579. slot: 'weight',
  580. prop: 'weight',
  581. label: `重量(${this.current.newWeightUnit})`,
  582. align: 'center',
  583. width: 140
  584. },
  585. {
  586. slot: 'teamTimeDetailId',
  587. prop: 'teamTimeDetailId',
  588. label: '班次',
  589. align: 'center',
  590. minWidth: 150
  591. },
  592. {
  593. slot: 'startTime',
  594. prop: 'startTime',
  595. label: '计划开始时间',
  596. align: 'center',
  597. minWidth: 240
  598. },
  599. {
  600. slot: 'endTime',
  601. prop: 'endTime',
  602. label: '计划完成时间',
  603. align: 'center',
  604. minWidth: 240
  605. },
  606. {
  607. columnKey: 'action',
  608. label: '操作',
  609. width: 120,
  610. align: 'center',
  611. resizable: false,
  612. fixed: 'right',
  613. slot: 'action'
  614. }
  615. ];
  616. }
  617. },
  618. watch: {},
  619. created() {
  620. this.workCenterData(); // 查询工作中心
  621. this.getClassesData(); // 查询班次
  622. this.queryCheckExists(); // 查询是否派单
  623. this.form.singleReport = this.clientEnvironmentId == 2 ? 0 : 1;
  624. this.dateValue = this.getFormattedDate();
  625. },
  626. methods: {
  627. // 查询班次
  628. getClassesData() {
  629. if (!this.current.factoriesId) return;
  630. listByFactoryId(this.current.factoriesId).then((res) => {
  631. if (!res) return;
  632. this.shiftList = res;
  633. });
  634. },
  635. // 查询是否派单
  636. queryCheckExists() {
  637. let params = {
  638. workOrderId: this.current.id,
  639. workCenterId: 123,
  640. teamId: 345
  641. };
  642. checkExists(params)
  643. .then((res) => {
  644. if (!res) return;
  645. this.isDispatchRow = res;
  646. if (res.hasExists) {
  647. this.form.taskAss = 0;
  648. this.orderDis = true;
  649. this.procTaskDis = false;
  650. // 报工类型 判断
  651. this.form.singleReport = res.dispatchType;
  652. if (res.dispatchType == 1) {
  653. this.batchDis = true;
  654. this.singleDis = false;
  655. } else {
  656. this.singleDis = true;
  657. this.batchDis = false;
  658. }
  659. } else {
  660. this.batchDis = false;
  661. this.singleDis = false;
  662. this.orderDis = false;
  663. this.procTaskDis = false;
  664. }
  665. })
  666. .catch((err) => {
  667. this.$message.error(err.message);
  668. });
  669. },
  670. // 获取当前年月日
  671. getFormattedDate() {
  672. const now = new Date();
  673. const year = now.getFullYear();
  674. const month = String(now.getMonth() + 1).padStart(2, '0');
  675. const date = String(now.getDate()).padStart(2, '0');
  676. return `${year}-${month}-${date}`;
  677. },
  678. // 查询工作中心
  679. async workCenterData() {
  680. // const res = await listWorkCenter(this.current.firstTaskId);
  681. const res = await listWorkCenter(this.current.firstTaskId);
  682. this.workCenterList = res;
  683. if (res.length > 0) {
  684. this.form.factoryName = res[0].factoryName;
  685. this.form.workCenterId = res[0].id;
  686. // 查首工序
  687. await this.changeWork(res[0].id); // 选择工作中心
  688. this.getProductionData(res[0].id); // 查询产线
  689. this.FirstTaskIdFn(); // 查询工位数据
  690. } else {
  691. this.$message.warning(
  692. `${this.current.firstTaskName}工序没有工作中心,请到主数据工序管理维护工序信息!`
  693. );
  694. }
  695. },
  696. // 查询工序列表数据
  697. changeDispatch(e) {
  698. this.tabsLoading = true;
  699. // listByWorkCenter(this.form.workCenterId)
  700. listByRoutingIds([this.current.produceRoutingId])
  701. .then((res) => {
  702. this.tabsLoading = false;
  703. // 如果没有首工序的数据 就不能选择工序任务派单
  704. if (!res || res.length == 0) {
  705. this.processList = [];
  706. this.form.taskAss = 1;
  707. this.procTaskDis = true;
  708. return;
  709. }
  710. this.procTaskDis = false;
  711. let list = [];
  712. let isExist = false;
  713. let firstTaskindex = '';
  714. res.forEach((item, index) => {
  715. isExist = isExist
  716. ? isExist
  717. : item.sourceTaskId === this.current.firstTaskId;
  718. // 如果有首工序id 存储它的下标
  719. if (isExist) {
  720. if (!firstTaskindex && firstTaskindex !== 0) {
  721. firstTaskindex = index;
  722. }
  723. }
  724. let obj = {
  725. id: item.sourceTaskId, //工序 id
  726. name: item.name, //工序 名称
  727. assignType: 1, // 默认的指派数据
  728. assignName: '工位', // 默认指派数据名称
  729. list: [], // 当前工序下面的指派 绑定的表格
  730. selection: [], // 当前工序下面的指派 选中的数据
  731. code: item.code, // 工序 编码
  732. index: index, // 当前工序数据的下标
  733. radioBun: {
  734. // 指派按钮的操作状态 绑定 默认false(可操作)
  735. stationDis: false, // 工位按钮
  736. staffDis: false, // 人员按钮
  737. lineDis: false // 产线按钮
  738. },
  739. startDate: '', // 开始日期 (当前工序中最早的计划开始时间)
  740. endDate: '' // 结束日期 (当前工序中最晚的计划结束时间)
  741. };
  742. list.push(obj);
  743. });
  744. this.firstTaskindex = firstTaskindex;
  745. // 存在首工序报工
  746. if (isExist) {
  747. this.processList = list;
  748. this.handleClick({ name: res[0].sourceTaskId });
  749. } else {
  750. this.processList = [];
  751. this.form.taskAss = 1;
  752. this.procTaskDis = true;
  753. this.$message.warning('当前任务没有首工序报工');
  754. }
  755. console.log(this.processList, '工序的数据 1234');
  756. })
  757. .catch((err) => {
  758. this.processList = [];
  759. this.tabsLoading = false;
  760. this.$message.error(err.message);
  761. });
  762. },
  763. // 选择工作中心
  764. async changeWork(e) {
  765. this.form.workCenterId = e;
  766. // this.changeDispatch(); // 查询工序列表
  767. let data = this.workCenterList.find((item) => item.id == e);
  768. this.form.workCenterName = data.name;
  769. this.teamList = data.teamList || []; // 重新获取 班组数据
  770. if (this.teamList.length > 0) {
  771. this.form.teamId = this.teamList[0].id;
  772. await this.changeGroups(this.teamList[0].id); // 获取人员数据方法
  773. } else {
  774. // 如果没有 班组数据 将人员数据清空 并且判断
  775. this.crewList = [];
  776. this.form.teamId = '';
  777. let data = this.processList.find((item) => item.id == this.processId);
  778. if (data.assignType == 2) {
  779. this.$set(data, 'list', []);
  780. }
  781. }
  782. },
  783. // 选择班组 查询人员的数据
  784. async changeGroups(e) {
  785. let data = this.teamList.find((item) => item.id == e);
  786. this.form.teamName = data.name;
  787. try {
  788. const res = await listUserByIds([e]);
  789. this.crewList =
  790. res &&
  791. res.map((el) => {
  792. return {
  793. code: el.code,
  794. name: el.name,
  795. id: el.id
  796. };
  797. });
  798. // 查看当前的工序数据是不是 选择的人员 是的话同步更改
  799. if (!this.processId || this.processId == 0) {
  800. return;
  801. }
  802. let data = this.processList.find((item) => item.id == this.processId);
  803. if (data.assignType == 2) {
  804. this.handleClick({ name: this.processId });
  805. // this.$set(data, 'list', res);
  806. }
  807. } catch {
  808. this.crewList = [];
  809. }
  810. },
  811. // 获取产线数据
  812. async getProductionData() {
  813. const res = await lineByCurrentUser(this.form.workCenterId);
  814. this.productionList =
  815. res &&
  816. res.map((el) => {
  817. return {
  818. name: el.name,
  819. code: el.code,
  820. id: el.id
  821. };
  822. });
  823. },
  824. // 查询工位数据
  825. FirstTaskIdFn() {
  826. // listByFirstTaskId(this.current.firstTaskId)
  827. listByFirstTaskId(this.current.firstTaskId)
  828. .then((res) => {
  829. console.log(res, 'res -----');
  830. this.stationList = res;
  831. // res &&
  832. // res.map((el) => {
  833. // return {
  834. // name: el.name,
  835. // code: el.code,
  836. // id: el.id
  837. // };
  838. // });
  839. this.changeDispatch();
  840. })
  841. .catch((err) => {
  842. this.stationList = [];
  843. this.$message.error(err.message);
  844. });
  845. },
  846. // 重置(单个)
  847. resetData(row, item) {
  848. if (!row.changeId) {
  849. return this.$message.warning('只能对已撤回跟已保存的数据进行重置');
  850. }
  851. this.toolbarLoading = true;
  852. resetAssignee(row.changeId)
  853. .then((res) => {
  854. this.toolbarLoading = false;
  855. if (res) {
  856. this.$message.success('操作成功');
  857. // 更改当前表格数据
  858. this.setCurrentTab(item);
  859. }
  860. })
  861. .catch((err) => {
  862. this.toolbarLoading = false;
  863. this.$message.error(err.message);
  864. });
  865. },
  866. // 撤回的逻辑
  867. getWithdrawT(row, type) {
  868. if (type != 2) {
  869. return true;
  870. }
  871. let isFlag = true;
  872. row.selection.forEach((item) => {
  873. if (!item.status) {
  874. isFlag = false;
  875. return;
  876. }
  877. if (!item.status.code) {
  878. isFlag = false;
  879. return;
  880. }
  881. });
  882. return isFlag;
  883. },
  884. // 派单
  885. dispatch(row, type) {
  886. if (row.selection.length == 0) {
  887. return this.$message.warning('请最少选择一条数据');
  888. }
  889. let isWithdraw = this.getWithdrawT(row, type);
  890. if (!isWithdraw) {
  891. this.$message.warning('只有状态为派单的数据才能进行撤回');
  892. return;
  893. }
  894. let assignees = [];
  895. let changeIds = [];
  896. let flag = true; // 是否填写 校验
  897. row.selection.forEach((item) => {
  898. if (!item.quantity || !item.startTime || !item.endTime) {
  899. flag = false;
  900. return;
  901. }
  902. let Aobj = {
  903. assigneeId: item.id,
  904. quantity: item.quantity,
  905. weight: item.weight,
  906. startTime: item.startTime,
  907. endTime: item.endTime,
  908. assigneeType: row.assignType,
  909. assigneeName: item.name
  910. };
  911. if (item.teamTimeDetailId) {
  912. Aobj.teamTimeDetailId = item.teamTimeDetailId;
  913. }
  914. assignees.push(Aobj);
  915. changeIds.push(item.changeId);
  916. });
  917. // 校验没过 就不往下进行
  918. if (!flag) {
  919. this.$message.warning(
  920. '请将所选数据的 数量,开始时间,完成时间 填写完毕'
  921. );
  922. return;
  923. }
  924. let data = null;
  925. this.toolbarLoading = true;
  926. if (type == 2) {
  927. data = changeIds;
  928. } else {
  929. data = {
  930. taskId: this.processId,
  931. taskName: row.name,
  932. taskCode: row.code,
  933. teamName: this.form.teamName,
  934. teamId: this.form.teamId,
  935. workCenterId: this.form.workCenterId,
  936. workCenterName: this.form.workCenterName,
  937. workOrderId: this.current.id,
  938. dispatchMethod: 0,
  939. assignees
  940. };
  941. // 先判断是否派单过 有的话直接用前面派单的 类型数据 否则就是自己选择的数据
  942. if (this.isDispatchRow.hasExists) {
  943. data.dispatchType = this.isDispatchRow.dispatchType;
  944. } else {
  945. data.dispatchType = this.form.singleReport;
  946. }
  947. }
  948. const api =
  949. type == 1 ? taskAssignment : type == 2 ? taskRevoked : taskSave;
  950. api(data)
  951. .then((res) => {
  952. this.toolbarLoading = false;
  953. if (res) {
  954. this.$message.success('操作成功');
  955. // 更改当前表格数据
  956. this.setCurrentTab(row);
  957. // 查询是否派单
  958. this.queryCheckExists();
  959. }
  960. })
  961. .catch((err) => {
  962. this.toolbarLoading = false;
  963. this.$message.error(err.message);
  964. });
  965. },
  966. cancel() {
  967. this.$emit('update:dispatchVisible', false);
  968. },
  969. // 按钮操作成功后 更改当前的表格数据
  970. setCurrentTab(row) {
  971. let arr = [];
  972. if (row.assignType == 1) {
  973. arr = this.stationList;
  974. } else if (row.assignType == 2) {
  975. arr = this.crewList;
  976. } else {
  977. arr = this.productionList;
  978. }
  979. this.getAssignData(row.index, arr);
  980. },
  981. // 最后提交
  982. async confirm() {
  983. if (this.form.singleReport != 1 && this.form.singleReport != 0) {
  984. this.$message.warning('请先选择报工类型');
  985. return;
  986. }
  987. // if (!this.form.singleReport) {
  988. // }
  989. if (!this.form.teamId) {
  990. this.$message.warning('请先选择班组');
  991. return;
  992. }
  993. if (this.form.taskAss == 1) {
  994. this.issue();
  995. // 按原来的逻辑
  996. return;
  997. }
  998. // 获取到首工序id 的 绑定表格数据
  999. let data = this.processList[this.firstTaskindex];
  1000. // 是否进行首工序派单
  1001. let isFirstDispatch = false;
  1002. let dispatchArr = []; // 已派单数据
  1003. data.list.map((item) => {
  1004. if (!item.status) {
  1005. return;
  1006. }
  1007. if (item.status.code == 1) {
  1008. isFirstDispatch = true;
  1009. dispatchArr.push(item.id);
  1010. }
  1011. });
  1012. // 判断是否进行首工序派单
  1013. if (!isFirstDispatch) {
  1014. this.$message.warning(`请您先进行首工序任务(${data.name}工序)派单`);
  1015. this.handleClick({ name: data.id });
  1016. return;
  1017. }
  1018. let totalSum = 0;
  1019. // 判断派单的数据 数量相加是否为 要求生产数量
  1020. data.list.map((item) => {
  1021. if (item.status && item.status.code == 1) {
  1022. totalSum += item.quantity - 0;
  1023. }
  1024. });
  1025. if (totalSum != this.current.formingNum - 0) {
  1026. this.$message.warning(
  1027. `已派单的数据数量相加需要等于要求生产数量${this.current.formingNum}`
  1028. );
  1029. return;
  1030. }
  1031. let params = {
  1032. teamId: this.form.teamId,
  1033. workCenterId: this.form.workCenterId,
  1034. workOrderId: this.current.id
  1035. };
  1036. this.toolbarLoading = true;
  1037. try {
  1038. const res = await checkAssignConfirm(params);
  1039. if (!res) {
  1040. this.toolbarLoading = false;
  1041. return;
  1042. }
  1043. let paramsD = {
  1044. assignType: data.assignType,
  1045. singleReport: this.form.singleReport,
  1046. teamId: this.form.teamId,
  1047. crewIds: data.assignType == 2 ? dispatchArr : [], // 人员 2
  1048. workstationIds: data.assignType == 1 ? dispatchArr : [], // 工位 1
  1049. id: this.current.id
  1050. };
  1051. const response = await releaseWorkOrder(paramsD);
  1052. this.toolbarLoading = false;
  1053. if (response) {
  1054. this.$message.success('操作成功');
  1055. this.cancel();
  1056. this.$emit('createSuccess');
  1057. }
  1058. } catch (err) {
  1059. this.toolbarLoading = false;
  1060. // this.$message.warning(err.message);
  1061. }
  1062. },
  1063. // 下达
  1064. issue() {
  1065. if (this.form.assignType == 1) {
  1066. if (
  1067. !this.form.workstationIds ||
  1068. this.form.workstationIds.length == 0
  1069. ) {
  1070. this.$message.warning('请选择工位数据');
  1071. return;
  1072. }
  1073. }
  1074. if (this.form.assignType == 3) {
  1075. if (
  1076. !this.form.factoryLineIds ||
  1077. this.form.factoryLineIds.length == 0
  1078. ) {
  1079. this.$message.warning('请选择产线数据');
  1080. return;
  1081. }
  1082. }
  1083. let data = {
  1084. assignType: this.form.assignType,
  1085. singleReport: this.form.singleReport,
  1086. teamId: this.form.teamId,
  1087. crewIds: [],
  1088. workstationIds: [],
  1089. id: this.current.id,
  1090. factoryLineIds: []
  1091. };
  1092. if (this.form.assignType == 1) {
  1093. data.workstationIds = this.form.workstationIds || [];
  1094. } else if (this.form.assignType == 2) {
  1095. data.crewIds = this.form.crewIds || [];
  1096. } else {
  1097. data.factoryLineIds = this.form.factoryLineIds || [];
  1098. }
  1099. this.toolbarLoading = true;
  1100. releaseWorkOrder(data)
  1101. .then((res) => {
  1102. this.toolbarLoading = false;
  1103. if (res) {
  1104. this.$message.success('操作成功');
  1105. this.cancel();
  1106. this.$emit('createSuccess');
  1107. }
  1108. })
  1109. .catch((err) => {
  1110. this.toolbarLoading = false;
  1111. this.$message.error(err.message);
  1112. });
  1113. },
  1114. // 工序选择
  1115. handleClick(tab) {
  1116. let id = tab.name;
  1117. this.processId = id;
  1118. let data = this.processList.find((item) => item.id == this.processId);
  1119. // 传指定的指派类型
  1120. // if (data.list.length == 0) {
  1121. this.changeRadio(data.assignType, data.index);
  1122. // }
  1123. },
  1124. // 指派选择
  1125. changeRadio(e, index) {
  1126. let data = this.processList[index];
  1127. if (e == 1) {
  1128. this.dynamicName = '工位名称';
  1129. data.assignName = '工位';
  1130. this.getAssignData(index, this.stationList);
  1131. } else if (e == 2) {
  1132. this.dynamicName = '人员名称';
  1133. data.assignName = '人员';
  1134. this.getAssignData(index, this.crewList);
  1135. } else {
  1136. this.dynamicName = '产线名称';
  1137. data.assignName = '产线';
  1138. this.getAssignData(index, this.productionList);
  1139. }
  1140. },
  1141. // 指派数据处理
  1142. async getAssignData(index, arr) {
  1143. let list = JSON.parse(JSON.stringify(arr));
  1144. let dataRow = this.processList[index];
  1145. // 不存在 班组数据的话 就不调用这个方法
  1146. if (!this.form.teamId) {
  1147. return;
  1148. }
  1149. let params = {
  1150. workOrderId: this.current.id,
  1151. workCenterId: this.form.workCenterId,
  1152. teamId: this.form.teamId,
  1153. taskId: this.processId
  1154. };
  1155. this.tabLoading = true;
  1156. try {
  1157. const res = await listAssign(params);
  1158. this.tabLoading = false;
  1159. // 如果 res 没有数据 说明未对数据进行操作 直接赋值
  1160. if (res.length == 0) {
  1161. this.$set(dataRow, 'list', list);
  1162. return;
  1163. }
  1164. // 对有操作过的数据进行赋值
  1165. this.operationalData(index, res, list);
  1166. } catch (err) {
  1167. console.log(err, 'errerrerrerrerr');
  1168. this.tabLoading = false;
  1169. this.$message.warning(err.message);
  1170. }
  1171. },
  1172. // 操作过的数据 赋值
  1173. operationalData(index, res, list) {
  1174. const dataRow = this.processList[index];
  1175. // 键值对存储 当前工序 操作的数据 指派的code(键) 数据(list:值)
  1176. let arrMap = {};
  1177. // 要先判断有没有操作的数据 如果有的话 其它的指派操作置灰
  1178. let codeT = null; // 表示有已操作的数据(对应的 code)
  1179. res[0].assignees.map((el) => {
  1180. let code = el.assigneeType.code;
  1181. if (arrMap[code]) {
  1182. arrMap[code].arr.push(el);
  1183. arrMap[code].bunDis = arrMap[code].bunDis
  1184. ? arrMap[code].bunDis
  1185. : el.status.desc
  1186. ? true
  1187. : false;
  1188. } else {
  1189. arrMap[code] = {
  1190. arr: [el],
  1191. bunDis: el.status.desc ? true : false
  1192. };
  1193. }
  1194. codeT = codeT ? codeT : el.status.desc ? code : '';
  1195. });
  1196. let radioBun = {
  1197. lineDis: false, // 产线 3
  1198. staffDis: false, // 人员 2
  1199. stationDis: false // 工位 1
  1200. };
  1201. // 默认是传递下来的 list 数据 但是如果 codeT有值 说明 工位 人员 产线 有派单数据
  1202. // 需要自动切换过去
  1203. let listArr = list;
  1204. if (codeT) {
  1205. if (codeT == 1) {
  1206. radioBun.staffDis = true;
  1207. radioBun.lineDis = true;
  1208. radioBun.stationDis = false;
  1209. listArr = JSON.parse(JSON.stringify(this.stationList));
  1210. dataRow.assignType = 1;
  1211. dataRow.assignName = '工位';
  1212. } else if (codeT == 2) {
  1213. radioBun.stationDis = true;
  1214. radioBun.lineDis = true;
  1215. radioBun.staffDis = false;
  1216. listArr = JSON.parse(JSON.stringify(this.crewList));
  1217. dataRow.assignType = 2;
  1218. dataRow.assignName = '人员';
  1219. } else {
  1220. radioBun.stationDis = true;
  1221. radioBun.staffDis = true;
  1222. radioBun.lineDis = false;
  1223. listArr = JSON.parse(JSON.stringify(this.productionList));
  1224. dataRow.assignType = 3;
  1225. dataRow.assignName = '产线';
  1226. }
  1227. }
  1228. // 切换完后 对 指派的数组数据进行赋值
  1229. let listMap = {};
  1230. listArr.map((el, index) => (listMap[el.id] = index));
  1231. let arrList = codeT ? arrMap[codeT].arr : res[0].assignees;
  1232. dataRow.startDate = ''; // 每次计算的时候清空之前的
  1233. dataRow.endDate = '';
  1234. arrList.map((item) => {
  1235. if (item.assigneeType.code == dataRow.assignType) {
  1236. console.log(item, 'itemitemitemitemitemitemitemitemitemitem');
  1237. let idx = listMap[item.assigneeId];
  1238. if (!idx && idx !== 0) {
  1239. return;
  1240. }
  1241. listArr[idx].status = item.status;
  1242. listArr[idx].startTime = item.startTime;
  1243. listArr[idx].endTime = item.endTime;
  1244. listArr[idx].quantity = item.quantity;
  1245. listArr[idx].weight = item.weight;
  1246. listArr[idx].changeId = item.id;
  1247. listArr[idx].teamTimeDetailId = item.teamTimeDetailId;
  1248. // this.compareAndSetTime(listArr[idx], dataRow);
  1249. // this.compareEndSetTime(listArr[idx], dataRow);
  1250. }
  1251. });
  1252. console.log(arrList, 'arrList arrList');
  1253. // 这里重新调用一个方法 计算出 startDate endDate
  1254. console.log(dataRow, 'dataRow +++++');
  1255. this.$set(dataRow, 'list', listArr);
  1256. this.$set(dataRow, 'radioBun', radioBun);
  1257. },
  1258. // 时间比较与赋值方法 开始时间
  1259. compareAndSetTime(data, dataRow) {
  1260. // 如果startDate为空,直接赋值为startTime
  1261. if (!dataRow.startDate) {
  1262. dataRow.startDate = data['startTime'];
  1263. return;
  1264. }
  1265. // 转换为Date对象进行比较
  1266. const startTimeDate = new Date(data['startTime']);
  1267. const startDateDate = new Date(dataRow.startDate);
  1268. // 比较时间(getTime()获取时间戳)
  1269. if (startTimeDate.getTime() < startDateDate.getTime()) {
  1270. dataRow.startDate = data['startTime'];
  1271. }
  1272. },
  1273. // 时间比较与赋值方法 结束时间时间
  1274. compareEndSetTime(data, dataRow) {
  1275. // 如果startDate为空,直接赋值为endTime
  1276. if (!dataRow.endDate) {
  1277. dataRow.endDate = data['endTime'];
  1278. return;
  1279. }
  1280. // 转换为Date对象进行比较
  1281. const endTimeDate = new Date(data['endTime']);
  1282. const endDateDate = new Date(dataRow.endDate);
  1283. // 比较时间(getTime()获取时间戳)
  1284. if (endTimeDate.getTime() > endDateDate.getTime()) {
  1285. dataRow.endDate = data['endTime'];
  1286. }
  1287. },
  1288. assignRadio(e) {},
  1289. // 数量正则 quantity
  1290. handleQuantityInput(e, row, item) {
  1291. // 过滤非数字字符(包括负号)
  1292. let value = e.replace(/[^\d]/g, '');
  1293. // 限制不能以 0 开头(除非是 0 本身)
  1294. if (value.startsWith('0') && value.length > 1) {
  1295. value = value.slice(1);
  1296. }
  1297. // 更新绑定值
  1298. row.quantity = value;
  1299. this.calculateQuantity(row, item);
  1300. this.bringWeight(row.quantity, row);
  1301. },
  1302. // 自动算重量
  1303. bringWeight(value, row) {
  1304. if (!this.current.formingWeight) {
  1305. this.$set(row, 'weight', 0);
  1306. return;
  1307. }
  1308. let weight =
  1309. (this.current.formingWeight / this.current.formingNum) * value;
  1310. if (weight > 0) {
  1311. weight = weight.toFixed(4) - 0;
  1312. }
  1313. this.$set(row, 'weight', weight);
  1314. },
  1315. calculateQuantity(row, item) {
  1316. // 如果没有该字段 就不做判断
  1317. if (!this.current.formingNum) {
  1318. return;
  1319. }
  1320. let total = 0;
  1321. item.list.forEach((el) => {
  1322. if (el.quantity) {
  1323. total = total + (el.quantity - 0);
  1324. }
  1325. });
  1326. if (total > this.current.formingNum - 0) {
  1327. this.$message.warning('列表数量相加不能大于目标要求生产数量');
  1328. row.quantity = 0;
  1329. }
  1330. },
  1331. // 计算重量
  1332. calculateWeight(row, item) {
  1333. // 如果没有该字段 就不做判断
  1334. if (!this.current.formingWeight) {
  1335. return;
  1336. }
  1337. let total = 0;
  1338. item.list.forEach((el) => {
  1339. if (el.weight) {
  1340. total = total + (el.weight - 0);
  1341. }
  1342. });
  1343. if (total > this.current.formingWeight - 0) {
  1344. this.$message.warning('列表数量相加不能大于目标要求生产数量');
  1345. row.weight = 0;
  1346. }
  1347. },
  1348. // 重量正则 weight
  1349. handleWeightInput(e, row, item) {
  1350. // 过滤非数字和非小数点字符(包括负号)
  1351. let value = e.replace(/[^\d.]/g, '');
  1352. // 限制只能有一个小数点
  1353. const dotCount = (value.match(/\./g) || []).length;
  1354. if (dotCount > 1) {
  1355. value = value.slice(0, value.lastIndexOf('.'));
  1356. }
  1357. // 限制不能以小数点开头
  1358. if (value.startsWith('.')) {
  1359. value = '0' + value;
  1360. }
  1361. // 更新绑定值
  1362. row.weight = value;
  1363. this.calculateWeight(row, item);
  1364. },
  1365. // 选中班次
  1366. shiftSelection(e, row, item) {
  1367. let data = this.shiftList.find((item) => item.id == e);
  1368. let startTime = `${this.dateValue} ${data.startTime}`;
  1369. let endTime = `${this.dateValue} ${data.endTime}`;
  1370. this.$set(row, 'startTime', startTime);
  1371. this.$set(row, 'endTime', endTime);
  1372. this.handleStartTimeChange(row, item);
  1373. this.handleEndTimeChange(row, item);
  1374. },
  1375. // 【开始时间变化时】触发
  1376. handleStartTimeChange(row, item) {
  1377. // 后一道工序的开始时间 不能小于前一道工序的结束时间
  1378. // if (item.index !== 0) {
  1379. // let frontIdx = item.index - 1;
  1380. // let frontName = this.processList[frontIdx].name;
  1381. // let time = this.processList[frontIdx].endDate;
  1382. // const frontTime = new Date(time); // 上一道工序的结束时间
  1383. // const startTime = new Date(row.startTime); // 开始时间
  1384. // const endTime = item.endTime ? new Date(item.endTime) : null; // 结束时间
  1385. // console.log(startTime,'startTime 开始的')
  1386. // if (endTime && endTime < frontTime) {
  1387. // row.endTime = '';
  1388. // }
  1389. // if (startTime < frontTime) {
  1390. // this.$message.info(
  1391. // `开始时间不能小于上一道工序${frontName}的结束时间${time}`
  1392. // );
  1393. // row.startTime = time;
  1394. // return;
  1395. // }
  1396. // }
  1397. // 校验 是否 大于结束时间 wda
  1398. this.checkEndTimeValid(row);
  1399. // 更新当前结束时间段 每次计算的时候清空之前的
  1400. // item.startDate = '';
  1401. // item.list.forEach((el) => {
  1402. // this.compareAndSetTime(el, item);
  1403. // });
  1404. },
  1405. // 【结束时间变化时】触发
  1406. handleEndTimeChange(row, item) {
  1407. // 当前工序的结束时间 不能大于后一道工序的开始时间
  1408. // if (item.index !== this.processList.length - 1) {
  1409. // let latterIdx = item.index + 1;
  1410. // let latterName = this.processList[latterIdx].name;
  1411. // let time = this.processList[latterIdx].startDate;
  1412. // const latterTime = new Date(time); // 下一道工序的开始时间
  1413. // const endTime = new Date(row.endTime); // 结束时间
  1414. // const startTime = item.startTime ? new Date(item.startTime) : null; // 开始时间
  1415. // console.log(startTime,'startTime')
  1416. // console.log(latterTime,'latterTime')
  1417. // if (startTime && startTime > latterTime) {
  1418. // row.startTime = '';
  1419. // }
  1420. // if (endTime > latterTime) {
  1421. // this.$message.info(
  1422. // `结束时间不能大于下一道工序${latterName}的开始时间${time}`
  1423. // );
  1424. // row.endTime = time;
  1425. // return;
  1426. // }
  1427. // }
  1428. this.checkEndTimeValid(row, item);
  1429. // 更新当前结束时间段 每次计算的时候清空之前的
  1430. // item.endDate = '';
  1431. // item.list.forEach((el) => {
  1432. // this.compareEndSetTime(el, item);
  1433. // });
  1434. console.log(item, 'item,结束');
  1435. },
  1436. // 时间校验
  1437. checkEndTimeValid(row) {
  1438. const { startTime: start, endTime: end } = row;
  1439. // if (!start || !end) return; // 开始/结束时间未填,跳过
  1440. const startTime = new Date(start); // 开始时间
  1441. const endTime = new Date(end); // 结束时间
  1442. if (endTime < startTime) {
  1443. row.endTime = new Date(startTime); // 修正为开始时间
  1444. this.$message.info('结束时间不能早于开始时间,已自动设为开始时间');
  1445. }
  1446. }
  1447. }
  1448. };
  1449. </script>
  1450. <style lang="scss" scoped>
  1451. .top-box {
  1452. display: flex;
  1453. margin-bottom: 10px;
  1454. .item-box {
  1455. flex: 1;
  1456. }
  1457. }
  1458. .radio-box {
  1459. margin: 10px 0;
  1460. }
  1461. .table {
  1462. margin-top: 20px;
  1463. }
  1464. ::v-deep .el-radio-button__orig-radio:checked + .el-radio-button__inner {
  1465. background-color: #10d070;
  1466. border-color: #10d070;
  1467. }
  1468. ::v-deep .el-radio-button__orig-radio:checked + .el-radio-button__inner {
  1469. box-shadow: none;
  1470. }
  1471. // ::v-deep .ele-block{
  1472. // width: 240px;
  1473. // }
  1474. // ::v-deep .basic {
  1475. // .el-form-item {
  1476. // width: 100%;
  1477. // }
  1478. // .form80 {
  1479. // .el-form-item__content {
  1480. // width: calc(100% - 80px);
  1481. // }
  1482. // }
  1483. // .form65 {
  1484. // .el-form-item__content {
  1485. // width: calc(100% - 65px);
  1486. // }
  1487. // }
  1488. // .el-form-item__label {
  1489. // padding: 0 4px 0 0;
  1490. // }
  1491. // .item_label {
  1492. // white-space: nowrap;
  1493. // overflow: hidden;
  1494. // text-overflow: ellipsis;
  1495. // width: 100%;
  1496. // }
  1497. // }
  1498. </style>