Card.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 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. flag: 'User/flag',
  66. unFlag: 'User/unFlag'
  67. }),
  68. flagIsActive(collid) {
  69. // console.log(this.item.uuid);
  70. // console.log(this.flagcolls[collid].items_uuids);
  71. return this.flagcolls[collid].items_uuids.indexOf(this.item.uuid) !== -1;
  72. },
  73. flagIsLoading(collid) {
  74. // console.log(this.item.uuid);
  75. // console.log(this.flagcolls[collid].items_uuids);
  76. return collid === this.loadingFlag;
  77. },
  78. onFlagActionCard (e) {
  79. console.log("Card onFlagActionCard", e);
  80. if (!this.loadingFlag) {
  81. let collid = e.target.getAttribute('collid');
  82. let isActive = this.flagIsActive(collid);
  83. // console.log('collid', collid);
  84. // console.log("this.item", this.item);
  85. this.loadingFlag = collid;
  86. if (isActive) {
  87. this.unFlag({uuid: this.item.uuid, collid: collid})
  88. .then(data => {
  89. console.log("onFlagActionCard then", data);
  90. this.loadingFlag = false;
  91. })
  92. }else{
  93. this.flag({uuid: this.item.uuid, collid: collid})
  94. .then(data => {
  95. console.log("onFlagActionCard then", data);
  96. this.loadingFlag = false;
  97. })
  98. }
  99. }
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss" scoped>
  105. </style>