| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- (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 = "<span style='color:#FF5E00;'>参赛要求</span><br>";
- hint += "① 赛事以自身安全为最高要求,请正确评估自身健康,切勿超负荷运动,适时参赛<br>② 参赛人群建议:6-60岁健康居民<br>";
- hint += "<br><span style='color:#FF5E00;'>安全提醒</span><br>";
- hint += "① 请着运动服及运动鞋<br>② 避免聚集、分散参与<br>③ 及时增减衣物,预防感冒<br>④ 注意交通安全与自身安全";
- const contact = `联系人:${matchInfo.contactName} 电话:<a href='tel:${matchInfo.phone}' style='color: #ff5500;'>${matchInfo.phone}</a>`;
- const content = `${hint}<br><br>${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);
- },
- });
- },
-
- }
- })();
|