Card.vue 6.2 KB

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