<template>
  <view>
    <m-nav-bar title="开通会员" :transparent="true" />
    <div class="buyvip-box">
      <img class="top-img" :src="topImg" alt="头部背景" />
      <div class="info-warn">您还未开通完整版系统，付费购买后享受更多功能</div>
      <div class="item-box">
        <van-cell class="cell-title" title="选择充值方式" />
        <div class="radio-box">
          <div
            v-for="(item, index) in goodsList"
            class="radio-item"
            :class="{ select: index === goodsIndex }"
            :key="index"
            @click="
              () => {
                goodsIndex = index;
              }
            "
          >
            <span>{{ item.dictLabel }}</span>
            <div v-if="index === 1" class="radio-item-recom">推荐</div>
            <span>¥{{ item.dictValue.split(",")[0] }}</span>
            <span>原价{{ item.dictValue.split(",")[1] }}元</span>
          </div>
        </div>
      </div>
      <div class="item-box">
        <van-cell class="cell-title" title="使用说明" />
        <div class="readme">
          <span>1. 有效期内拥有VIP权限.</span>
          <span>2. 过期后可以使用免费用户的权限.</span>
          <span>3. 可以续费.</span>
        </div>
      </div>
      <div class="button-box">
        <div v-if="!isIos" class="button" @click="buy">立即开通</div>
        <div v-if="isIos&&!ios_vip_open" class="button_gray">ios不支持</div>
        <div v-if="isIos&&ios_vip_open" class="button" @click="buy">立即开通</div>
      </div>
      <div style="height: 60px"></div>
    </div>
  </view>
</template>

<script>
import topImg from "./top-background.png";
import api from "@/api/index";
export default {
  data() {
    return {
      isIos:false,
      ios_vip_open:0,
      goodsList: [
        {
          searchValue: null,
          createBy: "admin",
          createTime: "2021-11-18 18:01:26",
          updateTime: null,
          updateBy: null,
          remark: null,
          params: {},
          dictCode: 29,
          dictSort: 0,
          dictLabel: "一个月",
          dictValue: "38,48,30",
          dictType: "vip_type_price",
          cssClass: null,
          listClass: null,
          isDefault: "N",
          status: "0",
          default: false,
        },
        {
          searchValue: null,
          createBy: "admin",
          createTime: "2021-11-18 18:01:39",
          updateTime: null,
          updateBy: null,
          remark: null,
          params: {},
          dictCode: 30,
          dictSort: 0,
          dictLabel: "六个月",
          dictValue: "68,98,180",
          dictType: "vip_type_price",
          cssClass: null,
          listClass: null,
          isDefault: "N",
          status: "0",
          default: false,
        },
        {
          searchValue: null,
          createBy: "admin",
          createTime: "2021-11-18 18:01:50",
          updateTime: null,
          updateBy: null,
          remark: null,
          params: {},
          dictCode: 31,
          dictSort: 0,
          dictLabel: "两年",
          dictValue: "98,128,730",
          dictType: "vip_type_price",
          cssClass: null,
          listClass: null,
          isDefault: "N",
          status: "0",
          default: false,
        },
      ],
      goodsIndex: 1,
      topImg,
    };
  },
  methods: {
    buy(e) {
      api.buy
        .studentXcxWxPrepareOrder({
          dictCode: this.goodsList[this.goodsIndex].dictCode,
        })
        .then((res) => {
          uni.requestPayment({
            ...res.data,
          });
        });
    },
  },
  mounted() {
    const systemInfo = wx.getSystemInfoSync()
    console.log(systemInfo)
    api.buy.systemConfigConfigKeyIos_vip_open().then(res=>{
      this.ios_vip_open = Number(res.data)
    })
    this.isIos = systemInfo.platform=='ios'
    api.buy.systemDictDataType("vip_type_price").then((res) => {
      this.goodsList = res.data;
    });
  },
};
// import { getVipPrice, prepareOrder } from "@/api";
// const goodsIndex = ref(1);
// const goodsList = ref<any[]>([]);
// getVipPrice().then((res) => {
//   goodsList.value = res.data;
// });
// const buy = () => {
//   prepareOrder(goodsList.value[goodsIndex.value].dictCode);
// };
</script>

<style scoped lang="scss">
.buyvip-box {
  width: 100%;
  margin-top: -50px;
  min-height: 100vh;
  display: flex;
  align-items: center;
  flex-direction: column;
  background: #ffdda6;
  .top-img {
    width: 100%;
  }
  .info-warn {
    width: 345px;
    height: 49px;
    background: #ffffff;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #91540f;
    margin-top: -70px;
    margin-bottom: 10px;
  }
  .item-box {
    width: 345px;
    background: #ffffff;
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 10px;
    .cell-title {
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: bold;
      line-height: 20px;
      color: #0a1a33;
      margin-left: -10px;
      margin-bottom: 15px;
    }
  }
  .readme {
    display: flex;
    flex-direction: column;
    font-size: 13px;
    line-height: 20px;
    span {
      margin-bottom: 5px;
    }
  }
  .radio-box {
    display: flex;
    justify-content: space-around;
    align-items: center;
    .select {
      background: #fcf1de !important;
    }
    .radio-item {
      position: relative;
      .radio-item-recom {
        position: absolute;
        top: 0;
        width: 30px;
        height: 15px;
        line-height: 15px;
        font-size: 10px;
        background: #ff4d53;
        border-radius: 0%;
        right: 0;
        transform: translate(15%, -30%);
        border-radius: 5px 0px 5px 0px;
        color: #fff;
      }
    }
    div {
      width: 98px;
      font-size: 20px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-around;
      background: #ffffff;
      border: 1px solid #faca93;
      height: 124px;
      border-radius: 5px;
      span {
        font-family: PingFang SC;
        &:nth-of-type(1) {
          font-size: 13px;
          font-weight: bold;
          color: #91540f;
        }
        &:nth-of-type(2) {
          font-size: 30px;
          font-weight: bold;
          color: #ff4d53;
        }
        &:nth-of-type(3) {
          font-size: 11px;
          font-weight: 400;
          color: #8a9099;
          text-decoration: line-through;
        }
      }
    }
  }
  .button-box {
    position: fixed;
    background-color: #ffffff;
    bottom: 0;
    width: 375px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    .button_gray {
      width: 152px;
      height: 40px;
      background: #b1b1b1;
      border-radius: 30px;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #fff;
      letter-spacing: 0px;
    }
    .button {
      width: 152px;
      height: 40px;
      background: #faca93;
      border-radius: 30px;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #91540f;
      letter-spacing: 0px;

      &:active {
        background-color: red;
      }
    }
  }
}
</style>
