logisticsDetail.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <el-drawer v-model="visible" title="物流信息" size="38%" direction="rtl" :before-close="handleClose" :close-on-click-modal="true">
  3. <div class="logistics-detail">
  4. <div class="section-title">单号查询</div>
  5. <el-form :model="form" label-width="80px">
  6. <el-form-item label="物流单号">
  7. <el-select v-model="form.selectedLogisticNo" placeholder="请选择物流单号" @change="handleLogisticNoChange" style="width: 100%">
  8. <el-option
  9. v-for="item in logisticsList"
  10. :key="item.id"
  11. :label="`${item.logisticNo || item.deliverCode},${getDictLabel(deliver_method, item.deliverMethod)}`"
  12. :value="item.logisticNo || item.deliverCode"
  13. />
  14. </el-select>
  15. </el-form-item>
  16. </el-form>
  17. <div class="section-title">物流信息</div>
  18. <el-timeline v-if="logisticsInfo.length > 0">
  19. <el-timeline-item v-for="(item, index) in logisticsInfo" :key="index" :timestamp="item.time" placement="top">
  20. <div class="timeline-content">
  21. <div class="timeline-status">{{ index + 1 }}</div>
  22. <div class="timeline-detail">
  23. <div>{{ item.time }}</div>
  24. <div>{{ item.location }}</div>
  25. <div>{{ item.status }}</div>
  26. <div v-if="item.imagesUrl" class="timeline-images">
  27. <div class="image-label">签收图片:</div>
  28. <div class="image-list">
  29. <el-image
  30. v-for="(url, imgIndex) in item.imagesUrl.split(',')"
  31. :key="imgIndex"
  32. :src="url"
  33. :preview-src-list="item.imagesUrl.split(',')"
  34. :initial-index="imgIndex"
  35. fit="cover"
  36. class="sign-image"
  37. >
  38. <template #error>
  39. <div class="image-error">
  40. <el-icon><Picture /></el-icon>
  41. </div>
  42. </template>
  43. </el-image>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </el-timeline-item>
  49. </el-timeline>
  50. <el-empty v-else description="暂无物流信息" />
  51. </div>
  52. </el-drawer>
  53. </template>
  54. <script setup lang="ts">
  55. import { listOrderDeliver, queryTrack } from '@/api/order/orderDeliver';
  56. import { OrderDeliverVO } from '@/api/order/orderDeliver/types';
  57. import { listOrderStatusLog } from '@/api/order/orderStatusLog';
  58. import { Picture } from '@element-plus/icons-vue';
  59. interface Props {
  60. modelValue: boolean;
  61. orderId?: string | number;
  62. }
  63. interface LogisticsInfo {
  64. time: string;
  65. location: string;
  66. status: string;
  67. imagesUrl: string;
  68. }
  69. const props = defineProps<Props>();
  70. const emit = defineEmits(['update:modelValue']);
  71. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  72. const { deliver_method } = toRefs<any>(proxy?.useDict('deliver_method'));
  73. const visible = ref(false);
  74. const logisticsList = ref<OrderDeliverVO[]>([]);
  75. const form = ref({
  76. id: null,
  77. selectedLogisticNo: ''
  78. });
  79. const logisticsInfo = ref<LogisticsInfo[]>([]);
  80. watch(
  81. () => props.modelValue,
  82. (val) => {
  83. visible.value = val;
  84. if (val && props.orderId) {
  85. loadLogisticsList();
  86. }
  87. }
  88. );
  89. watch(visible, (val) => {
  90. emit('update:modelValue', val);
  91. });
  92. const loadLogisticsList = async () => {
  93. try {
  94. const res = await listOrderDeliver({
  95. orderId: props.orderId,
  96. pageNum: 1,
  97. pageSize: 100
  98. });
  99. logisticsList.value = res.rows || [];
  100. if (logisticsList.value.length > 0) {
  101. form.value.selectedLogisticNo = logisticsList.value[0].logisticNo || logisticsList.value[0].deliverCode;
  102. form.value.id = logisticsList.value[0].id;
  103. handleLogisticNoChange(form.value.selectedLogisticNo, form.value.id);
  104. }
  105. } catch (error) {
  106. console.error('Failed to load logistics list:', error);
  107. }
  108. };
  109. const handleLogisticNoChange = async (logisticNo: string, id: string) => {
  110. const selected = logisticsList.value.find((item) => item.logisticNo === logisticNo);
  111. try {
  112. if (selected) {
  113. const res = await queryTrack({
  114. id: form.value.id,
  115. logisticNo: logisticNo,
  116. logisticsCompanyCode: selected.logisticsCompanyCode,
  117. //先使用送货人手机号其实应该是收货人手机号
  118. phone: selected.consigneePhone,
  119. pageNum: 1,
  120. pageSize: 100
  121. });
  122. // 1. 兼容处理:有些接口返回在 res.data,有些可能直接是 res
  123. const dataList = res.data || [];
  124. if (Array.isArray(dataList) && dataList.length > 0) {
  125. logisticsInfo.value = dataList.map((item: any) => {
  126. // 2. 核心修复:精准匹配时间字段
  127. // 顺丰用 'time',韵达用 'ftime'。
  128. // 优先取 ftime (韵达标准),如果没有则取 time (顺丰标准)
  129. const displayTime = item.ftime || item.time || item.acceptTime || '';
  130. return {
  131. time: displayTime,
  132. // 3. 建议:保留原始状态字段,方便后续筛选(如"已签收")
  133. status: item.context || item.content || '',
  134. // 4. 建议:如果有地址字段,也可以映射进来,没有则保持订单号
  135. location: item.location || (selected.orderCode ? `${selected.orderCode}` : ''),
  136. imagesUrl: ''
  137. };
  138. });
  139. }
  140. } else {
  141. await listOrderStatusLog({
  142. orderId: props.orderId,
  143. logisticNos: form.value.selectedLogisticNo,
  144. logisticsCompanyCode: selected?.logisticsCompanyCode,
  145. pageNum: 1,
  146. pageSize: 100
  147. }).then((res) => {
  148. logisticsInfo.value = res.rows.map((item: any) => {
  149. return {
  150. time: item.createTime,
  151. location: item.orderCode ? `${item.orderCode}` : '',
  152. status: item.statusName,
  153. imagesUrl: item.imagesUrl
  154. };
  155. });
  156. });
  157. // logisticsInfo.value = [
  158. // {
  159. // time: (selected as any).createTime || '',
  160. // location: selected.orderCode ? `${selected.orderCode}` : '',
  161. // status: '已下单'
  162. // }
  163. // ];
  164. }
  165. } catch (error) {
  166. console.error('Failed to query track:', error);
  167. logisticsInfo.value = [
  168. {
  169. time: (selected as any).createTime || '',
  170. location: selected.orderCode ? `${selected.orderCode}` : '',
  171. status: '已下单',
  172. imagesUrl: ''
  173. }
  174. ];
  175. }
  176. };
  177. const getDictLabel = (dictOptions: any[], value: string) => {
  178. if (!dictOptions || !value) return value;
  179. const dict = dictOptions.find((item) => item.value === value);
  180. return dict ? dict.label : value;
  181. };
  182. const handleClose = () => {
  183. visible.value = false;
  184. form.value.selectedLogisticNo = '';
  185. logisticsInfo.value = [];
  186. };
  187. </script>
  188. <style scoped lang="scss">
  189. .logistics-detail {
  190. .section-title {
  191. font-size: 16px;
  192. font-weight: 500;
  193. margin-bottom: 16px;
  194. color: #303133;
  195. }
  196. .timeline-content {
  197. display: flex;
  198. align-items: flex-start;
  199. gap: 12px;
  200. .timeline-status {
  201. width: 24px;
  202. height: 24px;
  203. border-radius: 50%;
  204. background-color: #409eff;
  205. color: white;
  206. display: flex;
  207. align-items: center;
  208. justify-content: center;
  209. font-size: 12px;
  210. flex-shrink: 0;
  211. }
  212. .timeline-detail {
  213. flex: 1;
  214. div {
  215. margin-bottom: 4px;
  216. color: #606266;
  217. font-size: 14px;
  218. &:last-child {
  219. margin-bottom: 0;
  220. }
  221. }
  222. .timeline-images {
  223. margin-top: 8px;
  224. padding-top: 8px;
  225. border-top: 1px dashed #dcdfe6;
  226. .image-label {
  227. font-size: 13px;
  228. color: #909399;
  229. margin-bottom: 6px;
  230. }
  231. .image-list {
  232. display: flex;
  233. flex-wrap: wrap;
  234. gap: 8px;
  235. .sign-image {
  236. width: 60px;
  237. height: 60px;
  238. border-radius: 4px;
  239. border: 1px solid #dcdfe6;
  240. cursor: pointer;
  241. .image-error {
  242. width: 100%;
  243. height: 100%;
  244. display: flex;
  245. align-items: center;
  246. justify-content: center;
  247. background-color: #f5f7fa;
  248. color: #c0c4cc;
  249. }
  250. }
  251. }
  252. }
  253. }
  254. }
  255. :deep(.el-timeline-item__timestamp) {
  256. display: none;
  257. }
  258. }
  259. </style>