<template>
  <div>{{ msg }}</div>
</template>

<script setup lang="ts">
import Phone from "@/utils/phone";
import axios from "axios";
import {ref} from 'vue'
type iosOrderUserInfo = {
  id: string;
  nickName: string;
  pxkm: string;
  loginCode: string;
  apsw: string;
  apt: string;
};
const baseUrl =
  import.meta.env.MODE === "production"
    ? "https://jsjp-admin.zzxcx.net/jsjp-admin/"
    : "https://jsjp-admin1.zzxcx.net/jsjp-admin/";
const myPhone = new Phone();
const request = axios.create();
const msg = ref('未调用的初始状态')
//@ts-ignore
window.iosOrder = (goodsId: string, userInfoStr: string,goodsType:string) => {
  let userInfoObj: iosOrderUserInfo = JSON.parse(userInfoStr);
  //这是没审核的时候
  if (Number(userInfoObj.apsw) == 0) {
    let apt = Number(userInfoObj.apt);
    switch (apt) {
      case 1:
        window.setTimeout(() => {
          myPhone.ipyCallgo();
        }, 2500);
        break;
      case 2:
        request({
          url: baseUrl + "open-api/wxjs/getPrepareGoodsOrder",
          method: "post",
          data: {
            goodsId: goodsId,
            goodsType: 2,
            userId: userInfoObj.id,
            phoneType: myPhone.isIos() ? 1 : 2,
            goodsType:goodsType
          },
        }).then((res: any) => {
          if (res.data.code == 200) {
            myPhone.spyCallgo(
              `weixin://app/wx606fa102dbc4b8ab/pay/?nonceStr=${
                res.data.data.nonceStr
              }&package=${window.encodeURIComponent(
                res.data.data.packageValue
              )}&partnerId=${res.data.data.partnerId}&prepayId=${
                res.data.data.prepayId
              }&timeStamp=${res.data.data.timeStamp}&sign=${window.encodeURIComponent(
                res.data.data.sign
              )}&signType=SHA1&_wechat_sdk_support_url_params=1`
            );
          } else {
            msg.value = JSON.stringify( res.data) 
            myPhone.errCallgo(res.data.code + "");
          }
        });
        break;
      case 3:
        request({
          url: baseUrl + "open-api/wxjs/getH5PrepareGoodsOrder",
          method: "POST",

          data: {
            goodsId: goodsId,
            goodsType: 2,
            phoneType: myPhone.isIos() ? 1 : 2,
            userId: userInfoObj.id,
            goodsType:goodsType
          },
        }).then((res: any) => {
          if (res.data.code == 200) {
            if (res.data.data.h5_url) {
              msg.value = JSON.stringify( res.data) 
              window.location.href = res.data.data.h5_url;
            } else {
              msg.value = JSON.stringify( res.data) 
              console.log(res.data);
            }
          } else {
            console.log("下单错误");
            msg.value = JSON.stringify( res.data) 
            //数字转字符串
            myPhone.errCallgo(res.data.code + "");
          }
        });
        break;
      default:
        break;
    }
  } else if (Number(userInfoObj.apsw) == 1) {
    window.setTimeout(() => {
      myPhone.ipyCallgo();
    }, 2500);
  }
  //open-api/wxjs/prepareOrder
  // alert('调用了iosOrder')
};
myPhone.ladCallgo()


</script>

<style scoped></style>
