Advertisement
Guest User

list card

a guest
Dec 7th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.66 KB | None | 0 0
  1. <template>
  2. <div>
  3. <div v-if="courses.length > 0">
  4. <div class="list-cards-header">
  5. <div class="row">
  6. <div class="col-6">
  7. <h3 class="align-middle">{{ title }}</h3>
  8. </div>
  9. <div class="col-6 text-right type-view">
  10. <div class="d-flex flex-column bd-highlight mb-3">
  11. <div
  12. class="bd-highlight pull-right"
  13. v-show="cardType === 'card'"
  14. >
  15. <button
  16. class="btn-transparent"
  17. style="outline:none;"
  18. @click="learnMore"
  19. v-show="course.data.length > 0 && showAll && course.total > course.to"
  20. >
  21. <span class="learn-more">Lihat Semua</span>
  22. <i class="fas fa-chevron-right"></i>
  23. </button>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. <shimmer
  31. :list-type="cardType"
  32. :is-loading="isLoading"
  33. :total-per-slide="totalPerSlide"
  34. />
  35.  
  36. <swiper
  37. :options="swiperOption"
  38. ref="mySwiper"
  39. v-if="cardType === 'card'"
  40. >
  41. <div
  42. v-show="!isLoading && course.data.length === 0"
  43. >
  44. <span>
  45. <div class="card-no-data align-items-center
  46. justify-content-center d-flex bd-highlight">
  47. <div class="p-2 flex-fill bd-highlight">
  48. <span><i class="fas fa-info-circle mb-3" style="font-size:38px;"></i></span>
  49. <div>
  50. <b>Belum ada <i>Learning Video</i> maupun <i>In-class Program</i> pada kategori ini</b>
  51. </div>
  52. </div>
  53. </div>
  54. </span>
  55. </div>
  56. <swiper-slide
  57. v-for="item in courses"
  58. :key="item.key"
  59. >
  60. <div
  61. :class="listView"
  62. v-show="!isLoading"
  63. >
  64. <card
  65. :id="item.id"
  66. :img-cover="getUrlThumbnail(item.type, item)"
  67. :vid-preview="item.attachment ? item.attachment.url.preview : '' "
  68. :category="item.category"
  69. :title="item.title"
  70. :author="item.author"
  71. :lastUpdate="formatDate(item.updated_at)"
  72. :rating="item.rating"
  73. :total="item.total_participant"
  74. :style-view="cardView"
  75. :viewer="item.viewer"
  76. :type="item.type"
  77. :startDate="item.start_date"
  78. :endDate="item.end_date"
  79. :available="item.quota - item.total_participant"
  80. :total-participant="item.total_participant"
  81. :duration="(item.attachment) ? item.attachment.duration : 0"
  82. :urlTo="(getLink(item.type, item))"
  83. />
  84. </div>
  85. </swiper-slide>
  86. <div
  87. class="swiper-button-prev"
  88. slot="button-prev"
  89. @click="prev"
  90. ></div>
  91. <div
  92. class="swiper-button-next"
  93. slot="button-next"
  94. @click="next"
  95. ></div>
  96. </swiper>
  97. <div
  98. v-else
  99. :class="listView"
  100. v-show="!isLoading"
  101. >
  102. <span v-show="course.data.length === 0">
  103. <div class="card-no-data align-items-center
  104. justify-content-center d-flex bd-highlight">
  105. <div class="p-2 flex-fill bd-highlight">
  106. <span><i class="fas fa-info-circle mb-3" style="font-size:38px;"></i></span>
  107. <div>
  108. <b>Belum ada <i>Learning Video</i> maupun <i>In-class Program</i> pada kategori ini</b>
  109. </div>
  110. </div>
  111. </div>
  112. </span>
  113. <card
  114. v-for="item in courses"
  115. :id="item.id"
  116. :img-cover="getUrlThumbnail(item.type, item)"
  117. :vid-preview="item.attachment ? item.attachment.url.preview : '' "
  118. :key="item.key"
  119. :category="item.category"
  120. :title="item.title"
  121. :author="item.author"
  122. :lastUpdate="formatDate(item.updated_at)"
  123. :rating="item.rating"
  124. :total="item.total_participant"
  125. :style-view="cardView"
  126. :viewer="item.viewer"
  127. :type="item.type"
  128. :startDate="item.start_date"
  129. :endDate="item.end_date"
  130. :available="item.quota - item.total_participant"
  131. :total-participant="item.total_participant"
  132. :duration="(item.attachment) ? item.attachment.duration : 0"
  133. :urlTo="(getLink(item.type, item))"
  134. />
  135. </div>
  136. <div class="" v-if="isLogin() && cardView === 'list' && course !== null">
  137. <pagination :data="course" :limit=2 @pagination-change-page="fetchData" />
  138. </div>
  139. </div>
  140. </template>
  141. <script>
  142. import { swiper, swiperSlide } from 'vue-awesome-swiper';
  143. import store from 'store';
  144. import Pagination from 'laravel-vue-pagination';
  145. import Card from '../Card/Card.vue';
  146. import ApiContent from '../../../services/api/content';
  147. import ApiUser from '../../../services/api/user';
  148. import Shimmer from '../Atomic/ShimmerCard/ShimmerCard.vue';
  149.  
  150. // eslint-disable-next-line
  151. import 'swiper/dist/css/swiper.css';
  152.  
  153. export default {
  154. name: 'ListCards',
  155. components: {
  156. Card,
  157. Shimmer,
  158. Pagination,
  159. swiper,
  160. swiperSlide
  161. },
  162. props: {
  163. title: { type: String, default: '' },
  164. sizeOfCard: { required: true },
  165. type: { type: String },
  166. cardType: { type: String, default: 'card' },
  167. listType: { type: String, default: 'grid-view' },
  168. totalPerSlide: { type: Number, default: 3 },
  169. typeListCard: { type: String, default: 'all' },
  170. showAll: { type: Boolean, default: true },
  171. firstLoad: { type: Boolean, default: false }
  172. },
  173. data() {
  174. return {
  175. firstLoadData: this.firstLoad,
  176. pageNumber: 1,
  177. course: null,
  178. cardView: this.cardType,
  179. listView: this.listType,
  180. showViewMore: false,
  181. isLoading: true,
  182. swiperOption: {
  183. slidesPerView: this.totalPerSlide,
  184. pagination: {
  185. el: '.swiper-pagination',
  186. clickable: true
  187. },
  188. navigation: {
  189. nextEl: '.swiper-button-next',
  190. prevEl: '.swiper-button-prev'
  191. },
  192. observer: true,
  193. observeParents: true
  194. }
  195. };
  196. },
  197. mounted() {
  198. if (this.course === null) {
  199. this.fetchData();
  200. this.firstLoadData = false;
  201. }
  202. },
  203.  
  204. computed: {
  205. swiper() {
  206. return this.$refs.mySwiper.swiper;
  207. },
  208. courses() {
  209. if (this.course !== null) {
  210. if (this.type === 'myStudy') {
  211. const temp = [];
  212. if (this.course.data.length > 0) {
  213. this.course.data.forEach((item) => {
  214. temp.push(item.content);
  215. });
  216. }
  217. return temp;
  218. }
  219. return this.course.data;
  220. }
  221. return [];
  222. }
  223. },
  224.  
  225. methods: {
  226. formatDate(date) {
  227. if (date == null) return '';
  228. const splitDate = date.split(' ');
  229. return splitDate[0];
  230. },
  231.  
  232. async fetch(page = 1, callback) {
  233. switch (this.type) {
  234. case 'popular':
  235. await ApiContent.popular(page, this.sizeOfCard, this.typeListCard)
  236. .then(callback)
  237. .catch(() => { this.isLoading = false; });
  238. break;
  239. case 'newest':
  240. await ApiContent.latest(page, this.sizeOfCard, this.typeListCard)
  241. .then(callback)
  242. .catch(() => { this.isLoading = false; });
  243. break;
  244. case 'bestRated':
  245. await ApiContent.bestRated(page, this.sizeOfCard, this.typeListCard)
  246. .then(callback)
  247. .catch(() => { this.isLoading = false; });
  248. break;
  249. case 'myStudy':
  250. await ApiUser.myStudy(page, this.sizeOfCard, this.typeListCard)
  251. .then(callback)
  252. .catch(() => { this.isLoading = false; });
  253. break;
  254. default:
  255. break;
  256. }
  257. },
  258.  
  259. fetchData(page = 1) {
  260. this.isLoading = true;
  261. this.fetch(page, (response) => {
  262. this.course = response;
  263. setTimeout(() => {
  264. this.isLoading = false;
  265. }, 1000);
  266. });
  267. },
  268.  
  269. next() {
  270. this.pageNumber += 1;
  271. },
  272.  
  273. prev() {
  274. if (this.pageNumber > 1) {
  275. this.pageNumber -= 1;
  276. } else {
  277. this.pageNumber = 1;
  278. }
  279. },
  280.  
  281. sizeOf(param) {
  282. this.size = param;
  283. },
  284.  
  285. styleCard(param) {
  286. this.cardView = param.cardView;
  287. this.listView = param.listView;
  288. },
  289. getUrlThumbnail(param, data) {
  290. if (param === '1') {
  291. try {
  292. return data.attachment.url.thumbnail;
  293. } catch {
  294. return 'https://cdn5.f-cdn.com/contestentries/1122631/9339617/59ac19e21539b_thumb900.jpg';
  295. }
  296. } else if (param === '2') {
  297. try {
  298. return data.attachment.url.original;
  299. } catch {
  300. return 'https://cdn5.f-cdn.com/contestentries/1122631/9339617/59ac19e21539b_thumb900.jpg';
  301. }
  302. }
  303. return 'https://cdn5.f-cdn.com/contestentries/1122631/9339617/59ac19e21539b_thumb900.jpg';
  304. },
  305. learnMore() {
  306. if (!this.isLogin()) {
  307. this.$bvModal.show('login');
  308. this.pageNumber -= 1;
  309. } else if (this.type === 'popular') this.$router.push({ name: 'Course-List-Popular' });
  310. else if (this.type === 'myStudy') this.$router.push({ name: 'Course-List-Study' });
  311. else if (this.type === 'newest') this.$router.push({ name: 'Course-List-Latest' });
  312. else this.$router.push({ name: 'Course-List-Best-Rated' });
  313. },
  314. isLogin() {
  315. if (store.get('jwt-token') === '' || typeof store.get('jwt-token') === 'undefined') {
  316. return false;
  317. }
  318. return true;
  319. },
  320. getLink(param, item) {
  321. if (this.isLogin()) {
  322. if (param === '1') {
  323. return `/detail_list_video/${item.id}`;
  324. }
  325. return `/detail_list_offline_course/${item.id}`;
  326. }
  327.  
  328. return '';
  329. }
  330. }
  331. };
  332. </script>
  333.  
  334. <style lang="scss" scoped>
  335. @import 'style.scss';
  336.  
  337. .btn-transparent {
  338. background: transparent;
  339. padding: 5px;
  340. border: none;
  341. margin-left: 10px;
  342. color: #808080;
  343. }
  344.  
  345. #view-more:hover {
  346. color: #ffffff;
  347. background-color: #1d6499;
  348. border: 2px solid #ffffff;
  349. }
  350.  
  351. #view-more {
  352. visibility: visible;
  353. opacity: 1;
  354. transition: visibility 0s linear 0.33s, opacity 10s linear;
  355. // transition: 0.3s;
  356. transition-delay: 0s;
  357. display: inline-block;
  358. width: 250px;
  359. margin: 0 14px;
  360. height: 313px;
  361. line-height: 313px;
  362. border: 2px solid #ffffff;
  363. text-align: center;
  364. border-radius: 8px;
  365. color: #1d6499;
  366. background-color: #ffffff;
  367. overflow: hidden;
  368. margin-top: -40px;
  369. box-shadow: 0px 4px 15px 0px rgba(0, 0, 0, 0.3);
  370. cursor: pointer;
  371.  
  372. }
  373. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement