cardfunc.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. (function() {
  2. window.cardfunc = {
  3. caller: null,
  4. token: "",
  5. ecId: 0, // 卡片id
  6. isNewUser: false, // 是否新用户
  7. cardConfigData: {
  8. tabActiveColor: "#81cd00",
  9. popupRuleConfig: {}, // 规则弹窗配置
  10. popupRuleList: [], // 规则弹窗数据
  11. popupExchgConfig: {}, // 兑换地址弹窗配置
  12. popupExchgList: [], // 兑换地址弹窗数据
  13. popupHelpConfig: {}, // 帮助弹窗配置
  14. popupHelpList: [],
  15. popupMessageConfig: {}, // 通知弹窗配置
  16. popupMessageList: [], // 通知弹窗数据
  17. popupWarnConfig: {}, // 警告弹窗配置
  18. popupWarnList: [], // 警告弹窗数据
  19. },
  20. userConfigData: {
  21. },
  22. init(token, ecId) {
  23. // this.caller = caller; // Not used in pure HTML logic usually
  24. this.token = token;
  25. this.ecId = ecId;
  26. this.removeCss();
  27. },
  28. // 清除css
  29. removeCss() {
  30. if(window.tools) {
  31. window.tools.removeCssCode("css-common");
  32. window.tools.removeCssCode("css-custom");
  33. window.tools.removeCssCode("css-user");
  34. }
  35. },
  36. getCardConfig(loadConfig, testconfig) {
  37. // Assuming remote config for H5
  38. this.cardConfigQuery(loadConfig);
  39. },
  40. getUserConfig(loadConfig, testconfig) {
  41. this.userConfigQuery(loadConfig);
  42. },
  43. parseCardConfig(cardconfig) {
  44. if (cardconfig == undefined || cardconfig == "") {
  45. return;
  46. }
  47. if (typeof cardconfig == "string") {
  48. cardconfig = cardconfig.replace(/[\r|\n|\t]/g, "");
  49. const config = JSON.parse(cardconfig);
  50. return config;
  51. } else {
  52. return cardconfig;
  53. }
  54. },
  55. // 加载卡片通用配置
  56. loadCardCommonConfig(config_common) {
  57. config_common = this.parseCardConfig(config_common);
  58. if (config_common == undefined || config_common == "") {
  59. return;
  60. }
  61. if (config_common.css != undefined && config_common.css.length > 0) {
  62. if(window.tools) window.tools.loadCssCode(config_common.css, "css-common");
  63. }
  64. if (config_common.tabActiveColor != undefined && config_common.tabActiveColor.length > 0) {
  65. this.cardConfigData.tabActiveColor = config_common.tabActiveColor;
  66. }
  67. // 加载规则弹窗配置
  68. if (config_common.popupRuleConfig != undefined) {
  69. this.cardConfigData.popupRuleConfig = config_common.popupRuleConfig;
  70. }
  71. // 加载帮助弹窗配置
  72. if (config_common.popupHelpConfig != undefined) {
  73. this.cardConfigData.popupHelpConfig = config_common.popupHelpConfig;
  74. }
  75. // 加载警告弹窗配置
  76. if (config_common.popupWarnConfig != undefined) {
  77. this.cardConfigData.popupWarnConfig = config_common.popupWarnConfig;
  78. }
  79. // 加载兑换地址弹窗配置
  80. if (config_common.popupExchgConfig != undefined) {
  81. this.cardConfigData.popupExchgConfig = config_common.popupExchgConfig;
  82. }
  83. // 加载通知弹窗配置
  84. if (config_common.popupMessageConfig != undefined) {
  85. this.cardConfigData.popupMessageConfig = config_common.popupMessageConfig;
  86. }
  87. // 加载弹窗(规则)数据
  88. const popupRuleList = config_common.popupRuleList;
  89. if (popupRuleList != undefined && popupRuleList.length > 0) {
  90. this.cardConfigData.popupRuleList.length = 0;
  91. for (var i = 0; i < popupRuleList.length; i++) {
  92. if (popupRuleList[i] == 'default') {
  93. for (var j = 0; j < defaultPopUpDataList.length; j++) {
  94. this.cardConfigData.popupRuleList.push(defaultPopUpDataList[j]);
  95. }
  96. } else if (popupRuleList[i] == 'default2') {
  97. for (var j = 0; j < defaultPopUpDataList2.length; j++) {
  98. this.cardConfigData.popupRuleList.push(defaultPopUpDataList2[j]);
  99. }
  100. } else if (popupRuleList[i] == 'default3') {
  101. for (var j = 0; j < defaultPopUpDataList3.length; j++) {
  102. this.cardConfigData.popupRuleList.push(defaultPopUpDataList3[j]);
  103. }
  104. } else {
  105. this.cardConfigData.popupRuleList.push(popupRuleList[i]);
  106. }
  107. }
  108. } else {
  109. this.cardConfigData.popupRuleList = defaultPopUpDataList2;
  110. }
  111. // 加载弹窗(兑换地址)数据
  112. const popupExchgList = config_common.popupExchgList;
  113. if (popupExchgList != undefined && popupExchgList.length > 0) {
  114. this.cardConfigData.popupExchgList.length = 0;
  115. for (var i = 0; i < popupExchgList.length; i++) {
  116. this.cardConfigData.popupExchgList.push(popupExchgList[i]);
  117. }
  118. }
  119. // 加载弹窗(帮助)数据
  120. const popupHelpList = config_common.popupHelpList;
  121. if (popupHelpList != undefined && popupHelpList.length > 0) {
  122. this.cardConfigData.popupHelpList.length = 0;
  123. for (var i = 0; i < popupHelpList.length; i++) {
  124. this.cardConfigData.popupHelpList.push(popupHelpList[i]);
  125. }
  126. }
  127. },
  128. // 加载用户的弹窗数据
  129. loadUserPopupRule(config) {
  130. const tplInfo = config.tplInfo;
  131. const matchInfo = config.matchInfo;
  132. if (matchInfo) {
  133. let hint = "<span style='color:#FF5E00;'>参赛要求</span><br>";
  134. hint += "① 赛事以自身安全为最高要求,请正确评估自身健康,切勿超负荷运动,适时参赛<br>② 参赛人群建议:6-60岁健康居民<br>";
  135. hint += "<br><span style='color:#FF5E00;'>安全提醒</span><br>";
  136. hint += "① 请着运动服及运动鞋<br>② 避免聚集、分散参与<br>③ 及时增减衣物,预防感冒<br>④ 注意交通安全与自身安全";
  137. const contact = `联系人:${matchInfo.contactName} &nbsp;&nbsp; 电话:<a href='tel:${matchInfo.phone}' style='color: #ff5500;'>${matchInfo.phone}</a>`;
  138. const content = `${hint}<br><br>${contact}`;
  139. const defaultMatchLogo = getApp().globalData.defaultMatchLogo;
  140. const logoSrc = (tplInfo.matchLogo != undefined && tplInfo.matchLogo != "") ? tplInfo.matchLogo : defaultMatchLogo;
  141. const popupRule = [{
  142. "type": 1,
  143. "data": {
  144. "title": matchInfo.compName,
  145. "logo": {
  146. "src": logoSrc,
  147. "width": "260px",
  148. "height": "90px"
  149. },
  150. "content": content
  151. }
  152. }];
  153. this.cardConfigData.popupRuleList.unshift(...popupRule);
  154. }
  155. },
  156. // 获取用户的比赛路线数据
  157. getUserPathList(config) {
  158. const mapInfo = config.mapInfo;
  159. const mapNum = mapInfo.length;
  160. let pathList = {};
  161. if (mapNum > 0) {
  162. let activityList = [];
  163. // 将多地图的路线信息数组合并成一个数组
  164. for (var m = 0; m < mapNum; m++) {
  165. activityList.push(...mapInfo[m].activityList);
  166. }
  167. const activityNum = activityList.length;
  168. let type = 4;
  169. let navImg = "/static/common/nav3.png";
  170. if (activityNum > 1) {
  171. type = 3;
  172. navImg = "/static/common/nav.png";
  173. }
  174. if (activityNum > 0) {
  175. const rowSize = 2; // 每行显示的路线数量
  176. const rowNum = Math.ceil(activityNum / rowSize);
  177. for (var i = 0; i < rowNum; i++) {
  178. let row = [];
  179. for (var j = 0; j < rowSize; j++) {
  180. const activity = activityList[i * rowSize + j];
  181. if (!activity) {
  182. break;
  183. }
  184. const path = {
  185. "type": type,
  186. "pathName": activity.showName,
  187. "pathImg": activity.pathImg,
  188. "path": {
  189. "ocaId": activity.ocaId,
  190. "mcType": activity.matchType
  191. },
  192. "navImg": navImg,
  193. "point": {
  194. "longitude": activity.point.longitude,
  195. "latitude": activity.point.latitude,
  196. "name": activity.point.name
  197. }
  198. };
  199. row.push(path);
  200. }
  201. pathList["row" + (i + 1)] = row;
  202. }
  203. }
  204. } else {
  205. console.warn("[getUserPathList] mapInfo err:", mapInfo);
  206. }
  207. return pathList;
  208. },
  209. // 卡片配置信息查询
  210. cardConfigQuery(callback) {
  211. uni.request({
  212. url: window.apiCardConfigQuery,
  213. header: {
  214. "Content-Type": "application/x-www-form-urlencoded",
  215. "token": this.token,
  216. },
  217. method: "POST",
  218. data: {
  219. ecId: this.ecId,
  220. pageName: "all"
  221. },
  222. success: (res) => {
  223. if(res.data && res.data.data) {
  224. const data = res.data.data;
  225. const config = data.configJson;
  226. callback(config);
  227. }
  228. },
  229. fail: (err) => {
  230. console.log("[cardConfigQuery] err", err);
  231. },
  232. });
  233. },
  234. // 用户自定义配置信息查询
  235. userConfigQuery(callback) {
  236. uni.request({
  237. url: window.apiUserConfigQuery,
  238. header: {
  239. "Content-Type": "application/x-www-form-urlencoded",
  240. "token": this.token,
  241. },
  242. method: "POST",
  243. data: {
  244. ecId: this.ecId,
  245. pageName: "all"
  246. },
  247. success: (res) => {
  248. if(res.data && res.data.data) {
  249. const data = res.data.data;
  250. const config = data.configJson;
  251. callback(config);
  252. }
  253. },
  254. fail: (err) => {
  255. console.log("[userConfigQuery] err", err);
  256. },
  257. });
  258. },
  259. // 警告列表查询
  260. warnMessageQuery(callback=null) {
  261. uni.request({
  262. url: window.apiWarnMessageQuery,
  263. header: {
  264. "Content-Type": "application/x-www-form-urlencoded",
  265. "token": this.token,
  266. },
  267. method: "POST",
  268. data: {
  269. ecId: this.ecId
  270. },
  271. success: (res) => {
  272. if (checkResCode(res)) {
  273. const warnRs = res.data.data;
  274. this.cardConfigData.popupWarnList.length = 0;
  275. for (var i = 0; i < warnRs.length; i++) {
  276. let popupData = {
  277. type: 9, // 9: 警告
  278. data: {}
  279. };
  280. popupData.data.warnType = warnRs[i].warnType;
  281. popupData.data.title = warnRs[i].warnTitle;
  282. popupData.data.iconUrl = warnRs[i].iconUrl;
  283. popupData.data.iconNum = warnRs[i].iconNum;
  284. popupData.data.message = warnRs[i].warnMessage;
  285. popupData.data.qrCodeUrl = warnRs[i].qrCodeUrl;
  286. this.cardConfigData.popupWarnList.push(popupData);
  287. }
  288. if (callback != null) {
  289. callback(this.cardConfigData.popupWarnList);
  290. }
  291. }
  292. },
  293. fail: (err) => {
  294. console.log("warnMessageQuery err", err)
  295. },
  296. });
  297. },
  298. // 未读消息列表查询
  299. unReadMessageQuery(callback=null) {
  300. uni.request({
  301. url: window.apiUnReadMessageQuery,
  302. header: {
  303. "Content-Type": "application/x-www-form-urlencoded",
  304. "token": this.token,
  305. },
  306. method: "POST",
  307. data: {
  308. relationType: 2, // 类型 1 成就 2 卡片
  309. relationId: this.ecId
  310. },
  311. success: (res) => {
  312. if (checkResCode(res)) {
  313. const unReadMessageRs = res.data.data;
  314. this.cardConfigData.popupMessageList.length = 0;
  315. let mqIdListStr = "";
  316. for (var i = 0; i < unReadMessageRs.length; i++) {
  317. let popupData = {
  318. type: 6, // 6: 通知
  319. data: {}
  320. };
  321. mqIdListStr += "-" + unReadMessageRs[i].mqId;
  322. popupData.data.mqType = unReadMessageRs[i].mqType;
  323. popupData.data.title = unReadMessageRs[i].mqTitle;
  324. popupData.data.message = unReadMessageRs[i].mqMessage;
  325. this.cardConfigData.popupMessageList.push(popupData);
  326. }
  327. if (callback != null) {
  328. callback(this.cardConfigData.popupMessageList, mqIdListStr);
  329. }
  330. }
  331. },
  332. fail: (err) => {
  333. console.log("getUnReadMessageQuery err", err);
  334. },
  335. });
  336. },
  337. // 用户是否新用户
  338. isNewUserQuery(callback=null) {
  339. uni.request({
  340. url: window.apiIsNewUserInCardComp,
  341. header: {
  342. "Content-Type": "application/x-www-form-urlencoded",
  343. "token": this.token,
  344. },
  345. method: "POST",
  346. data: {
  347. // ecId: this.ecId
  348. ecId: 0 // 0 全部赛事活动
  349. },
  350. success: (res) => {
  351. if (checkResCode(res)) {
  352. this.isNewUser = res.data.data.isNew;
  353. if (callback != null) {
  354. callback(this.isNewUser);
  355. }
  356. }
  357. },
  358. fail: (err) => {
  359. console.log("isNewUserInCardComp err", err);
  360. },
  361. });
  362. },
  363. }
  364. })();