import { h5AppyUrl } from "@/api/pay.api.js";
import confg from "@/config/index";
export function h5Mixin() {
  return {
    methods: {
      goH5(url) {
        const vccToken = uni.getStorageSync("token");
        const phoneNo = uni.getStorageSync("phone");
        const vccChannel = confg["VCC_CHANNEL"];
        let jumpUrl = url;
        const regArr = ["phoneNo", "token", "vccChannel"];
        const regvalue = [phoneNo, vccToken, vccChannel];
        for (let i = 0; i < regArr.length; i++) {
          // eslint-disable-next-line no-useless-escape
          var reg = new RegExp(`{${regArr[i]}\}`, "g");
          jumpUrl = jumpUrl.replace(reg, regvalue[i]);
        }
        uni.redirectTo({
          url: `/pages/webview/webview?url=${encodeURIComponent(JSON.stringify(jumpUrl))}`
        });
      },
      async goApply(type = "user") {
        let flag = "";
        console.log(type);
        console.log(uni.getStorageSync("channlFlag"));
        if (uni.getStorageSync("channlFlag") === "ka") {
          // const [data] = await kaGetNextUrl({
          //   vccChannel: uni.getStorageSync('vccChannel') || '',
          //   sonVccChannel: uni.getStorageSync('sonVccChannel') || '',
          //   'x-auth-token': uni.getStorageSync('token') || '',
          //   'fromXcxPage': 'pay'
          // });
          // console.log(data)
          // this.url = data.nextUrl;
          // console.log(this.url)
          if (type == "pay") {
            flag = "pay";
          } else if (type == "user") {
            flag = "user";
          }
          uni.redirectTo({
            url: `/pages/webview/webview?&from=${flag}`
          });
        } else {
          let [{ url }] = await h5AppyUrl();
          // user:我的；pay:收银台
          url += `&fromXcxPage=${type}`;
          this.goH5(url);
        }
      }
    }
  };
}
