CartItem.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 {{ formatPrice() }}
  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.list_price, this.currencySymbol, 0, '.', ',')
  46. },
  47. formatSubtotal() {
  48. return accounting.formatMoney(this.item.list_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, 'discount', 0)
  60. }
  61. }
  62. </script>
  63. <style lang="sass">
  64. .cart-item
  65. width: 100%
  66. height: 90px
  67. list-style: none outside none
  68. border-bottom: 1px solid #d3d3d3
  69. box-sizing: border-box
  70. position: relative
  71. &:nth-child(1)
  72. border-top: 1px solid #d3d3d3
  73. &:hover
  74. transition-duration: 1s
  75. border-bottom: 2px solid #7c7bad
  76. .item-name
  77. width: 100%
  78. height: 20px
  79. margin: 10px 0 5px 0
  80. float: left
  81. font:
  82. size: 8pt
  83. .item-quantity
  84. width: 50px
  85. height: 28px
  86. margin-top: 6px
  87. text-align: right
  88. float: left
  89. .item-x
  90. width: 20px
  91. height: 20px
  92. margin-top: 12px
  93. text-align: center
  94. float: left
  95. .item-price
  96. width: 80px
  97. height: 20px
  98. margin-top: 12px
  99. text-align: right
  100. float: left
  101. .item-equals
  102. width: 20px
  103. height: 20px
  104. margin-top: 12px
  105. text-align: center
  106. float: left
  107. .item-subtotal
  108. width: 100px
  109. height: 20px
  110. margin-top: 12px
  111. padding-right: 15px
  112. text-align: right
  113. float: right
  114. font-weight: bold
  115. .cart-item-options-wrapper
  116. width: 100%
  117. height: 20px
  118. position: absolute
  119. bottom: 0
  120. display: flex
  121. justify-content: center
  122. .cart-item-options
  123. width: 100px
  124. height: 20px
  125. border: 1px solid #d3d3d3
  126. border-bottom: none
  127. display: flex
  128. justify-content: center
  129. .cart-item-option
  130. width: 18px
  131. height: 18px
  132. margin: 0 5px
  133. color: #666
  134. &:hover
  135. cursor: pointer
  136. &.fa
  137. padding-left: 2px
  138. line-height: 20px
  139. &.fa-plus:hover
  140. color: #2196f3
  141. &.fa-minus:hover
  142. color: #ffc107
  143. &.fa-money:hover
  144. color: #4caf50
  145. &.fa-trash:hover
  146. color: #f44336
  147. </style>