Card.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <article class="card search-card">
  3. <header>
  4. <h1>{{ item.title }}</h1>
  5. <h4>{{ item.field_short_description }}</h4>
  6. <span class="ref">{{ item.field_reference }}</span>
  7. </header>
  8. <nav class="tools">
  9. <section class="tool flags">
  10. <span class="btn mdi mdi-folder-outline"/>
  11. <div class="tool-content">
  12. <ul>
  13. <li v-if="flagcolls" v-for="coll in flagcolls" :key="coll.id">
  14. <span
  15. class="flag mdi"
  16. :class="[
  17. flagIsLoading(coll.id) ? 'mdi-loading mdi-spin' : flagIsActive(coll.id) ? 'mdi-close-circle isActive' : 'mdi-plus'
  18. ]"
  19. :collid="coll.id"
  20. @click.prevent="onFlagActionCard"
  21. >
  22. {{ coll.name }}
  23. </span>
  24. </li>
  25. </ul>
  26. </div>
  27. </section>
  28. </nav>
  29. <section class="images" v-switcher>
  30. <figure
  31. v-for="(img, index) in item.images"
  32. :key="img.url"
  33. >
  34. <img
  35. class="lazy"
  36. v-lazy="index"
  37. :data-src="img.url"
  38. :title="img.title"
  39. />
  40. <img class="blank" :src="blanksrc">
  41. </figure>
  42. </section>
  43. </article>
  44. </template>
  45. <script>
  46. import { mapState, mapActions } from 'vuex'
  47. import cardMixins from 'vuejs/components/cardMixins'
  48. export default {
  49. name: "Card",
  50. props: ['item'],
  51. mixins: [cardMixins],
  52. data() {
  53. return {
  54. blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
  55. loadingFlag: false
  56. }
  57. },
  58. computed: {
  59. ...mapState({
  60. flagcolls: state => state.User.flagcolls
  61. })
  62. },
  63. methods: {
  64. ...mapActions({
  65. flagUnflag: 'User/flagUnflag'
  66. }),
  67. flagIsActive(collid) {
  68. // console.log(this.item.uuid);
  69. // console.log(this.flagcolls[collid].items_uuids);
  70. return this.flagcolls[collid].items_uuids.indexOf(this.item.uuid) !== -1;
  71. },
  72. flagIsLoading(collid) {
  73. // console.log(this.item.uuid);
  74. // console.log(this.flagcolls[collid].items_uuids);
  75. return collid === this.loadingFlag;
  76. },
  77. onFlagActionCard (e) {
  78. console.log("Card onFlagActionCard", e);
  79. if (!this.loadingFlag) {
  80. let collid = e.target.getAttribute('collid');
  81. let isActive = this.flagIsActive(collid);
  82. let action = isActive ? 'unflag' : 'flag';
  83. // console.log('collid', collid);
  84. // console.log("this.item", this.item);
  85. this.loadingFlag = collid;
  86. this.flagUnflag({ action: action, uuid: this.item.uuid, collid: collid})
  87. .then(data => {
  88. console.log("onFlagActionCard then", data);
  89. this.loadingFlag = false;
  90. })
  91. }
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. </style>