CartItem.vue 4.5 KB

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