mobileclient/index.html

787 lines
31 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>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,viewport-fit=cover">
<title>权益兑换页</title>
<script src="https://lsxdemall.oss-cn-beijing.aliyuncs.com/common/vue.min.js?v=1367936144322" type="text/javascript"
charset="utf-8"></script>
<script type="text/javascript" src="https://lsxdemall.oss-cn-beijing.aliyuncs.com/common/axios.js?v=1367936144999">
</script>
<link rel="stylesheet" href="https://lsxdemall.oss-cn-beijing.aliyuncs.com/MarketingSystem/css/loading.css">
<link rel="stylesheet" href="https://lsxdemall.oss-cn-beijing.aliyuncs.com/MarketingSystem/css/index.css">
<script src="https://lsxdemall.oss-cn-beijing.aliyuncs.com/MarketingSystem/js/loading.js"></script>
<!-- <script src="https://lsxdemall.oss-cn-beijing.aliyuncs.com/MarketingSystem/js/api2_0.js?v=1000"></script> -->
<script src="https://lsxdemall.oss-cn-beijing.aliyuncs.com/common/modelPop.js"></script>
<script src="https://lsxdemall.oss-cn-beijing.aliyuncs.com/MarketingSystem/js/libs.js?v=sdfhksdfklwrwer"></script>
<style>
input {
color: var(--placeholderColor);
}
input::placeholder {
color: var(--placeholderColor);
}
</style>
</head>
<body>
<div id="app" :style={background:bgcolor}>
<!-- 弹出提示 -->
<model-pop :show.sync="popShow" :title="popTitle" :status="popStatus" :text="popText"></model-pop>
<!-- 单条弹出框 -->
<div class="prompt" :class="promtshow?'proactive':''">
{{this.promttip}}
</div>
<div class="um-content" v-if="loading" ref="load">
<preload-component />
</div>
<div v-show="!loading">
<div class="top">
<img :src="topImg" id="top">
</div>
<div class="center" id="center" style="margin-top: -0.01rem;">
<img :src="middleImg" style="position: absolute;z-index: 1;" id="center_img">
<input class="key" :maxlength="16" v-if="[3,4].includes(pageType)" :style="bindInputStyle"
placeholder="请输入兑换码" v-model="key" />
<input class="code" :maxlength="5" v-if="[3,4].includes(pageType)" :style="bindInputStyle"
placeholder="请输入验证码" v-model="code" />
<input class="key" :maxlength="11" v-if="[1,8].includes(pageType)" :style="bindInputStyle"
placeholder="请输入手机号" v-model="key" />
<input class="code" :maxlength="6" v-if="[1,8].includes(pageType)" :style="bindInputStyle"
placeholder="请输入验证码" v-model="code" />
<img src="#" alt="" class="codeimg" v-if="[3,4].includes(pageType)" id="captcha_img"
@click="captchaimg()" />
<button class="codeimg" :class="disabled?'disabledstyle':'active'" v-if="[1,8].includes(pageType)"
@click="getcode()" :disabled="disabled">{{codetip}}</button>
<div class="submit" @click="submit"></div>
</div>
<div class="bottom" id="bottom">
<img :src="describe.bg_image" v-show="describe.type&&describe.bg_image">
<div v-html="describe.content" class="tipBottomtext" v-show="describe.type==2&&describe.content"></div>
</div>
</div>
</div>
</body>
<script>
let baseurl = "http://192.168.6.75";
let pathname = window.location.host;
function global_dev_fun(hots) {
if (hots.includes("test")) {
baseurl = "http://192.168.6.75";
return;
}
if (hots.includes("pre")) {
baseurl = "https://pre.marketapi.1688sup.com";
return;
}
if (
hots.includes("1688sup") ||
hots.includes("83323") ||
hots.includes("86885") ||
hots.includes("22233")
) {
baseurl = "https://marketapi.1688sup.com";
return;
}
}
global_dev_fun(pathname);
//统一请求
axios.interceptors.request.use((config) => {
// config.headers.Version = 'v1.3.0';
return config;
});
const req = {
//get请求
axiosGet(url, params) {
const obj = { method: "get", url: baseurl + url, params };
var result = axios(obj)
.then(function (res) {
return res.data;
})
.catch(function (error) {
return;
});
return result;
},
//获取key列表
axiosPostgetKey(url, data) {
let result = axios({
method: "post",
url: baseurl + url,
data: data,
header: {
"Content-type": "application/x-www-form-urlencoded"
}
})
.then((res) => {
return res;
})
.catch((error) => {
alert("服务器错误");
return "exception=" + error;
});
return result;
},
//post请求
axiosPost(url, data) {
let result = axios({
method: "post",
url: baseurl + url,
data: data,
header: {
"Content-type": "application/x-www-form-urlencoded"
}
})
.then((res) => {
return res.data;
})
.catch((error) => {
// return "exception=" + error
});
return result;
},
//put请求
axiosPut(url, data) {
let result = axios({
method: "put",
url: baseurl + url,
data: data,
header: {
"Content-type": "application/x-www-form-urlencoded"
}
})
.then((res) => {
return res.data;
})
.catch((error) => {
alert("服务器错误");
return "exception=" + error;
});
return result;
}
};
//图形验证码
function captchaimg() {
let parmas = {};
let customsessionid = "";
const xhr = new XMLHttpRequest();
xhr.open("GET", baseurl + "/auth/login/verify");
// xhr.setRequestHeader('Version', 'v1.1.0');
xhr.responseType = "arraybuffer";
xhr.onreadystatechange = function (response) {
response.header = {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
};
var img = document.getElementById("captcha_img");
var byteArray = new Uint8Array(response.target.response);
var binary = "";
for (var i = 0; i < byteArray.byteLength; i++) {
binary += String.fromCharCode(byteArray[i]);
}
let str = "data:image/png;base64," + window.btoa(binary);
img.src = str;
customsessionid = xhr.getResponseHeader("Unique-Str");
sessionStorage.setItem("unique_str", customsessionid);
};
xhr.send();
}
/*公共方法提取 */
//!商品的各种异常状态。1是可以兑换不作提示
//!type:1 兑换码 2:立减金 3:红包
const product_status = (status, row) => {
const message = JSON.parse(sessionStorage.getItem("message"));
const messageCurrent = {};
message.map((item) => {
if (item.type == row.type || item.type == 0) {
return (messageCurrent[item.message_type] = replaceVariables(
row.type,
item,
row
));
}
});
return messageCurrent[status];
};
/* 替换变量 */
function replaceVariables(type, val, row) {
let mes = "";
let prompt = val.customize || val.default;
switch (Number(type)) {
case 2:
mes = prompt
.replace(
"${effect_time_start}",
row.entity.time_limit.effect_time.start_time
)
.replace(
"${effect_time_end}",
row.entity.time_limit.effect_time.end_time
)
.replace("${start_time}", row.entity.time_limit.receive_time.start_time)
.replace("${end_time}", row.entity.time_limit.receive_time.end_time);
break;
case 3:
mes = prompt
.replace("${effect_time_start}", row.entity.begin_time)
.replace("${effect_time_end}", row.entity.end_time);
break;
default:
mes = prompt
.replace("${start_time}", row.begin_time)
.replace("${end_time}", row.end_time)
.replace("${effect_time_start}", row.begin_time)
.replace("${effect_time_end}", row.end_time);
break;
}
return mes;
}
/* 周天排序 */
function sortWeeks(weeks) {
const staticWeeks = [
{ id: 1, name: "周一" },
{ id: 2, name: "周二" },
{ id: 3, name: "周三" },
{ id: 4, name: "周四" },
{ id: 5, name: "周五" },
{ id: 6, name: "周六" },
{ id: 7, name: "周日" }
];
var _weeks = weeks
.map((item) =>
staticWeeks.filter((item1) => item1.name === item || item1.id == item)
)
.flat(Infinity)
.sort((a, b) => a.id - b.id);
//将weeks清空并将排序好的值赋给weeks
const weeksData = [];
if (isContinuityNum(_weeks.map((item) => item.id)) && _weeks.length > 1) {
weeksData.push(`${_weeks[0].name}${_weeks.slice(-1)[0].name}`);
} else {
for (var i = 0; i < _weeks.length; i++) {
weeksData.push(_weeks[i].name);
}
}
return weeksData;
}
//判断一串数字是否是连续的
function isContinuityNum(num) {
let array = [];
if (num instanceof Array) {
array = [...num];
} else {
array = Array.from(num.toString()); //转换为数组
}
var i = array[0];
var isContinuation = true;
for (var e in array) {
if (array[e] != i) {
isContinuation = false;
break;
}
i++;
}
return isContinuation;
}
//判断是不是微信
function isWx() {
var ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return true;
}
return false;
}
//判断是不是钉钉
function isAli() {
var ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/dingtalk/i) == "dingtalk") {
return true;
}
return false;
}
//判断是不是微信小程序环境打开
function isWxminiprogram() {
const ua = navigator.userAgent.toLowerCase();
const isWeixin = ua.indexOf("micromessenger") != -1;
if (isWeixin) {
if (window.__wxjs_environment == "miniprogram") {
return true;
} else {
return false;
}
} else {
return false;
}
}
/* 自定义按钮文案 */
function buttonTextFun(type, code) {
const buttonData = JSON.parse(sessionStorage.getItem("bm_auth")).button_conf;
const lastText = buttonData.filter(
(item) => item.type == type && item.code == code
)[0];
return lastText.custom || lastText.default;
}
</script>
<script>
new Vue({
el: '#app',
data() {
return {
loading: true,
pageType: 1,
key: '',
code: '',
disabled: true,
codetip: '获取验证码',
topImg: '',
middleImg: '',
describe: {},
ftcolor: '',
bgcolor: '#333',
promttip: '',
promtshow: false,
tiptext: '提示信息',
plan_id: '',
disabledBtn: false,
typeList: {//1 白名单 3 兑换码 4优惠券 8 优惠券白名单
'1': 'access_conf',
'3': 'exchange',
'4': 'coupon',
'8': 'coupon',
},
/* 提示框状态 */
popShow: false,
popTitle: '',
popText: '',
popStatus: 1 /*1 成功 2提示 3失败 */
};
},
components: {
modelPop
},
async created() {
sessionStorage.clear();
localStorage.clear();
await req.axiosGet('/conf/apiStatus').then(res => {
if (res.data.update) {
sessionStorage.setItem('notice', res.data.msg);
location.replace('./notice.html');
return;
}
});
let self = this;
//获取链接携带的参数
let linkId = getQueryString('id');
let keyCode = getQueryString('key');
// linkId = '3438'
// keyCode="AAACm5p65D48ZquM"
if (!linkId) {//地址栏无携带id
let path = window.location.pathname;
let parmas = path.split('/');
let parmasResult = parmas.filter(n => n);
linkId = parmasResult && parmasResult.length > 0 ? parmasResult[0] : 1402; //链接携带落地页渲染id
keyCode = parmasResult && parmasResult.length > 1 ? parmasResult[1] : null; //链接携带key
console.log(keyCode);
}
if (linkId.length > 10) {
req.axiosGet('/plan/plan_theme/' + linkId).then(res => {
if (res.code == 200) {
locationReplace(res.data)
self.loading = false;
return;
} else {
self.openErrorDialog(res.message);
}
}).catch(err => { });
}
req.axiosGet('/plan/plan_theme/' + linkId).then(res => {
if (res.code == 200) {
//内置页顶图
document.title = res.data.title;
self.plan_id = res.data.plan_id;
self.getMessage(res.data.plan_id);
self.pageType = res.data.page;
localStorage.setItem('title', res.data.title);
localStorage.setItem('product_list', JSON.stringify(res.data[this.typeList[res.data.page]].product_list));
localStorage.setItem('product_detail', JSON.stringify(res.data[this.typeList[res.data.page]].product_detail));
localStorage.setItem('test', window.location.href);
// localStorage.setItem('plan_id', res.data.plan_id); // 活动ID
self.loading = false;
localStorage.setItem('linkId', linkId);
//是否携带token
if (keyCode) {
let data = {
key: keyCode,
theme_type: this.pageType
};
req.axiosPost('/key/loginFromLink', data).then(res => {
if (res.code == 200) {
this.openDialog('正在加载商品...');
localStorage.setItem('key', keyCode);
localStorage.setItem('token', res.data.token);
localStorage.setItem('haskey', keyCode);
localStorage.setItem('entryLink', window.location.href);//存储起始页链接
sessionStorage.setItem("bm_auth", JSON.stringify(res.data)); // 存储包码数据
sessionStorage.setItem("key_expiration_time", res.data.key_expiration_time); // 存储时间
// 存储时间 注意!!!:新网项目需要跳转到 直连天下授权 所以需要存储时间,必须用 localStorage 不然会消失!!!
localStorage.setItem("key_expiration_time", res.data.key_expiration_time);
// 统一跳转函数
this.gotoPage(res.data, 1);
} else {
self.openErrorDialog(res.message);
}
}).catch(err => {
console.log(174, err);
});
} else {
if ([3, 4].includes(this.pageType)) {
captchaimg();
}
let keyName = this.typeList[this.pageType];
self.bgcolor = res.data[keyName].land.bg_color;
self.ftcolor = res.data[keyName].land.font_color;
self.topImg = res.data[keyName].land.top_image;
self.middleImg = res.data[keyName].land.middle_image;
if (this.pageType == 8) {
self.middleImg = res.data[keyName].land.white_image;
}
self.describe = res.data[keyName].land.describe;
}
}
}).catch(err => { });
},
mounted() {
this.$nextTick(() => {
let img = document.getElementById("center_img");
let center = document.getElementById("center");
img.onload = function (e) {
center.style.height = img.clientHeight + "px";
};
});
localStorage.clear();
},
computed: {
bindInputStyle() {
return {
'--placeholderColor': this.ftcolor,
};
},
},
methods: {
async isPageV2(data, type) {
return new Promise((resolve, reject) => {
try {
let params = {
token: data.token,
};
req.axiosGet('/key/isOnlyOneUnionVoucher', params).then(res => {
if (res.code === 200) {
if (res.data.is_only_one_union_voucher) {
resolve(true)
} else {
resolve(false)
}
} else {
resolve(false)
}
})
} catch (err) {
resolve(false)
}
})
},
// 统一跳转逻辑判断
async gotoPage(data, type) {
// 微信授权回调地址
let wxauth_url = "https://openapi.1688sup.com/wechat/oauth";
let pageV2 = await this.isPageV2(data, type); // 新页面,无须授权
if (pageV2) {
wxauth_url = "/goods-v2/ysf-reduce.html";
} else {
// xw 模块
if (data.is_voucher_auto) {
// 微信公众号授权
if (navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1) {
wxauth_url = `${wxauth_url}?jump=${location.origin}/xw-pages/homepage.html`;
} else {
wxauth_url = "/xw-pages/homepage.html"
}
setTimeout(() => {
if (type) {
locationReplace(wxauth_url);
} else {
window.location.href = wxauth_url;
}
}, 300);
return
}
// 第一步:判断是否是 微信静默授权 是 -> 拼接回调地址
if (data.is_have_webview_voucher) {
// 第二步:判断是否是包码 是 -> 走包码回调地址
if (data.settlement_data && data.settlement_data.settlement_type > 0) {
// ***包码逻辑 打开结算 2
if (!data.settlement_data.is_settlement && data.settlement_data.settlement_type === 2) {
settlementFun(data.token, data.settlement_data.settlement_type);
}
wxauth_url = `${wxauth_url}?jump=${location.origin}/packkey/bm-index.html`;
} else {
// 不是包码
if (this.pageType === 4 || this.pageType === 8) {
wxauth_url = `${wxauth_url}?jump=${location.origin}/coupon/couponCollection.html`;
} else {
wxauth_url = `${wxauth_url}?jump=${location.origin}/homepage.html`;
}
}
} else {
// 第一步:判断是否是 微信静默授权 是 -> 拼接回调地址
if (data.is_have_webview_voucher) {
// 第二步:判断是否是包码 是 -> 走包码回调地址
if (data.settlement_data && data.settlement_data.settlement_type > 0) {
// ***包码逻辑 打开结算 2
if (!data.settlement_data.is_settlement && data.settlement_data.settlement_type === 2) {
settlementFun(data.token, data.settlement_data.settlement_type);
}
wxauth_url = `${wxauth_url}?jump=${location.origin}/packkey/bm-index.html`;
} else {
// 不是包码
if (this.pageType === 4 || this.pageType === 8) {
wxauth_url = `${wxauth_url}?jump=${location.origin}/coupon/couponCollection.html`;
} else {
wxauth_url = `${wxauth_url}?jump=${location.origin}/homepage.html`;
}
}
} else {
// 第三步:不需要微信静默授权
if (data.settlement_data && data.settlement_data.settlement_type > 0) {
// ***包码逻辑 打开结算 2
if (!data.settlement_data.is_settlement && data.settlement_data.settlement_type === 2) {
settlementFun(data.token, data.settlement_data.settlement_type);
}
wxauth_url = '/packkey/bm-index.html';
} else {
// 不是包码
if (this.pageType === 4 || this.pageType === 8) {
wxauth_url = '/coupon/couponCollection.html';
} else {
wxauth_url = '/homepage.html';
}
}
}
}
}
// 第四步:是否需要记录 当前页面
setTimeout(() => {
if (type) {
locationReplace(wxauth_url);
} else {
window.location.href = wxauth_url;
}
}, 300);
},
/* 获取定制消息 */
getMessage(plan_id) {
if (plan_id) {
req.axiosGet(`/client/plan/${plan_id}/result_message`).then(res => {
if (res.code == 200) {
sessionStorage.setItem('message', JSON.stringify(res.data));
} else {
self.openErrorDialog(res.message);
}
}).catch(err => { });
}
},
//获取白名单验证码
getcode() {
let self = this;
let data = {
'mobile': this.key,
'plan_id': this.plan_id
};
req.axiosPost('/sms/sendMobileExchangeCode', data).then(res => {
if (res.code == 200) {
let timeId = 60;
let timer = setInterval(() => {
timeId--;
if (timeId > 0) {
self.codetip = timeId + 's';
self.disabled = true;
} else {
clearInterval(timer);
self.codetip = '获取验证码';
self.disabled = false;
}
}, 1000);
} else {
self.openErrorDialog(res.message);
}
}).catch(err => { });
},
submit() {
let self = this;
if (!this.key) {
this.openDialog('请输入兑换码');
return;
}
if (!this.code) {
this.openDialog('请输入验证码');
return;
}
if (this.disabledBtn) {
return;
}
this.disabledBtn = true;
if ([3, 4].includes(this.pageType)) {//兑换码、优惠卷
let data = {
"key": this.key,
"code": this.code,
"code_unique_str": sessionStorage.getItem('unique_str'),
"theme_type": this.pageType
};
req.axiosPost('/key/login', data).then(res => {
setTimeout(() => {
self.disabledBtn = false;
}, 2000);
if (res.code == 200) {
this.openDialog('正在加载商品...');
localStorage.setItem('key', self.key);
localStorage.setItem('token', res.data.token);
localStorage.setItem('entryLink', window.location.href); //存储起始页链接
sessionStorage.setItem("bm_auth", JSON.stringify(res.data)); // 存储包码数据
sessionStorage.setItem("key_expiration_time", res.data.key_expiration_time); // 存储时间
// 存储时间 注意!!!:新网项目需要跳转到 直连天下授权 所以需要存储时间,必须用 localStorage 不然会消失!!!
localStorage.setItem("key_expiration_time", res.data.key_expiration_time); // 存储时间
// 统一跳转函数
this.gotoPage(res.data);
} else {
self.openErrorDialog(res.message);
}
}).catch(err => { });
} else if ([1, 8].includes(this.pageType)) {//白名单
let par = {
"code": this.code,
"mobile": this.key,
"plan_id": this.plan_id,
};
let getTokenList = [];//多个批次下的key存放token
req.axiosPostgetKey('/key/getKeyByMobile', par).then(async res => {
setTimeout(() => {
self.disabledBtn = false;
}, 2000);
if (res.data.code == 200) {
localStorage.setItem('key', self.key);
localStorage.setItem('token', res.data.data);
localStorage.setItem('showType', 1);
localStorage.setItem('white_link', window.location.href);
let tokenArr = res.data.data;
let istoGoods = false;
let form_data_res = null;
for (item of tokenArr) {
let obj = {};
let data = {
"code_unique_str": res.headers['unique-str'],
"key": item,
"theme_type": this.pageType
};
let wait = await req.axiosPost('/key/loginFromMobileKey', data).then(res => {
if (res.code == 200) {
form_data_res = res;
getTokenList.push(res.data.token);
istoGoods = true;
} else {
if (res.message == '活动暂停中') {
self.tiptext = res.message;
istoGoods = false;
} else {
self.tiptext = res.message;
}
}
}).catch(err => { });
};
if (istoGoods) {
this.openDialog('正在加载商品...');
localStorage.setItem('getTokenList', JSON.stringify(getTokenList));
localStorage.setItem('entryLink', window.location.href);//存储起始页链接
sessionStorage.setItem("bm_auth", JSON.stringify(form_data_res.data)); // 存储包码数据
sessionStorage.setItem("key_expiration_time", res.data.key_expiration_time); // 存储时间
// 存储时间 注意!!!:新网项目需要跳转到 直连天下授权 所以需要存储时间,必须用 localStorage 不然会消失!!!
localStorage.setItem("key_expiration_time", res.data.key_expiration_time); // 存储时间
// 统一跳转函数
this.gotoPage(form_data_res.data);
} else {
self.openErrorDialog(self.tiptext);
}
} else {
self.openErrorDialog(res.data.message);
}
}).catch(err => { });
}
},
// 单条弹框
openDialog(tip) {
this.promtshow = true;
this.promttip = tip;
let clr = setTimeout(() => {
this.promtshow = false;
this.promttip = '';
}, 500);
},
//错误弹出框
openErrorDialog(tip) {
this.popTitle = '温馨提示';
this.popText = tip;
this.popStatus = 3;
this.popShow = true;
}
},
watch: {
key(val) {
this.disabled = Boolean(!([1, 8].includes(this.pageType) && val.length == 11));
}
}
});
</script>
</html>