<route lang="json5" type="page">
{
  style: {
    navigationStyle: "custom",
    navigationBarTitleText: "支付确认",
    navigationBarBackgroundColor: "#FFF",
  },
}
</route>

<template>
  <view
    class="flex flex-col flex-items-center flex-justify-between page-wrapper"
  >
    <view class="info">
      <view class="title-small">订单详情</view>
      <view class="flex detail-info">
        <view class="detail-img">
          <image :src="orderDetail.main_image" mode="scaleToFill" />
        </view>
        <view class="detail-other">
          <view class="flex flex-justify-between name-info">
            <text>{{ orderDetail.product_name }}</text>
            <text
              ><text style="font-size: 20rpx">￥</text
              >{{ orderDetail.order_amount }}元</text
            >
          </view>
          <view class="flex flex-justify-between count-info">
            <text>数量</text>
            <text>x1</text>
          </view>
        </view>
      </view>
      <view class="line"></view>
      <view class="order-info">
        <view class="order-item"
          >充值账户：{{ orderDetail.account ? maskPhoneNumber(orderDetail.account) : '' }}</view
        >
        <view class="order-item">充值类型：{{ orderDetail.product_type }}</view>
        <!-- <view class="order-item">优惠金额：{{ discount }}</view> -->
      </view>
      <view class="line"></view>
      <!-- <view class="order-info">
            <view class="count-item">共 1 件，应付总额：<text style="text-decoration: line-through;">￥{{ detail.order_amount }}</text></view>
            <view class="number-item">实际支付：¥{{ detail.order_amount }}</view>
        </view> -->
    </view>
    <view class="pay-btn" @click="goPay">立即支付</view>
  </view>
</template>

<script setup>
import { onShow, onLoad } from "@dcloudio/uni-app";
import { ref, reactive, unref, onMounted, computed } from "vue";
import { createOrder, getOrderList } from "@/api/ycysp";
import usePay from "./hooks/usePay";
import config from './config';
const orderDetail = reactive({});

const _order_no = ref("");

onLoad((options) => {
  const { order_no } = options;
  _order_no.value = order_no;
});

const discount = computed(() => {
  if (!unref(_product)) return 0;
  return (
    (Number(unref(_product).price) * 100 -
      Number(unref(_product).sell_price) * 100) /
    100
  );
});

function maskPhoneNumber(phoneNumber) {
  return phoneNumber.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
}

const goPay = () => {
  const { payFunc } = usePay();
  const { order_no, notify_url, sign, plain_text } = orderDetail.pay_info;
  payFunc({
    order_no,
    notify_url,
    TranAmt: orderDetail.order_amount,
    MerName: orderDetail.brandName,
    sign,
    plain_text,
  });
};

onMounted(() => {
  getDetail();
});

const getDetail = () => {
  const params = {
    order_no: unref(_order_no),
  };
  getOrderList({ params }).then((res) => {
    const { total, list } = res;
    Object.assign(orderDetail, res.list[0]);
  });
};
</script>
<style scoped lang="scss">
.page-wrapper {
  width: 100vw;
  height: 100vh;
  opacity: 1;
  // background: linear-gradient(180deg, #FFFFFF 18%, #F3F3F3 40%, #FAFBFD 60%, #FAFBFD 61%, #FAFBFD 65%);
  background: #fafbfd;
  padding: 33rpx 0;
  box-sizing: border-box;
}
.info {
  width: 702rpx;
  // height: 514rpx;
  height: 374rpx;
  border-radius: 24rpx;
  opacity: 1;
  background: #ffffff;
  box-sizing: border-box;
  padding: 32rpx 24rpx;
}
.line {
  width: 100%;
  height: 1rpx;
  background: #e1e1f0;
  transform: scaleY(0.5);
}
.title-small {
  font-size: 28rpx;
  font-weight: normal;
  line-height: 32rpx;
  letter-spacing: 0rpx;
  color: #333333;
}
.detail-info {
  padding: 24rpx 0;
}
.detail-img {
  width: 92rpx;
  height: 92rpx;
  margin-right: 30rpx;
  image {
    width: 100%;
    height: 100%;
  }
}
.detail-other {
  flex: 1;
  font-weight: 400;
  line-height: 32rpx;
  letter-spacing: 0rpx;
  .name-info {
    font-size: 24rpx;
    color: #333333;
  }
  .count-info {
    font-size: 20rpx;
    color: #9e9e9e;
    margin-top: 12rpx;
  }
}
.order-info {
  padding-bottom: 24rpx;
}
.order-item {
  font-size: 22rpx;
  font-weight: normal;
  line-height: 32rpx;
  letter-spacing: 0rpx;
  color: #6c6c6c;
  margin-top: 24rpx;
}
.bottom {
  font-weight: 400;
  line-height: 32rpx;
  text-align: right;
  font-style: normal;
  text-transform: none;
}
.count-item {
  font-size: 22rpx;
  color: #878787;
  text-align: right;
  margin-top: 16rpx;
}
.number-item {
  font-size: 24rpx;
  color: #2e92ff;
  text-align: right;
  margin-top: 16rpx;
}
.pay-btn {
  width: 710rpx;
  height: 88rpx;
  /* 自动布局 */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 12rpx 28rpx;
  border-radius: 392rpx;
  opacity: 1;
  background: linear-gradient(270deg, #2c91ff 0%, #9ad2ff 100%);
  box-sizing: border-box;
  font-size: 32rpx;
  font-weight: normal;
  line-height: normal;
  letter-spacing: 0em;
  color: #ffffff;
}
</style>
