(function() {
window.cardfunc = {
caller: null,
token: "",
ecId: 0, // 卡片id
isNewUser: false, // 是否新用户
cardConfigData: {
tabActiveColor: "#81cd00",
popupRuleConfig: {}, // 规则弹窗配置
popupRuleList: [], // 规则弹窗数据
popupExchgConfig: {}, // 兑换地址弹窗配置
popupExchgList: [], // 兑换地址弹窗数据
popupHelpConfig: {}, // 帮助弹窗配置
popupHelpList: [],
popupMessageConfig: {}, // 通知弹窗配置
popupMessageList: [], // 通知弹窗数据
popupWarnConfig: {}, // 警告弹窗配置
popupWarnList: [], // 警告弹窗数据
},
userConfigData: {
},
init(token, ecId) {
// this.caller = caller; // Not used in pure HTML logic usually
this.token = token;
this.ecId = ecId;
this.removeCss();
},
// 清除css
removeCss() {
if(window.tools) {
window.tools.removeCssCode("css-common");
window.tools.removeCssCode("css-custom");
window.tools.removeCssCode("css-user");
}
},
getCardConfig(loadConfig, testconfig) {
// Assuming remote config for H5
this.cardConfigQuery(loadConfig);
},
getUserConfig(loadConfig, testconfig) {
this.userConfigQuery(loadConfig);
},
parseCardConfig(cardconfig) {
if (cardconfig == undefined || cardconfig == "") {
return;
}
if (typeof cardconfig == "string") {
cardconfig = cardconfig.replace(/[\r|\n|\t]/g, "");
const config = JSON.parse(cardconfig);
return config;
} else {
return cardconfig;
}
},
// 加载卡片通用配置
loadCardCommonConfig(config_common) {
config_common = this.parseCardConfig(config_common);
if (config_common == undefined || config_common == "") {
return;
}
if (config_common.css != undefined && config_common.css.length > 0) {
if(window.tools) window.tools.loadCssCode(config_common.css, "css-common");
}
if (config_common.tabActiveColor != undefined && config_common.tabActiveColor.length > 0) {
this.cardConfigData.tabActiveColor = config_common.tabActiveColor;
}
// 加载规则弹窗配置
if (config_common.popupRuleConfig != undefined) {
this.cardConfigData.popupRuleConfig = config_common.popupRuleConfig;
}
// 加载帮助弹窗配置
if (config_common.popupHelpConfig != undefined) {
this.cardConfigData.popupHelpConfig = config_common.popupHelpConfig;
}
// 加载警告弹窗配置
if (config_common.popupWarnConfig != undefined) {
this.cardConfigData.popupWarnConfig = config_common.popupWarnConfig;
}
// 加载兑换地址弹窗配置
if (config_common.popupExchgConfig != undefined) {
this.cardConfigData.popupExchgConfig = config_common.popupExchgConfig;
}
// 加载通知弹窗配置
if (config_common.popupMessageConfig != undefined) {
this.cardConfigData.popupMessageConfig = config_common.popupMessageConfig;
}
// 加载弹窗(规则)数据
const popupRuleList = config_common.popupRuleList;
if (popupRuleList != undefined && popupRuleList.length > 0) {
this.cardConfigData.popupRuleList.length = 0;
for (var i = 0; i < popupRuleList.length; i++) {
if (popupRuleList[i] == 'default') {
for (var j = 0; j < defaultPopUpDataList.length; j++) {
this.cardConfigData.popupRuleList.push(defaultPopUpDataList[j]);
}
} else if (popupRuleList[i] == 'default2') {
for (var j = 0; j < defaultPopUpDataList2.length; j++) {
this.cardConfigData.popupRuleList.push(defaultPopUpDataList2[j]);
}
} else if (popupRuleList[i] == 'default3') {
for (var j = 0; j < defaultPopUpDataList3.length; j++) {
this.cardConfigData.popupRuleList.push(defaultPopUpDataList3[j]);
}
} else {
this.cardConfigData.popupRuleList.push(popupRuleList[i]);
}
}
} else {
this.cardConfigData.popupRuleList = defaultPopUpDataList2;
}
// 加载弹窗(兑换地址)数据
const popupExchgList = config_common.popupExchgList;
if (popupExchgList != undefined && popupExchgList.length > 0) {
this.cardConfigData.popupExchgList.length = 0;
for (var i = 0; i < popupExchgList.length; i++) {
this.cardConfigData.popupExchgList.push(popupExchgList[i]);
}
}
// 加载弹窗(帮助)数据
const popupHelpList = config_common.popupHelpList;
if (popupHelpList != undefined && popupHelpList.length > 0) {
this.cardConfigData.popupHelpList.length = 0;
for (var i = 0; i < popupHelpList.length; i++) {
this.cardConfigData.popupHelpList.push(popupHelpList[i]);
}
}
},
// 加载用户的弹窗数据
loadUserPopupRule(config) {
const tplInfo = config.tplInfo;
const matchInfo = config.matchInfo;
if (matchInfo) {
let hint = "参赛要求
";
hint += "① 赛事以自身安全为最高要求,请正确评估自身健康,切勿超负荷运动,适时参赛
② 参赛人群建议:6-60岁健康居民
";
hint += "
安全提醒
";
hint += "① 请着运动服及运动鞋
② 避免聚集、分散参与
③ 及时增减衣物,预防感冒
④ 注意交通安全与自身安全";
const contact = `联系人:${matchInfo.contactName} 电话:${matchInfo.phone}`;
const content = `${hint}
${contact}`;
const defaultMatchLogo = getApp().globalData.defaultMatchLogo;
const logoSrc = (tplInfo.matchLogo != undefined && tplInfo.matchLogo != "") ? tplInfo.matchLogo : defaultMatchLogo;
const popupRule = [{
"type": 1,
"data": {
"title": matchInfo.compName,
"logo": {
"src": logoSrc,
"width": "260px",
"height": "90px"
},
"content": content
}
}];
this.cardConfigData.popupRuleList.unshift(...popupRule);
}
},
// 获取用户的比赛路线数据
getUserPathList(config) {
const mapInfo = config.mapInfo;
const mapNum = mapInfo.length;
let pathList = {};
if (mapNum > 0) {
let activityList = [];
// 将多地图的路线信息数组合并成一个数组
for (var m = 0; m < mapNum; m++) {
activityList.push(...mapInfo[m].activityList);
}
const activityNum = activityList.length;
let type = 4;
let navImg = "/static/common/nav3.png";
if (activityNum > 1) {
type = 3;
navImg = "/static/common/nav.png";
}
if (activityNum > 0) {
const rowSize = 2; // 每行显示的路线数量
const rowNum = Math.ceil(activityNum / rowSize);
for (var i = 0; i < rowNum; i++) {
let row = [];
for (var j = 0; j < rowSize; j++) {
const activity = activityList[i * rowSize + j];
if (!activity) {
break;
}
const path = {
"type": type,
"pathName": activity.showName,
"pathImg": activity.pathImg,
"path": {
"ocaId": activity.ocaId,
"mcType": activity.matchType
},
"navImg": navImg,
"point": {
"longitude": activity.point.longitude,
"latitude": activity.point.latitude,
"name": activity.point.name
}
};
row.push(path);
}
pathList["row" + (i + 1)] = row;
}
}
} else {
console.warn("[getUserPathList] mapInfo err:", mapInfo);
}
return pathList;
},
// 卡片配置信息查询
cardConfigQuery(callback) {
uni.request({
url: window.apiCardConfigQuery,
header: {
"Content-Type": "application/x-www-form-urlencoded",
"token": this.token,
},
method: "POST",
data: {
ecId: this.ecId,
pageName: "all"
},
success: (res) => {
if(res.data && res.data.data) {
const data = res.data.data;
const config = data.configJson;
callback(config);
}
},
fail: (err) => {
console.log("[cardConfigQuery] err", err);
},
});
},
// 用户自定义配置信息查询
userConfigQuery(callback) {
uni.request({
url: window.apiUserConfigQuery,
header: {
"Content-Type": "application/x-www-form-urlencoded",
"token": this.token,
},
method: "POST",
data: {
ecId: this.ecId,
pageName: "all"
},
success: (res) => {
if(res.data && res.data.data) {
const data = res.data.data;
const config = data.configJson;
callback(config);
}
},
fail: (err) => {
console.log("[userConfigQuery] err", err);
},
});
},
// 警告列表查询
warnMessageQuery(callback=null) {
uni.request({
url: window.apiWarnMessageQuery,
header: {
"Content-Type": "application/x-www-form-urlencoded",
"token": this.token,
},
method: "POST",
data: {
ecId: this.ecId
},
success: (res) => {
if (checkResCode(res)) {
const warnRs = res.data.data;
this.cardConfigData.popupWarnList.length = 0;
for (var i = 0; i < warnRs.length; i++) {
let popupData = {
type: 9, // 9: 警告
data: {}
};
popupData.data.warnType = warnRs[i].warnType;
popupData.data.title = warnRs[i].warnTitle;
popupData.data.iconUrl = warnRs[i].iconUrl;
popupData.data.iconNum = warnRs[i].iconNum;
popupData.data.message = warnRs[i].warnMessage;
popupData.data.qrCodeUrl = warnRs[i].qrCodeUrl;
this.cardConfigData.popupWarnList.push(popupData);
}
if (callback != null) {
callback(this.cardConfigData.popupWarnList);
}
}
},
fail: (err) => {
console.log("warnMessageQuery err", err)
},
});
},
// 未读消息列表查询
unReadMessageQuery(callback=null) {
uni.request({
url: window.apiUnReadMessageQuery,
header: {
"Content-Type": "application/x-www-form-urlencoded",
"token": this.token,
},
method: "POST",
data: {
relationType: 2, // 类型 1 成就 2 卡片
relationId: this.ecId
},
success: (res) => {
if (checkResCode(res)) {
const unReadMessageRs = res.data.data;
this.cardConfigData.popupMessageList.length = 0;
let mqIdListStr = "";
for (var i = 0; i < unReadMessageRs.length; i++) {
let popupData = {
type: 6, // 6: 通知
data: {}
};
mqIdListStr += "-" + unReadMessageRs[i].mqId;
popupData.data.mqType = unReadMessageRs[i].mqType;
popupData.data.title = unReadMessageRs[i].mqTitle;
popupData.data.message = unReadMessageRs[i].mqMessage;
this.cardConfigData.popupMessageList.push(popupData);
}
if (callback != null) {
callback(this.cardConfigData.popupMessageList, mqIdListStr);
}
}
},
fail: (err) => {
console.log("getUnReadMessageQuery err", err);
},
});
},
// 用户是否新用户
isNewUserQuery(callback=null) {
uni.request({
url: window.apiIsNewUserInCardComp,
header: {
"Content-Type": "application/x-www-form-urlencoded",
"token": this.token,
},
method: "POST",
data: {
// ecId: this.ecId
ecId: 0 // 0 全部赛事活动
},
success: (res) => {
if (checkResCode(res)) {
this.isNewUser = res.data.data.isNew;
if (callback != null) {
callback(this.isNewUser);
}
}
},
fail: (err) => {
console.log("isNewUserInCardComp err", err);
},
});
},
}
})();