index.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. <template>
  2. <div class="page-container">
  3. <el-card shadow="never" class="table-card">
  4. <template #header>
  5. <div class="card-header">
  6. <div class="left-panel">
  7. <span class="title">订单列表</span>
  8. </div>
  9. <div class="right-panel">
  10. <el-radio-group v-model="filters.service" size="default" @change="handleSearch">
  11. <el-radio-button label="">全部类型</el-radio-button>
  12. <el-radio-button v-for="item in serviceOptions" :key="item.id" :label="item.id">{{ item.name
  13. }}</el-radio-button>
  14. </el-radio-group>
  15. <el-input v-model="filters.content" placeholder="订单号/品牌/宠主/手机号" class="search-input" prefix-icon="Search"
  16. clearable @clear="handleSearch" @keyup.enter="handleSearch" />
  17. <el-button type="primary" icon="Search" @click="handleSearch">查询</el-button>
  18. <el-button type="success" icon="Download" @click="handleExport"
  19. v-hasPermi="['order:orderList:export']">导出Excel</el-button>
  20. </div>
  21. </div>
  22. <el-tabs v-model="filters.status" class="status-tabs" @tab-change="handleStatusTabChange">
  23. <el-tab-pane label="全部订单" name="" />
  24. <el-tab-pane label="待派单" name="0" />
  25. <el-tab-pane label="待接单" name="1" />
  26. <el-tab-pane label="待服务" name="2" />
  27. <el-tab-pane label="服务中" name="3" />
  28. <el-tab-pane label="已完成" name="4" />
  29. <el-tab-pane label="已取消" name="5" />
  30. <el-tab-pane label="已拒绝" name="6" />
  31. <el-tab-pane label="已关闭" name="7" />
  32. </el-tabs>
  33. </template>
  34. <el-table :data="tableData" style="width: 100%" v-loading="loading"
  35. :header-cell-style="{ background: '#f5f7fa' }">
  36. <el-table-column prop="code" label="订单号" width="170" fixed="left" />
  37. <el-table-column label="服务类型" width="190">
  38. <template #default="{ row }">
  39. <div class="service-type-cell">
  40. <el-tag>{{ getServiceName(row.service) }}</el-tag>
  41. <el-tag v-if="getServiceModeTag(row)" class="sub-tag" type="warning" effect="plain">{{
  42. getServiceModeTag(row) }}</el-tag>
  43. <el-tag v-if="getServiceOrderTypeTag(row)" class="sub-tag" :type="getServiceOrderTypeTag(row).type"
  44. effect="dark">{{
  45. getServiceOrderTypeTag(row).label
  46. }}</el-tag>
  47. </div>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="宠物信息" min-width="150">
  51. <template #default="{ row }">
  52. <div class="pet-info">
  53. <el-avatar :size="30" class="avatar-type">{{ row.petName?.charAt(0) }}</el-avatar>
  54. <div class="pet-detail">
  55. <div class="pet-name">
  56. {{ row.petName }}
  57. </div>
  58. <div class="pet-breed">{{ row.petBreed }}</div>
  59. </div>
  60. </div>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="所属用户" width="120" prop="customerName">
  64. <template #default="{ row }">
  65. <span style="font-weight: 500">{{ row.customerName }}</span>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="城市/区域" width="140">
  69. <template #default="{ row }">
  70. <div>{{ getCityDistrictText(row).city || '-' }}</div>
  71. <div class="sub-text">{{ getCityDistrictText(row).district || '-' }}</div>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="商户/下单人" min-width="160">
  75. <template #default="{ row }">
  76. <div class="merchant-info">
  77. <div>{{ row.storeName }}</div>
  78. <div class="sub-text" v-if="row.placerUsername">{{ row.placerUsername }}</div>
  79. </div>
  80. </template>
  81. </el-table-column>
  82. <el-table-column prop="createTime" label="下单时间" width="165" sortable>
  83. <template #default="{ row }">
  84. <span class="time-text">{{ row.createTime }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column prop="createTime" label="预约服务时间" width="165" sortable>
  88. <template #default="{ row }">
  89. <span class="time-text">{{ row.serviceTime }}</span>
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="订单状态" width="100">
  93. <template #default="{ row }">
  94. <div class="status-cell">
  95. <div class="status-dot" :class="getStatusClass(row.status)"></div>
  96. <span>{{ getStatusName(row.status) }}</span>
  97. </div>
  98. </template>
  99. </el-table-column>
  100. <el-table-column label="订单佣金" width="100">
  101. <template #default="{ row }">
  102. <span v-if="row.orderCommission !== null && row.orderCommission !== undefined"
  103. style="color: #f56c6c; font-weight: bold;">¥{{ row.orderCommission / 100.0
  104. }}</span>
  105. <span v-else>-</span>
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="履约者" width="120">
  109. <template #default="{ row }">
  110. <span v-if="row.fulfillerName" style="font-weight: 500; color: #333;">{{ row.fulfillerName }}</span>
  111. <span v-else class="text-gray">暂未指派</span>
  112. </template>
  113. </el-table-column>
  114. <el-table-column label="履约电话" width="130">
  115. <template #default="{ row }">
  116. <div v-if="row.fulfillerPhone" style="display: flex; align-items: center; gap: 4px;">
  117. <el-icon>
  118. <Phone />
  119. </el-icon>
  120. <span>{{ row.fulfillerPhone }}</span>
  121. </div>
  122. <span v-else>-</span>
  123. </template>
  124. </el-table-column>
  125. <el-table-column label="履约佣金" width="100">
  126. <template #default="{ row }">
  127. <span v-if="row.fulfillmentCommission !== null && row.fulfillmentCommission !== undefined"
  128. style="color: #f56c6c; font-size: 14px; font-weight: bold;">
  129. ¥{{ (row.fulfillmentCommission / 100).toFixed(2) }}
  130. </span>
  131. <span v-else>-</span>
  132. </template>
  133. </el-table-column>
  134. <el-table-column label="操作" width="240" fixed="right">
  135. <template #default="{ row }">
  136. <div class="op-cell">
  137. <el-button link type="primary" size="small" @click="handleDetail(row)"
  138. v-hasPermi="['order:orderList:query']">详情</el-button>
  139. <el-button v-if="row.serviceFlag === 2 && row.status !== 7" link type="success" size="small"
  140. @click="openActivateDialog(row)" v-hasPermi="['order:orderList:activate']">开通服务</el-button>
  141. <el-button v-if="row.status === 0" link type="success" size="small" @click="openDispatchDialog(row)"
  142. v-hasPermi="['order:orderList:dispatch']">派单</el-button>
  143. <el-button v-if="![0, 4, 7].includes(row.status)" link type="warning" size="small"
  144. @click="openDispatchDialog(row)" v-hasPermi="['order:orderList:redispatch']">重新派单</el-button>
  145. <el-button v-if="[0, 1].includes(row.status)" link type="danger" size="small" @click="handleCancel(row)"
  146. v-hasPermi="['order:orderList:cancel']">取消</el-button>
  147. <el-button v-if="![4, 5, 6, 7].includes(row.status)" link type="info" size="small"
  148. @click="handleClose(row)" v-hasPermi="['order:orderList:close']">关闭</el-button>
  149. <el-dropdown v-if="[3, 4].includes(row.status)" trigger="click"
  150. @command="(cmd) => handleCommand(cmd, row)">
  151. <span class="el-dropdown-link">
  152. 更多<el-icon class="el-icon--right">
  153. <ArrowDown />
  154. </el-icon>
  155. </span>
  156. <template #dropdown>
  157. <el-dropdown-menu>
  158. <el-dropdown-item v-if="row.status === 4 && getServiceMode(row.service) == 0" command="care_summary"
  159. v-hasPermi="['order:orderList:nursingSummary']">护理小结</el-dropdown-item>
  160. <el-dropdown-item command="reward" v-hasPermi="['order:orderList:reward']">奖惩</el-dropdown-item>
  161. <el-dropdown-item command="remark" v-hasPermi="['order:orderList:remark']">备注</el-dropdown-item>
  162. </el-dropdown-menu>
  163. </template>
  164. </el-dropdown>
  165. </div>
  166. </template>
  167. </el-table-column>
  168. </el-table>
  169. <div class="pagination-container">
  170. <el-pagination v-model:current-page="pagination.current" v-model:page-size="pagination.size"
  171. :page-sizes="[10, 20, 50, 100]" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
  172. @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  173. </div>
  174. </el-card>
  175. <!-- 组件 -->
  176. <OrderDetailDrawer v-model:visible="detailVisible" :order="currentOrder" @dispatch="openDispatchDialog"
  177. @cancel="handleCancel" @command="handleCommand" @care-summary="openCareSummary" />
  178. <DispatchDialog v-model:visible="dispatchDialogVisible" :order="currentDispatchOrder" @success="handleSearch" />
  179. <CareSummaryDrawer v-model:visible="careSummaryVisible" :order="careSummaryOrder" @submit="saveCareSummary" />
  180. <RewardDialog v-model:visible="rewardDialogVisible" :order="currentOperateRow" @submit="handleRewardSubmit" />
  181. <RemarkDialog v-model:visible="remarkDialogVisible" :order="currentOperateRow" @submit="handleRemarkSubmit" />
  182. <!-- 开通服务弹窗 -->
  183. <el-dialog v-model="activateDialogVisible" title="开通服务" width="400px" append-to-body>
  184. <el-form :model="activateForm" label-width="100px">
  185. <el-form-item label="履约佣金" required>
  186. <el-input-number v-model="activateForm.fulfillmentCommission" :min="0" :precision="2" :step="1"
  187. placeholder="请输入履约佣金(元)" style="width: 100%" />
  188. </el-form-item>
  189. <el-form-item label="服务说明">
  190. <el-input v-model="activateForm.serviceSpecification" type="textarea" placeholder="请输入服务说明(选填)" :rows="3"
  191. style="width: 100%" />
  192. </el-form-item>
  193. </el-form>
  194. <template #footer>
  195. <el-button @click="activateDialogVisible = false">取消</el-button>
  196. <el-button type="primary" :loading="activateLoading" @click="submitActivate">确认</el-button>
  197. </template>
  198. </el-dialog>
  199. </div>
  200. </template>
  201. <script setup lang="ts">
  202. import { ref, reactive, onMounted, onUnmounted, nextTick, getCurrentInstance } from 'vue';
  203. import { useRouter, useRoute } from 'vue-router';
  204. import { ElMessage, ElMessageBox } from 'element-plus';
  205. import fulfillerEnums from '@/json/fulfiller.json';
  206. import OrderDetailDrawer from './components/OrderDetailDrawer.vue';
  207. import DispatchDialog from '@/components/DispatchDialog/index.vue';
  208. import CareSummaryDrawer from './components/CareSummaryDrawer.vue';
  209. import RewardDialog from './components/RewardDialog.vue';
  210. import RemarkDialog from './components/RemarkDialog.vue';
  211. import { useIntervalRefresh } from '@/hooks/useIntervalRefresh';
  212. import { listAllService } from '@/api/service/list/index';
  213. import { listSubOrder } from '@/api/order/subOrder/index';
  214. import { getSubOrderInfo } from '@/api/order/subOrder/index';
  215. import { cancelSubOrder } from '@/api/order/subOrder/index';
  216. import { closeSubOrder } from '@/api/order/subOrder/index';
  217. import { remarkSubOrder } from '@/api/order/subOrder/index';
  218. import { confirmSubOrder } from '@/api/order/subOrder/index';
  219. import { nursingSummarySubOrder } from '@/api/order/subOrder/index';
  220. import { exportSubOrder } from '@/api/order/subOrder/index';
  221. import { activateSubOrder } from '@/api/order/subOrder/index';
  222. import { listAreaStation as listAreaStationOnStore } from '@/api/system/areaStation';
  223. import { getStore } from '@/api/system/store';
  224. import { reward } from '@/api/fulfiller/pool';
  225. // 获取全局实例,用于调用 proxy.download
  226. const { proxy } = getCurrentInstance() as any;
  227. import { getPet } from '@/api/archieves/pet';
  228. import { getCustomer } from '@/api/archieves/customer';
  229. const route = useRoute();
  230. const loading = ref(false);
  231. const filters = reactive({
  232. service: '',
  233. status: '',
  234. content: ''
  235. });
  236. const pagination = reactive({
  237. current: 1,
  238. size: 10,
  239. total: 100
  240. });
  241. const tableData = ref([]);
  242. const serviceOptions = ref([]);
  243. const areaStationList = ref([]);
  244. const areaStationMap = ref({});
  245. const storeMap = ref({});
  246. onMounted(() => {
  247. getServiceList();
  248. getAreaStationList();
  249. handleSearch();
  250. if (route.query.id) {
  251. handleDetail({ id: route.query.id as any });
  252. }
  253. });
  254. // 监听路由参数变化,实现从消息直达详情 @Author: Antigravity
  255. watch(() => route.query.id, (newId) => {
  256. if (newId) {
  257. handleDetail({ id: newId as any });
  258. }
  259. });
  260. // 统一数据轮询 @Author: Antigravity
  261. useIntervalRefresh(() => handleSearch(true), 5000);
  262. const getServiceList = () => {
  263. listAllService().then((res) => {
  264. serviceOptions.value = res.data || [];
  265. });
  266. };
  267. const getAreaStationList = () => {
  268. listAreaStationOnStore().then((res) => {
  269. const list = res.data || [];
  270. areaStationList.value = list;
  271. const map = {};
  272. for (const item of list) {
  273. if (item && item.id !== undefined && item.id !== null) map[item.id] = item;
  274. }
  275. areaStationMap.value = map;
  276. });
  277. };
  278. const getCityDistrictText = (row) => {
  279. if (!row) return { city: '', district: '' };
  280. const map = areaStationMap.value || {};
  281. let stationId = row.site;
  282. if (!map[stationId] && row.store) {
  283. const store = (storeMap.value || {})[row.store];
  284. if (store?.site) stationId = store.site;
  285. }
  286. if (!stationId) return { city: '', district: '' };
  287. const station = map[stationId];
  288. if (!station) return { city: '', district: '' };
  289. const parent = station.parentId ? map[station.parentId] : undefined;
  290. if (!parent) return { city: station.name || '', district: '' };
  291. if (parent.type === 0) return { city: parent.name || '', district: '' };
  292. if (parent.type === 1) {
  293. const city = parent.parentId ? map[parent.parentId] : undefined;
  294. return { city: city?.name || '', district: parent.name || '' };
  295. }
  296. return { city: '', district: parent.name || '' };
  297. };
  298. const handleStatusTabChange = async () => {
  299. pagination.current = 1;
  300. await nextTick();
  301. handleSearch();
  302. };
  303. const handleSearch = (isPolling: any = false) => {
  304. const isAutoPoll = isPolling === true;
  305. if (!isAutoPoll) {
  306. loading.value = true;
  307. }
  308. listSubOrder({
  309. pageNum: pagination.current,
  310. pageSize: pagination.size,
  311. service: filters.service !== '' ? filters.service : undefined,
  312. status: filters.status !== '' ? Number(filters.status) : undefined,
  313. content: filters.content || undefined
  314. })
  315. .then((res) => {
  316. tableData.value = res.rows || [];
  317. pagination.total = res.total || 0;
  318. loadStoresForRows(tableData.value);
  319. if (!isAutoPoll) loading.value = false;
  320. })
  321. .catch(() => {
  322. if (!isAutoPoll) loading.value = false;
  323. });
  324. };
  325. const loadStoresForRows = async (rows) => {
  326. const map = storeMap.value || {};
  327. const ids = Array.from(new Set((rows || []).map((r) => r?.store).filter(Boolean)));
  328. const missing = ids.filter((id) => map[id] === undefined);
  329. if (missing.length === 0) return;
  330. await Promise.all(
  331. missing.map(async (id) => {
  332. try {
  333. const res = await getStore(id);
  334. if (res?.data) map[id] = res.data;
  335. } catch {
  336. map[id] = null;
  337. }
  338. })
  339. );
  340. storeMap.value = { ...map };
  341. };
  342. const handleSizeChange = (val) => {
  343. pagination.size = val;
  344. handleSearch();
  345. };
  346. const handleCurrentChange = (val) => {
  347. pagination.current = val;
  348. handleSearch();
  349. };
  350. const getServiceName = (serviceId) => {
  351. const item = serviceOptions.value.find((i) => i.id === serviceId);
  352. return item ? item.name : '未知服务';
  353. };
  354. const getServiceMode = (serviceId) => {
  355. const item = serviceOptions.value.find((i) => i.id === serviceId);
  356. return item ? item.mode : null;
  357. };
  358. const getServiceModeTag = (row) => {
  359. if (getServiceMode(row.service) !== 1) return '';
  360. const t = row?.type;
  361. if (t === 0 || t === '0' || t === 1 || t === '1') return '往返';
  362. return '';
  363. };
  364. const getServiceOrderTypeTag = (row) => {
  365. if (getServiceMode(row.service) !== 1) return null;
  366. const t = row?.type;
  367. if (t === 0 || t === '0') return { label: '接', type: 'primary' as const };
  368. if (t === 1 || t === '1') return { label: '送', type: 'success' as const };
  369. if (t === 2 || t === '2') return { label: '单程接', type: 'primary' as const };
  370. if (t === 3 || t === '3') return { label: '单程送', type: 'success' as const };
  371. return null;
  372. };
  373. const getStatusName = (status) => {
  374. const map = { 0: '待派单', 1: '待接单', 2: '待服务', 3: '服务中', 4: '已完成', 5: '已取消', 6: '已拒绝', 7: '已关闭' };
  375. return map[status] || '未知';
  376. };
  377. const getStatusClass = (status) => {
  378. const map = { 0: 'pending', 1: 'waiting', 2: 'waiting', 3: 'processing', 4: 'completed', 5: 'cancelled', 6: 'rejected', 7: 'closed' };
  379. return map[status] || '';
  380. };
  381. const getFulfillerStatusText = (status) => {
  382. const statusMap = {
  383. resting: '休息',
  384. busy: '接单中',
  385. disabled: '禁用'
  386. };
  387. return statusMap[status] || status;
  388. };
  389. const getFulfillerStatusType = (status) => {
  390. const typeMap = {
  391. resting: 'info',
  392. busy: 'success',
  393. disabled: 'danger'
  394. };
  395. return typeMap[status] || 'info';
  396. };
  397. // 弹窗状态管理
  398. const detailVisible = ref(false);
  399. const currentOrder = ref(null);
  400. const dispatchDialogVisible = ref(false);
  401. const currentDispatchOrder = ref(null);
  402. const careSummaryVisible = ref(false);
  403. const careSummaryOrder = ref(null);
  404. const rewardDialogVisible = ref(false);
  405. const remarkDialogVisible = ref(false);
  406. const currentOperateRow = ref(null);
  407. // 开通服务相关
  408. const activateDialogVisible = ref(false);
  409. const activateLoading = ref(false);
  410. const activateForm = reactive({
  411. id: 0,
  412. fulfillmentCommission: 0,
  413. serviceSpecification: ''
  414. });
  415. const openActivateDialog = (row) => {
  416. activateForm.id = row.id;
  417. activateForm.fulfillmentCommission = row.fulfillmentCommission !== undefined && row.fulfillmentCommission !== null ? row.fulfillmentCommission / 100 : 0;
  418. activateForm.serviceSpecification = '';
  419. activateDialogVisible.value = true;
  420. };
  421. const submitActivate = async () => {
  422. if (!activateForm.fulfillmentCommission) {
  423. ElMessage.warning('请填写履约佣金');
  424. return;
  425. }
  426. activateLoading.value = true;
  427. try {
  428. await activateSubOrder({
  429. id: activateForm.id,
  430. fulfillmentCommission: Math.round(Number(activateForm.fulfillmentCommission) * 100),
  431. serviceSpecification: activateForm.serviceSpecification || undefined
  432. });
  433. ElMessage.success('开通服务成功');
  434. activateDialogVisible.value = false;
  435. handleSearch();
  436. } catch (error) {
  437. // interceptor handled
  438. } finally {
  439. activateLoading.value = false;
  440. }
  441. };
  442. // 详情
  443. const handleDetail = async (row) => {
  444. const typeName = getServiceName(row?.service);
  445. const isTransport = row?.mode === 1 || row?.mode === '1';
  446. const typeCode = isTransport ? 'transport' : typeName?.includes('喂') || typeName?.includes('遛') ? 'feeding' : 'washing';
  447. currentOrder.value = {
  448. ...row,
  449. orderCommission: row.orderCommission !== undefined && row.orderCommission !== null ? row.orderCommission / 100.0 : undefined,
  450. fulfillerFee: row.fulfillmentCommission !== undefined && row.fulfillmentCommission !== null ? row.fulfillmentCommission / 100.0 : undefined,
  451. orderNo: row?.code || row?.orderCode || row?.orderNo || row?.orderNumber || row?.no || '',
  452. type: row?.typeCode || row?.type || typeCode,
  453. serviceItem: getServiceName(row?.service) || row?.serviceName || row?.service || '',
  454. userAvatar: '',
  455. address: '',
  456. groupBuyPackage: '',
  457. transportType: row.splitType || row.transportType,
  458. detail: {
  459. ...row.detail,
  460. pickTime: '',
  461. pickAddr: row.detail?.pickAddr || '',
  462. pickContact: '',
  463. pickPhone: '',
  464. dropTime: '',
  465. dropAddr: row.detail?.dropAddr || '',
  466. dropContact: '',
  467. dropPhone: '',
  468. packageName: row.detail?.packageName || '',
  469. petStatus: '',
  470. area: ''
  471. },
  472. petGender: '',
  473. petAge: '',
  474. petWeight: '',
  475. petVaccine: '',
  476. petSterilized: undefined,
  477. petCharacter: '',
  478. petHealth: '',
  479. fulfillerAvatar: '',
  480. fulfillerPhone: '',
  481. fulfillerStation: '',
  482. orderLogs: []
  483. };
  484. try {
  485. const res = await getSubOrderInfo(row?.id);
  486. const info = res?.data?.data || res?.data;
  487. if (info) {
  488. currentOrder.value = {
  489. ...(currentOrder.value || {}),
  490. id: info.id,
  491. orderNo: info.code || currentOrder.value?.orderNo,
  492. code: info.code,
  493. subOrderType: info.type,
  494. status: info.status ?? currentOrder.value?.status,
  495. mode: info.mode ?? getServiceMode(info.service) ?? currentOrder.value?.mode,
  496. type: info.mode === 1 || info.mode === '1' ? 'transport' : currentOrder.value?.type,
  497. transportType: info.mode === 1 || info.mode === '1' ? 'round' : currentOrder.value?.transportType,
  498. serviceTime: info.serviceTime || currentOrder.value?.serviceTime,
  499. endServiceTime: info.endServiceTime || currentOrder.value?.endServiceTime,
  500. contact: info.contact || currentOrder.value?.contact,
  501. contactPhoneNumber: info.contactPhoneNumber || currentOrder.value?.contactPhoneNumber,
  502. toAddress: info.toAddress || currentOrder.value?.toAddress,
  503. address:
  504. info.mode === 1 || info.mode === '1'
  505. ? info.toAddress || currentOrder.value?.address
  506. : info.address || info.toAddress || currentOrder.value?.address,
  507. fulfillmentCommission: info.fulfillmentCommission !== undefined && info.fulfillmentCommission !== null ? Number(info.fulfillmentCommission) / 100 : currentOrder.value?.fulfillmentCommission,
  508. orderCommission: info.orderCommission !== undefined && info.orderCommission !== null ? Number(info.orderCommission) / 100 : currentOrder.value?.orderCommission,
  509. fulfillerFee: info.fulfillmentCommission !== undefined && info.fulfillmentCommission !== null ? Number(info.fulfillmentCommission) / 100 : currentOrder.value?.fulfillerFee,
  510. merchantName: info.storeName || currentOrder.value?.merchantName,
  511. platformId: info.platformId ?? currentOrder.value?.platformId,
  512. groupBuyPackage: info.groupPurchasePackageName || currentOrder.value?.groupBuyPackage,
  513. fulfiller: info.fulfiller ?? currentOrder.value?.fulfiller,
  514. detail: {
  515. ...(currentOrder.value?.detail || {}),
  516. pickTime: info.serviceTime || currentOrder.value?.detail?.pickTime,
  517. pickAddr: info.fromAddress || currentOrder.value?.detail?.pickAddr,
  518. pickContact: info.contact || currentOrder.value?.detail?.pickContact,
  519. pickPhone: info.contactPhoneNumber || currentOrder.value?.detail?.pickPhone,
  520. dropTime: info.endServiceTime || currentOrder.value?.detail?.dropTime,
  521. dropAddr: info.toAddress || currentOrder.value?.detail?.dropAddr,
  522. dropContact: info.contact || currentOrder.value?.detail?.dropContact,
  523. dropPhone: info.contactPhoneNumber || currentOrder.value?.detail?.dropPhone,
  524. fromAddress: info.fromAddress || currentOrder.value?.detail?.fromAddress,
  525. toAddress: info.toAddress || currentOrder.value?.detail?.toAddress,
  526. area: info.area || info.address || info.toAddress || currentOrder.value?.detail?.area,
  527. packageName: info.packageName || info.servicePackageName || info.package || currentOrder.value?.detail?.packageName,
  528. petStatus: info.petStatus || info.specialRequirement || info.requirement || currentOrder.value?.detail?.petStatus,
  529. fromCode: info.fromCode || currentOrder.value?.detail?.fromCode,
  530. toCode: info.toCode || currentOrder.value?.detail?.toCode
  531. }
  532. };
  533. }
  534. } catch { }
  535. detailVisible.value = true;
  536. };
  537. // 取消订单
  538. const handleCancel = (row: any) => {
  539. ElMessageBox.prompt('请输入订单取消原因', '订单确认取消', {
  540. confirmButtonText: '确认取消',
  541. cancelButtonText: '暂不取消',
  542. inputPlaceholder: '请输入取消原因(必填)',
  543. inputValidator: (value) => {
  544. if (!value || !value.trim()) {
  545. return '取消原因不能为空';
  546. }
  547. return true;
  548. },
  549. type: 'warning'
  550. }).then(({ value }) => {
  551. cancelSubOrder({ orderId: row?.id, reason: value }).then(() => {
  552. ElMessage.success('订单已成功取消');
  553. handleSearch();
  554. });
  555. }).catch(() => {
  556. // 用户取消输入
  557. });
  558. };
  559. const handleClose = (row: any) => {
  560. const statusName = getStatusName(row.status);
  561. ElMessageBox.confirm(
  562. `<div style="line-height: 1.8;">
  563. <p style="color: #f56c6c; font-weight: bold; margin-bottom: 10px;">⚠️ 一旦关闭,该订单将无法进行操作!</p>
  564. <p><strong>订单号:</strong>${row.code}</p>
  565. <p><strong>服务类型:</strong>${getServiceName(row.service)}</p>
  566. <p><strong>宠物名称:</strong>${row.petName || '-'}</p>
  567. <p><strong>当前状态:</strong>${statusName}</p>
  568. </div>`,
  569. '确认关闭订单',
  570. {
  571. confirmButtonText: '确认关闭',
  572. cancelButtonText: '取消',
  573. type: 'warning',
  574. dangerouslyUseHTMLString: true,
  575. }
  576. ).then(() => {
  577. closeSubOrder({ orderId: row?.id }).then(() => {
  578. ElMessage.success('订单已成功关闭');
  579. handleSearch();
  580. });
  581. }).catch(() => {
  582. // 用户取消
  583. });
  584. };
  585. // 派单
  586. const openDispatchDialog = (row) => {
  587. currentDispatchOrder.value = row;
  588. dispatchDialogVisible.value = true;
  589. };
  590. // 护理小结
  591. const openCareSummary = async (row) => {
  592. const orderData = {
  593. ...row,
  594. careSummary: row.nursingSummary || undefined
  595. };
  596. // 获取宠物信息
  597. const petId = row?.pet || row?.petId;
  598. if (petId) {
  599. try {
  600. const petRes = await getPet(petId);
  601. const pet = petRes?.data;
  602. if (pet) {
  603. orderData.petAge = pet.age ? `${pet.age}岁` : '未知';
  604. orderData.petGender = pet.gender || 'male';
  605. orderData.petTags = pet.tags || [];
  606. orderData.petWeight = pet.weight ? `${pet.weight} kg` : '未知';
  607. orderData.petPersonality = pet.personality || '未知';
  608. orderData.healthStatus = pet.healthStatus || '未知';
  609. orderData.vaccineImg = pet.vaccineImg || '';
  610. orderData.allergy = pet.allergy || '无';
  611. orderData.petBreed = pet.breed || '未知';
  612. }
  613. } catch { }
  614. }
  615. // 获取客户信息(宠物主人)
  616. const customerId = row?.customer || row?.customerId;
  617. if (customerId) {
  618. try {
  619. const customerRes = await getCustomer(customerId);
  620. const customer = customerRes?.data;
  621. if (customer) {
  622. orderData.userName = customer.name || orderData.userName;
  623. orderData.homeTime = customer.homeTime || '未知';
  624. orderData.houseType = customer.houseType || '未知';
  625. orderData.entryMethod = customer.entryMethod || '未知';
  626. orderData.entryDetail = customer.entryMethod === 'password'
  627. ? (customer.entryPassword ? `密码: ${customer.entryPassword}` : '未设置密码')
  628. : (customer.keyLocation || '未设置');
  629. }
  630. } catch { }
  631. }
  632. orderData.summaryTime = row.nursingSummaryTime || orderData.summaryTime;
  633. careSummaryOrder.value = orderData;
  634. careSummaryVisible.value = true;
  635. };
  636. const saveCareSummary = async (text) => {
  637. if (!careSummaryOrder.value?.id) {
  638. ElMessage.warning('订单信息不存在');
  639. return;
  640. }
  641. try {
  642. await nursingSummarySubOrder({
  643. orderId: careSummaryOrder.value.id,
  644. content: text
  645. });
  646. if (careSummaryOrder.value) {
  647. careSummaryOrder.value.careSummary = text;
  648. careSummaryOrder.value.nursingSummary = text;
  649. }
  650. ElMessage.success('护理小结已保存');
  651. handleSearch();
  652. } catch {
  653. // Error handled by interceptor
  654. }
  655. };
  656. // 奖惩
  657. const openRewardDialog = (row) => {
  658. const typeName = getServiceName(row?.service);
  659. const isTransport = row?.mode === 1 || row?.mode === '1';
  660. const typeCode = isTransport ? 'transport' : typeName?.includes('喂') || typeName?.includes('遛') ? 'feeding' : 'washing';
  661. const t = row?.subOrderType ?? row?.type;
  662. const transportType =
  663. typeof t === 'number' ? (t === 0 ? 'pick' : t === 1 ? 'drop' : t === 2 ? 'round' : undefined) :
  664. (t === 'pick' || t === 'drop' || t === 'round' ? t : undefined);
  665. currentOperateRow.value = {
  666. ...row,
  667. orderNo: row?.code || row?.orderNo,
  668. type: typeCode,
  669. transportType,
  670. splitType: row?.splitType
  671. };
  672. rewardDialogVisible.value = true;
  673. };
  674. const handleRewardSubmit = async (form) => {
  675. if (!currentOperateRow.value?.fulfiller) {
  676. ElMessage.warning('当前订单未指派履约者,无法执行奖惩操作');
  677. return;
  678. }
  679. try {
  680. // 针对余额(balance)目标,将元转为分
  681. const submitAmount = form.item === 'balance' ? Math.round(form.value * 100) : form.value;
  682. await reward({
  683. fulfillerId: currentOperateRow.value.fulfiller,
  684. type: form.type,
  685. target: form.item,
  686. amount: submitAmount,
  687. reason: form.reason,
  688. bizType: form.type === fulfillerEnums.ActionType.ADD ? 'order_reward' : 'order_punish',
  689. orderId: currentOperateRow.value.id
  690. } as any);
  691. ElMessage.success(`操作成功:${form.type === fulfillerEnums.ActionType.ADD ? '增加' : '减少'}已执行`);
  692. handleSearch();
  693. } catch {
  694. // Error handled by interceptor
  695. }
  696. };
  697. // 备注
  698. const openRemarkDialog = (row) => {
  699. currentOperateRow.value = {
  700. ...row,
  701. orderNo: row?.code || row?.orderNo
  702. };
  703. remarkDialogVisible.value = true;
  704. };
  705. const handleRemarkSubmit = async (text) => {
  706. if (!currentOperateRow.value?.id) {
  707. ElMessage.warning('订单信息不存在');
  708. return;
  709. }
  710. try {
  711. await remarkSubOrder({ orderId: currentOperateRow.value.id, remark: text });
  712. ElMessage.success('备注添加成功');
  713. remarkDialogVisible.value = false;
  714. handleSearch();
  715. } catch { /* handled by interceptor */ }
  716. };
  717. // 更多操作
  718. const handleCommand = (cmd, row) => {
  719. if (cmd === 'reward') openRewardDialog(row);
  720. if (cmd === 'remark') openRemarkDialog(row);
  721. if (cmd === 'care_summary') openCareSummary(row);
  722. if (cmd === 'complete') {
  723. ElMessageBox.confirm('确认将该订单手动标记为完成吗?', '提示', { type: 'warning' }).then(async () => {
  724. try {
  725. await confirmSubOrder({ id: row.id });
  726. ElMessage.success('订单已确认完成');
  727. handleSearch();
  728. } catch {
  729. // Error handled by interceptor
  730. }
  731. }).catch(() => { });
  732. }
  733. if (cmd === 'delete') {
  734. ElMessageBox.confirm('确认删除该订单吗?此操作不可恢复', '警告', { type: 'error' }).then(() => {
  735. tableData.value = tableData.value.filter((item) => item.id !== row.id);
  736. ElMessage.success('订单已删除');
  737. });
  738. }
  739. };
  740. /** 导出为Excel */
  741. const handleExport = () => {
  742. proxy?.download(
  743. 'order/subOrder/export',
  744. {
  745. status: filters.status !== '' ? Number(filters.status) : undefined,
  746. service: filters.service !== '' ? filters.service : undefined,
  747. content: filters.content || undefined
  748. },
  749. '订单列表.xlsx'
  750. );
  751. };
  752. </script>
  753. <style scoped>
  754. .page-container {
  755. padding: 20px;
  756. }
  757. .card-header {
  758. display: flex;
  759. justify-content: space-between;
  760. align-items: center;
  761. }
  762. .left-panel {
  763. display: flex;
  764. align-items: center;
  765. gap: 12px;
  766. }
  767. .title {
  768. font-weight: bold;
  769. font-size: 18px;
  770. }
  771. .right-panel {
  772. display: flex;
  773. gap: 10px;
  774. align-items: center;
  775. }
  776. .search-input {
  777. width: 220px;
  778. }
  779. .status-tabs {
  780. margin-top: 10px;
  781. margin-bottom: -10px;
  782. }
  783. .pagination-container {
  784. display: flex;
  785. justify-content: flex-end;
  786. margin-top: 20px;
  787. }
  788. /* Table Content Styles */
  789. .service-type-cell {
  790. display: flex;
  791. flex-direction: row;
  792. gap: 4px;
  793. align-items: center;
  794. }
  795. .sub-tag {
  796. font-size: 11px;
  797. height: 20px;
  798. padding: 0 5px;
  799. }
  800. .pet-info {
  801. display: flex;
  802. align-items: center;
  803. gap: 10px;
  804. }
  805. .pet-info .el-avatar {
  806. background: #e0eaff;
  807. color: #409eff;
  808. font-weight: bold;
  809. flex-shrink: 0;
  810. }
  811. .pet-info .avatar-feeding {
  812. background: #fdf6ec;
  813. color: #e6a23c;
  814. }
  815. .pet-info .avatar-washing {
  816. background: #f0f9eb;
  817. color: #67c23a;
  818. }
  819. .pet-detail {
  820. display: flex;
  821. flex-direction: column;
  822. line-height: 1.4;
  823. }
  824. .pet-name {
  825. font-weight: bold;
  826. font-size: 14px;
  827. color: #303133;
  828. }
  829. .pet-breed {
  830. color: #909399;
  831. font-weight: normal;
  832. font-size: 12px;
  833. }
  834. .merchant-info {
  835. display: flex;
  836. flex-direction: column;
  837. line-height: 1.4;
  838. }
  839. .sub-text {
  840. font-size: 12px;
  841. color: #999;
  842. }
  843. .text-gray {
  844. color: #ccc;
  845. font-style: italic;
  846. }
  847. .time-text {
  848. font-size: 13px;
  849. color: #606266;
  850. }
  851. .status-cell {
  852. display: flex;
  853. align-items: center;
  854. }
  855. .status-dot {
  856. width: 6px;
  857. height: 6px;
  858. border-radius: 50%;
  859. margin-right: 6px;
  860. background-color: #909399;
  861. }
  862. .status-dot.pending_dispatch {
  863. background-color: #f56c6c;
  864. box-shadow: 0 0 4px rgba(245, 108, 108, 0.4);
  865. }
  866. .status-dot.pending_accept {
  867. background-color: #e6a23c;
  868. }
  869. .status-dot.serving {
  870. background-color: #409eff;
  871. }
  872. .status-dot.pending_confirm {
  873. background-color: #bf24e8;
  874. }
  875. .status-dot.completed {
  876. background-color: #67c23a;
  877. }
  878. .status-dot.cancelled {
  879. background-color: #909399;
  880. }
  881. .op-cell {
  882. display: flex;
  883. align-items: center;
  884. gap: 8px;
  885. }
  886. .el-dropdown-link {
  887. cursor: pointer;
  888. color: #409eff;
  889. font-size: 12px;
  890. display: flex;
  891. align-items: center;
  892. line-height: 1;
  893. height: 24px;
  894. }
  895. </style>