<template>
  <wd-popup
    v-model="show"
    position="bottom"
    :safe-area-inset-bottom="true"
    custom-style="border-radius: 16rpx 16rpx 0 0; height: 80vh"
    @close="show = false"
    lockScroll
  >
    <view class="content">
      <view class="header">
        <view class="rowbox">
          <view class="title">快递详情</view>
          <wd-icon name="close" size="10" color="#333" @tap="close"></wd-icon>
        </view>
        <view class="top">
          <view class="left">
            <image class="logo" src="/static/ticket/logo.png" mode="aspectFill"></image>
            <text>中通快递78810259271088</text>
          </view>
          <view class="right">
            <text>复制</text>
            <text>丨</text>
            <text>打电话</text>
          </view>
        </view>
      </view>
    </view>
    <view class="steps">
      <wd-steps :active="1" vertical>
        <wd-step>
          <template #icon>
            <view class="dot-red"></view>
          </template>
          <template #title>
            <view class="titlebox">
              <text class="title red-title">待取件</text>
              <text class="time red">06-25 17:37</text>
            </view>
          </template>
          <template #description>
            <view class="desc">您购买的包裹已暂存至贵阳市市政公园菜鸟驿站， 请凭取件码取件。</view>
          </template>
        </wd-step>
        <wd-step>
          <template #icon>
            <view class="dot"></view>
          </template>
          <template #title>
            <view class="titlebox">
              <text class="title">派送中</text>
              <text class="time">06-25 09:05</text>
            </view>
          </template>
          <template #description>
            <rich-text class="desc1" :nodes="detail"></rich-text>
          </template>
        </wd-step>
        <wd-step>
          <template #icon>
            <view class="dot"></view>
          </template>
          <template #title>
            <view class="titlebox">
              <text class="title">运输中</text>
              <text class="time">06-25 05:15</text>
            </view>
          </template>
          <template #description>
            <text class="desc2">【贵阳市】快件已到达 贵阳小河二部</text>
          </template>
        </wd-step>
        <wd-step>
          <template #icon>
            <view class="dot"></view>
          </template>
          <template #title>
            <view class="titlebox">
              <text class="time">06-20 01:25</text>
            </view>
          </template>
          <template #description>
            <text class="desc2">【黔南布依族苗族自治州】快件已发往 贵阳小河二部</text>
          </template>
        </wd-step>
        <wd-step>
          <template #icon>
            <view class="dot"></view>
          </template>
          <template #title>
            <view class="titlebox" @tap="close">
              <text class="time">收起更多物流</text>
              <wd-icon name="chevron-up" size="28rpx" color="#999"></wd-icon>
            </view>
          </template>
        </wd-step>
      </wd-steps>
    </view>
    <view class="bottom">
      <view class="b-icon">收</view>
      <view class="right">
        <text class="title">送至 贵阳市市政公园正门菜鸟驿站</text>
        <view class="rowbox">
          <text class="text1">李先生 +86-187****4253</text>
          <text class="text">隐藏保护中</text>
        </view>
      </view>
    </view>
  </wd-popup>
</template>

<script setup>
const show = ref(false);
// 正则表达式匹配电话号码
const phoneRegex = /\b(\d{3,4}-\d{7,8}|\d{11})\b/g;

const highlightedText = (val) => {
  return val.replace(phoneRegex, '<span class="highlight">$1</span>');
};
const detail = ref(
  '【贵阳市】贵阳小河二部的业务员【文凯凯， 18784286692】正在为您派件（95720为中通快递员外呼专属号码，请放心接听，如有问题可联系网点：0851-83876676，投诉电话：0851-83876678）',
);
const open = () => {
  detail.value = highlightedText(detail.value);
  show.value = true;
};
const close = () => {
  show.value = false;
};
defineExpose({
  open,
  close,
});
</script>

<style lang="scss" scoped>
.content {
  display: flex;
  flex-direction: column;

  .header {
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid #ededed;
    padding: 20rpx 30rpx 33rpx;
    gap: 26rpx;

    .rowbox {
      display: flex;
      align-items: center;
      justify-content: space-between;

      .title {
        font-size: 32rpx;
        font-weight: bold;
        color: #333;
        text-align: center;
        width: 100%;
      }
    }

    .top {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .left {
        display: flex;
        align-items: center;
        gap: 16rpx;

        .logo {
          width: 36rpx;
          height: 36rpx;
          border-radius: 50%;
        }

        text {
          font-family: PingFang SC;
          font-weight: 500;
          font-size: 28rpx;
          color: #333333;
        }
      }

      .right {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 16rpx;

        text {
          font-family: PingFang SC;
          font-weight: 500;
          font-size: 24rpx;
          color: #333333;
        }
      }
    }
  }
}

.steps {
  padding: 28rpx 30rpx;

  &:deep(.wd-step__icon.is-icon) {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30rpx;
    height: 30rpx;
    top: 8rpx;
  }

  &:deep(.wd-step.is-vertical .wd-step__line) {
    top: 16rpx;
  }

  .dot {
    width: 30rpx;
    height: 27rpx;
    border-radius: 50%;
    border: 2rpx solid #c9c9c9;
  }

  .dot-red {
    background-color: #f12a2a;
    width: 30rpx;
    height: 30rpx;
    border-radius: 50%;
  }

  .titlebox {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 33rpx;

    text {
      font-family:
        PingFang SC,
        PingFang SC;
      font-size: 28rpx;
      color: #999999;
    }

    .title {
      font-size: 32rpx;
    }

    .red-title {
      color: #ff0909;
      font-weight: bold;
    }

    .red {
      color: #ff0909;
    }
  }

  .desc {
    font-family:
      PingFang SC,
      PingFang SC;
    font-size: 28rpx;
    color: #333333;
    line-height: 34rpx;
  }

  .desc1 {
    font-family:
      PingFang SC,
      PingFang SC;
    font-size: 24rpx;
    color: #999999;
  }

  .desc2 {
    font-family:
      PingFang SC,
      PingFang SC;
    font-size: 28rpx;
    color: #999999;
  }

  .highlight {
    color: #ff0909;
  }
}

.bottom {
  display: flex;
  gap: 18rpx;
  padding: 0rpx 30rpx 33rpx;

  .b-icon {
    font-family:
      PingFang SC,
      PingFang SC;
    font-size: 24rpx;
    color: #ff0909;
    border: 1rpx solid #ff0909;
    border-radius: 50%;
    width: 34rpx;
    height: 34rpx;
    text-align: center;
  }

  .right {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6rpx;
    .title {
      font-family:
        PingFang SC,
        PingFang SC;
      font-weight: bold;
      font-size: 32rpx;
      color: #333333;
    }

    .rowbox {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .textbox {
        display: flex;
        flex-direction: row;
        gap: 30rpx;
        align-items: center;
      }

      .title {
        font-family: PingFang SC;
        font-weight: bold;
        font-size: 32rpx;
        color: #ff0909;
      }

      .text {
        font-family: PingFang SC;
        font-weight: 500;
        font-size: 28rpx;
        color: #ff0909;
      }

      .detail {
        font-family: PingFang SC;
        font-weight: 500;
        font-size: 28rpx;
        color: #ff0909;
      }

      .text1 {
        font-family: PingFang SC;
        font-weight: 500;
        font-size: 28rpx;
        color: #333333;
      }
    }
  }
}
</style>
