| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- <template>
- <view class="logistics-page">
- <!-- 顶部包裹切换 -->
- <scroll-view scroll-x class="package-tabs" :scroll-into-view="'tab-' + currentPackageIndex">
- <view class="tab-list">
- <view class="tab-item" v-for="(item, index) in packages" :key="index" :id="'tab-' + index"
- :class="{ active: currentPackageIndex === index }" @click="switchPackage(index)">
- {{ item.name }}
- </view>
- </view>
- </scroll-view>
- <!-- 物流基本信息 -->
- <view class="card info-card">
- <view class="info-row">
- <text class="label">承运商:</text>
- <text class="value">{{ currentPackage.expressName }}</text>
- </view>
- <view class="info-row">
- <text class="label">物流单号:</text>
- <text class="value">{{ currentPackage.waybillCode }}</text>
- <view class="copy-btn" @click="copyTrackingNo">复制</view>
- </view>
- </view>
- <!-- 物流轨迹 -->
- <view class="card timeline-card">
- <!-- 收货地址 -->
- <view class="timeline-item address-item">
- <view class="left-col">
- <view class="icon-box address-icon">收</view>
- <view class="line"></view>
- </view>
- <view class="right-col">
- <view class="status-title">收货地址:{{ currentPackage.receiveAddress }}</view>
- </view>
- </view>
- <!-- 轨迹列表 -->
- <view class="timeline-item" v-for="(trace, index) in currentPackage.trackingVoList" :key="index">
- <view class="left-col">
- <!-- 不同状态显示不同图标 -->
- <view v-if="index === 0 && trace.status === '已签收'" class="icon-box check-icon">
- <u-icon name="checkmark" color="#fff" size="20"></u-icon>
- </view>
- <view v-else-if="trace.status === '派送中'" class="icon-box delivery-icon">
- <u-icon name="man" color="#fff" size="24"></u-icon> <!-- 使用uView图标或自定义 -->
- </view>
- <view v-else-if="trace.status === '运输中'" class="icon-box transport-icon">
- <u-icon name="car" color="#fff" size="24"></u-icon>
- </view>
- <view v-else-if="trace.status === '已下单'" class="icon-box order-icon">
- <u-icon name="order" color="#fff" size="24"></u-icon>
- </view>
- <view v-else class="dot"></view>
- <view class="line" v-if="index !== currentPackage.trackingVoList.length - 1"></view>
- </view>
- <view class="right-col" :class="{ 'is-first': index === 0 }">
- <view class="status-title">{{ trace.status }}</view>
- <view class="status-desc">{{ trace.context }}</view>
- <view class="status-time">{{ trace.ftime }}</view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- currentPackageIndex: 0,
- packages: [], // Changed to empty array, will be populated by API
- orderId: '',
- refundOrderId: ''
- };
- },
- onLoad(options) {
- if (options.orderId) {
- this.orderId = options.orderId;
- this.getLogisticsData();
- } else if (options.refundOrderId) {
- this.refundOrderId = options.refundOrderId;
- this.getLogisticsData();
- }
- },
- computed: {
- currentPackage() {
- return this.packages[this.currentPackageIndex] || {};
- }
- },
- methods: {
- getLogisticsData() {
- uni.showLoading({
- title: '加载中'
- });
- const params = {};
- if (this.orderId) params.orderId = this.orderId;
- if (this.refundOrderId) params.refundOrderId = this.refundOrderId;
- this.$u.api.getOrderTrackingAjax(params).then(res => {
- uni.hideLoading();
- if (res.code == 200) {
- const data = res.data;
-
- // 直接使用后端返回的字段
- this.packages = [{
- name: '包裹1', // 前端固定名称,因为接口只返回一个包裹信息
- ...data
- }];
- } else {
- this.$u.toast(res.msg || '获取物流信息失败');
- }
- }).catch(() => {
- uni.hideLoading();
- this.$u.toast('网络请求失败');
- });
- },
- switchPackage(index) {
- this.currentPackageIndex = index;
- },
- copyTrackingNo() {
- if (!this.currentPackage.waybillCode) return;
- uni.setClipboardData({
- data: this.currentPackage.waybillCode,
- success: () => {
- uni.showToast({
- title: '复制成功',
- icon: 'none'
- });
- }
- });
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .logistics-page {
- min-height: 100vh;
- background-color: #f5f5f5;
- padding: 20rpx;
- padding-bottom: 40rpx;
- }
- .package-tabs {
- white-space: nowrap;
- margin-bottom: 20rpx;
- .tab-list {
- display: flex;
- padding: 10rpx 0;
- }
- .tab-item {
- display: inline-block;
- padding: 12rpx 36rpx;
- background-color: #ccc; // Default gray
- color: #fff;
- font-size: 28rpx;
- border-radius: 8rpx;
- margin-right: 20rpx;
- transition: all 0.3s;
- &.active {
- background-color: #38C148; // Theme green
- font-weight: bold;
- }
- &:last-child {
- margin-right: 0;
- }
- }
- }
- .card {
- background-color: #fff;
- border-radius: 16rpx;
- padding: 30rpx;
- margin-bottom: 20rpx;
- }
- .info-card {
- .info-row {
- display: flex;
- align-items: center;
- margin-bottom: 20rpx;
- font-size: 30rpx;
- &:last-child {
- margin-bottom: 0;
- }
- .label {
- color: #333;
- width: 160rpx;
- font-weight: 500;
- }
- .value {
- color: #333;
- font-weight: 500;
- }
- .copy-btn {
- font-size: 24rpx;
- color: $app-theme-color;
- background-color: #edf7e8;
- padding: 4rpx 12rpx;
- border-radius: 4rpx;
- margin-left: 20rpx;
- }
- }
- }
- .timeline-card {
- padding: 30rpx 20rpx;
- }
- .timeline-item {
- display: flex;
- position: relative;
- .left-col {
- width: 80rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- margin-right: 10rpx;
- position: relative;
- .line {
- width: 2rpx;
- background-color: #eee;
- flex: 1;
- min-height: 40rpx;
- margin-top: 10rpx;
- margin-bottom: -10rpx; // Connect to next
- }
- .icon-box {
- width: 40rpx;
- height: 40rpx;
- border-radius: 50%;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 20rpx;
- z-index: 1;
- &.address-icon {
- background-color: #ff5b5b;
- color: #fff;
- }
- &.check-icon {
- background-color: #ff5b5b;
- }
- &.delivery-icon,
- &.transport-icon,
- &.order-icon {
- background-color: #ccc;
- }
- }
- .dot {
- width: 16rpx;
- height: 16rpx;
- background-color: #eee;
- border-radius: 50%;
- margin-top: 12rpx;
- z-index: 1;
- }
- }
- .right-col {
- flex: 1;
- padding-bottom: 40rpx;
- &.is-first {
- .status-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #333;
- }
- .status-desc {
- color: #333;
- }
- }
- .status-title {
- font-size: 30rpx;
- font-weight: 500;
- color: #333;
- margin-bottom: 10rpx;
- line-height: 1.4;
- }
- .status-desc {
- font-size: 26rpx;
- color: #999;
- line-height: 1.5;
- margin-bottom: 10rpx;
- }
- .status-time {
- font-size: 24rpx;
- color: #999;
- }
- }
- &.address-item {
- .right-col {
- padding-bottom: 30rpx;
- .status-title {
- font-weight: bold;
- margin-bottom: 0;
- }
- }
- }
- }
- </style>
|