Unipay-H5/index.html

345 lines
14 KiB
HTML
Raw Normal View History

2024-05-29 10:42:31 +08:00
<!DOCTYPE html>
<!-- A11Y注意设置页面的 lang 属性 -->
<html lang="zh">
<head>
<meta charset="utf-8" />
<!-- A11Y打开页面时屏幕阅读器会首先阅读 title 的内容,确保 title 准确描述页面 -->
2024-05-30 17:02:05 +08:00
<title>权益会员N选1</title>
2024-05-29 10:42:31 +08:00
<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" />
<!-- 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>
2024-05-30 18:19:07 +08:00
<link rel="stylesheet" href="https://gw.alipayobjects.com/as/g/antui/antui/10.1.10/rem/widget/toast.css">
2024-05-30 17:02:05 +08:00
<link rel="stylesheet" href="./index-style.css">
2024-05-30 18:19:07 +08:00
<link rel="stylesheet" href="./style.css">
2024-05-29 10:42:31 +08:00
</head>
<body>
<div id="app">
2024-05-30 18:19:07 +08:00
<div v-if="state.showPage">
<div class="banner"></div>
<div class="goods-box">
<div class="goods-list-box-bg">
<div class="goods-list-box">
<h2 class="goods-title">兑换商品列表</h2>
<div class="goods-main">
2024-05-31 10:45:11 +08:00
<div class="goods-info" v-for="item in state.goodsList" :key="item.id">
2024-05-31 13:48:10 +08:00
<img :src="item.icon" alt=""
:class="state.isExchange !== -1 && state.isExchange !== item.id ? 'grayscale-image' : ''">
2024-05-30 18:19:07 +08:00
<div class="goods-info-text">
2024-05-31 10:45:11 +08:00
<p class="goods-name">{{ sliceStr(item.name)[0] }}</p>
<p class="goods-type">{{ sliceStr(item.name)[1] }}</p>
2024-05-30 18:19:07 +08:00
</div>
2024-05-30 16:51:12 +08:00
2024-05-31 13:48:10 +08:00
<div class="goods-checked"
v-show="state.isExchange !== -1 && state.isExchange !== item.id ? false : true"
:style="`border-color: ${selectColor(item.name)};`" @click="selectGoods(item.id)">
2024-05-31 10:45:11 +08:00
<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">
2024-05-30 18:19:07 +08:00
<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"
2024-05-31 10:45:11 +08:00
:fill="selectColor(item.name)" fill-opacity="1" />
2024-05-30 18:19:07 +08:00
</g>
</svg>
</div>
2024-05-30 16:51:12 +08:00
</div>
2024-05-31 10:45:11 +08:00
2024-05-30 16:51:12 +08:00
</div>
2024-05-31 13:48:10 +08:00
<div class="goods-btn" @click="exchangeBtn()">
{{ state.isExchange === -1 ? '立即兑换' : '查询详情' }}
2024-05-30 18:19:07 +08:00
</div>
2024-05-30 16:51:12 +08:00
2024-05-30 18:19:07 +08:00
</div>
2024-05-30 16:51:12 +08:00
</div>
</div>
2024-05-29 15:21:31 +08:00
2024-05-30 18:19:07 +08:00
<div class="pop" v-show="state.showPop">
<div class="pop-main">
2024-05-31 14:20:30 +08:00
<img :src="state.popObj.img" alt="">
2024-05-30 16:51:12 +08:00
2024-05-30 18:19:07 +08:00
<div class="pop-info">
2024-05-31 14:20:30 +08:00
<h1>{{ state.popObj.title }}</h1>
<p class="pop-msg">{{ state.popObj.msg1 }}</p>
<p class="pop-pip">{{ state.popObj.msg2}}</p>
2024-05-30 18:19:07 +08:00
</div>
2024-05-30 16:51:12 +08:00
2024-05-30 18:19:07 +08:00
<div class="pop-footer">
2024-05-31 14:20:30 +08:00
<button type="button" class="close-btn" @click="popCloseBtn()">{{ state.popObj.btnClose
}}</button>
2024-05-31 14:51:08 +08:00
2024-05-31 18:31:02 +08:00
<button type="button" class="ok-btn" :disabled="state.popLoading"
@click="popOkBtn(state.popOkType)" v-if="state.popOkType === 2 ? false : true">{{
state.popObj.btnOk
2024-05-31 14:20:30 +08:00
}}</button>
2024-05-30 18:19:07 +08:00
</div>
2024-05-30 16:51:12 +08:00
</div>
</div>
</div>
2024-05-30 18:19:07 +08:00
<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>
2024-05-30 18:30:23 +08:00
<div class="am-toast text" v-show="state.showToast">
2024-05-30 18:19:07 +08:00
<div class="am-toast-text">
{{ state.toastText }}
</div>
</div>
2024-05-29 10:42:31 +08:00
</div>
</body>
<script>
2024-05-30 18:19:07 +08:00
const { createApp, ref, onMounted, reactive } = Vue
2024-05-29 10:42:31 +08:00
createApp({
2024-05-30 18:19:07 +08:00
setup() {
const state = reactive({
token: "",
showPage: false,
2024-05-31 14:20:30 +08:00
showPop: false,
2024-05-30 18:19:07 +08:00
checkedGoods: "",
2024-05-30 18:30:23 +08:00
showToast: false,
2024-05-31 10:45:11 +08:00
toastText: "",
goodsList: [],
2024-05-31 13:48:10 +08:00
isChecked: -1,
isExchange: -1,
2024-05-31 14:20:30 +08:00
userPhone: "",
popOkType: 0,
popObj: {},
2024-05-31 18:31:02 +08:00
popLoading: false,
2024-05-31 14:20:30 +08:00
popObjArr: [
{
id: 1,
title: "充值确认",
img: "https://lsxd-customcard-h5.oss-cn-hangzhou.aliyuncs.com/department-of-finance/img/pop-1.png",
msg1: "",
msg2: "该权益只能充值到银联无界卡数字生活礼遇活动报名手机号",
btnClose: "取消",
btnOk: "我已确认"
},
{
id: 2,
title: "兑换成功",
img: "https://lsxd-customcard-h5.oss-cn-hangzhou.aliyuncs.com/department-of-finance/img/pop-2.png",
msg1: "",
btnClose: "关闭弹窗",
btnOk: "查看详情"
},
{
id: 3,
title: "兑换失败",
img: "https://lsxd-customcard-h5.oss-cn-hangzhou.aliyuncs.com/department-of-finance/img/pop-3.png",
2024-05-31 14:51:08 +08:00
msg1: "兑换失败,请稍后重试。",
2024-05-31 14:20:30 +08:00
btnClose: "关闭弹窗",
btnOk: "查看详情"
}
]
2024-05-30 18:19:07 +08:00
})
2024-05-31 10:45:11 +08:00
// toast
2024-05-30 18:30:23 +08:00
const openToast = (msg) => {
if (state.showToast) return;
state.toastText = msg;
state.showToast = true;
setTimeout(() => {
state.showToast = false;
}, 1500);
};
2024-05-31 10:45:11 +08:00
// 截取 字符串
const sliceStr = (str) => {
if (str) {
return str.split("|")
}
return []
}
2024-05-31 14:20:30 +08:00
const popCloseBtn = () => {
state.showPop = false;
}
const popOkBtn = (type = 0) => {
if (type === 0) {
2024-05-31 18:31:02 +08:00
state.popLoading = true;
setTimeout(() => {
state.popLoading = false;
}, 500)
2024-05-31 14:20:30 +08:00
req.axiosPost("/front/order/create", { prize_id: state.isChecked }).then(res => {
if (res.code === 200) {
state.popObj = state.popObjArr[1];
state.popObj.msg1 = `恭喜兑换成功 ${sliceStr(res.data.name)[0]}${sliceStr(res.data.name)[1]}`;
state.popOkType = 1;
2024-05-31 15:50:50 +08:00
getGoodsList();
2024-05-31 14:20:30 +08:00
} else {
state.popObj = state.popObjArr[2];
state.popOkType = 2;
}
})
return
} else {
window.location.href = "./detail.html";
}
}
2024-05-31 10:45:11 +08:00
// 选中颜色
const selectGoods = (id) => {
2024-05-31 13:48:10 +08:00
if (state.isExchange !== -1) return
2024-05-31 10:45:11 +08:00
state.isChecked = id;
}
// 判断商品类型,返回不同的颜色
const selectColor = (name) => {
// 1腾讯2爱奇艺3网易云4饿了么5青桔6keep
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("KEEP") !== -1) {
type = 6;
}
switch (type) {
case 1:
return "#4998FB";
case 2:
return "#59D736";
case 3:
return "#FE3E37";
case 4:
return "#4B99FB";
case 5:
return "#15C8C0";
case 6:
return "#574E5F";
default:
return "#4998FB"
}
}
2024-05-30 18:30:23 +08:00
// 获取用户信息
const getUserInfo = () => {
try {
2024-05-31 13:48:10 +08:00
req.axiosGet("/front/getAccountInfo").then(res => {
2024-05-30 18:30:23 +08:00
if (res.code === 200) {
2024-05-31 13:48:10 +08:00
state.userPhone = res.data.phone;
2024-05-30 18:30:23 +08:00
} else {
openToast(res.message);
}
})
} catch (err) {
console.log("err =>", err);
}
2024-05-30 18:34:31 +08:00
}
2024-05-30 18:30:23 +08:00
2024-05-30 18:34:31 +08:00
// 获取商品列表
const getGoodsList = () => {
try {
2024-05-31 10:45:11 +08:00
req.axiosGet("/front/homeData").then(res => {
if (res.code === 200) {
state.goodsList = res.data.prizes;
// 设置勾选
let el = res.data.prizes.find(item => item.is_receive === 1);
if (el) {
state.isChecked = el.id;
2024-05-31 13:48:10 +08:00
state.isExchange = el.id;
2024-05-31 10:45:11 +08:00
}
} else {
openToast(res.message);
}
2024-05-30 18:34:31 +08:00
})
} catch (err) {
console.log("err =>", err);
}
2024-05-30 18:30:23 +08:00
}
2024-05-31 13:48:10 +08:00
// 兑换
const exchangeBtn = () => {
// 判断是否被选中
if (state.isExchange !== -1) {
window.location.href = "./detail.html";
} else {
if (state.isChecked !== -1) {
2024-05-31 14:20:30 +08:00
state.popObj = state.popObjArr[0];
state.popObj.msg1 = `即将充值到尾号${state.userPhone}的手机号`;
state.popOkType = 0;
2024-05-31 13:48:10 +08:00
state.showPop = true;
} else {
openToast("请选择兑换商品");
}
}
}
2024-05-30 18:19:07 +08:00
onMounted(() => {
const url = new URL(window.location.href);
const searchParams = new URLSearchParams(url.search);
const token = searchParams.get("token");
if (token) {
state.token = token;
2024-05-30 18:30:23 +08:00
localStorage.setItem("yl_token", token);
state.showPage = true;
2024-05-30 18:34:31 +08:00
getGoodsList();
2024-05-30 18:30:23 +08:00
getUserInfo();
2024-05-31 13:48:10 +08:00
return
2024-05-30 18:30:23 +08:00
} else {
openToast("未登录");
2024-05-30 18:19:07 +08:00
}
})
return {
2024-05-31 14:20:30 +08:00
popOkBtn,
popCloseBtn,
2024-05-31 13:48:10 +08:00
exchangeBtn,
selectGoods,
2024-05-31 10:45:11 +08:00
selectColor,
sliceStr,
2024-05-30 18:19:07 +08:00
state
}
}
2024-05-29 10:42:31 +08:00
}).mount('#app')
</script>
</html>