Card.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <article class="card search-card">
  3. <header
  4. @click.prevent="openModalCard"
  5. >
  6. <h1 v-if="isloggedin">{{ item.title }}</h1>
  7. <h4>{{ item.short_description }}</h4>
  8. <span v-if="isloggedin" class="ref">{{ item.reference }}</span>
  9. </header>
  10. <nav class="tools" v-if="isloggedin">
  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. <li v-if="collsLength<15" class="create-flag">
  28. <input
  29. placeholder="new folder"
  30. v-model="new_folder_name"
  31. @keyup.enter.prevent.stop="onCreateFlagColl"
  32. />
  33. <span
  34. class="add-btn mdi"
  35. :class="addFlagBtnClassObj"
  36. @click.prevent.stop="onCreateFlagColl"
  37. />
  38. </li>
  39. </ul>
  40. </div>
  41. </section>
  42. <section class="tool samples" v-if="item.samples && item.samples.length">
  43. <span class="btn mdi mdi-beaker-outline"/>
  44. <div class="tool-content">
  45. <span class="label">{{ $t("materio.Samples") }}</span>
  46. <ul>
  47. <li
  48. v-for="sample in item.samples"
  49. :key="sample.showroom.id"
  50. >
  51. <span class="showroom">{{ sample.showroom.name }}</span>: {{ sample.location }}
  52. </li>
  53. </ul>
  54. </div>
  55. </section>
  56. <section class="tool print">
  57. <a :href="item.path+'/printable/print'" target="_blank">
  58. <span class="btn mdi mdi-printer"/>
  59. </a>
  60. </section>
  61. </nav>
  62. <section class="images" v-switcher>
  63. <figure
  64. v-for="(img, index) in item.images"
  65. :key="img.url"
  66. >
  67. <img
  68. class="lazy"
  69. v-lazy="index"
  70. :data-src="img.style_cardmedium_url"
  71. :title="img.title"
  72. />
  73. <img
  74. class="blank"
  75. :src="blanksrc"
  76. @click.prevent="openModalCard"
  77. />
  78. </figure>
  79. </section>
  80. <!-- <CoolLightBox
  81. v-if="isloggedin"
  82. :items="item.images"
  83. :index="lightbox_index"
  84. srcName="style_hd_url"
  85. :loop="true"
  86. @close="lightbox_index = null">
  87. </CoolLightBox> -->
  88. </article>
  89. </template>
  90. <script>
  91. import { mapState, mapActions } from 'vuex'
  92. import cardMixins from 'vuejs/components/cardMixins'
  93. import ModalCard from 'vuejs/components/Content/ModalCard'
  94. export default {
  95. name: "Card",
  96. props: ['item'],
  97. mixins: [cardMixins],
  98. components: {
  99. ModalCard
  100. },
  101. data() {
  102. return {
  103. blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
  104. loadingFlag: false,
  105. new_folder_name: "",
  106. is_creating_folder: false
  107. // lightbox_index: null
  108. }
  109. },
  110. computed: {
  111. ...mapState({
  112. flagcolls: state => state.User.flagcolls,
  113. isloggedin: state => state.User.isloggedin
  114. }),
  115. collsLength() {
  116. return Object.keys(this.flagcolls).length
  117. },
  118. addFlagBtnClassObj() {
  119. return {
  120. 'mdi-plus-circle-outline': !this.is_creating_folder,
  121. 'mdi-loading': this.is_creating_folder,
  122. active: this.new_folder_name.length > 4 && !this.is_creating_folder,
  123. loading: this.is_creating_folder
  124. }
  125. }
  126. },
  127. methods: {
  128. ...mapActions({
  129. createFlagColl: 'User/createFlagColl',
  130. flagUnflag: 'User/flagUnflag'
  131. }),
  132. onCreateFlagColl () {
  133. console.log("Card onCreateFlagColl", this.new_folder_name)
  134. this.is_creating_folder = true;
  135. this.createFlagColl(this.new_folder_name)
  136. .then(data => {
  137. console.log("Card onCreateFlagColl then", data);
  138. this.new_folder_name = "";
  139. this.is_creating_folder = false;
  140. let collid = data.id
  141. this.loadingFlag = collid;
  142. this.flagUnflag({ action: 'flag', id: this.item.id, collid: collid})
  143. .then(data => {
  144. console.log("onFlagActionCard then", data);
  145. this.loadingFlag = false;
  146. })
  147. })
  148. },
  149. flagIsActive(collid) {
  150. // console.log("Card flagIsActive",
  151. // this.item.id,
  152. // this.flagcolls[collid].items,
  153. // this.flagcolls[collid].items.indexOf(this.item.id)
  154. // );
  155. // console.log(this.flagcolls[collid].items_uuids);
  156. // return this.flagcolls[collid].items_uuids.indexOf(this.item.uuid) !== -1;
  157. return this.flagcolls[collid].items.indexOf(this.item.id) !== -1;
  158. },
  159. flagIsLoading(collid) {
  160. // console.log(this.item.uuid);
  161. // console.log(this.flagcolls[collid].items_uuids);
  162. return collid === this.loadingFlag;
  163. },
  164. onFlagActionCard (e) {
  165. console.log("Card onFlagActionCard", e, this.item);
  166. if (!this.loadingFlag) {
  167. let collid = e.target.getAttribute('collid');
  168. let isActive = this.flagIsActive(collid);
  169. let action = isActive ? 'unflag' : 'flag';
  170. // console.log('collid', collid);
  171. // console.log("this.item", this.item);
  172. this.loadingFlag = collid;
  173. this.flagUnflag({ action: action, id: this.item.id, collid: collid})
  174. .then(data => {
  175. console.log("onFlagActionCard then", data);
  176. this.loadingFlag = false;
  177. })
  178. }
  179. },
  180. // onClickImg (e, index) {
  181. // this.lightbox_index = index
  182. // },
  183. openModalCard (e) {
  184. console.log('openModalCard', this.isLoggedin);
  185. if(this.isloggedin){
  186. this.$modal.show(
  187. ModalCard,
  188. { item: this.item },
  189. {
  190. name: `modal-${this.item.id}`,
  191. draggable: true,
  192. width: '850px',
  193. height: '610px'
  194. }
  195. )
  196. }
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. </style>