taskInfoTable.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <template>
  2. <div>
  3. <el-form ref="form" :model="form">
  4. <!-- 数据表格 -->
  5. <ele-pro-table
  6. ref="table"
  7. :columns="columns"
  8. :datasource="form.datasource"
  9. :needPage="false"
  10. :minHeight="100"
  11. tool-class="ele-toolbar-form"
  12. cache-key="eomContactPageTable"
  13. >
  14. <!-- 表头工具栏 -->
  15. <template v-slot:toolbar>
  16. <el-button
  17. v-if="dialogType !== 'view'"
  18. size="small"
  19. type="primary"
  20. icon="el-icon-plus"
  21. class="ele-btn-icon"
  22. @click="handleAddInfo"
  23. >
  24. 新增
  25. </el-button>
  26. <!-- 新增需求 -->
  27. <el-button
  28. v-if="dialogType !== 'view'"
  29. size="small"
  30. type="primary"
  31. icon="el-icon-circle-plus"
  32. class="ele-btn-icon"
  33. @click="association"
  34. >
  35. 关联工单
  36. </el-button>
  37. </template>
  38. <template v-slot:action="{ row, $index }" v-if="dialogType !== 'view'">
  39. <el-popconfirm
  40. class="ele-action"
  41. title="确定要删除此信息吗?"
  42. @confirm="handleDelInfo($index)"
  43. >
  44. <template v-slot:reference>
  45. <el-link type="danger" :underline="false" icon="el-icon-delete">
  46. 删除
  47. </el-link>
  48. </template>
  49. </el-popconfirm>
  50. </template>
  51. <template
  52. v-slot:trakNumber="{ row, $index }"
  53. v-if="dialogType !== 'view'"
  54. >
  55. <el-form-item
  56. :prop="'datasource.' + $index + '.trakNumber'"
  57. :rules="{
  58. required: true,
  59. message: '请选择车辆',
  60. trigger: ['blur', 'change']
  61. }"
  62. >
  63. <el-input
  64. :disabled="disableInput(row)"
  65. v-model="row.trakNumber"
  66. @click.native="handleCar(row, $index)"
  67. ></el-input>
  68. </el-form-item>
  69. </template>
  70. <template
  71. v-slot:driverName="{ row, $index }"
  72. v-if="dialogType !== 'view'"
  73. >
  74. <el-form-item
  75. :prop="'datasource.' + $index + '.driverName'"
  76. :rules="{
  77. required: false,
  78. message: '请选择司机',
  79. trigger: ['blur', 'change']
  80. }"
  81. >
  82. <el-input
  83. :disabled="disableInput(row)"
  84. v-model="row.driverName"
  85. @click.native="() => handleDriver(row, $index)"
  86. ></el-input>
  87. </el-form-item>
  88. </template>
  89. <template v-slot:phone="{ row, $index }" v-if="dialogType !== 'view'">
  90. <el-form-item
  91. :prop="'datasource.' + $index + '.phone'"
  92. :rules="{
  93. required: false,
  94. message: '请输入司机电话',
  95. trigger: ['blur', 'change']
  96. }"
  97. >
  98. <el-input
  99. :disabled="disableInput(row)"
  100. v-model="row.phone"
  101. ></el-input>
  102. </el-form-item>
  103. </template>
  104. <template
  105. v-slot:startPlace="{ row, $index }"
  106. v-if="dialogType !== 'view'"
  107. >
  108. <el-form-item
  109. :prop="'datasource.' + $index + '.startPlace'"
  110. :rules="{
  111. required: false,
  112. message: '请输入出发地',
  113. trigger: ['blur', 'change']
  114. }"
  115. >
  116. <el-input
  117. :disabled="disableInput(row)"
  118. v-model="row.startPlace"
  119. ></el-input>
  120. </el-form-item>
  121. </template>
  122. <template
  123. v-slot:endPlace="{ row, $index }"
  124. v-if="dialogType !== 'view'"
  125. >
  126. <el-form-item
  127. :prop="'datasource.' + $index + '.endPlace'"
  128. :rules="{
  129. required: false,
  130. message: '请输入目的地',
  131. trigger: ['blur', 'change']
  132. }"
  133. >
  134. <el-input
  135. :disabled="disableInput(row)"
  136. v-model="row.endPlace"
  137. ></el-input>
  138. </el-form-item>
  139. </template>
  140. <template
  141. v-slot:planTimeStart="{ row, $index }"
  142. v-if="dialogType !== 'view'"
  143. >
  144. <el-form-item
  145. :prop="'datasource.' + $index + '.planTimeStart'"
  146. :rules="{
  147. required: false,
  148. message: '请选择发车时间',
  149. trigger: ['blur', 'change']
  150. }"
  151. >
  152. <el-date-picker
  153. :disabled="disableInput(row)"
  154. v-model="row.planTimeStart"
  155. :picker-options="{
  156. disabledDate: (time) => {
  157. return (
  158. row.planTimeEnd &&
  159. time.getTime() > new Date(row.planTimeEnd)
  160. );
  161. }
  162. }"
  163. type="datetime"
  164. @change="() => handleCheckCarOrDriverIsBusy(row)"
  165. style="width: 90%"
  166. value-format="yyyy-MM-dd HH:mm:ss"
  167. placeholder="选择日期时间"
  168. >
  169. </el-date-picker>
  170. </el-form-item>
  171. </template>
  172. <template
  173. v-slot:planTimeEnd="{ row, $index }"
  174. v-if="dialogType !== 'view'"
  175. >
  176. <el-form-item
  177. :prop="'datasource.' + $index + '.planTimeEnd'"
  178. :rules="{
  179. required: false,
  180. message: '请选择结束时间',
  181. trigger: ['blur', 'change']
  182. }"
  183. >
  184. <el-date-picker
  185. :disabled="disableInput(row)"
  186. v-model="row.planTimeEnd"
  187. :picker-options="{
  188. disabledDate: (time) => {
  189. return (
  190. row.planTimeStart &&
  191. time.getTime() < new Date(row.planTimeStart)
  192. );
  193. }
  194. }"
  195. type="datetime"
  196. @change="() => handleCheckCarOrDriverIsBusy(row)"
  197. style="width: 90%"
  198. value-format="yyyy-MM-dd HH:mm:ss"
  199. placeholder="选择日期时间"
  200. >
  201. </el-date-picker>
  202. </el-form-item>
  203. </template>
  204. <template v-slot:remark="{ row, $index }" v-if="dialogType !== 'view'">
  205. <el-form-item :prop="'datasource.' + $index + '.remark'">
  206. <el-input
  207. :disabled="disableInput(row)"
  208. type="textarea"
  209. v-model="row.remark"
  210. ></el-input>
  211. </el-form-item>
  212. </template>
  213. <template v-slot:taskType="{ row, $index }">
  214. <el-form-item
  215. :prop="'datasource.' + $index + '.taskType'"
  216. :rules="{
  217. required: false,
  218. message: '请选择任务类型',
  219. trigger: ['blur', 'change']
  220. }"
  221. >
  222. <DictSelection
  223. clearable
  224. dictName="派车任务类型"
  225. v-model="row.taskType"
  226. :disabled="dialogType === 'view'"
  227. disabled
  228. @itemChange="(val) => handleChangeFinLink(val, row, $index)"
  229. ></DictSelection>
  230. </el-form-item>
  231. </template>
  232. <template v-slot:headerGLLXMC="{ column }">
  233. <span class="is-required">{{ column.label }}</span>
  234. </template>
  235. </ele-pro-table>
  236. </el-form>
  237. <!-- 选择司机 -->
  238. <select-driver-dialog
  239. ref="selectDriverDialogRef"
  240. :selectDriverDialogFlag.sync="selectDriverDialogFlag"
  241. v-if="selectDriverDialogFlag"
  242. @changeParent="getDriverInfo"
  243. ></select-driver-dialog>
  244. <select-car-dialog
  245. ref="selectCarDialogRef"
  246. :selectCarDialogFlag.sync="selectCarDialogFlag"
  247. v-if="selectCarDialogFlag"
  248. @changeParent="getCarInfo"
  249. ></select-car-dialog>
  250. <!-- 关联工单 -->
  251. <relatedWorkDialog
  252. v-if="associationVisible"
  253. :associationVisible.sync="associationVisible"
  254. @associationSelect="associationSelect"
  255. />
  256. </div>
  257. </template>
  258. <script>
  259. import { checkDriverIsBusyAPI } from '@/api/transportManager/shipManage';
  260. import SelectDriverDialog from '@/views/transportManager/shipManage/dispatchManage/components/selectDriverDialog.vue';
  261. import SelectCarDialog from '@/views/transportManager/shipManage/dispatchManage/components/selectCarDialog.vue';
  262. import { getWarehouseOutStock } from '@/api/saleManage/saleorder';
  263. import relatedWorkDialog from './relatedWorkOrder/relatedWorkDialog.vue';
  264. export default {
  265. name: 'relatedInfoTable',
  266. components: { SelectCarDialog, SelectDriverDialog, relatedWorkDialog },
  267. props: {
  268. trakNoteList: {
  269. type: Array,
  270. default: () => []
  271. },
  272. dialogType: {
  273. type: String,
  274. default: ''
  275. },
  276. taskType: {
  277. type: String,
  278. default: '1'
  279. }
  280. },
  281. data() {
  282. return {
  283. editIndex: undefined, //当前修改数据的下标
  284. selectDriverDialogFlag: false,
  285. selectCarDialogFlag: false,
  286. form: {
  287. datasource: []
  288. },
  289. associationVisible: false
  290. };
  291. },
  292. computed: {
  293. columns() {
  294. let list = [
  295. {
  296. columnKey: 'index',
  297. label: '序号',
  298. type: 'index',
  299. width: 55,
  300. align: 'center',
  301. showOverflowTooltip: true,
  302. fixed: 'left'
  303. },
  304. {
  305. prop: 'trakNumber',
  306. label: '车牌号',
  307. align: 'center',
  308. showOverflowTooltip: true,
  309. minWidth: 120,
  310. slot: 'trakNumber',
  311. headerSlot: 'headerGLLXMC'
  312. },
  313. {
  314. prop: 'startPlace',
  315. label: '出发地',
  316. align: 'center',
  317. showOverflowTooltip: true,
  318. minWidth: 120,
  319. slot: 'startPlace'
  320. // headerSlot: 'headerGLLXMC',
  321. },
  322. {
  323. prop: 'endPlace',
  324. label: '目的地',
  325. align: 'center',
  326. showOverflowTooltip: true,
  327. minWidth: 120,
  328. slot: 'endPlace'
  329. // headerSlot: 'headerGLLXMC',
  330. },
  331. {
  332. prop: 'planTimeStart',
  333. label: '预计发车日期',
  334. align: 'center',
  335. showOverflowTooltip: true,
  336. minWidth: 240,
  337. slot: 'planTimeStart'
  338. // headerSlot: 'headerGLLXMC',
  339. },
  340. {
  341. prop: 'planTimeEnd',
  342. label: '预计结束日期',
  343. align: 'center',
  344. showOverflowTooltip: true,
  345. minWidth: 240,
  346. slot: 'planTimeEnd'
  347. // headerSlot: 'headerGLLXMC',
  348. },
  349. {
  350. prop: 'driverName',
  351. label: '司机',
  352. align: 'center',
  353. showOverflowTooltip: true,
  354. minWidth: 120,
  355. slot: 'driverName'
  356. // headerSlot: 'headerGLLXMC',
  357. },
  358. {
  359. prop: 'phone',
  360. label: '司机电话',
  361. align: 'center',
  362. showOverflowTooltip: true,
  363. minWidth: 120,
  364. slot: 'phone'
  365. // headerSlot: 'headerGLLXMC',
  366. },
  367. {
  368. prop: 'taskType',
  369. label: '任务类型',
  370. align: 'center',
  371. showOverflowTooltip: true,
  372. minWidth: 120,
  373. slot: 'taskType'
  374. // headerSlot: 'headerGLLXMC',
  375. },
  376. {
  377. prop: 'taskCode',
  378. label: '单据名称',
  379. align: 'center',
  380. showOverflowTooltip: true,
  381. minWidth: 130
  382. },
  383. {
  384. prop: 'remark',
  385. label: '备注',
  386. align: 'center',
  387. showOverflowTooltip: true,
  388. minWidth: 120,
  389. slot: 'remark'
  390. }
  391. ];
  392. let action = [
  393. {
  394. columnKey: 'action',
  395. slot: 'action',
  396. label: '操作',
  397. resizable: false,
  398. width: 80,
  399. align: 'center',
  400. showOverflowTooltip: true,
  401. fixed: 'right'
  402. }
  403. ];
  404. this.dialogType === 'view'
  405. ? (list = [...list])
  406. : (list = [...list, ...action]);
  407. return list;
  408. },
  409. disableInput() {
  410. return (row) => {
  411. if (!row.id) return false;
  412. return true;
  413. };
  414. }
  415. },
  416. mounted() {
  417. this.form.datasource = this.trakNoteList;
  418. console.log(this.form.datasource);
  419. },
  420. methods: {
  421. //新增任务信息数据
  422. handleAddInfo() {
  423. this.form.datasource.push({
  424. driverId: '',
  425. driverName: '',
  426. endPlace: '',
  427. phone: '',
  428. planId: '',
  429. planTimeEnd: '',
  430. planTimeStart: '',
  431. realEntTime: '',
  432. realStartTime: '',
  433. remark: '',
  434. startPlace: '',
  435. trakId: '',
  436. trakNumber: '',
  437. taskId: '',
  438. taskType: this.taskType,
  439. taskCode: ''
  440. });
  441. this.$emit('setAddress');
  442. },
  443. setSelectData(val) {
  444. this.$set(this.form.datasource[this.editIndex], 'taskId', val.id);
  445. this.$set(this.form.datasource[this.editIndex], 'taskCode', val.code);
  446. },
  447. setAddress(startPlace, endPlace) {
  448. this.form.datasource.forEach((item) => {
  449. item.startPlace = startPlace;
  450. item.endPlace = endPlace;
  451. });
  452. },
  453. // 关联工单
  454. association() {
  455. console.log('关联工单 ----');
  456. this.associationVisible = true;
  457. },
  458. // 关联工单回调
  459. associationSelect(list) {
  460. // this.form.datasource.push(...list);
  461. // 判断如果 不存在已经关联的数据再进行添加
  462. let dataObj = {};
  463. this.form.datasource.map((item) => {
  464. if (item.id) dataObj[item.id] = true;
  465. });
  466. list.map((el) => {
  467. if (!dataObj[el.id]) {
  468. this.form.datasource.push(el);
  469. }
  470. });
  471. console.log(dataObj, 'dataObj -----');
  472. console.log(list, 'list --- 关联的数据');
  473. },
  474. //删除任务信息数据
  475. handleDelInfo(index) {
  476. this.form.datasource.splice(index, 1);
  477. },
  478. //修改任务类型
  479. handleChangeFinLink(val, row, index) {
  480. this.editIndex = index;
  481. this.setSelectData({
  482. id: '',
  483. code: ''
  484. });
  485. this.$nextTick(() => {
  486. this.$refs.form.clearValidate('datasource.' + index + '.taskCode');
  487. });
  488. },
  489. //选择司机
  490. handleDriver(row, index) {
  491. this.editIndex = index;
  492. this.selectDriverDialogFlag = true;
  493. },
  494. //选择司机回调
  495. getDriverInfo(row) {
  496. this.$set(
  497. this.form.datasource[this.editIndex],
  498. 'driverId',
  499. row.driverId
  500. );
  501. this.$set(
  502. this.form.datasource[this.editIndex],
  503. 'driverName',
  504. row.driverName
  505. );
  506. this.$set(this.form.datasource[this.editIndex], 'phone', row.phone);
  507. this.handleCheckCarOrDriverIsBusy(this.form.datasource[this.editIndex]);
  508. },
  509. //选择车辆
  510. handleCar(row, index) {
  511. this.editIndex = index;
  512. this.selectCarDialogFlag = true;
  513. },
  514. //选择车辆回调
  515. getCarInfo(row) {
  516. this.$set(
  517. this.form.datasource[this.editIndex],
  518. 'driverId',
  519. row.defaultDriverId
  520. );
  521. this.$set(
  522. this.form.datasource[this.editIndex],
  523. 'driverName',
  524. row.defaultDriver
  525. );
  526. this.$set(this.form.datasource[this.editIndex], 'phone', row.phone);
  527. this.$set(
  528. this.form.datasource[this.editIndex],
  529. 'trakNumber',
  530. row.trakNumber
  531. );
  532. this.$set(this.form.datasource[this.editIndex], 'trakId', row.id);
  533. this.handleCheckCarOrDriverIsBusy(this.form.datasource[this.editIndex]);
  534. },
  535. //检查车辆或司机是否在运输中
  536. async handleCheckCarOrDriverIsBusy(row) {
  537. if (
  538. (row.driverName || row.trakNumber) &&
  539. row.planTimeStart &&
  540. row.planTimeEnd
  541. ) {
  542. let data = await checkDriverIsBusyAPI(row);
  543. console.log(data);
  544. if (data.code == 1) {
  545. this.$message.warning(data.message);
  546. }
  547. }
  548. },
  549. //修改回显
  550. putTableValue(data) {
  551. if (data) {
  552. this.form.datasource = data;
  553. }
  554. },
  555. getTableValue() {
  556. return this.form.datasource;
  557. },
  558. getTableValidate(callback) {
  559. this.$refs.form.validate((valid) => {
  560. callback(valid);
  561. });
  562. }
  563. }
  564. };
  565. </script>
  566. <style scoped lang="scss">
  567. :deep(.el-form-item) {
  568. margin-bottom: 0;
  569. }
  570. </style>