<template>
  <div class="vip">
    <div class="vip-item" v-for="(item, index) in vipArr" :key="index">
      <div class="time">{{ item.price }}元/月</div>
      <div class="discount">
        <div class="discount-nuw">{{ item.pricePercentage }}折</div>
        <div class="sale-word">热销中! 超值体验</div>
      </div>
      <div class="openNow" @click="toPay(item.id)">马上开通</div>
    </div>
  </div>
</template>

<script>
import { errToast, alert, toast } from "@/utils/uniapi.js";
import apiStore from '@/apis/apiStore';
import { handleCreatePay } from '@/utils/uniapi.js'
import orderPage from '@/apis/orderPage'
export default {
  data() {
    return {
      vipArr: []
    }
  },
  async created() {
    let res = await apiStore.getConfigInfo('vip')
    // console.log(res);
    res.map(item => {
      item.price = (item.price / 100).toFixed()
      item.pricePercentage = (item.pricePercentage / 10).toFixed(1)
      //item.id = item.id
    })
    this.vipArr = res
    // console.log(this.vipArr);
  },
  methods: {
    async toPay(id) {
      // let subAppID = ''
      // subAppID='wxf3657c94aa01a3f0'
      try {
        let payInfo = null

        // #ifdef MP-WEIXIN
        payInfo = await orderPage.pay4User({
          thingID: Number(id),
          payType: 3,
          vendorPayType: "W06",
          subAppID:'wx4b5930c13f8b1170',
        })
        await handleCreatePay(
          payInfo.vendorOrderID,
          payInfo.prepayID,
          JSON.parse(payInfo.codeURL)
        );
        // #endif

        // #ifdef APP-PLUS || APP
        // let payInfo = await orderPage.pay4User({
        //   thingID: Number(id),
        //   payType: 3,
        //   vendorPayType: "W06",
        //   subAppID:'wxf3657c94aa01a3f0',
        // })
        // console.log('打印订单信息',payInfo);
        // await handleCreatePay(
        //   payInfo.vendorOrderID,
        //   payInfo.prepayID,
        //   JSON.parse(payInfo.codeURL)
        // );

        // let res = await modal("温馨提示", '为了保证您的账户安全，即将跳转到微信进行支付');
        // if (res) {
        //   let jxParams = {
        //   "origin": "weixinappcs",
        //   "vendorOrderID": orderInfo.orderID,
        //   "storeID": this.storeID[0],
        //   "name": this.storeMap[this.storeID].name,
        //   "totalPrice":this.preCreateData.actualPayPrice?preCreateData.actualPayPrice:totalPay
        // }
        //   // console.log('打印jxParams', JSON.stringify(jxParams))

        //   openWeixinMiniprogram(`pagesPay/JX-pay/JX-pay?jxParams=${JSON.stringify(jxParams)}`)
        // }

        // #endif

        // #ifdef MP-ALIPAY
        payInfo = await orderPage.pay4User({
          thingID: Number(id),
          payType: 3,
          vendorPayType: "A02",
          // subAppID:'wx4b5930c13f8b1170',
        })
        await handleCreatePay(
          payInfo.vendorOrderID,
          payInfo.prepayID,
          payInfo.codeURL
        );
        // #endif

        toast("支付成功");
      } catch (e) {
        console.error(e);
      }
    }
  }
}
</script>

<style lang="scss" >
page {
  width: 100%;
  height: 100%;
  background-color: #f5f5f5;
}
@import "./vip.scss";
</style>