CartItem.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template lang="pug">
  2. li.cart-item
  3. h3.item-name {{ item.display_name }}
  4. input.item-quantity(:value="quantity" v-model="quantity" number)
  5. span.item-x x
  6. span.item-price {{ formatPrice() }}
  7. span.item-equals =
  8. span.item-subtotal {{ formatSubtotal() }}
  9. .cart-item-options-wrapper
  10. .cart-item-options
  11. .cart-item-option(class="fa fa-plus" @click="add(item)")
  12. .cart-item-option(class="fa fa-minus" @click="subtract(item)")
  13. .cart-item-option(class="fa fa-money" @click="discount(item)")
  14. .cart-item-option(class="fa fa-trash" @click="remove(item)")
  15. </template>
  16. <script>
  17. import { mapGetters, mapActions } from 'vuex'
  18. export default {
  19. props: {
  20. item: {
  21. type: Object,
  22. required: true,
  23. default: () => {
  24. return {}
  25. }
  26. }
  27. },
  28. computed: {
  29. quantity: {
  30. get() {
  31. return this.item.qty || 1
  32. },
  33. set(value) {
  34. this.item.qty = value || 1
  35. }
  36. },
  37. ...mapGetters([
  38. 'currencySymbol'
  39. ])
  40. },
  41. methods: {
  42. add(item) {
  43. this.addToCart(item)
  44. },
  45. subtract(item) {
  46. this.subtractFromCart(item)
  47. },
  48. discount(item) {
  49. this.discountFromCart(item)
  50. },
  51. remove(item) {
  52. this.removeFromCart(item)
  53. },
  54. formatPrice() {
  55. return accounting.formatMoney(this.item.price, this.currencySymbol, 0, '.', ',')
  56. },
  57. formatSubtotal() {
  58. return accounting.formatMoney(this.item.price * this.item.qty, this.currencySymbol, 0, '.', ',')
  59. },
  60. ...mapActions([
  61. 'addToCart',
  62. 'subtractFromCart',
  63. 'discountFromCart',
  64. 'removeFromCart'
  65. ])
  66. },
  67. mounted() {
  68. this.$set(this.item, 'qty', 1)
  69. this.$set(this.item, 'price', this.item.list_price)
  70. this.$set(this.item, 'discount', 0)
  71. }
  72. }
  73. </script>
  74. <style lang="sass">
  75. .cart-item
  76. width: 100%
  77. height: 90px
  78. list-style: none outside none
  79. border-bottom: 1px solid #d3d3d3
  80. box-sizing: border-box
  81. position: relative
  82. &:nth-child(1)
  83. border-top: 1px solid #d3d3d3
  84. &:hover
  85. transition-duration: 1s
  86. border-bottom: 2px solid #7c7bad
  87. .item-name
  88. width: 100%
  89. height: 20px
  90. margin: 10px 0 5px 0
  91. float: left
  92. font:
  93. size: 8pt
  94. .item-quantity
  95. width: 50px
  96. height: 28px
  97. margin-top: 6px
  98. text-align: right
  99. float: left
  100. .item-x
  101. width: 20px
  102. height: 20px
  103. margin-top: 12px
  104. text-align: center
  105. float: left
  106. .item-price
  107. width: 80px
  108. height: 20px
  109. margin-top: 12px
  110. text-align: right
  111. float: left
  112. .item-equals
  113. width: 20px
  114. height: 20px
  115. margin-top: 12px
  116. text-align: center
  117. float: left
  118. .item-subtotal
  119. width: 100px
  120. height: 20px
  121. margin-top: 12px
  122. padding-right: 15px
  123. text-align: right
  124. float: right
  125. font-weight: bold
  126. .cart-item-options-wrapper
  127. width: 100%
  128. height: 20px
  129. position: absolute
  130. bottom: 0
  131. display: flex
  132. justify-content: center
  133. .cart-item-options
  134. width: 100px
  135. height: 20px
  136. border: 1px solid #d3d3d3
  137. border-bottom: none
  138. display: flex
  139. justify-content: center
  140. .cart-item-option
  141. width: 18px
  142. height: 18px
  143. margin: 0 5px
  144. color: #666
  145. &:hover
  146. cursor: pointer
  147. &.fa
  148. padding-left: 2px
  149. line-height: 20px
  150. &.fa-plus:hover
  151. color: #2196f3
  152. &.fa-minus:hover
  153. color: #ffc107
  154. &.fa-money:hover
  155. color: #4caf50
  156. &.fa-trash:hover
  157. color: #f44336
  158. </style>