Express.js 4.43 KB
const LOGISTICS_STATUS = {
  1000: "待揽件",
  1001: "已揽件",
  1002: "运输中",
  1003: "已签收",
  1004: "拒收",
};
Component({
  properties: {
    expressInfo: {
      type: Object,
      value: {},
      observer: function (val) {
        if (!val) return;
        this.processExpressInfo(val);
      },
    },
    showAll: {
      type: Boolean,
      value: false,
    },
    // height: {
    //   type: String,
    //   value: '256rpx'
    // }
  },
  data: {
    logisticsData: {},
    // timelineData: [
    //   {
    //     time: "2021-02-02 10:30:30",
    //     tips: ["这是主要内容部分"],
    //     title: "已发货",
    //     type: 'active',// 高亮显示
    //   },
    //   {
    //     time: "2021-02-02 10:30:30",
    //     tips: ["这是主要内容部分"],
    //     title:'运输中',
    //     type: 'small',// 小点显示
    //   },
    //   {
    //     time: "2021-02-02 10:30:30",
    //     tips: ["这是主要内容部分11111111111",
    //       "这是主要内容部分11111111111",
    //       "这是主要内容部分11111111111"
    //     ],
    //     title:'运输中',
    //     type: 'normal',
    //   },
    //   {
    //     title:'收货地址',
    //     tips: ["这是主要内容部分"],
    //     type: 'special'  // 地址节点,使用专门的样式
    //   }
    // ],
  },
  methods: {
    processShipmentTrack(shipmentTrack, logisticsStatus) {
      if (!shipmentTrack || !shipmentTrack.length) return;
      if (!this.data.showAll) {
        shipmentTrack = shipmentTrack.slice(0, 2);
      }
      return shipmentTrack
        .map((track, index) => {
          let status = 1000;
          let statusDesc = "待揽件";
          const content = track.content;
          const operateTime = track.operateTime;
          const isLast = index === 0;
          // 根据内容判断状态
          if (content.includes("已签收") || content.includes("签收人")) {
            status = 1003;
            statusDesc = "已签收";
          } else if (content.includes("拒收") || content.includes("退回")) {
            status = 1004;
            statusDesc = "拒收";
          } else if (
            content.includes("派件") ||
            content.includes("驿站") ||
            content.includes("暂存")
          ) {
            status = 1002;
            statusDesc = "运输中";
          } else if (
            content.includes("转运中心") ||
            content.includes("发往") ||
            content.includes("到达")
          ) {
            status = 1002;
            statusDesc = "运输中";
          } else if (content.includes("已收件") || content.includes("揽收")) {
            status = 1001;
            statusDesc = "已揽件";
          } else if (content.includes("已发往")) {
            status = 1001;
            statusDesc = "已揽件";
          }

          // 根据整体物流状态进行最终调整
          if (logisticsStatus < status) {
            // 如果整体状态低于当前轨迹状态,说明该轨迹尚未完成
            statusDesc = LOGISTICS_STATUS[logisticsStatus] + "(进行中)";
          }

          return {
            ...track,
            type: isLast ? "active" : "small",
            status,
            statusDesc,
          };
        })
        .filter((track) => {
          // 根据整体物流状态过滤轨迹
          switch (logisticsStatus) {
            case 1000: // 待揽件 - 只显示收件相关记录
              return track.status === 1000;
            case 1001: // 已揽件 - 显示揽件和发往记录
              return track.status <= 1001;
            case 1002: // 运输中 - 显示所有运输中的记录
              return track.status <= 1002;
            case 1003: // 已签收 - 显示所有记录
              return track.status <= 1003;
            case 1004: // 拒收 - 显示所有记录
              return track.status <= 1004;
            default:
              return true;
          }
        });
    },
    processExpressInfo(expressInfo) {
      const { logisticsStatus, shipmentTrack, ...rest } = expressInfo;
      const processedTrack = this.processShipmentTrack(
        shipmentTrack,
        logisticsStatus
      );
      const logisticsData = {
        ...rest,
        logisticsStatus,
        logisticsStatusDesc: LOGISTICS_STATUS[logisticsStatus],
        shipmentTrack: processedTrack,
      };
      this.setData({
        logisticsData,
      });
    },
  },
});