taskInfoTable.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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. },
  277. data() {
  278. return {
  279. editIndex: undefined, //当前修改数据的下标
  280. selectDriverDialogFlag: false,
  281. selectCarDialogFlag: false,
  282. form: {
  283. datasource: []
  284. },
  285. associationVisible: false
  286. };
  287. },
  288. computed: {
  289. columns() {
  290. let list = [
  291. {
  292. columnKey: 'index',
  293. label: '序号',
  294. type: 'index',
  295. width: 55,
  296. align: 'center',
  297. showOverflowTooltip: true,
  298. fixed: 'left'
  299. },
  300. {
  301. prop: 'trakNumber',
  302. label: '车牌号',
  303. align: 'center',
  304. showOverflowTooltip: true,
  305. minWidth: 120,
  306. slot: 'trakNumber',
  307. headerSlot: 'headerGLLXMC'
  308. },
  309. {
  310. prop: 'startPlace',
  311. label: '出发地',
  312. align: 'center',
  313. showOverflowTooltip: true,
  314. minWidth: 120,
  315. slot: 'startPlace'
  316. // headerSlot: 'headerGLLXMC',
  317. },
  318. {
  319. prop: 'endPlace',
  320. label: '目的地',
  321. align: 'center',
  322. showOverflowTooltip: true,
  323. minWidth: 120,
  324. slot: 'endPlace'
  325. // headerSlot: 'headerGLLXMC',
  326. },
  327. {
  328. prop: 'planTimeStart',
  329. label: '预计发车日期',
  330. align: 'center',
  331. showOverflowTooltip: true,
  332. minWidth: 240,
  333. slot: 'planTimeStart'
  334. // headerSlot: 'headerGLLXMC',
  335. },
  336. {
  337. prop: 'planTimeEnd',
  338. label: '预计结束日期',
  339. align: 'center',
  340. showOverflowTooltip: true,
  341. minWidth: 240,
  342. slot: 'planTimeEnd'
  343. // headerSlot: 'headerGLLXMC',
  344. },
  345. {
  346. prop: 'driverName',
  347. label: '司机',
  348. align: 'center',
  349. showOverflowTooltip: true,
  350. minWidth: 120,
  351. slot: 'driverName'
  352. // headerSlot: 'headerGLLXMC',
  353. },
  354. {
  355. prop: 'phone',
  356. label: '司机电话',
  357. align: 'center',
  358. showOverflowTooltip: true,
  359. minWidth: 120,
  360. slot: 'phone'
  361. // headerSlot: 'headerGLLXMC',
  362. },
  363. {
  364. prop: 'taskType',
  365. label: '任务类型',
  366. align: 'center',
  367. showOverflowTooltip: true,
  368. minWidth: 120,
  369. slot: 'taskType'
  370. // headerSlot: 'headerGLLXMC',
  371. },
  372. {
  373. prop: 'taskCode',
  374. label: '单据名称',
  375. align: 'center',
  376. showOverflowTooltip: true,
  377. minWidth: 130
  378. },
  379. {
  380. prop: 'remark',
  381. label: '备注',
  382. align: 'center',
  383. showOverflowTooltip: true,
  384. minWidth: 120,
  385. slot: 'remark'
  386. }
  387. ];
  388. let action = [
  389. {
  390. columnKey: 'action',
  391. slot: 'action',
  392. label: '操作',
  393. resizable: false,
  394. width: 80,
  395. align: 'center',
  396. showOverflowTooltip: true,
  397. fixed: 'right'
  398. }
  399. ];
  400. this.dialogType === 'view'
  401. ? (list = [...list])
  402. : (list = [...list, ...action]);
  403. return list;
  404. },
  405. disableInput() {
  406. return (row) => {
  407. if (!row.id) return false;
  408. return true;
  409. };
  410. }
  411. },
  412. mounted() {
  413. this.form.datasource = this.trakNoteList;
  414. console.log(this.form.datasource);
  415. },
  416. methods: {
  417. //新增任务信息数据
  418. handleAddInfo() {
  419. this.form.datasource.push({
  420. driverId: '',
  421. driverName: '',
  422. endPlace: '',
  423. phone: '',
  424. planId: '',
  425. planTimeEnd: '',
  426. planTimeStart: '',
  427. realEntTime: '',
  428. realStartTime: '',
  429. remark: '',
  430. startPlace: '',
  431. trakId: '',
  432. trakNumber: '',
  433. taskId: '',
  434. taskType: '1',
  435. taskCode: ''
  436. });
  437. this.$emit('setAddress');
  438. },
  439. setSelectData(val) {
  440. this.$set(this.form.datasource[this.editIndex], 'taskId', val.id);
  441. this.$set(this.form.datasource[this.editIndex], 'taskCode', val.code);
  442. },
  443. setAddress(startPlace, endPlace) {
  444. this.form.datasource.forEach((item) => {
  445. item.startPlace = startPlace;
  446. item.endPlace = endPlace;
  447. });
  448. },
  449. // 关联工单
  450. association() {
  451. console.log('关联工单 ----');
  452. this.associationVisible = true;
  453. },
  454. // 关联工单回调
  455. associationSelect(list) {
  456. // this.form.datasource.push(...list);
  457. // 判断如果 不存在已经关联的数据再进行添加
  458. let dataObj = {};
  459. this.form.datasource.map((item) => {
  460. if (item.id) dataObj[item.id] = true;
  461. });
  462. list.map((el) => {
  463. if (!dataObj[el.id]) {
  464. this.form.datasource.push(el);
  465. }
  466. });
  467. console.log(dataObj, 'dataObj -----');
  468. console.log(list, 'list --- 关联的数据');
  469. },
  470. //删除任务信息数据
  471. handleDelInfo(index) {
  472. this.form.datasource.splice(index, 1);
  473. },
  474. //修改任务类型
  475. handleChangeFinLink(val, row, index) {
  476. this.editIndex = index;
  477. this.setSelectData({
  478. id: '',
  479. code: ''
  480. });
  481. this.$nextTick(() => {
  482. this.$refs.form.clearValidate('datasource.' + index + '.taskCode');
  483. });
  484. },
  485. //选择司机
  486. handleDriver(row, index) {
  487. this.editIndex = index;
  488. this.selectDriverDialogFlag = true;
  489. },
  490. //选择司机回调
  491. getDriverInfo(row) {
  492. this.$set(
  493. this.form.datasource[this.editIndex],
  494. 'driverId',
  495. row.driverId
  496. );
  497. this.$set(
  498. this.form.datasource[this.editIndex],
  499. 'driverName',
  500. row.driverName
  501. );
  502. this.$set(this.form.datasource[this.editIndex], 'phone', row.phone);
  503. this.handleCheckCarOrDriverIsBusy(this.form.datasource[this.editIndex]);
  504. },
  505. //选择车辆
  506. handleCar(row, index) {
  507. this.editIndex = index;
  508. this.selectCarDialogFlag = true;
  509. },
  510. //选择车辆回调
  511. getCarInfo(row) {
  512. this.$set(
  513. this.form.datasource[this.editIndex],
  514. 'driverId',
  515. row.defaultDriverId
  516. );
  517. this.$set(
  518. this.form.datasource[this.editIndex],
  519. 'driverName',
  520. row.defaultDriver
  521. );
  522. this.$set(this.form.datasource[this.editIndex], 'phone', row.phone);
  523. this.$set(
  524. this.form.datasource[this.editIndex],
  525. 'trakNumber',
  526. row.trakNumber
  527. );
  528. this.$set(this.form.datasource[this.editIndex], 'trakId', row.id);
  529. this.handleCheckCarOrDriverIsBusy(this.form.datasource[this.editIndex]);
  530. },
  531. //检查车辆或司机是否在运输中
  532. async handleCheckCarOrDriverIsBusy(row) {
  533. if (
  534. (row.driverName || row.trakNumber) &&
  535. row.planTimeStart &&
  536. row.planTimeEnd
  537. ) {
  538. let data = await checkDriverIsBusyAPI(row);
  539. console.log(data);
  540. if (data.code == 1) {
  541. this.$message.warning(data.message);
  542. }
  543. }
  544. },
  545. //修改回显
  546. putTableValue(data) {
  547. if (data) {
  548. this.form.datasource = data;
  549. }
  550. },
  551. getTableValue() {
  552. return this.form.datasource;
  553. },
  554. getTableValidate(callback) {
  555. this.$refs.form.validate((valid) => {
  556. callback(valid);
  557. });
  558. }
  559. }
  560. };
  561. </script>
  562. <style scoped lang="scss">
  563. :deep(.el-form-item) {
  564. margin-bottom: 0;
  565. }
  566. </style>