<template>
  <view class="page">
    <text class="tips">金币可以用来生成写真和制作视频</text>
    <view
      v-for="item in coinList"
      class="orderListItem"
      :class="active == item.id ? 'border' : ''"
      @click="select(item)"
    >
      <image src="../../assets/icon/coin.png" mode="scaleToFill" />
      <text class="num">{{ item.title }}</text>
      <text class="price">￥{{ item.sellPriceRmb / 100 }}</text>
    </view>
    <view class="buyBtn">
      <view class="btn" @click="createProductOrder">立刻购买</view>
      <view class="pro" @click="goPro">《慧拍金币充值协议》</view>
    </view>
  </view>
</template>

<script setup>
//#region 导入
import { ref, reactive } from "vue";
import { getCoinList, createOrder, createPay } from "../../api/coin.js";
//#endregion --------------

//#region 列表数据
const active = ref("");
const coinList = ref([]);
function select(item) {
  active.value = item.id;
}
const goPro = () => {
  uni.navigateTo({
    url: "/pages/protocol/coin",
  });
};

const getList = async () => {
  try {
    const res = await getCoinList(5, 1);
    coinList.value = res.data.list;
    console.log(coinList.value, "coinList.value");
  } catch (error) {
    console.log(error, "error");
  }
};

const createProductOrder = async () => {
  try {
    const res = await createOrder(1);
    console.log(res, "res");
    // createProductPay()
  } catch (error) {
    console.log(error, "error");
  }
};

const createProductPay = async () => {
  try {
    const res = await createPay(1);
    console.log(res, "res");
  } catch (error) {
    console.log(error, "error");
  }
};

getList();
</script>

<style lang="scss">
.tips {
  font-size: 33rpx;
  margin-top: 70rpx;
  margin-bottom: 70rpx;
}

.orderListItem {
  position: relative;
  margin-bottom: 40rpx;
  padding: 0 70rpx 0 30rpx;
  width: 690rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 140rpx;
  line-height: 120rpx;
  font-size: 40rpx;
  background-color: #484848;
  border-radius: 36rpx;
  font-size: 30rpx;
  font-weight: 900;
  border: 6px solid #484848;
  transform: scale(1);
  transition: all 0.3s;
  image {
    width: 53rpx;
    height: 53rpx;
    margin-right: 25rpx;
  }
  .num {
    font-size: 36rpx;
    flex: 1;
  }
}
.border {
  transform: scale(1.03);
  border: 6px solid #ff4f00;
}

.buyBtn {
  position: absolute;
  bottom: 80rpx;
  .btn {
    width: 520rpx;
    height: 100rpx;
    background: #ff4f00;
    border-radius: 50rpx;
    text-align: center;
    line-height: 100rpx;
    font-size: 30rpx;
    font-weight: bold;
    margin-bottom: 40rpx;
  }
  .pro {
    text-align: center;
    color: #ff4f00;
  }
}
</style>
