<template>
  <view class="exchange_detail">
    <dHeader :title="detail.exchangeTitle"></dHeader>
    <div class="container">
      <div class="header">
        <div class="header-image">
          <image class="img" src="../../static/img/exchange.png"></image>
        </div>
        <div class="header-content">
          <div class="header-content-title">
            {{ locale === "zh" ? detailInfo.statusZh : detailInfo.statusEn }}
          </div>
          <div class="header-content-text">
            <view class="header-content-small">{{ detail.total }}</view
            >{{ detailInfo.totalCount }}{{ detail.integral }}
          </div>
        </div>
      </div>
      <div class="nav">
        <div class="nav-image">
          <image class="img" :src="locale === 'zh' ? detailInfo.imgZh : detailInfo.imgEn"></image>
        </div>
        <div class="nav-content">
          <div class="nav-content-text">
            {{ locale === "zh" ? detailInfo.rewardTitleZh : detailInfo.rewardTitleEn }}
          </div>
          <div class="nav-content-tag">
            <div class="tag-image">
              <image class="img" src="../../static/img/score_b.png"></image
              >{{ detailInfo.oncePointsRequire }}
            </div>
            <view class="tag-text">
              {{ detail.num(detailInfo.rewardCount) }}
            </view>
          </div>
        </div>
      </div>
      <div class="main">
        <div class="main-cell">
          <div class="cell-label">{{ detail.activityTime }}</div>
          <div class="cell-content">
            {{ getTimeRange(detailInfo.startTime, detailInfo.endTime) }}
          </div>
        </div>
        <div class="main-cell">
          <div class="cell-label">{{ detail.exchangeOutlets }}</div>
          <div class="cell-content">
            {{ locale === "zh" ? detailInfo.nodeTitleZh : detailInfo.nodeTitleEn }}
          </div>
        </div>
        <div class="main-cell">
          <div class="cell-label">{{ detail.exchangeType }}</div>
          <div class="cell-content">
            {{ locale === "zh" ? detailInfo.redeemTypeZh : detailInfo.redeemTypeEn }}
          </div>
        </div>
        <template v-if="detailInfo.redeemType != 1">
          <div class="main-cell">
            <div class="cell-label">{{ detail.address }}</div>
            <div class="cell-content">
              {{ detailInfo.recipientName }}&ensp;+{{ detailInfo.recipientPhoneNum }},
              {{ detailInfo.recipientAddress }}
              <view class="red">{{ detail.errorMsg }}</view>
            </div>
          </div>
          <div class="main-cell">
            <div class="cell-label">{{ detail.courierNum }}</div>
            <div class="cell-content">{{ detailInfo.expressNo }}</div>
          </div>
          <div class="main-cell">
            <div class="cell-label">{{ detail.courierCompany }}</div>
            <div class="cell-content">{{ detailInfo.courierCompanyName }}</div>
          </div>
          <div class="main-cell">
            <div class="cell-label">{{ detail.courierTime }}</div>
            <div class="cell-content">
              {{ formatDate(detailInfo.expressDate) }}
            </div>
          </div>
        </template>
        <div class="main-cell">
          <div class="cell-label">{{ detail.remark }}</div>
          <div class="cell-content">{{ detailInfo.remark }}</div>
        </div>
      </div>
    </div>
  </view>
</template>

<script>
import dHeader from "../../components/dHeader/index.vue"
export default {
  components: {
    dHeader
  },
  data() {
    return {
      id: null,
      detailInfo: {}
    }
  },
  onLoad(route) {
    console.log(route)
    this.id = route.id
    this.getDetail()
  },
  computed: {
    locale() {
      return this.$lang.locale
    },
    detail() {
      return this.$lang.lang.detail
    }
  },
  methods: {
    // 获取详情
    getDetail() {
      this.$request
        .post("/app-api/reward/redeem/record/detail", {
          redeemId: this.id
        })
        .then(({ code, data }) => {
          if (code == 0 && data) {
            this.detailInfo = data
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    // 时间范围返回
    getTimeRange(start, end) {
      return `${this.formatDate(start)}${this.detail.to}${this.formatDate(end)}`
    },
    // 时间戳转换为YYYY-MM-DD HH:mm:ss
    formatDate(timestamp) {
      if (!timestamp) return ""
      const date = new Date(timestamp)
      const year = date.getFullYear()
      const month = String(date.getMonth() + 1).padStart(2, "0")
      const day = String(date.getDate()).padStart(2, "0")
      const hours = String(date.getHours()).padStart(2, "0")
      const minutes = String(date.getMinutes()).padStart(2, "0")
      const seconds = String(date.getSeconds()).padStart(2, "0")
      return `${year}-${month}-${day}`
    }
  }
}
</script>

<style lang="scss">
page {
  /* #ifdef H5 */
  padding-top: 140upx;
  /* #endif */
  /* #ifdef APP-PLUS */
  padding-top: calc(var(--status-bar-height) + 100upx);
  /* #endif */

  box-sizing: border-box;
  height: 100%;
  background: linear-gradient(#317beb, #d3e5fe);
}
.exchange_detail {
  padding: 50upx 40upx;
  height: inherit;
  box-sizing: border-box;
  background-color: #fff;
  border-top-right-radius: 20upx;
  border-top-left-radius: 20upx;
  background: linear-gradient(#fff, #d3e5fe);
}
.header {
  display: flex;
  box-sizing: border-box;
  .header-image {
    width: 90upx;
    height: 90upx;
    .img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
  .header-content {
    margin-left: 20upx;
    display: flex;
    height: inherit;
    flex-direction: column;
    justify-content: space-between;
    .header-content-title {
      font-size: 26upx;
      color: #333;
    }
    .header-content-text {
      display: flex;
      align-items: end;
      font-size: 24upx;
      color: #666;

      .header-content-small {
        margin-right: 10upx;
        font-size: 20upx;
        color: #999;
      }
    }
  }
}
.nav {
  margin-top: 60upx;
  width: 100%;
  display: flex;
  .nav-image {
    width: 140upx;
    height: 140upx;
    .img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
  .nav-content {
    flex: 1;
    margin-left: 20upx;
    display: flex;
    height: inherit;
    flex-direction: column;
    .nav-content-text {
      width: 70%;
      font-size: 24upx;
      color: var(--cb7b);
    }
    .nav-content-tag {
      margin-top: auto;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .tag-image {
        display: flex;
        align-items: center;
        .img {
          width: 32upx;
          height: 32upx;
          object-fit: cover;
        }
      }
      .tag-text {
        font-size: 24upx;
        color: #666;
      }
    }
  }
}
.main {
  margin-top: 60upx;
  width: 100%;
  display: flex;
  flex-direction: column;
  .main-cell {
    margin-top: 20upx;
    width: 100%;
    display: flex;
    align-items: start;
    justify-content: space-between;
    .cell-label {
      width: 30%;
      font-size: 24upx;
      color: #333;
    }
    .cell-content {
      text-align: right;
      width: 70%;
      font-size: 24upx;
      color: var(--cb7b);
      .red {
        color: red;
        font-size: 16upx;
      }
    }
  }
}
</style>
