page-learn-child.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div class="contentBody" v-if="learnChildList.length > 0">
  3. <van-tabs
  4. :active="active"
  5. type="line"
  6. line-height="0px"
  7. @click="childChange"
  8. >
  9. <!-- 子目录 -->
  10. <van-tab
  11. v-for="(tabItem, tabIndex) in learnChildList"
  12. :key="tabIndex"
  13. :title="tabItem.name"
  14. :title-style="titleStyle"
  15. >
  16. <van-list
  17. v-model="loading"
  18. :finished="finished"
  19. finished-text="没有更多了"
  20. @load="onLoad"
  21. >
  22. <van-cell
  23. v-for="(contentItem, contentIndex) in contentList"
  24. :key="contentIndex"
  25. @click="chooseContent(contentIndex)"
  26. >
  27. <div slot="default" class="contentItemDiv">
  28. <div class="contentItemTitleTitleRow">
  29. <div class="contentItemTitle">{{ contentItem.name }}</div>
  30. <div
  31. v-if="contentItem.isNeedStudyToday"
  32. class="contentItemstates"
  33. >
  34. 今日必学
  35. </div>
  36. </div>
  37. <div class="contentItemDescription">
  38. <div class="contentItemDescriptionTime">
  39. {{
  40. formateDatesFun(contentItem.createdTime) ||
  41. contentItem.createdTime
  42. }}
  43. </div>
  44. <div class="contentItemDescriptionStudyNeedTime">
  45. 所需学习时间:{{
  46. getTimeHoursMinuteSecondsFun(contentItem.readTimeInSec)
  47. }}
  48. </div>
  49. </div>
  50. </div>
  51. </van-cell>
  52. </van-list>
  53. </van-tab>
  54. </van-tabs>
  55. </div>
  56. </template>
  57. <script>
  58. import { Toast } from "vant";
  59. import { getTodayStr } from "@/utils/date";
  60. import { mapState } from "vuex";
  61. export default {
  62. name: "page-learn-child",
  63. components: {},
  64. props: {
  65. // 分组的数据列表
  66. parentId: {
  67. type: String,
  68. default: ""
  69. }
  70. },
  71. data() {
  72. return {
  73. active: 0,
  74. titleStyle: {
  75. fontSize: "10px"
  76. },
  77. choosedChildIndex: 0,
  78. contentList: [],
  79. loading: false,
  80. finished: false,
  81. learnChildList: [],
  82. learnPage: 0,
  83. learnSize: 10
  84. };
  85. },
  86. computed: {
  87. ...mapState({
  88. chooseEngneeringWork: state => state.user.chooseEngneeringWork
  89. })
  90. },
  91. created() {},
  92. mounted() {
  93. this.getChildList();
  94. },
  95. destroyed () {},
  96. watch: {
  97. // 监听:工种
  98. chooseEngneeringWork(value) {
  99. if (value.value) {
  100. this.getContentList(); // 查询:考试的场次列表信息
  101. }
  102. }
  103. },
  104. methods: {
  105. // 查询子目录
  106. getChildList() {
  107. this.$store.commit("toggleLoading", true);
  108. let path = {
  109. categoryId: this.parentId
  110. };
  111. this.$_http
  112. .get(this.$pathParams(this.$_API.JTXT_GET_CATEGORIES_CATEGROYID, path))
  113. .then(res => {
  114. res.data.shift();
  115. this.learnChildList = res.data;
  116. this.$store.commit("toggleLoading", false);
  117. this.learnPage = 0;
  118. })
  119. .catch(() => {
  120. this.$store.commit("toggleLoading", false);
  121. });
  122. },
  123. childChange(index) {
  124. this.choosedChildIndex = index;
  125. this.learnPage = 0;
  126. this.getContentList();
  127. },
  128. // 查询子目录
  129. getContentList() {
  130. this.$store.commit("toggleLoading", true);
  131. let path = {
  132. categoryId: this.learnChildList[this.choosedChildIndex].id
  133. };
  134. let params = {
  135. engineertypeid: this.chooseEngneeringWork.id,
  136. page: this.learnPage,
  137. size: this.learnSize
  138. };
  139. this.$_http
  140. .get(
  141. this.$pathParams(
  142. this.$_API.JTXT_GET_CATEGORIES_CATEGROYID_MATERIALS,
  143. path
  144. ),
  145. { params }
  146. )
  147. .then(res => {
  148. this.formatNeedStudyTodayFun(res.data.content);
  149. // 分页到底了
  150. this.finished = res.data.last;
  151. this.learnPage++;
  152. this.$store.commit("toggleLoading", false);
  153. })
  154. .catch(() => {
  155. Toast("系统异常");
  156. this.$store.commit("toggleLoading", false);
  157. });
  158. },
  159. // 判断是否今日必学
  160. formatNeedStudyTodayFun(datas) {
  161. let todayStr = getTodayStr();
  162. datas.forEach(item => {
  163. item.tags.forEach(itemChild => {
  164. if (itemChild === todayStr) {
  165. item.isNeedStudyToday = true;
  166. }
  167. });
  168. });
  169. this.contentList = datas;
  170. },
  171. onLoad() { this.getContentList(); },
  172. chooseContent(index) {
  173. this.$router.push({
  174. name: "learn-content",
  175. params: { materialId: this.contentList[index].id }
  176. });
  177. }
  178. }
  179. };
  180. </script>
  181. <style lang="scss" scoped>
  182. @import "~@/styles/mixin";
  183. .contentBody {
  184. background-color: #fff;
  185. .contentItemDiv {
  186. width: 100%;
  187. .contentItemTitle {
  188. font-size: 0.65rem;
  189. }
  190. .contentItemTitleTitleRow {
  191. width: 100%;
  192. display: flex;
  193. justify-content: space-between;
  194. align-items: center;
  195. .contentItemTitle {
  196. text-align: center;
  197. font-size: 0.65rem;
  198. color: #000;
  199. white-space: nowrap;
  200. text-overflow: ellipsis;
  201. overflow: hidden;
  202. }
  203. .contentItemstates {
  204. font-size: 0.6rem;
  205. color: #f56c6c;
  206. border-radius: 0.2rem;
  207. margin-left: 0.5rem;
  208. flex-wrap: nowrap;
  209. white-space: nowrap;
  210. }
  211. }
  212. .contentItemDescription {
  213. margin-top: 0.5rem;
  214. display: flex;
  215. justify-content: space-between;
  216. align-items: center;
  217. .contentItemDescriptionTime {
  218. color: #696969;
  219. font-size: 0.55rem;
  220. }
  221. .contentItemDescriptionStudyNeedTime {
  222. color: #0088e9;
  223. font-size: 0.55rem;
  224. }
  225. }
  226. }
  227. .my-swipe .van-swipe-item {
  228. background-color: #7cc8ff;
  229. height: 10rem;
  230. }
  231. }
  232. </style>