Unipay-H5/index.html

482 lines
16 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<!-- A11Y注意设置页面的 lang 属性 -->
<html lang="zh">
<head>
<meta charset="utf-8" />
<!-- A11Y打开页面时屏幕阅读器会首先阅读 title 的内容,确保 title 准确描述页面 -->
<title>银联无界卡数字生活礼遇</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no, email=no" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0,viewport-fit=cover"
/>
<!-- A11Y如果有无障碍方面的需求建议使用下面的 viewport 设置,不要禁止页面缩放 -->
<!--<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />-->
<script>
var docEl = document.documentElement;
docEl.style.fontSize = (100 / 375) * docEl.clientWidth + "px";
window.addEventListener("resize", function () {
docEl.style.fontSize = (100 / 375) * docEl.clientWidth + "px";
});
</script>
<script src="https://lsxdemall.oss-cn-beijing.aliyuncs.com/common/axios.js?v=1367936144999"></script>
<script src="./dof-api.js"></script>
<script src="https://lsxdemall.oss-cn-beijing.aliyuncs.com/MarketingSystem/libs/vue.global.js"></script>
<link
rel="stylesheet"
href="https://gw.alipayobjects.com/as/g/antui/antui/10.1.10/rem/widget/toast.css"
/>
<link rel="stylesheet" href="./index-style.css" />
<link rel="stylesheet" href="./style.css" />
<!-- 引入字体 -->
<!-- <link type="text/css" rel="stylesheet" href="https://webfont.hellofont.cn/webfont/puhuiti-2?weight=65&family=puhuiti-2-65"> -->
</head>
<body>
<div id="app">
<div
v-if="state.showPage"
class="main"
:style="`background:url(${state.id === 10 ? state.bg[0] : state.bg[1]}) no-repeat;background-size: 100%;`"
>
<div :class="`${(state.id)===10?'back':'back-2'}`">
<div
:class="`${(state.id)===10?'back-text':'back-text-2'}`"
@click="goBack()"
>
返回
</div>
</div>
<div
:class="`${(state.id)===10?'buy':'buy-2'}`"
@click="exchangeBtnDetail()"
>
<div class="buy-text">购买详情</div>
</div>
<div
:class="`${(state.id)===10?'goods-box':'goods-box-2'}`"
:style="`background:url(${state.id === 10 ? state.goodsBoxBg[0] : state.goodsBoxBg[1]}) no-repeat;background-size: 100%;`"
>
<div
:class="`${(state.id)===10?'goods-list-box-bg':'goods-list-box-bg-2'}`"
>
<div
:class="`${(state.id)===10?'goods-list-box':'goods-list-box-2'}`"
>
<h2 :class="`${(state.id)===10?'goods-title':'goods-title-2'}`">
购买商品列表
</h2>
<div :class="`${(state.id)===10?'goods-main':'goods-main-2'}`">
<div
:class="`${(state.id)===10?'goods-info':'goods-info-2'}`"
v-for="item in state.goodsList"
:key="item.id"
>
<img
:src="item.icon"
alt=""
:class="state.isExchange !== -1 && state.isExchange !== item.id ? 'grayscale-image' : ''"
/>
<div class="goods-info-text">
<p class="goods-name">{{ sliceStr(item.name)[0] }}</p>
<p class="goods-type">{{ sliceStr(item.name)[1] }}</p>
</div>
<div
class="goods-checked"
v-show="state.isExchange !== -1 && state.isExchange !== item.id ? false : true"
:style="`border-color: ${selectColor(item.name)};`"
@click="selectGoods(item)"
>
<svg
v-show="state.isChecked === item.id"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
fill="none"
version="1.1"
width="11"
height="8"
viewBox="0 0 11 8"
>
<g>
<path
d="M10.7716,0.256416C10.4617,-0.0798496,9.95367,-0.0861736,9.6369,0.242132L4.16883,5.90732L1.34478,2.91081C1.05152,2.59933,0.559823,2.61661,0.246253,2.94906C-0.0673045,3.28156,-0.0836348,3.80343,0.209982,4.11484L3.66203,7.77757C3.95522,8.08862,4.44698,8.07134,4.76048,7.7389C4.83232,7.66275,4.8861,7.57641,4.92645,7.48511C4.95749,7.46114,4.98845,7.4384,5.01657,7.40895L10.7582,1.46051C11.0754,1.13188,11.0811,0.593098,10.7716,0.256416L10.7716,0.256416Z"
:fill="selectColor(item.name)"
fill-opacity="1"
/>
</g>
</svg>
</div>
<div class="goods-price">¥{{item.price}}</div>
<div
class="goods-showprice"
:style="`color:${selectColor(item.name)}`"
>
原价{{item.show_price}}
</div>
</div>
</div>
<div class="goods-btn" @click="exchangeBtn()">
{{ state.isExchange === -1 ? '优惠购买' : '查询详情' }}
</div>
</div>
</div>
</div>
<div class="pop" v-show="state.showPop">
<div class="pop-main">
<img :src="state.popObj.img" alt="" />
<div class="pop-info">
<h1
class="pop-title"
:style="`background:url(${state.popObj.buyImg}) no-repeat;background-size: 100%;`"
:class="`${(state.popObj.id)!=1?'pop-title-fail':''}`"
></h1>
<p
class="pop-msg"
v-html="state.popObj.msg1"
v-if="state.popObj.id==1"
></p>
<p class="pop-phone" v-else>{{ state.popObj.msg3 }}</p>
<p class="pop-pip" v-show="state.popObj.id==1">
{{ state.popObj.msg2 }}
</p>
</div>
<div class="pop-footer">
<button type="button" class="close-btn" @click="popCloseBtn()">
{{ state.popObj.btnClose }}
</button>
<button
type="button"
class="ok-btn"
:disabled="state.popLoading"
@click="popOkBtn(state.popOkType)"
v-if="state.popOkType === 2 ? false : true"
>
{{ state.popObj.btnOk }}
</button>
</div>
</div>
</div>
</div>
<div v-else class="skeleton-box">
<div class="skeleton-loader" style="width: 2rem; height: 0.3rem"></div>
<div class="skeleton-loader" style="height: 0.2rem"></div>
<div class="skeleton-loader" style="height: 0.2rem"></div>
<div class="skeleton-loader" style="height: 0.2rem"></div>
<div class="skeleton-loader" style="height: 0.2rem"></div>
<div
class="skeleton-loader"
style="width: 2.5rem; height: 0.2rem"
></div>
</div>
<div class="am-toast text" v-show="state.showToast">
<div class="am-toast-text">{{ state.toastText }}</div>
</div>
</div>
</body>
<script>
const { createApp, ref, onMounted, reactive } = Vue;
createApp({
setup() {
const state = reactive({
bg: [
"https://lsxdmgoss.oss-cn-chengdu.aliyuncs.com/unipay/bg1.png?v=2224",
"https://lsxdmgoss.oss-cn-chengdu.aliyuncs.com/unipay/bg2.png?v=444",
],
goodsBoxBg: [
"https://lsxdmgoss.oss-cn-chengdu.aliyuncs.com/unipay/goodsbox1.png?v=22244",
"https://lsxdmgoss.oss-cn-chengdu.aliyuncs.com/unipay/goodsbox2.png?v=22244",
],
Title: [
"https://lsxdmgoss.oss-cn-chengdu.aliyuncs.com/unipay/%E5%B9%B4%E8%BD%BB%E5%AE%A2%E7%BE%A4%E4%BC%98%E6%83%A0%E8%B4%AD.png?v=222",
],
id: 10,
token: "",
showPage: false,
showPop: false,
showToast: false,
toastText: "",
goodsList: [],
isChecked: -1,
isExchange: -1,
userPhone: "",
popOkType: 0,
popObj: {},
popLoading: false,
CheckedGoods: {},
popObjArr: [
{
id: 1,
title: "购买确认",
img: "https://lsxdmgoss.oss-cn-chengdu.aliyuncs.com/unipay/pop-1.png?v=111",
buyImg:
"https://lsxdmgoss.oss-cn-chengdu.aliyuncs.com/unipay/popbuy.png?v=111",
msg1: "",
msg2: "该权益只能充值到银联无界卡数字生活礼遇活动报名手机号",
msg3: "",
btnClose: "取消",
btnOk: "我已确认",
},
{
id: 2,
title: "购买成功",
img: "https://lsxd-customcard-h5.oss-cn-hangzhou.aliyuncs.com/department-of-finance/img/pop-2.png",
buyImg:
"https://lsxdmgoss.oss-cn-chengdu.aliyuncs.com/unipay/popbuy.png",
msg1: "",
btnClose: "关闭弹窗",
btnOk: "查看详情",
},
{
id: 3,
title: "购买失败",
img: "https://lsxdmgoss.oss-cn-chengdu.aliyuncs.com/unipay/pop-3.png",
buyImg:
"https://lsxdmgoss.oss-cn-chengdu.aliyuncs.com/unipay/popbuyfail.png",
msg1: "购买失败,请稍后重试。",
msg3: "购买失败,请稍后重试。",
btnClose: "关闭弹窗",
btnOk: "查看详情",
},
],
});
// toast
const openToast = (msg) => {
if (state.showToast) return;
state.toastText = msg;
state.showToast = true;
setTimeout(() => {
state.showToast = false;
}, 1500);
};
// 截取 字符串
const sliceStr = (str) => {
if (str) {
return str.split("|");
}
return [];
};
const popCloseBtn = () => {
state.showPop = false;
};
const popOkBtn = (type = 0) => {
if (type === 0) {
state.popLoading = true;
setTimeout(() => {
state.popLoading = false;
}, 500);
req
.axiosPost("/front/order/create", { prize_id: state.isChecked })
.then((res) => {
if (res.code === 200) {
window.location.href = res.data.pay_url;
// state.popObj = state.popObjArr[1];
// state.popObj.msg1 = `恭喜兑换成功 ${sliceStr(res.data.name)[0]}${sliceStr(res.data.name)[1]}`;
// state.popOkType = 1;
// getGoodsList();
} else {
state.popObj = state.popObjArr[2];
state.popObj.msg3 = res.message;
state.popOkType = 2;
}
});
return;
} else {
window.location.href = "./detail.html";
}
};
// 选中颜色
const selectGoods = (value) => {
if (state.isExchange !== -1) return;
state.isChecked = value.id;
state.CheckedGoods = value;
console.log(state.CheckedGoods, value);
};
// 判断商品类型,返回不同的颜色
const selectColor = (name) => {
// 1网易云 2 喜马拉雅 3 优酷 4 咪咕 5 爱奇艺
let type = 1;
if (name.indexOf("网易云") !== -1) {
type = 1;
}
if (name.indexOf("喜马拉雅") !== -1) {
type = 2;
}
if (name.indexOf("优酷") !== -1) {
type = 3;
}
if (name.indexOf("咪咕") !== -1) {
type = 4;
}
if (name.indexOf("爱奇艺") !== -1) {
type = 5;
}
if (name.indexOf("咖啡") !== -1) {
type = 6;
}
if (name.indexOf("奈雪的茶") !== -1) {
type = 7;
}
if (name.indexOf("茶百道") !== -1) {
type = 8;
}
if (name.indexOf("蜜雪") !== -1) {
type = 9;
}
switch (type) {
case 1:
return "#FF231E";
case 2:
return "#F82801";
case 3:
return "#4B99FB";
case 4:
return "#1782C7";
case 5:
return "#8AE471";
case 6:
return "#FFD9D9";
case 7:
return "#F6FFD9";
case 8:
return "#D9DEFF";
case 9:
return "#FFD9D9";
default:
return "#4998FB";
}
};
// 获取用户信息
const getUserInfo = () => {
try {
req.axiosGet("/front/getAccountInfo").then((res) => {
if (res.code === 200) {
state.userPhone = res.data.phone;
} else {
openToast(res.message);
}
});
} catch (err) {
console.log("err =>", err);
}
};
// 获取商品列表
const getGoodsList = () => {
try {
req.axiosGet("/front/homeData").then((res) => {
if (res.code === 200) {
state.id = res.data.id;
state.goodsList = res.data.prizes;
// 设置勾选
let el = res.data.prizes.find((item) => item.is_receive === 1);
if (el) {
state.isChecked = el.id;
state.isExchange = el.id;
}
} else {
state.showPage = false;
openToast(res.message);
}
});
} catch (err) {
console.log("err =>", err);
}
};
// 兑换
const exchangeBtn = () => {
// 判断是否被选中
if (state.isExchange !== -1) {
window.location.href = "./detail.html";
} else {
if (state.isChecked !== -1) {
state.popObj = state.popObjArr[0];
// `${sliceStr(res.data.name)[0]}`
state.popObj.msg3 = `即将充值到尾号${state.userPhone}的手机号`;
state.popObj.msg1 =
'<div class="pop-goods-name">' +
`${sliceStr(state.CheckedGoods.name)[0]}:` +
"</div>" +
'<div class="pop-goods-price">' +
`${state.CheckedGoods.price}` +
"</div>";
state.popOkType = 0;
state.showPop = true;
} else {
openToast("请选择购买商品");
}
}
};
const exchangeBtnDetail = () => {
// 判断是否被选中
if (state.isExchange !== -1) {
window.location.href = "./detail.html";
}else{
openToast("请选择购买商品");
}
};
const goBack = () => {
window.history.back();
};
onMounted(() => {
const url = new URL(window.location.href);
const searchParams = new URLSearchParams(url.search);
const token = searchParams.get("token");
if (token) {
state.token = token;
localStorage.setItem("yl_new_token", token);
state.showPage = true;
getGoodsList();
getUserInfo();
return;
} else {
openToast("未登录");
}
});
return {
exchangeBtnDetail,
popOkBtn,
popCloseBtn,
exchangeBtn,
selectGoods,
selectColor,
sliceStr,
goBack,
state,
};
},
}).mount("#app");
</script>
</html>