Card.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <article class="card search-card">
  3. <header
  4. @click="openModalCard"
  5. >
  6. <h1>{{ item.title }}</h1>
  7. <h4>{{ item.short_description }}</h4>
  8. <span class="ref">{{ item.reference }}</span>
  9. </header>
  10. <nav class="tools">
  11. <section class="tool flags">
  12. <span class="btn mdi mdi-folder-outline"/>
  13. <div class="tool-content">
  14. <ul>
  15. <li v-if="flagcolls" v-for="coll in flagcolls" :key="coll.id">
  16. <span
  17. class="flag mdi"
  18. :class="[
  19. flagIsLoading(coll.id) ? 'mdi-loading mdi-spin' : flagIsActive(coll.id) ? 'mdi-close-circle isActive' : 'mdi-plus'
  20. ]"
  21. :collid="coll.id"
  22. @click.prevent="onFlagActionCard"
  23. >
  24. {{ coll.name }}
  25. </span>
  26. </li>
  27. </ul>
  28. </div>
  29. </section>
  30. </nav>
  31. <section class="images" v-switcher>
  32. <figure
  33. v-for="(img, index) in item.images"
  34. :key="img.url"
  35. >
  36. <img
  37. class="lazy"
  38. v-lazy="index"
  39. :data-src="img.style_cardmedium.url"
  40. :title="img.title"
  41. />
  42. <img
  43. class="blank"
  44. :src="blanksrc"
  45. @click="lightbox_index = index"
  46. >
  47. </figure>
  48. </section>
  49. <CoolLightBox
  50. :items="item.images"
  51. :index="lightbox_index"
  52. srcName="url"
  53. :loop="true"
  54. @close="lightbox_index = null">
  55. </CoolLightBox>
  56. </article>
  57. </template>
  58. <script>
  59. import { mapState, mapActions } from 'vuex'
  60. import cardMixins from 'vuejs/components/cardMixins'
  61. import ModalCard from 'vuejs/components/Content/ModalCard'
  62. export default {
  63. name: "Card",
  64. props: ['item'],
  65. mixins: [cardMixins],
  66. components: {
  67. ModalCard
  68. },
  69. data() {
  70. return {
  71. blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
  72. loadingFlag: false,
  73. lightbox_index: null
  74. }
  75. },
  76. computed: {
  77. ...mapState({
  78. flagcolls: state => state.User.flagcolls
  79. })
  80. },
  81. methods: {
  82. ...mapActions({
  83. flagUnflag: 'User/flagUnflag'
  84. }),
  85. flagIsActive(collid) {
  86. // console.log("Card flagIsActive",
  87. // this.item.id,
  88. // this.flagcolls[collid].items,
  89. // this.flagcolls[collid].items.indexOf(this.item.id)
  90. // );
  91. // console.log(this.flagcolls[collid].items_uuids);
  92. // return this.flagcolls[collid].items_uuids.indexOf(this.item.uuid) !== -1;
  93. return this.flagcolls[collid].items.indexOf(this.item.id) !== -1;
  94. },
  95. flagIsLoading(collid) {
  96. // console.log(this.item.uuid);
  97. // console.log(this.flagcolls[collid].items_uuids);
  98. return collid === this.loadingFlag;
  99. },
  100. onFlagActionCard (e) {
  101. console.log("Card onFlagActionCard", e, this.item);
  102. if (!this.loadingFlag) {
  103. let collid = e.target.getAttribute('collid');
  104. let isActive = this.flagIsActive(collid);
  105. let action = isActive ? 'unflag' : 'flag';
  106. // console.log('collid', collid);
  107. // console.log("this.item", this.item);
  108. this.loadingFlag = collid;
  109. this.flagUnflag({ action: action, id: this.item.id, collid: collid})
  110. .then(data => {
  111. console.log("onFlagActionCard then", data);
  112. this.loadingFlag = false;
  113. })
  114. }
  115. },
  116. openModalCard (e) {
  117. this.$modal.show(
  118. ModalCard,
  119. { item: this.item },
  120. {
  121. draggable: true,
  122. width: '850px',
  123. height: '610px'
  124. }
  125. )
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. </style>