cardfunc.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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 popupRule = [{
  174. "type": 1,
  175. "data": {
  176. "title": matchInfo.compName,
  177. "logo": {
  178. "src": tplInfo.matchLogo,
  179. "width": "260px",
  180. "height": "90px"
  181. },
  182. "content": content
  183. }
  184. }];
  185. this.cardConfigData.popupRuleList.unshift(...popupRule);
  186. }
  187. },
  188. // 获取用户的比赛路线数据
  189. getUserPathList(config) {
  190. const mapInfo = config.mapInfo;
  191. const mapNum = mapInfo.length;
  192. let pathList = {};
  193. if (mapNum > 0) {
  194. let activityList = [];
  195. // 将多地图的路线信息数组合并成一个数组
  196. for (var m = 0; m < mapNum; m++) {
  197. activityList.push(...mapInfo[m].activityList);
  198. }
  199. console.log("[getUserPathList] activityList:", activityList);
  200. const activityNum = activityList.length;
  201. let type = 4;
  202. let navImg = "/static/common/nav3.png";
  203. if (activityNum > 1) {
  204. type = 3;
  205. navImg = "/static/common/nav.png";
  206. }
  207. if (activityNum > 0) {
  208. const rowSize = 2; // 每行显示的路线数量
  209. const rowNum = Math.ceil(activityNum / rowSize);
  210. for (var i = 0; i < rowNum; i++) {
  211. let row = [];
  212. for (var j = 0; j < rowSize; j++) {
  213. // console.log(`[getUserPathList] i: ${i} j: ${j}`);
  214. const activity = activityList[i * rowSize + j];
  215. if (!activity) {
  216. break;
  217. }
  218. const path = {
  219. "type": type,
  220. "pathName": activity.showName,
  221. "pathImg": activity.pathImg,
  222. "path": {
  223. "ocaId": activity.ocaId,
  224. "mcType": activity.matchType
  225. },
  226. "navImg": navImg,
  227. "point": {
  228. "longitude": activity.point.longitude,
  229. "latitude": activity.point.latitude,
  230. "name": activity.point.name
  231. }
  232. };
  233. // console.log(`[getUserPathList] i: ${i} j: ${j} path: ${JSON.stringify(path)}`);
  234. row.push(path);
  235. }
  236. pathList["row" + (i + 1)] = row;
  237. // console.log("[getUserPathList] row:", row);
  238. }
  239. }
  240. } else {
  241. console.warn("[getUserPathList] mapInfo err:", mapInfo);
  242. }
  243. return pathList;
  244. },
  245. // 卡片配置信息查询
  246. cardConfigQuery(callback) {
  247. uni.request({
  248. url: apiCardConfigQuery,
  249. header: {
  250. "Content-Type": "application/x-www-form-urlencoded",
  251. "token": this.token,
  252. },
  253. method: "POST",
  254. data: {
  255. ecId: this.ecId,
  256. pageName: "all"
  257. },
  258. success: (res) => {
  259. console.log("[cardConfigQuery]", res);
  260. const data = res.data.data;
  261. const config = data.configJson;
  262. // console.log("[cardConfigQuery] config", config);
  263. callback(config);
  264. },
  265. fail: (err) => {
  266. console.log("[cardConfigQuery] err", err);
  267. },
  268. });
  269. },
  270. // 用户自定义配置信息查询
  271. userConfigQuery(callback) {
  272. uni.request({
  273. url: apiUserConfigQuery,
  274. header: {
  275. "Content-Type": "application/x-www-form-urlencoded",
  276. "token": this.token,
  277. },
  278. method: "POST",
  279. data: {
  280. ecId: this.ecId,
  281. pageName: "all"
  282. },
  283. success: (res) => {
  284. // console.log("[userConfigQuery]", res);
  285. const data = res.data.data;
  286. const config = data.configJson;
  287. // console.log("[userConfigQuery] config", config);
  288. callback(config);
  289. },
  290. fail: (err) => {
  291. console.log("[userConfigQuery] err", err);
  292. },
  293. });
  294. },
  295. // 警告列表查询
  296. warnMessageQuery(callback=null) {
  297. uni.request({
  298. url: apiWarnMessageQuery,
  299. header: {
  300. "Content-Type": "application/x-www-form-urlencoded",
  301. "token": this.token,
  302. },
  303. method: "POST",
  304. data: {
  305. ecId: this.ecId
  306. },
  307. success: (res) => {
  308. // console.log("warnMessageQuery", res);
  309. if (checkResCode(res)) {
  310. const warnRs = res.data.data;
  311. this.cardConfigData.popupWarnList.length = 0;
  312. for (var i = 0; i < warnRs.length; i++) {
  313. let popupData = {
  314. type: 9, // 9: 警告
  315. data: {}
  316. };
  317. popupData.data.warnType = warnRs[i].warnType;
  318. popupData.data.title = warnRs[i].warnTitle;
  319. popupData.data.iconUrl = warnRs[i].iconUrl;
  320. popupData.data.iconNum = warnRs[i].iconNum;
  321. popupData.data.message = warnRs[i].warnMessage;
  322. popupData.data.qrCodeUrl = warnRs[i].qrCodeUrl;
  323. this.cardConfigData.popupWarnList.push(popupData);
  324. }
  325. /* this.cardConfigData.popupWarnList.push(
  326. {
  327. type: 9, // 9: 警告
  328. data: {
  329. warnType: 1,
  330. title: "黄牌",
  331. iconUrl: "/static/common/card_yellows.png",
  332. iconNum: 1,
  333. message: `亲爱的参赛者:
  334.    收到此黄牌,说明您的比赛数据被系统判定为存在异常,此次比赛(活动)为徒步定向校园文化主题活动,请自觉遵守规则,如果您收到的黄牌数量过多<span style='color: red'>(超过2张)</span>,您的成绩将影响到您的院系/单位成绩,同时您的个人成绩也有可能根据规则被取消。如果您坚持您的比赛数据没有问题,请联系我们的客服人员,谢谢!
  335.   让我们一起创造文明、和谐的校园生活,感谢您的支持!`,
  336. qrCodeUrl: "https://orienteering.beswell.com/shanda/%E8%AD%A6%E5%91%8A%E4%BA%8C%E7%BB%B4%E7%A0%81%402x.png"
  337. }
  338. }
  339. ); */
  340. // console.log("popupWarnList", this.cardConfigData.popupWarnList);
  341. // console.log("caller.popupWarnList length:", this.caller.cardConfigData.popupWarnList.length);
  342. if (callback != null) {
  343. callback(this.cardConfigData.popupWarnList);
  344. }
  345. }
  346. },
  347. fail: (err) => {
  348. console.log("warnMessageQuery err", err)
  349. },
  350. });
  351. },
  352. // 未读消息列表查询
  353. unReadMessageQuery(callback=null) {
  354. uni.request({
  355. url: apiUnReadMessageQuery,
  356. header: {
  357. "Content-Type": "application/x-www-form-urlencoded",
  358. "token": this.token,
  359. },
  360. method: "POST",
  361. data: {
  362. relationType: 2, // 类型 1 成就 2 卡片
  363. relationId: this.ecId
  364. },
  365. success: (res) => {
  366. // console.log("getUnReadMessageQuery", res);
  367. if (checkResCode(res)) {
  368. const unReadMessageRs = res.data.data;
  369. this.cardConfigData.popupMessageList.length = 0;
  370. let mqIdListStr = "";
  371. for (var i = 0; i < unReadMessageRs.length; i++) {
  372. let popupData = {
  373. type: 6, // 6: 通知
  374. data: {}
  375. };
  376. mqIdListStr += "-" + unReadMessageRs[i].mqId;
  377. popupData.data.mqType = unReadMessageRs[i].mqType;
  378. popupData.data.title = unReadMessageRs[i].mqTitle;
  379. popupData.data.message = unReadMessageRs[i].mqMessage;
  380. this.cardConfigData.popupMessageList.push(popupData);
  381. }
  382. /* this.cardConfigData.popupMessageList.push(
  383. {
  384. type: 6, // 6: 通知
  385. data: {
  386. mqType: 3,
  387. title: "特别提醒",
  388. message: `本次比赛的目的为体验校园文化,提升身体素质,让大家感受和熟悉定向运动魅力及技巧。<br>
  389. 在此特别提醒:<br>
  390. 无论是驰骋校园,还是漫步秋色,<b>“勿以轮带步,唯愿步量途”。让我们用脚步来丈量这片共同热爱的家园</b>,见证山大123周年的辉煌时刻!<br>
  391. <div style='text-align: right;'>山东大学体育委员会</div>`
  392. }
  393. }
  394. ); */
  395. // console.log("popupMessageList", this.cardConfigData.popupMessageList);
  396. if (callback != null) {
  397. callback(this.cardConfigData.popupMessageList, mqIdListStr);
  398. }
  399. }
  400. },
  401. fail: (err) => {
  402. console.log("getUnReadMessageQuery err", err);
  403. },
  404. });
  405. },
  406. // 用户是否新用户
  407. isNewUserQuery(callback=null) {
  408. uni.request({
  409. url: apiIsNewUserInCardComp,
  410. header: {
  411. "Content-Type": "application/x-www-form-urlencoded",
  412. "token": this.token,
  413. },
  414. method: "POST",
  415. data: {
  416. // ecId: this.ecId
  417. ecId: 0 // 0 全部赛事活动
  418. },
  419. success: (res) => {
  420. // console.log("isNewUserInCardComp", res);
  421. if (checkResCode(res)) {
  422. this.isNewUser = res.data.data.isNew;
  423. // this.isNewUser = true; // test
  424. if (callback != null) {
  425. callback(this.isNewUser);
  426. }
  427. }
  428. },
  429. fail: (err) => {
  430. console.log("isNewUserInCardComp err", err);
  431. },
  432. });
  433. },
  434. }
  435. export default cardfunc;