|
@@ -1,7 +1,7 @@
|
|
|
<template lang="pug">
|
|
|
- li.cart-item
|
|
|
+ li.cart-item(:class="{'cart-item-invalid': !isValid()}")
|
|
|
h3.item-name {{ item.displayName }}
|
|
|
- input.item-quantity(type='number' min='1' :value='item.quantity' readonly)
|
|
|
+ input.item-quantity(type='number' v-model.number='quantity' @focus='onFocus' @blur='onBlur')
|
|
|
span.item-x x
|
|
|
span.item-price {{ item.price | currency(...options) }}
|
|
|
span.item-equals =
|
|
@@ -10,7 +10,8 @@
|
|
|
.cart-item-options
|
|
|
.cart-item-option(class='fa fa-plus' @click='onClickIncrement')
|
|
|
.cart-item-option(class='fa fa-minus' @click='onClickDecrement')
|
|
|
- .cart-item-option(class="fa fa-money" @click='onClickMoney')
|
|
|
+ .cart-item-option(class='fa fa-money' @click='onClickMoney')
|
|
|
+ .cart-item-option(class='fa fa-undo' @click='onClickUndo')
|
|
|
.cart-item-option(class='fa fa-trash' @click='onClickDelete')
|
|
|
</template>
|
|
|
|
|
@@ -37,6 +38,24 @@
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ quantity: {
|
|
|
+ get() {
|
|
|
+ return this.item.quantity
|
|
|
+ },
|
|
|
+ set(value) {
|
|
|
+ this.input = !value ? 1 : value
|
|
|
+
|
|
|
+ if (this.editing) {
|
|
|
+ this.handleEditing(value)
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ this.computeQuantity()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
watch: {
|
|
|
item: {
|
|
|
handler(value) {
|
|
@@ -47,20 +66,73 @@
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ handleEditing(value) {
|
|
|
+ if (value === '') {
|
|
|
+ clearTimeout(this.inputDaemon)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.inputDaemon !== null) {
|
|
|
+ clearTimeout(this.inputDaemon)
|
|
|
+ }
|
|
|
+
|
|
|
+ this.inputDaemon = setTimeout(() => {
|
|
|
+ this.computeQuantity()
|
|
|
+ }, 300)
|
|
|
+ },
|
|
|
+ computeQuantity() {
|
|
|
+ if (this.input > this.item.quantity) {
|
|
|
+ this.onClickIncrement()
|
|
|
+ } else {
|
|
|
+ this.onClickDecrement()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onFocus() {
|
|
|
+ this.editing = true
|
|
|
+ this.input = 0
|
|
|
+ },
|
|
|
+ onBlur() {
|
|
|
+ this.editing = false
|
|
|
+ this.input = 0
|
|
|
+ },
|
|
|
+ onInputChange(e) {
|
|
|
+ console.log(e)
|
|
|
+ },
|
|
|
onChange(item) {
|
|
|
this.$emit('onChange', item)
|
|
|
},
|
|
|
onClickIncrement() {
|
|
|
- this.$emit('onClickIncrement', this.item)
|
|
|
+ this.$emit('onClickIncrement', {
|
|
|
+ id: this.item.id,
|
|
|
+ quantity: this.editing ? this.input : 1
|
|
|
+ })
|
|
|
},
|
|
|
onClickDecrement() {
|
|
|
- this.$emit('onClickDecrement', this.item)
|
|
|
+ this.$emit('onClickDecrement', {
|
|
|
+ id: this.item.id,
|
|
|
+ quantity: this.editing ? this.input : -1
|
|
|
+ })
|
|
|
},
|
|
|
onClickMoney() {
|
|
|
this.$emit('onClickMoney', this.item)
|
|
|
},
|
|
|
+ onClickUndo() {
|
|
|
+ this.$emit('onClickUndo', this.item)
|
|
|
+ },
|
|
|
onClickDelete() {
|
|
|
- this.$emit('onClickDelete', this.item)
|
|
|
+ this.$emit('onClickDelete', {
|
|
|
+ id: this.item.id
|
|
|
+ })
|
|
|
+ },
|
|
|
+ isValid() {
|
|
|
+ return this.item.price > 0
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ editing: false,
|
|
|
+ input: 0,
|
|
|
+ inputDaemon: null
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -75,6 +147,8 @@
|
|
|
border-bottom: 1px solid $app-border-color
|
|
|
box-sizing: border-box
|
|
|
position: relative
|
|
|
+ &.cart-item-invalid
|
|
|
+ border-bottom: 2px solid $app-error-color
|
|
|
&:nth-child(1)
|
|
|
border-top: 1px solid $app-border-color
|
|
|
&:hover
|
|
@@ -88,12 +162,15 @@
|
|
|
font-size: 8pt
|
|
|
display: inline-block
|
|
|
.item-quantity
|
|
|
- width: 50px
|
|
|
+ width: 60px
|
|
|
height: 28px
|
|
|
margin-top: 6px
|
|
|
text-align: right
|
|
|
float: left
|
|
|
display: inline-block
|
|
|
+ user-select: none
|
|
|
+ cursor: pointer
|
|
|
+ border-radius: 0
|
|
|
.item-x
|
|
|
width: 20px
|
|
|
height: 20px
|
|
@@ -130,7 +207,7 @@
|
|
|
display: flex
|
|
|
justify-content: center
|
|
|
.cart-item-options
|
|
|
- width: 100px
|
|
|
+ width: 120px
|
|
|
height: 20px
|
|
|
border: 1px solid #d3d3d3
|
|
|
border-bottom: none
|
|
@@ -152,6 +229,8 @@
|
|
|
color: #ffc107
|
|
|
&.fa-money:hover
|
|
|
color: #4caf50
|
|
|
+ &.fa-undo:hover
|
|
|
+ color: #3f51b5
|
|
|
&.fa-trash:hover
|
|
|
color: #f44336
|
|
|
</style>
|