PaymentAmount.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template lang="pug">
  2. form.payment-amount-form
  3. .payment-form-separator
  4. h3 Detalles del Pago
  5. hr
  6. .payment-amount-item
  7. label.payment-label Monto a pagar
  8. input.payment-input(readonly :value="formatTotal()")
  9. .payment-amount-item
  10. label.payment-label Monto recibido
  11. input.payment-input(:value="paid" v-model="paid" autofocus)
  12. hr.result-separator
  13. .payment-amount-item
  14. label.payment-label Monto a devolver
  15. input.payment-input(readonly :value="formatResidual()")
  16. </template>
  17. <script>
  18. import { mapGetters, mapActions } from 'vuex'
  19. export default {
  20. computed: {
  21. paid: {
  22. get() {
  23. return accounting.formatMoney(this.amountPaid, this.currencySymbol, 0, '.', ',')
  24. },
  25. set(value) {
  26. value = accounting.unformat(value, ',')
  27. this.changeAmountPaid(value)
  28. this.calculateResidual()
  29. }
  30. },
  31. ...mapGetters([
  32. 'total',
  33. 'currencySymbol',
  34. 'amountPaid'
  35. ])
  36. },
  37. methods: {
  38. formatTotal() {
  39. return accounting.formatMoney(this.total, this.currencySymbol, 0, '.', ',')
  40. },
  41. formatResidual() {
  42. return accounting.formatMoney(this.residual, this.currencySymbol, 0, '.', ',')
  43. },
  44. calculateResidual() {
  45. this.residual = this.amountPaid >= this.total ? this.amountPaid - this.total : 0
  46. },
  47. ...mapActions([
  48. 'changeAmountPaid'
  49. ])
  50. },
  51. data() {
  52. return {
  53. residual: 0
  54. }
  55. },
  56. mounted() {
  57. this.changeAmountPaid(0)
  58. }
  59. }
  60. </script>
  61. <style lang="sass">
  62. .payment-amount-form
  63. width: calc(100% - 450px)
  64. height: 100%
  65. margin-right: 50px
  66. padding: 35px
  67. background: #f5f5f5
  68. .payment-amount-item
  69. width: 100%
  70. height: 45px
  71. margin-bottom: 15px
  72. .payment-label
  73. width: 250px
  74. height: 45px
  75. font-size: 14pt
  76. .payment-input
  77. width: 350px
  78. height: 45px
  79. font-size: 24pt
  80. border-radius: 0
  81. text-align: right
  82. .payment-form-separator
  83. h3
  84. color: #9e9e9e
  85. font-size: 8pt
  86. hr
  87. margin-top: 5px
  88. .result-separator
  89. margin: 30px 165px 30px 250px
  90. border-top: 1px solid #bdbdbd
  91. </style>