cardfunc.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. import tools from '/common/tools';
  2. import {
  3. apiCardConfigQuery,
  4. apiUserConfigQuery,
  5. apiWarnMessageQuery,
  6. apiUnReadMessageQuery,
  7. apiIsNewUserInCardComp,
  8. checkResCode
  9. } from '/common/api';
  10. import {
  11. defaultPopUpDataList,
  12. defaultPopUpDataList2,
  13. defaultPopUpDataList3
  14. } from '/common/define';
  15. var cardfunc = {
  16. caller: null,
  17. token: "",
  18. ecId: 0, // 卡片id
  19. isNewUser: false, // 是否新用户
  20. cardConfigData: {
  21. tabActiveColor: "#81cd00",
  22. popupRuleConfig: {}, // 规则弹窗配置
  23. popupRuleList: [], // 规则弹窗数据
  24. popupExchgConfig: {}, // 兑换地址弹窗配置
  25. popupExchgList: [], // 兑换地址弹窗数据
  26. popupHelpConfig: {}, // 帮助弹窗配置
  27. popupHelpList: [],
  28. popupMessageConfig: {}, // 通知弹窗配置
  29. popupMessageList: [], // 通知弹窗数据
  30. popupWarnConfig: {}, // 警告弹窗配置
  31. popupWarnList: [], // 警告弹窗数据
  32. },
  33. userConfigData: {
  34. },
  35. init(caller, token, ecId) {
  36. this.caller = caller;
  37. this.token = token;
  38. this.ecId = ecId;
  39. this.removeCss();
  40. },
  41. // 清除css
  42. removeCss() {
  43. tools.removeCssCode("css-common");
  44. tools.removeCssCode("css-custom");
  45. tools.removeCssCode("css-user");
  46. },
  47. getCardConfig(loadConfig, testconfig) {
  48. const cardconfigType = getApp().$cardconfigType;
  49. // console.log("[getConfig] cardconfigType:", cardconfigType);
  50. if (cardconfigType == "local") {
  51. loadConfig(testconfig);
  52. // this.testCardConfig(testconfig, loadConfig);
  53. } else {
  54. this.cardConfigQuery(loadConfig);
  55. }
  56. },
  57. getUserConfig(loadConfig, testconfig) {
  58. const cardconfigType = getApp().$cardconfigType;
  59. // console.log("[getConfig] cardconfigType:", cardconfigType);
  60. if (cardconfigType == "local") {
  61. loadConfig(testconfig);
  62. // this.testCardConfig(testconfig, loadConfig);
  63. } else {
  64. this.userConfigQuery(loadConfig);
  65. }
  66. },
  67. parseCardConfig(cardconfig) {
  68. // console.log("[parseCardConfig] cardconfig:", cardconfig);
  69. if (cardconfig == undefined || cardconfig == "") {
  70. return;
  71. }
  72. if (typeof cardconfig == "string") {
  73. cardconfig = cardconfig.replace(/[\r|\n|\t]/g, "");
  74. const config = JSON.parse(cardconfig);
  75. // console.log("[parseCardConfig] config:", config);
  76. return config;
  77. } else {
  78. return cardconfig;
  79. }
  80. },
  81. // 加载卡片通用配置
  82. loadCardCommonConfig(config_common) {
  83. // console.log("[loadCardCommonConfig] config_common:", config_common);
  84. config_common = this.parseCardConfig(config_common);
  85. if (config_common == undefined || config_common == "") {
  86. return;
  87. }
  88. if (config_common.css != undefined && config_common.css.length > 0) {
  89. tools.loadCssCode(config_common.css, "css-common");
  90. }
  91. if (config_common.tabActiveColor != undefined && config_common.tabActiveColor.length > 0) {
  92. this.cardConfigData.tabActiveColor = config_common.tabActiveColor;
  93. }
  94. // 加载规则弹窗配置
  95. if (config_common.popupRuleConfig != undefined) {
  96. this.cardConfigData.popupRuleConfig = config_common.popupRuleConfig;
  97. }
  98. // 加载帮助弹窗配置
  99. if (config_common.popupHelpConfig != undefined) {
  100. this.cardConfigData.popupHelpConfig = config_common.popupHelpConfig;
  101. }
  102. // 加载警告弹窗配置
  103. if (config_common.popupWarnConfig != undefined) {
  104. this.cardConfigData.popupWarnConfig = config_common.popupWarnConfig;
  105. }
  106. // 加载兑换地址弹窗配置
  107. if (config_common.popupExchgConfig != undefined) {
  108. this.cardConfigData.popupExchgConfig = config_common.popupExchgConfig;
  109. }
  110. // 加载通知弹窗配置
  111. if (config_common.popupMessageConfig != undefined) {
  112. this.cardConfigData.popupMessageConfig = config_common.popupMessageConfig;
  113. }
  114. // 加载弹窗(规则)数据
  115. const popupRuleList = config_common.popupRuleList;
  116. // console.log("[loadCardCommonConfig] popupRuleList:", popupRuleList);
  117. if (popupRuleList != undefined && popupRuleList.length > 0) {
  118. this.cardConfigData.popupRuleList.length = 0;
  119. for (var i = 0; i < popupRuleList.length; i++) {
  120. // console.log("[loadCardCommonConfig] popupRuleList", i, popupRuleList[i]);
  121. if (popupRuleList[i] == 'default') {
  122. for (var j = 0; j < defaultPopUpDataList.length; j++) {
  123. this.cardConfigData.popupRuleList.push(defaultPopUpDataList[j]);
  124. }
  125. } else if (popupRuleList[i] == 'default2') {
  126. for (var j = 0; j < defaultPopUpDataList2.length; j++) {
  127. this.cardConfigData.popupRuleList.push(defaultPopUpDataList2[j]);
  128. }
  129. } else if (popupRuleList[i] == 'default3') {
  130. for (var j = 0; j < defaultPopUpDataList3.length; j++) {
  131. this.cardConfigData.popupRuleList.push(defaultPopUpDataList3[j]);
  132. }
  133. } else {
  134. this.cardConfigData.popupRuleList.push(popupRuleList[i]);
  135. }
  136. }
  137. } else {
  138. this.cardConfigData.popupRuleList = defaultPopUpDataList2;
  139. // console.log("[loadCardCommonConfig] popupRuleList 加载默认列表");
  140. }
  141. // 加载弹窗(兑换地址)数据
  142. const popupExchgList = config_common.popupExchgList;
  143. if (popupExchgList != undefined && popupExchgList.length > 0) {
  144. this.cardConfigData.popupExchgList.length = 0;
  145. for (var i = 0; i < popupExchgList.length; i++) {
  146. // console.log("[loadCardCommonConfig] popupExchgList", i, popupExchgList[i]);
  147. this.cardConfigData.popupExchgList.push(popupExchgList[i]);
  148. }
  149. }
  150. // 加载弹窗(帮助)数据
  151. const popupHelpList = config_common.popupHelpList;
  152. if (popupHelpList != undefined && popupHelpList.length > 0) {
  153. this.cardConfigData.popupHelpList.length = 0;
  154. for (var i = 0; i < popupHelpList.length; i++) {
  155. // console.log("[loadCardCommonConfig] popupHelpList", i, popupHelpList[i]);
  156. this.cardConfigData.popupHelpList.push(popupHelpList[i]);
  157. }
  158. }
  159. // console.log("[loadCardCommonConfig] cardConfigData:", this.cardConfigData);
  160. },
  161. // 加载用户的弹窗数据
  162. loadUserPopupRule(config) {
  163. const tplInfo = config.tplInfo;
  164. const matchInfo = config.matchInfo;
  165. if (matchInfo) {
  166. let hint = "<span style='color:#FF5E00;'>参赛要求</span><br>";
  167. hint += "① 赛事以自身安全为最高要求,请正确评估自身健康,切勿超负荷运动,适时参赛<br>② 参赛人群建议:6-60岁健康居民<br>";
  168. hint += "<br><span style='color:#FF5E00;'>安全提醒</span><br>";
  169. hint += "① 请着运动服及运动鞋<br>② 避免聚集、分散参与<br>③ 及时增减衣物,预防感冒<br>④ 注意交通安全与自身安全";
  170. const contact = `联系人:${matchInfo.contactName} &nbsp;&nbsp; 电话:<a href='tel:${matchInfo.phone}' style='color: #ff5500;'>${matchInfo.phone}</a>`;
  171. const content = `${hint}<br><br>${contact}`;
  172. // const content = `${matchInfo.description}<br><br>${contact}`;
  173. const defaultMatchLogo = getApp().globalData.defaultMatchLogo;
  174. // console.log(defaultMatchLogo);
  175. const logoSrc = (tplInfo.matchLogo != undefined && tplInfo.matchLogo != "") ? tplInfo.matchLogo : defaultMatchLogo;
  176. const popupRule = [{
  177. "type": 1,
  178. "data": {
  179. "title": matchInfo.compName,
  180. "logo": {
  181. "src": logoSrc,
  182. "width": "260px",
  183. "height": "90px"
  184. },
  185. "content": content
  186. }
  187. }];
  188. this.cardConfigData.popupRuleList.unshift(...popupRule);
  189. }
  190. },
  191. // 获取用户的比赛路线数据
  192. getUserPathList(config) {
  193. const mapInfo = config.mapInfo;
  194. const mapNum = mapInfo.length;
  195. let pathList = {};
  196. if (mapNum > 0) {
  197. let activityList = [];
  198. // 将多地图的路线信息数组合并成一个数组
  199. for (var m = 0; m < mapNum; m++) {
  200. activityList.push(...mapInfo[m].activityList);
  201. }
  202. console.log("[getUserPathList] activityList:", activityList);
  203. const activityNum = activityList.length;
  204. let type = 4;
  205. let navImg = "/static/common/nav3.png";
  206. if (activityNum > 1) {
  207. type = 3;
  208. navImg = "/static/common/nav.png";
  209. }
  210. if (activityNum > 0) {
  211. const rowSize = 2; // 每行显示的路线数量
  212. const rowNum = Math.ceil(activityNum / rowSize);
  213. for (var i = 0; i < rowNum; i++) {
  214. let row = [];
  215. for (var j = 0; j < rowSize; j++) {
  216. // console.log(`[getUserPathList] i: ${i} j: ${j}`);
  217. const activity = activityList[i * rowSize + j];
  218. if (!activity) {
  219. break;
  220. }
  221. const path = {
  222. "type": type,
  223. "pathName": activity.showName,
  224. "pathImg": activity.pathImg,
  225. "path": {
  226. "ocaId": activity.ocaId,
  227. "mcType": activity.matchType
  228. },
  229. "navImg": navImg,
  230. "point": {
  231. "longitude": activity.point.longitude,
  232. "latitude": activity.point.latitude,
  233. "name": activity.point.name
  234. }
  235. };
  236. // console.log(`[getUserPathList] i: ${i} j: ${j} path: ${JSON.stringify(path)}`);
  237. row.push(path);
  238. }
  239. pathList["row" + (i + 1)] = row;
  240. // console.log("[getUserPathList] row:", row);
  241. }
  242. }
  243. } else {
  244. console.warn("[getUserPathList] mapInfo err:", mapInfo);
  245. }
  246. return pathList;
  247. },
  248. // 卡片配置信息查询
  249. cardConfigQuery(callback) {
  250. uni.request({
  251. url: apiCardConfigQuery,
  252. header: {
  253. "Content-Type": "application/x-www-form-urlencoded",
  254. "token": this.token,
  255. },
  256. method: "POST",
  257. data: {
  258. ecId: this.ecId,
  259. pageName: "all"
  260. },
  261. success: (res) => {
  262. // console.log("[cardConfigQuery]", res);
  263. const data = res.data.data;
  264. const config = data.configJson;
  265. // console.log("[cardConfigQuery] config", config);
  266. callback(config);
  267. },
  268. fail: (err) => {
  269. console.log("[cardConfigQuery] err", err);
  270. },
  271. });
  272. },
  273. // 用户自定义配置信息查询
  274. userConfigQuery(callback) {
  275. uni.request({
  276. url: apiUserConfigQuery,
  277. header: {
  278. "Content-Type": "application/x-www-form-urlencoded",
  279. "token": this.token,
  280. },
  281. method: "POST",
  282. data: {
  283. ecId: this.ecId,
  284. pageName: "all"
  285. },
  286. success: (res) => {
  287. // console.log("[userConfigQuery]", res);
  288. const data = res.data.data;
  289. const config = data.configJson;
  290. // console.log("[userConfigQuery] config", config);
  291. callback(config);
  292. },
  293. fail: (err) => {
  294. console.log("[userConfigQuery] err", err);
  295. },
  296. });
  297. },
  298. // 警告列表查询
  299. warnMessageQuery(callback=null) {
  300. uni.request({
  301. url: apiWarnMessageQuery,
  302. header: {
  303. "Content-Type": "application/x-www-form-urlencoded",
  304. "token": this.token,
  305. },
  306. method: "POST",
  307. data: {
  308. ecId: this.ecId
  309. },
  310. success: (res) => {
  311. // console.log("warnMessageQuery", res);
  312. if (checkResCode(res)) {
  313. const warnRs = res.data.data;
  314. this.cardConfigData.popupWarnList.length = 0;
  315. for (var i = 0; i < warnRs.length; i++) {
  316. let popupData = {
  317. type: 9, // 9: 警告
  318. data: {}
  319. };
  320. popupData.data.warnType = warnRs[i].warnType;
  321. popupData.data.title = warnRs[i].warnTitle;
  322. popupData.data.iconUrl = warnRs[i].iconUrl;
  323. popupData.data.iconNum = warnRs[i].iconNum;
  324. popupData.data.message = warnRs[i].warnMessage;
  325. popupData.data.qrCodeUrl = warnRs[i].qrCodeUrl;
  326. this.cardConfigData.popupWarnList.push(popupData);
  327. }
  328. /* this.cardConfigData.popupWarnList.push(
  329. {
  330. type: 9, // 9: 警告
  331. data: {
  332. warnType: 1,
  333. title: "黄牌",
  334. iconUrl: "/static/common/card_yellows.png",
  335. iconNum: 1,
  336. message: `亲爱的参赛者:
  337.    收到此黄牌,说明您的比赛数据被系统判定为存在异常,此次比赛(活动)为徒步定向校园文化主题活动,请自觉遵守规则,如果您收到的黄牌数量过多<span style='color: red'>(超过2张)</span>,您的成绩将影响到您的院系/单位成绩,同时您的个人成绩也有可能根据规则被取消。如果您坚持您的比赛数据没有问题,请联系我们的客服人员,谢谢!
  338.   让我们一起创造文明、和谐的校园生活,感谢您的支持!`,
  339. qrCodeUrl: "https://orienteering.beswell.com/shanda/%E8%AD%A6%E5%91%8A%E4%BA%8C%E7%BB%B4%E7%A0%81%402x.png"
  340. }
  341. }
  342. ); */
  343. // console.log("popupWarnList", this.cardConfigData.popupWarnList);
  344. // console.log("caller.popupWarnList length:", this.caller.cardConfigData.popupWarnList.length);
  345. if (callback != null) {
  346. callback(this.cardConfigData.popupWarnList);
  347. }
  348. }
  349. },
  350. fail: (err) => {
  351. console.log("warnMessageQuery err", err)
  352. },
  353. });
  354. },
  355. // 未读消息列表查询
  356. unReadMessageQuery(callback=null) {
  357. uni.request({
  358. url: apiUnReadMessageQuery,
  359. header: {
  360. "Content-Type": "application/x-www-form-urlencoded",
  361. "token": this.token,
  362. },
  363. method: "POST",
  364. data: {
  365. relationType: 2, // 类型 1 成就 2 卡片
  366. relationId: this.ecId
  367. },
  368. success: (res) => {
  369. // console.log("getUnReadMessageQuery", res);
  370. if (checkResCode(res)) {
  371. const unReadMessageRs = res.data.data;
  372. this.cardConfigData.popupMessageList.length = 0;
  373. let mqIdListStr = "";
  374. for (var i = 0; i < unReadMessageRs.length; i++) {
  375. let popupData = {
  376. type: 6, // 6: 通知
  377. data: {}
  378. };
  379. mqIdListStr += "-" + unReadMessageRs[i].mqId;
  380. popupData.data.mqType = unReadMessageRs[i].mqType;
  381. popupData.data.title = unReadMessageRs[i].mqTitle;
  382. popupData.data.message = unReadMessageRs[i].mqMessage;
  383. this.cardConfigData.popupMessageList.push(popupData);
  384. }
  385. /* this.cardConfigData.popupMessageList.push(
  386. {
  387. type: 6, // 6: 通知
  388. data: {
  389. mqType: 3,
  390. title: "特别提醒",
  391. message: `本次比赛的目的为体验校园文化,提升身体素质,让大家感受和熟悉定向运动魅力及技巧。<br>
  392. 在此特别提醒:<br>
  393. 无论是驰骋校园,还是漫步秋色,<b>“勿以轮带步,唯愿步量途”。让我们用脚步来丈量这片共同热爱的家园</b>,见证山大123周年的辉煌时刻!<br>
  394. <div style='text-align: right;'>山东大学体育委员会</div>`
  395. }
  396. }
  397. ); */
  398. // console.log("popupMessageList", this.cardConfigData.popupMessageList);
  399. if (callback != null) {
  400. callback(this.cardConfigData.popupMessageList, mqIdListStr);
  401. }
  402. }
  403. },
  404. fail: (err) => {
  405. console.log("getUnReadMessageQuery err", err);
  406. },
  407. });
  408. },
  409. // 用户是否新用户
  410. isNewUserQuery(callback=null) {
  411. uni.request({
  412. url: apiIsNewUserInCardComp,
  413. header: {
  414. "Content-Type": "application/x-www-form-urlencoded",
  415. "token": this.token,
  416. },
  417. method: "POST",
  418. data: {
  419. // ecId: this.ecId
  420. ecId: 0 // 0 全部赛事活动
  421. },
  422. success: (res) => {
  423. // console.log("isNewUserInCardComp", res);
  424. if (checkResCode(res)) {
  425. this.isNewUser = res.data.data.isNew;
  426. // this.isNewUser = true; // test
  427. if (callback != null) {
  428. callback(this.isNewUser);
  429. }
  430. }
  431. },
  432. fail: (err) => {
  433. console.log("isNewUserInCardComp err", err);
  434. },
  435. });
  436. },
  437. }
  438. export default cardfunc;