CartItem.vue 4.6 KB

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