CartItem.vue 4.3 KB

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