_id.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <!--MAIN-->
  3. <main>
  4. <!--REVIEW ADDRESS-->
  5. <div class="reviewPage mt-3">
  6. <div class="container-fluid c-section">
  7. <div class="row">
  8. <div class="col-sm-2"></div>
  9. <div class="col-sm-8">
  10. <div class="a-spacing-top-medium">
  11. <h1 class="a-spacing-base">
  12. <b>Create Review</b>
  13. </h1>
  14. <div class="row">
  15. <!-- Product Photo -->
  16. <div class="col-md-2 col-sm-3 col-3">
  17. <img :src="product.photo" style="width: 80px" />
  18. </div>
  19. <!-- Product Title -->
  20. <div class="col-md-10 col-sm-9 col-9 m-auto">
  21. <h4>
  22. <b>{{ product.title }}</b>
  23. </h4>
  24. </div>
  25. </div>
  26. <div class="a-spacing-top-medium"></div>
  27. <hr />
  28. <h2 class="a-spacing-base">Overall Rating</h2>
  29. <div class="a-row">
  30. <!-- Rating -->
  31. <no-ssr>
  32. <StartRating v-model="rating"></StartRating>
  33. </no-ssr>
  34. </div>
  35. <div class="a-row a-spacing-top-large">
  36. <h2>Add photo or video</h2>
  37. <p
  38. style="font-size: 14px; font-weight: 700;"
  39. >Shoppers find images and videos more helpful than text alone.</p>
  40. </div>
  41. <div class="a-row a-spacing-top-medium">
  42. <!-- Choose a Photo -->
  43. <label class="choosefile-button">
  44. <i class="fal fa-plus"></i>
  45. <input @change="onFileSelected" type="file" />
  46. </label>
  47. <p>{{ fileName }}</p>
  48. </div>
  49. <div class="a-spacing-top-large"></div>
  50. <hr />
  51. <!-- Headline -->
  52. <div class="headline a-spacing-large">
  53. <h2 class="a-spacing-base">Add a headline</h2>
  54. <input
  55. v-model="headline"
  56. type="text"
  57. class="a-input-text"
  58. style="width: 70%;"
  59. placeholder="What's most important to know?"
  60. />
  61. </div>
  62. <!-- Body -->
  63. <div class="a-spacing-base">
  64. <h2 class="a-spacing-base">Write your review</h2>
  65. <textarea
  66. v-model="body"
  67. placeholder="What do you like or dislike? What did you see this product for?"
  68. style="height:6em; width: 100%;"
  69. ></textarea>
  70. </div>
  71. </div>
  72. <br />
  73. <br />
  74. <hr />
  75. <div class="a-spacing-top-medium">
  76. <p
  77. style="font-size: 14px; font-weight: 700;"
  78. >This is how you'll appear to other customers:</p>
  79. <div class="media a-spacing-top-large">
  80. <div class="media-left">
  81. <img src="/img/avatar.png" class="img-fluid" style="width: 50px;" />
  82. </div>
  83. <div class="media-body pl-3 pt-2">
  84. <input
  85. :value="$auth.$state.user.name"
  86. type="text"
  87. class="a-input-text"
  88. style="width: 100%;" />
  89. </div>
  90. </div>
  91. </div>
  92. <div class="a-row a-spacing-top-medium">
  93. <span class="a-color-tertiary">Don't worry, you can always change this on your profile</span>
  94. </div>
  95. <div class="a-row text-right a-spacing-top-large">
  96. <span class="a-button-register">
  97. <span class="a-button-inner">
  98. <span @click="onAddReview" class="a-button-text">Submit</span>
  99. </span>
  100. </span>
  101. </div>
  102. </div>
  103. <div class="col-sm-2"></div>
  104. </div>
  105. <div class="a-spacing-large pb-5"></div>
  106. <hr />
  107. </div>
  108. </div>
  109. <!--/REVIEW ADDRESS-->
  110. </main>
  111. <!--/MAIN-->
  112. </template>
  113. <script>
  114. import StarRating from 'vue-star-rating'
  115. export default {
  116. components: {
  117. StarRating
  118. },
  119. async asyncData ({ $axios, params }) {
  120. try {
  121. let response = await $axios.$get(`/api/products/${params.id}`)
  122. return {
  123. product: response.product
  124. }
  125. } catch (err) {
  126. console.log(err)
  127. }
  128. },
  129. data () {
  130. return {
  131. rating: 0,
  132. body: '',
  133. headline: '',
  134. selectedFile: null,
  135. fileName: null
  136. }
  137. },
  138. methods: {
  139. onFileSelected () {
  140. this.selectedFile = event.target.files[0]
  141. this.fileName = event.target.files[0].name
  142. },
  143. async onAddReview () {
  144. try {
  145. let data = new FormData()
  146. data.append('headline', this.headline)
  147. data.append('body', this.body)
  148. data.append('rating', this.rating)
  149. data.append('photo', this.selectedFile, this.selectedFile.name)
  150. let response = await this.$axios.$post(`/api/reviews/${this.$route.params.id}`, data)
  151. if (response.success) {
  152. this.$router.push(`/products/${this.$route.params.id}`)
  153. }
  154. } catch (err) {
  155. }
  156. }
  157. }
  158. }
  159. </script>