CartItem.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template lang="pug">
  2. li.cart-item(:class="{'cart-item-invalid': !isValid()}")
  3. h3.item-name {{ item.displayName }}
  4. input.item-quantity(type='number' min='1' :value='item.quantity' readonly)
  5. span.item-x x
  6. span.item-price {{ item.price | currency(...options) }}
  7. span.item-equals =
  8. span.item-subtotal {{ (item.price * (item.quantity || 1)) | currency(...options) }}
  9. .cart-item-options-wrapper
  10. .cart-item-options
  11. .cart-item-option(class='fa fa-plus' @click='onClickIncrement')
  12. .cart-item-option(class='fa fa-minus' @click='onClickDecrement')
  13. .cart-item-option(class="fa fa-money" @click='onClickMoney')
  14. .cart-item-option(class='fa fa-trash' @click='onClickDelete')
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. index: {
  20. type: Number,
  21. default: -1,
  22. required: true
  23. },
  24. item: {
  25. type: Object,
  26. default: null
  27. },
  28. options: {
  29. type: Object,
  30. default: {
  31. symbol: '$',
  32. position: 'before',
  33. thousandsSeparator: '.',
  34. decimalPlaces: 2,
  35. decimalSeparator: ','
  36. }
  37. }
  38. },
  39. watch: {
  40. item: {
  41. handler(value) {
  42. this.onChange(value)
  43. },
  44. deep: true,
  45. immediate: true
  46. }
  47. },
  48. methods: {
  49. onChange(item) {
  50. this.$emit('onChange', item)
  51. },
  52. onClickIncrement() {
  53. this.$emit('onClickIncrement', this.item)
  54. },
  55. onClickDecrement() {
  56. this.$emit('onClickDecrement', this.item)
  57. },
  58. onClickMoney() {
  59. this.$emit('onClickMoney', this.item)
  60. },
  61. onClickDelete() {
  62. this.$emit('onClickDelete', this.item)
  63. },
  64. isValid() {
  65. return this.item.price > 0
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="sass">
  71. @import '../../assets/variables'
  72. .cart-item
  73. width: 100%
  74. height: 90px
  75. list-style: none outside none
  76. border-bottom: 1px solid $app-border-color
  77. box-sizing: border-box
  78. position: relative
  79. &.cart-item-invalid
  80. border-bottom: 2px solid $app-error-color
  81. &:nth-child(1)
  82. border-top: 1px solid $app-border-color
  83. &:hover
  84. transition-duration: 1000ms
  85. border-bottom: 2px solid $app-main-color
  86. .item-name
  87. width: 100%
  88. height: 20px
  89. margin: 10px 0 5px 0
  90. float: left
  91. font-size: 8pt
  92. display: inline-block
  93. .item-quantity
  94. width: 50px
  95. height: 28px
  96. margin-top: 6px
  97. text-align: right
  98. float: left
  99. display: inline-block
  100. .item-x
  101. width: 20px
  102. height: 20px
  103. margin-top: 12px
  104. text-align: right
  105. float: left
  106. display: inline-block
  107. .item-price
  108. width: 80px
  109. height: 20px
  110. margin-top: 12px
  111. text-align: right
  112. float: left
  113. display: inline-block
  114. .item-equals
  115. width: 20px
  116. height: 20px
  117. margin-top: 12px
  118. text-align: center
  119. float: left
  120. display: inline-block
  121. .item-subtotal
  122. width: 100px
  123. height: 20px
  124. margin-top: 12px
  125. text-align: right
  126. font-weight: bold
  127. display: inline-block
  128. .cart-item-options-wrapper
  129. width: 100%
  130. height: 20px
  131. position: absolute
  132. bottom: 0
  133. display: flex
  134. justify-content: center
  135. .cart-item-options
  136. width: 100px
  137. height: 20px
  138. border: 1px solid #d3d3d3
  139. border-bottom: none
  140. display: flex
  141. justify-content: center
  142. .cart-item-option
  143. width: 18px
  144. height: 18px
  145. margin: 0 5px
  146. color: #666
  147. &:hover
  148. cursor: pointer
  149. &.fa
  150. padding-left: 2px
  151. line-height: 20px
  152. &.fa-plus:hover
  153. color: #2196f3
  154. &.fa-minus:hover
  155. color: #ffc107
  156. &.fa-money:hover
  157. color: #4caf50
  158. &.fa-trash:hover
  159. color: #f44336
  160. </style>