user-manual.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <div class="user-manual-box">
  3. <van-nav-bar title="学习积分" left-arrow @click-left="onClickLeft" />
  4. <div class="user-manual-div">
  5. <div class="user-manual-grades-div">
  6. <div class="user-manual-name-description">学习积分</div>
  7. <div class="user-manual-grades">
  8. {{ this.userLearnPonits }}
  9. </div>
  10. <div class="user-manual-description" @click="clickLearnRule">
  11. 积分说明
  12. </div>
  13. </div>
  14. <div class="user-manual-earn-points-row">
  15. <div class="user-manual-earn-points">赚积分</div>
  16. <div class="user-manual-earn-points-text">
  17. 今日已累计<span class="user-manual-earn-points-today">{{
  18. todayEarnPoints
  19. }}</span
  20. ><span>积分</span>
  21. </div>
  22. </div>
  23. <div class="user-manual-list">
  24. <div
  25. v-for="(item, index) in eventList"
  26. :key="index"
  27. class="user-manual-item"
  28. >
  29. <div class="user-manual-item-left">
  30. <div class="user-manual-item-left-title">{{ item.name }}</div>
  31. <div>{{ item.rule }}</div>
  32. <div class="user-manual-item-left-percentage">
  33. <div class="user-manual-item-left-schedule">
  34. <van-progress
  35. :percentage="
  36. formatePercentageFun(item.getPoints, item.totalPonits)
  37. "
  38. :show-pivot="false"
  39. />
  40. </div>
  41. <div class="user-manual-item-left-schedule-text">
  42. 已获得 {{ item.getPoints || 0 }} 分 / 上限
  43. {{ item.totalPonits }} 分
  44. </div>
  45. </div>
  46. </div>
  47. <div class="user-manual-item-right">
  48. <div class="user-manual-item-btn" @click="toManualEarnFun(item)">
  49. {{
  50. item.getPoints === item.totalPonits
  51. ? "已完成"
  52. : item.rightButton
  53. }}
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. </template>
  61. <script>
  62. import { mapState } from "vuex";
  63. import { getTodayStr } from "@/utils/date";
  64. export default {
  65. name: "user-manual",
  66. components: {},
  67. data() {
  68. return {
  69. loading: false,
  70. eventList: [
  71. {
  72. name: "每日登录",
  73. type: "LOGIN",
  74. rule: "1分/登录",
  75. isFinish: false,
  76. getPoints: 1,
  77. totalPonits: 1,
  78. rightButton: "已完成",
  79. router: ""
  80. },
  81. {
  82. name: "今日必读",
  83. type: "MANDATORY_LEARNING_COMPLETE",
  84. rule: "2分/每有效阅读一篇今日必读文章",
  85. isFinish: false,
  86. getPoints: 0,
  87. totalPonits: 10,
  88. rightButton: "去看看",
  89. router: ""
  90. },
  91. {
  92. name: "阅读文章",
  93. type: "LEARNING_COMPLETE",
  94. rule: "1分/每有效阅读一篇非今日必读文章",
  95. isFinish: false,
  96. getPoints: 0,
  97. totalPonits: 5,
  98. rightButton: "去看看",
  99. router: ""
  100. },
  101. {
  102. name: "今日答题",
  103. type: "DAILY_QUESTIONS",
  104. rule: "1分/每答对一题",
  105. isFinish: false,
  106. getPoints: 0,
  107. totalPonits: 5,
  108. rightButton: "去答题",
  109. router: ""
  110. },
  111. {
  112. name: "每周答题",
  113. type: "WEEKLY_QUESTION",
  114. rule: "1分/每答对一题",
  115. isFinish: false,
  116. getPoints: 0,
  117. totalPonits: 10,
  118. rightButton: "去答题",
  119. router: ""
  120. },
  121. {
  122. name: "专项答题",
  123. type: "SPECIAL_QUESTIONS",
  124. rule: "1分/每答对一道专项答题",
  125. isFinish: false,
  126. getPoints: 0,
  127. totalPonits: 10,
  128. rightButton: "去答题",
  129. router: ""
  130. },
  131. {
  132. name: "答题闯关",
  133. type: "CHALLENGE_QUESTIONS",
  134. rule: "20分/全部通关",
  135. isFinish: false,
  136. getPoints: 0,
  137. totalPonits: 20,
  138. rightButton: "去答题",
  139. router: ""
  140. }
  141. ],
  142. userLearnPonits: 0, // 用户的总积分
  143. todayEarnPoints: 0, // 今日已累计的积分
  144. sumPointsObj: {
  145. LOGIN: 0, // 登录
  146. DAILY_QUESTIONS: 0, // 每日答题
  147. WEEKLY_QUESTION: 0, // 每周考试
  148. READ_5_MINS: 0, // 阅读时长
  149. READ_2_HOURS: 0, // 阅读时长
  150. LEARNING_COMPLETE: 0, // 阅读完成
  151. SPECIAL_QUESTIONS: 0, // 专项答题
  152. MANDATORY_LEARNING_COMPLETE: 0, // 今日必读
  153. CHALLENGE_QUESTIONS: 0 // 闯关答题
  154. }
  155. };
  156. },
  157. mounted() {
  158. this.getEvents();
  159. this.getDailyPoints();
  160. this.getLearnPoints();
  161. },
  162. created() {
  163. this.setLanXinNavigator();
  164. },
  165. activated() {
  166. this.setLanXinNavigator();
  167. },
  168. computed: {
  169. ...mapState({
  170. user: state => state.user
  171. })
  172. },
  173. methods: {
  174. // 设置蓝信navigator
  175. setLanXinNavigator() {
  176. lx.ui.setNavigationBarTitle({
  177. title: "学习积分"
  178. });
  179. },
  180. getEvents() {
  181. let path = {
  182. userName: this.user.userInfo.userName,
  183. date: getTodayStr()
  184. };
  185. this.$_http
  186. .get(this.$pathParams(this.$_API.JTXT_GET_EVENTS_USERNAME_DATE, path))
  187. .then(res => {
  188. if (res.data.length !== 0) {
  189. res.data.forEach(element => {
  190. this.sumPointsObj[element.event] += element.delta;
  191. });
  192. this.updateGetPoints();
  193. }
  194. })
  195. .catch(() => {
  196. this.$store.commit("toggleLoading", false);
  197. });
  198. },
  199. // 修改获得积分
  200. updateGetPoints() {
  201. this.eventList.forEach(element => {
  202. element.getPoints = this.sumPointsObj[element.type];
  203. });
  204. console.log("-this.eventList--" + JSON.stringify(this.eventList));
  205. },
  206. // 获取今日分数
  207. getDailyPoints() {
  208. let path = {
  209. userName: this.user.userInfo.userName
  210. };
  211. this.$_http
  212. .get(this.$pathParams(this.$_API.JTXT_GET_USER_DAIYL_POINTS, path))
  213. .then(res => {
  214. this.todayEarnPoints = res.data || 0;
  215. })
  216. .catch(() => {
  217. this.$store.commit("toggleLoading", false);
  218. });
  219. },
  220. // 查询总积分
  221. getLearnPoints() {
  222. let path = {
  223. userName: this.user.userInfo.userName
  224. };
  225. this.$_http
  226. .get(this.$pathParams(this.$_API.JTXT_GET_USER_LEARN_POINTS, path))
  227. .then(res => {
  228. this.userLearnPonits = res.data || 0;
  229. })
  230. .catch(() => {
  231. this.$store.commit("toggleLoading", false);
  232. });
  233. },
  234. // 格式化已获得的积分/总积分的数
  235. formatePercentageFun(getPoints, totalPonits) {
  236. if (
  237. (!getPoints && getPoints !== 0) ||
  238. (!totalPonits && totalPonits !== 0)
  239. ) {
  240. return 0;
  241. }
  242. if (isNaN(getPoints) || isNaN(totalPonits)) {
  243. return 0;
  244. }
  245. return Math.round((getPoints / totalPonits) * 100) || 0;
  246. },
  247. // 操作:返回
  248. onClickLeft() {
  249. this.$router.back();
  250. },
  251. // 操作:点击积分说明按钮
  252. clickLearnRule() {
  253. this.$router.push({ name: "learnPointRule" });
  254. },
  255. // 操作:点击了去看看、去学习、去训练
  256. toManualEarnFun(item) {
  257. // 获得的积分已满,不作操作
  258. if (item.getPoints === item.totalPonits) {
  259. return;
  260. }
  261. switch (item.rightButton) {
  262. case "已完成":
  263. break;
  264. case "去看看":
  265. // 1.跳转到首页
  266. this.$router.replace({
  267. name: "home"
  268. });
  269. // 2.告知需要首页切换tab-阅读
  270. this.$store.commit("updateStudyItemStore", {
  271. field: "homeChangeTabIndex",
  272. value: 0
  273. });
  274. break;
  275. case "去答题":
  276. // 1. 重置vuex的answerRecruitId
  277. this.$store.commit("updateAnswerItemStore", {
  278. field: "answerRecruitId",
  279. value: "daily-questions" // item.id
  280. });
  281. // 2.跳转到首页
  282. this.$router.replace({
  283. name: "home"
  284. });
  285. // 3.告知需要首页切换tab-答题
  286. this.$store.commit("updateStudyItemStore", {
  287. field: "homeChangeTabIndex",
  288. value: 1
  289. });
  290. break;
  291. default:
  292. break;
  293. }
  294. }
  295. }
  296. };
  297. </script>
  298. <style lang="scss" scoped>
  299. .user-manual-box {
  300. .user-manual-div {
  301. width: 100%;
  302. height: 100vh;
  303. overflow-y: auto;
  304. padding: 0 0.75rem;
  305. background-color: #fff;
  306. font-size: 0.6rem;
  307. .user-manual-grades-div {
  308. display: flex;
  309. flex-direction: column;
  310. justify-content: center;
  311. align-items: center;
  312. padding-top: 1rem;
  313. .user-manual-name-description {
  314. padding: 0.15rem 0.5rem;
  315. // border: 1px solid #7cc8ff;
  316. // border-radius: 0.25rem;
  317. color: #0088e9;
  318. font-size: 0.75rem;
  319. }
  320. .user-manual-grades {
  321. font-size: 1rem;
  322. color: #0088e9;
  323. margin-top: 0.5rem;
  324. }
  325. .user-manual-description {
  326. margin-top: 0.5rem;
  327. padding: 0.15rem 0.5rem;
  328. border: 1px solid #7cc8ff;
  329. border-radius: 0.25rem;
  330. color: #7cc8ff;
  331. }
  332. }
  333. .user-manual-earn-points-row {
  334. display: flex;
  335. justify-content: space-between;
  336. align-items: center;
  337. margin-top: 1rem;
  338. .user-manual-earn-points {
  339. font-size: 0.7rem;
  340. font-weight: bold;
  341. }
  342. .user-manual-earn-points-text {
  343. color: #696969;
  344. display: flex;
  345. align-items: center;
  346. span {
  347. color: #df371e;
  348. }
  349. .user-manual-earn-points-today {
  350. font-size: 0.8rem;
  351. margin: 0 0.25rem;
  352. }
  353. }
  354. }
  355. .user-manual-list {
  356. padding: 0.5rem 0;
  357. .user-manual-item {
  358. padding: 0.5rem 0;
  359. border-top: 1px solid #e5e5e5;
  360. display: flex;
  361. justify-content: space-between;
  362. align-items: center;
  363. .user-manual-item-left {
  364. .user-manual-item-left-title {
  365. font-weight: bold;
  366. word-break: break-all;
  367. word-wrap: break-word;
  368. }
  369. .user-manual-item-left-percentage {
  370. display: flex;
  371. align-items: center;
  372. margin-top: 0.5rem;
  373. .user-manual-item-left-schedule {
  374. width: 100px;
  375. }
  376. .user-manual-item-left-schedule-text {
  377. color: #999;
  378. font-size: 0.55rem;
  379. margin-left: 0.5rem;
  380. }
  381. }
  382. }
  383. .user-manual-item-right {
  384. margin-left: 1rem;
  385. .user-manual-item-btn {
  386. padding: 0.1rem 0.25rem;
  387. border-radius: 0.1rem;
  388. color: #0088e9;
  389. background-color: #d8e9f5;
  390. flex-wrap: nowrap;
  391. white-space: nowrap;
  392. }
  393. }
  394. }
  395. }
  396. }
  397. }
  398. </style>