DispatchDialog.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <template>
  2. <el-dialog v-model="dialogVisible" title="派单调度" width="900px" top="5vh" destroy-on-close append-to-body>
  3. <div class="dispatch-dialog-content">
  4. <!-- Top: Order Info (OrderDispatch Style) -->
  5. <div class="dispatch-order-info" v-if="order">
  6. <div class="list-card order-card" style="margin:0; box-shadow:none; cursor:default; border:none;">
  7. <div class="card-left">
  8. <div class="type-tag" :class="order.typeCode">
  9. {{ getShortType(order.typeCode) }}
  10. </div>
  11. </div>
  12. <div class="card-main">
  13. <template v-if="order.typeCode === 'transport'">
  14. <div class="row-addr" :title="order.toAddress || order.pickAddr || order.dropAddr">
  15. <span class="tag home">址</span> {{ order.toAddress || order.pickAddr || order.dropAddr
  16. }}
  17. </div>
  18. </template>
  19. <template v-else>
  20. <div class="row-addr" :title="order.address">
  21. <span class="tag home">址</span> {{ order.address }}
  22. </div>
  23. </template>
  24. <div class="row-time" style="margin-top: 4px;">
  25. <el-icon>
  26. <Clock />
  27. </el-icon> {{ order.time }}
  28. <span class="days-tag" v-if="order.daysLater">{{ order.daysLater }}</span>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <!-- Current Rider Info (If Exists) -->
  34. <div class="current-rider-section" v-if="currentRider">
  35. <div class="select-header" style="margin-bottom:8px;">
  36. <span class="tit">当前派单履约者</span>
  37. </div>
  38. <div class="list-card rider-card"
  39. style="margin-bottom: 20px; border: 1px solid #e4e7ed; background:#fafafa; cursor:default;">
  40. <div class="card-left relative">
  41. <el-avatar :src="currentRider.avatar" :size="40" />
  42. </div>
  43. <div class="card-main">
  44. <div class="row-1"
  45. style="justify-content: space-between; align-items: flex-start; display: flex;">
  46. <div style="display:flex; align-items:baseline; gap:8px;">
  47. <span class="r-name">{{ currentRider.name || '--' }}</span>
  48. <span class="r-phone">{{ currentRider.phone || '--' }}</span>
  49. <el-tag v-if="currentRider.status" size="small" :type="getStatusType(currentRider.status)" effect="plain">
  50. {{ getStatusText(currentRider.status) }}
  51. </el-tag>
  52. </div>
  53. </div>
  54. <div class="row-2 categories-row"
  55. style="margin-top: 6px; display:flex; gap:4px; flex-wrap:wrap;">
  56. <el-tag v-for="cat in (currentRider.tags || [])" :key="cat" size="small"
  57. :type="getTagType(cat)" effect="plain">{{ getTagText(cat) }}</el-tag>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. <!-- Middle: Rider Selection -->
  63. <div class="dispatch-rider-select">
  64. <div class="select-header">
  65. <span class="tit">选择履约者</span>
  66. <el-input v-model="dispatchSearchQuery" placeholder="搜索履约者姓名/手机号" prefix-icon="Search" clearable
  67. style="width: 240px" />
  68. </div>
  69. <div class="rider-grid-wrapper">
  70. <el-scrollbar class="rider-scroll">
  71. <div class="rider-grid">
  72. <div v-for="rider in filteredDispatchRiders" :key="rider.id"
  73. class="list-card rider-card select-card"
  74. :class="{ active: selectedRiderId === rider.id }" @click="selectedRiderId = rider.id">
  75. <!-- Reusing Rider Card Layout -->
  76. <div class="card-left relative">
  77. <el-avatar :src="rider.avatar" :size="40" />
  78. </div>
  79. <div class="card-main">
  80. <div class="row-1" style="justify-content: space-between; align-items: flex-start; display: flex;">
  81. <div style="display:flex; align-items:baseline; gap:8px;">
  82. <span class="r-name">{{ rider.name || '--' }}</span>
  83. <span class="r-phone">{{ rider.phone || '--' }}</span>
  84. </div>
  85. <el-tag v-if="rider.status" size="small" :type="getStatusType(rider.status)" effect="plain">
  86. {{ getStatusText(rider.status) }}
  87. </el-tag>
  88. </div>
  89. <div class="row-2 categories-row"
  90. style="margin-top: 6px; display:flex; gap:4px; flex-wrap:wrap;">
  91. <el-tag v-for="cat in (rider.tags || [])" :key="cat" size="small"
  92. :type="getTagType(cat)" effect="plain">{{ getTagText(cat) }}</el-tag>
  93. </div>
  94. </div>
  95. <!-- Selected Check -->
  96. <div class="selected-mark" v-if="selectedRiderId === rider.id">
  97. <el-icon>
  98. <Check />
  99. </el-icon>
  100. </div>
  101. </div>
  102. <div v-if="filteredDispatchRiders.length === 0" class="empty-text">暂无符合条件的履约者</div>
  103. </div>
  104. </el-scrollbar>
  105. </div>
  106. <div class="rider-pagination" style="margin-top: 20px;">
  107. <el-pagination v-model:current-page="pageNum" v-model:page-size="pageSize"
  108. :page-sizes="[10, 20, 50]" layout="total, sizes, prev, pager, next" :total="total"
  109. @current-change="loadRiders" @size-change="handlePageSizeChange" />
  110. </div>
  111. </div>
  112. <!-- Bottom: Fee & Submit -->
  113. <div class="dispatch-footer">
  114. <div class="fee-input">
  115. <span class="label">服务费用:</span>
  116. <el-input-number v-model="dispatchFee" :min="0" :precision="2" :step="10" placeholder="请输入"
  117. style="width: 140px;" />
  118. <span class="unit">元</span>
  119. </div>
  120. <div class="btns">
  121. <el-button @click="dialogVisible = false">取消</el-button>
  122. <el-button type="primary" :disabled="!canSubmit" @click="handleDispatchSubmit">确认派单</el-button>
  123. </div>
  124. </div>
  125. </div>
  126. </el-dialog>
  127. </template>
  128. <script setup>
  129. import { ref, computed, watch } from 'vue'
  130. import { ElMessage } from 'element-plus'
  131. import { pageFulfillerOnOrder } from '@/api/fulfiller/pool'
  132. import { listAllTag } from '@/api/fulfiller/tag'
  133. const props = defineProps({
  134. visible: Boolean,
  135. order: Object
  136. })
  137. const emit = defineEmits(['update:visible', 'submit'])
  138. const dialogVisible = computed({
  139. get: () => props.visible,
  140. set: (val) => emit('update:visible', val)
  141. })
  142. const ridersList = ref([])
  143. const total = ref(0)
  144. const pageNum = ref(1)
  145. const pageSize = ref(10)
  146. const allTags = ref([])
  147. const tagMap = computed(() => {
  148. const map = {}
  149. for (const t of (allTags.value || [])) {
  150. if (t && t.id !== undefined && t.id !== null) map[t.id] = t
  151. }
  152. return map
  153. })
  154. const currentRider = ref(null)
  155. const dispatchSearchQuery = ref('')
  156. const selectedRiderId = ref(null)
  157. const dispatchFee = ref(0)
  158. const loadAllTags = async () => {
  159. if (allTags.value && allTags.value.length > 0) return
  160. try {
  161. const res = await listAllTag({ category: 'fulfiller' })
  162. allTags.value = res?.data || []
  163. } catch {
  164. allTags.value = []
  165. }
  166. }
  167. const loadRiders = async () => {
  168. try {
  169. const res = await pageFulfillerOnOrder({
  170. content: dispatchSearchQuery.value || undefined,
  171. pageNum: pageNum.value,
  172. pageSize: pageSize.value
  173. })
  174. ridersList.value = res?.rows || []
  175. total.value = res?.total || 0
  176. if (props.order?.riderId) {
  177. currentRider.value = ridersList.value.find(r => r.id === props.order.riderId) || null
  178. }
  179. } catch {
  180. ridersList.value = []
  181. total.value = 0
  182. }
  183. }
  184. const handlePageSizeChange = (size) => {
  185. pageSize.value = size
  186. pageNum.value = 1
  187. loadRiders()
  188. }
  189. watch(() => props.visible, (val) => {
  190. if (val && props.order) {
  191. currentRider.value = null
  192. dispatchSearchQuery.value = ''
  193. selectedRiderId.value = null
  194. dispatchFee.value = 0
  195. pageNum.value = 1
  196. loadAllTags()
  197. loadRiders()
  198. }
  199. })
  200. const getTagText = (tagId) => {
  201. const t = tagMap.value?.[tagId]
  202. return t?.name || String(tagId)
  203. }
  204. const getTagType = (tagId) => {
  205. const t = tagMap.value?.[tagId]
  206. const type = t?.colorType
  207. if (type === 'success' || type === 'warning' || type === 'danger' || type === 'info') return type
  208. return ''
  209. }
  210. watch(dispatchSearchQuery, () => {
  211. pageNum.value = 1
  212. loadRiders()
  213. })
  214. const getShortType = (code) => {
  215. const map = { 'transport': '接送', 'feeding': '喂遛', 'washing': '洗护' }
  216. return map[code] || '订单'
  217. }
  218. const getStatusText = (status) => {
  219. const statusMap = {
  220. resting: '休息',
  221. busy: '接单中',
  222. disabled: '禁用'
  223. }
  224. return statusMap[status] || status
  225. }
  226. const getStatusType = (status) => {
  227. const typeMap = {
  228. resting: 'info',
  229. busy: 'success',
  230. disabled: 'danger'
  231. }
  232. return typeMap[status] || 'info'
  233. }
  234. const filteredDispatchRiders = computed(() => {
  235. return ridersList.value || []
  236. })
  237. const canSubmit = computed(() => {
  238. return !!selectedRiderId.value && !!dispatchFee.value
  239. })
  240. const handleDispatchSubmit = () => {
  241. if (!selectedRiderId.value) {
  242. ElMessage.warning('请选择履约者')
  243. return
  244. }
  245. if (!dispatchFee.value) {
  246. ElMessage.warning('请输入服务费用')
  247. return
  248. }
  249. const rider = ridersList.value.find(r => r.id === selectedRiderId.value)
  250. emit('submit', {
  251. riderId: rider.id,
  252. riderName: rider.name,
  253. fee: dispatchFee.value
  254. })
  255. dialogVisible.value = false
  256. }
  257. </script>
  258. <style scoped>
  259. /* Dispatch Dialog Styles */
  260. .list-card {
  261. background: #fff;
  262. border: 1px solid #ebeef5;
  263. border-radius: 8px;
  264. padding: 12px;
  265. margin-bottom: 10px;
  266. display: flex;
  267. align-items: stretch;
  268. gap: 12px;
  269. transition: all 0.2s;
  270. cursor: pointer;
  271. }
  272. .list-card:hover {
  273. border-color: #c6e2ff;
  274. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  275. }
  276. .card-left {
  277. flex-shrink: 0;
  278. display: flex;
  279. align-items: center;
  280. }
  281. .order-card .type-tag {
  282. width: 40px;
  283. height: 40px;
  284. border-radius: 8px;
  285. color: #fff;
  286. display: flex;
  287. align-items: center;
  288. justify-content: center;
  289. font-size: 12px;
  290. font-weight: bold;
  291. }
  292. .type-tag.transport {
  293. background: #e6a23c;
  294. }
  295. .type-tag.feeding {
  296. background: #67c23a;
  297. }
  298. .type-tag.washing {
  299. background: #409eff;
  300. }
  301. .card-main {
  302. flex: 1;
  303. overflow: hidden;
  304. display: flex;
  305. flex-direction: column;
  306. justify-content: center;
  307. gap: 4px;
  308. }
  309. .row-addr {
  310. font-size: 13px;
  311. color: #303133;
  312. display: flex;
  313. align-items: center;
  314. gap: 4px;
  315. white-space: nowrap;
  316. overflow: hidden;
  317. text-overflow: ellipsis;
  318. line-height: 1.5;
  319. }
  320. .row-addr .tag {
  321. font-size: 11px;
  322. color: #fff;
  323. padding: 1px 4px;
  324. border-radius: 4px;
  325. flex-shrink: 0;
  326. transform: scale(0.9);
  327. }
  328. .tag.pick {
  329. background: #409eff;
  330. }
  331. .tag.drop {
  332. background: #e6a23c;
  333. }
  334. .tag.home {
  335. background: #67c23a;
  336. }
  337. .row-time {
  338. font-size: 12px;
  339. color: #909399;
  340. display: flex;
  341. align-items: center;
  342. gap: 4px;
  343. }
  344. .days-tag {
  345. color: #f56c6c;
  346. background: #fef0f0;
  347. padding: 0 4px;
  348. border-radius: 4px;
  349. font-size: 11px;
  350. border: 1px solid #fde2e2;
  351. transform: scale(0.95);
  352. }
  353. .dispatch-order-info {
  354. background: #f5f7fa;
  355. padding: 10px;
  356. border-radius: 4px;
  357. margin-bottom: 20px;
  358. border: 1px solid #e4e7ed;
  359. display: block;
  360. }
  361. .dispatch-rider-select .select-header {
  362. display: flex;
  363. justify-content: space-between;
  364. align-items: center;
  365. margin-bottom: 10px;
  366. }
  367. .dispatch-rider-select .tit {
  368. font-weight: bold;
  369. font-size: 14px;
  370. }
  371. .rider-scroll {
  372. max-height: 45vh;
  373. }
  374. .rider-grid {
  375. display: grid;
  376. grid-template-columns: repeat(2, 1fr);
  377. gap: 12px;
  378. padding-right: 10px;
  379. }
  380. .rider-pagination {
  381. margin-top: 10px;
  382. }
  383. .rider-card.select-card {
  384. cursor: pointer;
  385. border: 1px solid #dcdfe6;
  386. position: relative;
  387. transition: all 0.2s;
  388. margin-bottom: 0;
  389. }
  390. .rider-card.select-card:hover {
  391. border-color: #409eff;
  392. }
  393. .rider-card.select-card.active {
  394. border-color: #409eff;
  395. background-color: #ecf5ff;
  396. }
  397. .selected-mark {
  398. position: absolute;
  399. top: 0;
  400. right: 0;
  401. background: #409eff;
  402. color: #fff;
  403. border-bottom-left-radius: 6px;
  404. width: 20px;
  405. height: 20px;
  406. display: flex;
  407. align-items: center;
  408. justify-content: center;
  409. font-size: 12px;
  410. }
  411. .rider-card .card-left .dot {
  412. position: absolute;
  413. bottom: 0;
  414. right: 0;
  415. width: 10px;
  416. height: 10px;
  417. border-radius: 50%;
  418. border: 2px solid #fff;
  419. }
  420. .dot.online {
  421. background: #67c23a;
  422. }
  423. .dot.busy {
  424. background: #409eff;
  425. }
  426. .dot.offline {
  427. background: #909399;
  428. }
  429. .r-name {
  430. font-weight: bold;
  431. font-size: 14px;
  432. color: #303133;
  433. margin-right: 8px;
  434. }
  435. .r-phone {
  436. font-size: 12px;
  437. color: #909399;
  438. }
  439. .status-badge {
  440. font-size: 11px;
  441. padding: 2px 6px;
  442. border-radius: 4px;
  443. display: inline-block;
  444. font-weight: bold;
  445. }
  446. .status-badge.online {
  447. background: #f0f9eb;
  448. color: #67c23a;
  449. }
  450. .status-badge.busy {
  451. background: #ecf5ff;
  452. color: #409eff;
  453. }
  454. .status-badge.offline {
  455. background: #f4f4f5;
  456. color: #909399;
  457. }
  458. .cat-tag {
  459. background: #f4f4f5;
  460. color: #909399;
  461. font-size: 10px;
  462. padding: 1px 4px;
  463. border-radius: 2px;
  464. margin-right: 4px;
  465. }
  466. .cat-tag.cat-transport {
  467. background: #e6f7ff;
  468. color: #1890ff;
  469. border: 1px solid #91d5ff;
  470. }
  471. .cat-tag.cat-feeding {
  472. background: #f6ffed;
  473. color: #52c41a;
  474. border: 1px solid #b7eb8f;
  475. }
  476. .cat-tag.cat-washing {
  477. background: #fff0f6;
  478. color: #eb2f96;
  479. border: 1px solid #ffadd2;
  480. }
  481. .last-time {
  482. font-size: 11px;
  483. color: #999;
  484. }
  485. .empty-text {
  486. text-align: center;
  487. color: #909399;
  488. padding: 20px;
  489. width: 100%;
  490. grid-column: span 2;
  491. }
  492. .dispatch-footer {
  493. margin-top: 20px;
  494. padding-top: 20px;
  495. border-top: 1px solid #ebeef5;
  496. display: flex;
  497. justify-content: space-between;
  498. align-items: center;
  499. }
  500. .dispatch-footer .fee-input {
  501. display: flex;
  502. align-items: center;
  503. gap: 8px;
  504. font-size: 14px;
  505. }
  506. </style>