logisticsDetail.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. selectedLogisticNo: ''
  77. });
  78. const logisticsInfo = ref<LogisticsInfo[]>([]);
  79. watch(
  80. () => props.modelValue,
  81. (val) => {
  82. visible.value = val;
  83. if (val && props.orderId) {
  84. loadLogisticsList();
  85. }
  86. }
  87. );
  88. watch(visible, (val) => {
  89. emit('update:modelValue', val);
  90. });
  91. const loadLogisticsList = async () => {
  92. try {
  93. const res = await listOrderDeliver({
  94. orderId: props.orderId,
  95. pageNum: 1,
  96. pageSize: 100
  97. });
  98. logisticsList.value = res.rows || [];
  99. if (logisticsList.value.length > 0) {
  100. form.value.selectedLogisticNo = logisticsList.value[0].logisticNo || logisticsList.value[0].deliverCode;
  101. handleLogisticNoChange(form.value.selectedLogisticNo);
  102. }
  103. } catch (error) {
  104. console.error('Failed to load logistics list:', error);
  105. }
  106. };
  107. const handleLogisticNoChange = async (logisticNo: string) => {
  108. const selected = logisticsList.value.find((item) => item.logisticNo === logisticNo);
  109. try {
  110. if (selected) {
  111. const res = await queryTrack({
  112. logisticNo: logisticNo,
  113. logisticsCompanyCode: selected.logisticsCompanyCode,
  114. //先使用送货人手机号其实应该是收货人手机号
  115. phone: selected.consigneePhone,
  116. pageNum: 1,
  117. pageSize: 100
  118. });
  119. // 1. 兼容处理:有些接口返回在 res.data,有些可能直接是 res
  120. const dataList = res.data || [];
  121. if (Array.isArray(dataList) && dataList.length > 0) {
  122. logisticsInfo.value = dataList.map((item: any) => {
  123. // 2. 核心修复:精准匹配时间字段
  124. // 顺丰用 'time',韵达用 'ftime'。
  125. // 优先取 ftime (韵达标准),如果没有则取 time (顺丰标准)
  126. const displayTime = item.ftime || item.time || item.acceptTime || '';
  127. return {
  128. time: displayTime,
  129. // 3. 建议:保留原始状态字段,方便后续筛选(如"已签收")
  130. status: item.context || item.content || '',
  131. // 4. 建议:如果有地址字段,也可以映射进来,没有则保持订单号
  132. location: item.location || (selected.orderCode ? `${selected.orderCode}` : ''),
  133. imagesUrl: ''
  134. };
  135. });
  136. }
  137. } else {
  138. await listOrderStatusLog({
  139. orderId: props.orderId,
  140. logisticNos: form.value.selectedLogisticNo,
  141. logisticsCompanyCode: selected?.logisticsCompanyCode,
  142. pageNum: 1,
  143. pageSize: 100
  144. }).then((res) => {
  145. logisticsInfo.value = res.rows.map((item: any) => {
  146. return {
  147. time: item.createTime,
  148. location: item.orderCode ? `${item.orderCode}` : '',
  149. status: item.statusName,
  150. imagesUrl: item.imagesUrl
  151. };
  152. });
  153. });
  154. // logisticsInfo.value = [
  155. // {
  156. // time: (selected as any).createTime || '',
  157. // location: selected.orderCode ? `${selected.orderCode}` : '',
  158. // status: '已下单'
  159. // }
  160. // ];
  161. }
  162. } catch (error) {
  163. console.error('Failed to query track:', error);
  164. logisticsInfo.value = [
  165. {
  166. time: (selected as any).createTime || '',
  167. location: selected.orderCode ? `${selected.orderCode}` : '',
  168. status: '已下单',
  169. imagesUrl: ''
  170. }
  171. ];
  172. }
  173. };
  174. const getDictLabel = (dictOptions: any[], value: string) => {
  175. if (!dictOptions || !value) return value;
  176. const dict = dictOptions.find((item) => item.value === value);
  177. return dict ? dict.label : value;
  178. };
  179. const handleClose = () => {
  180. visible.value = false;
  181. form.value.selectedLogisticNo = '';
  182. logisticsInfo.value = [];
  183. };
  184. </script>
  185. <style scoped lang="scss">
  186. .logistics-detail {
  187. .section-title {
  188. font-size: 16px;
  189. font-weight: 500;
  190. margin-bottom: 16px;
  191. color: #303133;
  192. }
  193. .timeline-content {
  194. display: flex;
  195. align-items: flex-start;
  196. gap: 12px;
  197. .timeline-status {
  198. width: 24px;
  199. height: 24px;
  200. border-radius: 50%;
  201. background-color: #409eff;
  202. color: white;
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. font-size: 12px;
  207. flex-shrink: 0;
  208. }
  209. .timeline-detail {
  210. flex: 1;
  211. div {
  212. margin-bottom: 4px;
  213. color: #606266;
  214. font-size: 14px;
  215. &:last-child {
  216. margin-bottom: 0;
  217. }
  218. }
  219. .timeline-images {
  220. margin-top: 8px;
  221. padding-top: 8px;
  222. border-top: 1px dashed #dcdfe6;
  223. .image-label {
  224. font-size: 13px;
  225. color: #909399;
  226. margin-bottom: 6px;
  227. }
  228. .image-list {
  229. display: flex;
  230. flex-wrap: wrap;
  231. gap: 8px;
  232. .sign-image {
  233. width: 60px;
  234. height: 60px;
  235. border-radius: 4px;
  236. border: 1px solid #dcdfe6;
  237. cursor: pointer;
  238. .image-error {
  239. width: 100%;
  240. height: 100%;
  241. display: flex;
  242. align-items: center;
  243. justify-content: center;
  244. background-color: #f5f7fa;
  245. color: #c0c4cc;
  246. }
  247. }
  248. }
  249. }
  250. }
  251. }
  252. :deep(.el-timeline-item__timestamp) {
  253. display: none;
  254. }
  255. }
  256. </style>