<template>
  <div>1</div>
</template>

<script setup lang="ts">
import Phone from "@/utils/phone";
import axios from "axios";
type iosOrderUserInfo = {
  id: string;
  nickName: string;
  pxkm: string;
  loginCode: string;
  apsw: string;
  apt: string;
};
const myPhone = new Phone();
const request = axios.create();
//@ts-ignore
window.iosOrder = (goodsId: string, userInfoStr: 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:
            "https://jsjp-admin1.zzxcx.net/jsjp-admin/open-api/wxjs/getPrepareGoodsOrder",
          method: "post",
          data: {
            dictCode: goodsId,
            goodsType: 2,
            userId: userInfoObj.id,
            phoneType: myPhone.isIos() ? 1 : 2,
          },
        }).then((res: any) => {
          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`
          );
        });
        break;
      case 3:
        request({
          url:
            "https://jsjp-admin1.zzxcx.net/jsjp-admin/open-api/wxjs/getH5PrepareGoodsOrder",
          method: "POST",

          data: {
            dictCode: goodsId,
            goodsType: 2,
            phoneType: myPhone.isIos() ? 1 : 2,
            userId: userInfoObj.id,
          },
        }).then((res: any) => {
          window.location.href = res.data.data.h5_url;
        });
        break;
      default:
        break;
    }
  } else if (Number(userInfoObj.apsw) == 1) {
    window.setTimeout(() => {
      myPhone.ipyCallgo();
    }, 2500);
  }
  //open-api/wxjs/prepareOrder
  // alert('调用了iosOrder')
};
</script>

<style scoped></style>
