page-learn-child.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <div class="contentBody" v-if="learnChildList.length > 0">
  3. <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
  4. <van-tabs
  5. :active="active"
  6. type="line"
  7. line-height="0px"
  8. @click="childChange"
  9. >
  10. <!-- 子目录 -->
  11. <van-tab
  12. v-for="(tabItem, tabIndex) in learnChildList"
  13. :key="tabIndex"
  14. :title="tabItem.name"
  15. :title-style="titleStyle"
  16. >
  17. <div class="contentLoading" v-if="contentLoading">
  18. <van-loading type="spinner" vertical>加载中...</van-loading>
  19. </div>
  20. <van-list
  21. v-else
  22. v-model="loading"
  23. :finished="finished"
  24. finished-text="没有更多了"
  25. @load="onLoad"
  26. >
  27. <van-cell
  28. v-for="(contentItem, contentIndex) in contentList"
  29. :key="contentIndex"
  30. @click="chooseContent(contentIndex)"
  31. >
  32. <div slot="default" class="contentItemDiv">
  33. <div class="contentItemTitleTitleRow">
  34. <!-- 文章 -->
  35. <div
  36. v-if="contentItem.type == 'ARTICLE'"
  37. class="contentItemTitleTitleRow"
  38. >
  39. <div class="contentItemTitle">
  40. {{ contentItem.name }}
  41. </div>
  42. <div
  43. v-if="contentItem.isNeedStudyToday"
  44. class="contentItemstates"
  45. >
  46. 今日必学
  47. </div>
  48. </div>
  49. <!-- 视频 -->
  50. <div
  51. v-else-if="contentItem.type == 'VIDEO'"
  52. class="contentItemTitleTitleRow-video"
  53. >
  54. <div class="contentVideoTitle">
  55. <div class="contentVideoTitleTxt">
  56. <img :src="redIcon" />
  57. <span>{{ contentItem.name }}</span>
  58. </div>
  59. <div
  60. v-if="contentItem.isNeedStudyToday"
  61. class="contentItemstates"
  62. >
  63. 今日必学
  64. </div>
  65. </div>
  66. <div class="contentItem-video-img">
  67. <img
  68. class="img-bofang"
  69. :src="require('@/assets/image/learn/boFang.png')"
  70. />
  71. <img
  72. :src="getContentObj(contentItem.contents).faceUrl"
  73. fit="cover"
  74. />
  75. </div>
  76. </div>
  77. </div>
  78. <div class="contentItemDescription">
  79. <div class="contentItemDescriptionTime">
  80. {{
  81. formateDatesFun(contentItem.createdTime) ||
  82. contentItem.createdTime
  83. }}
  84. </div>
  85. <div class="contentItemDescriptionStudyNeedTime">
  86. 所需学习时间:{{
  87. getTimeHoursMinuteSecondsFun(contentItem.readTimeInSec)
  88. }}
  89. </div>
  90. </div>
  91. </div>
  92. </van-cell>
  93. </van-list>
  94. </van-tab>
  95. </van-tabs>
  96. </van-pull-refresh>
  97. </div>
  98. </template>
  99. <script>
  100. import { Toast } from "vant";
  101. import { getTodayStr } from "@/utils/date";
  102. import { mapState } from "vuex";
  103. export default {
  104. name: "page-learn-child",
  105. components: {},
  106. props: {
  107. // 分组的数据列表
  108. parentId: {
  109. type: String,
  110. default: ""
  111. }
  112. },
  113. data() {
  114. return {
  115. active: 0,
  116. titleStyle: {
  117. fontSize: "10px"
  118. },
  119. choosedChildIndex: 0,
  120. contentList: [],
  121. loading: false,
  122. contentLoading: false,
  123. finished: false,
  124. learnChildList: [],
  125. learnPage: 0,
  126. learnSize: 10,
  127. isLoading: false,
  128. arrowRightPng: require("@/assets/image/learn/arrowRight.png"),
  129. redIcon: require("@/assets/image/learn/redIcon.jpg")
  130. };
  131. },
  132. computed: {
  133. ...mapState({
  134. chooseEngneeringWork: state => state.user.chooseEngneeringWork
  135. })
  136. },
  137. created() {},
  138. mounted() {
  139. this.getChildList();
  140. },
  141. destroyed() {},
  142. watch: {
  143. // 监听:工种
  144. chooseEngneeringWork(value) {
  145. if (value.value) {
  146. this.getContentList(); // 查询:考试的场次列表信息
  147. }
  148. }
  149. },
  150. methods: {
  151. // 查询子目录
  152. getChildList() {
  153. this.$store.commit("toggleLoading", true);
  154. let path = {
  155. categoryId: this.parentId
  156. };
  157. this.$_http
  158. .get(this.$pathParams(this.$_API.JTXT_GET_CATEGORIES_CATEGROYID, path))
  159. .then(res => {
  160. this.learnChildList = res.data;
  161. this.$store.commit("toggleLoading", false);
  162. this.learnPage = 0;
  163. })
  164. .catch(() => {
  165. this.$store.commit("toggleLoading", false);
  166. });
  167. },
  168. childChange(index) {
  169. this.choosedChildIndex = index;
  170. this.learnPage = 0;
  171. this.getContentList();
  172. },
  173. // 查询子目录
  174. getContentList() {
  175. this.contentLoading = true;
  176. this.$store.commit("toggleLoading", true);
  177. let path = {
  178. categoryId: this.learnChildList[this.choosedChildIndex].id
  179. };
  180. let params = {
  181. engineertypeid: this.chooseEngneeringWork.id,
  182. page: this.learnPage,
  183. size: this.learnSize
  184. };
  185. this.$_http
  186. .get(
  187. this.$pathParams(
  188. this.$_API.JTXT_GET_CATEGORIES_CATEGROYID_MATERIALS,
  189. path
  190. ),
  191. { params }
  192. )
  193. .then(res => {
  194. this.formatNeedStudyTodayFun(res.data.content);
  195. // 分页到底了
  196. this.finished = res.data.last;
  197. this.learnPage++;
  198. this.$store.commit("toggleLoading", false);
  199. this.contentLoading = false;
  200. })
  201. .catch(() => {
  202. Toast("系统异常");
  203. this.$store.commit("toggleLoading", false);
  204. this.contentLoading = false;
  205. });
  206. },
  207. // 判断是否今日必学
  208. formatNeedStudyTodayFun(datas) {
  209. let todayStr = getTodayStr();
  210. datas.forEach(item => {
  211. item.tags.forEach(itemChild => {
  212. if (itemChild === todayStr) {
  213. item.isNeedStudyToday = true;
  214. }
  215. });
  216. });
  217. this.contentList = datas;
  218. },
  219. onLoad() {
  220. this.getContentList();
  221. },
  222. chooseContent(index) {
  223. this.$router.push({
  224. name: "learn-content",
  225. params: { materialId: this.contentList[index].id }
  226. });
  227. },
  228. onRefresh() {
  229. this.getChildList();
  230. setTimeout(() => {
  231. Toast("刷新成功");
  232. this.isLoading = false;
  233. }, 500);
  234. },
  235. getContentObj(content) {
  236. console.log("---" + content);
  237. return JSON.parse(content);
  238. }
  239. }
  240. };
  241. </script>
  242. <style lang="scss" scoped>
  243. @import "~@/styles/mixin";
  244. .contentBody {
  245. background-color: #fff;
  246. .contentLoading {
  247. height: 10vh;
  248. display: flex;
  249. justify-content: center;
  250. align-items: center;
  251. }
  252. .contentItemDiv {
  253. width: 100%;
  254. .contentItemTitleTitleRow {
  255. width: 100%;
  256. display: flex;
  257. justify-content: space-between;
  258. align-items: center;
  259. .contentItemTitle {
  260. text-align: left;
  261. font-size: 0.8rem;
  262. color: #000;
  263. display: -webkit-box;
  264. -webkit-box-orient: ho;
  265. -webkit-line-clamp: 10;
  266. // font-family: SimSun;
  267. font-family: fangSong-FZFSJW;
  268. line-height: 1.4rem;
  269. }
  270. .contentItemstates {
  271. font-size: 0.6rem;
  272. color: #f56c6c;
  273. border-radius: 0.2rem;
  274. margin-left: 0.5rem;
  275. flex-wrap: nowrap;
  276. white-space: nowrap;
  277. }
  278. img {
  279. max-width: 100%;
  280. width: auto;
  281. height: auto;
  282. }
  283. }
  284. .contentItemTitleTitleRow-video {
  285. width: 100%;
  286. .contentVideoTitle {
  287. display: flex;
  288. justify-content: space-between;
  289. // align-items: center;
  290. .contentVideoTitleTxt {
  291. position: relative;
  292. display: flex;
  293. margin-bottom: 0.25rem;
  294. img {
  295. width: 0.1rem;
  296. height: 1rem;
  297. margin-right: 0.25rem;
  298. }
  299. span {
  300. font-size: 0.8rem;
  301. font-weight: bold;
  302. color: #000;
  303. }
  304. }
  305. .contentVideoDK {
  306. flex-wrap: nowrap;
  307. white-space: nowrap;
  308. margin-left: 0.5rem;
  309. color: #999;
  310. display: flex;
  311. align-items: center;
  312. img {
  313. width: 0.75rem;
  314. height: 0.75rem;
  315. }
  316. }
  317. }
  318. .contentItemstates {
  319. font-size: 0.6rem;
  320. color: #f56c6c;
  321. border-radius: 0.2rem;
  322. margin-left: 0.5rem;
  323. flex-wrap: nowrap;
  324. white-space: nowrap;
  325. }
  326. .contentItem-video-img {
  327. width: 100%;
  328. height: 9rem;
  329. position: relative;
  330. img {
  331. width: 100%;
  332. height: 9rem;
  333. }
  334. .img-bofang {
  335. width: 2rem;
  336. height: 2rem;
  337. position: absolute;
  338. top: 0;
  339. left: 0;
  340. right: 0;
  341. bottom: 0;
  342. margin: auto;
  343. }
  344. }
  345. }
  346. .contentItemDescription {
  347. margin-top: 0.5rem;
  348. display: flex;
  349. justify-content: space-between;
  350. align-items: center;
  351. .contentItemDescriptionTime {
  352. color: #696969;
  353. font-size: 0.55rem;
  354. }
  355. .contentItemDescriptionStudyNeedTime {
  356. color: #0088e9;
  357. font-size: 0.55rem;
  358. }
  359. }
  360. }
  361. .my-swipe .van-swipe-item {
  362. background-color: #7cc8ff;
  363. height: 10rem;
  364. }
  365. }
  366. </style>