ProductCard.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template lang="pug">
  2. .product-card(@click="selectProduct({ data })")
  3. h2.product-title {{ data.name }}
  4. img.product-image(:src="this.data.image_medium ? 'data:image/png;base64,' + this.data.image_medium : '/web/static/src/img/placeholder.png'")
  5. .product-price
  6. span Gs {{ data.list_price }}
  7. .product-qty
  8. </template>
  9. <script>
  10. import { mapActions } from 'vuex'
  11. export default {
  12. props: {
  13. data: {
  14. type: Object,
  15. default: () => {
  16. return {}
  17. }
  18. }
  19. },
  20. computed: {
  21. // FIXME
  22. productImage() {
  23. let img = new Image()
  24. img.src = this.data.image_medium ? 'data:image/png;base64,' + this.data.image_medium : '/web/static/src/img/placeholder.png'
  25. return img.src
  26. }
  27. },
  28. methods: {
  29. // TODO
  30. drawImage() {
  31. let ctx = this.$el.querySelector('.product-image').getContext('2d')
  32. let img = new Image()
  33. img.onload = () => {
  34. ctx.drawImage(img, 0, 0, 80, 80)
  35. }
  36. console.log(this.data.image_medium)
  37. img.src = this.data.image_medium ? 'data:image/png;base64,' + this.data.image_medium : '/web/static/src/img/placeholder.png'
  38. },
  39. ...mapActions([
  40. 'selectProduct'
  41. ])
  42. },
  43. mounted() {
  44. // this.drawImage()
  45. }
  46. }
  47. </script>
  48. <style lang="sass">
  49. .product-card
  50. width: 130px
  51. height: 160px
  52. margin: 5px
  53. border: 1px solid #d3d3d3
  54. display: inline-block
  55. position: relative
  56. &:hover
  57. cursor: pointer
  58. .product-title
  59. width: 100%
  60. height: 30px
  61. font-size: 9pt
  62. text-align: center
  63. margin-top: 10px
  64. position: absolute
  65. top: 0
  66. .product-image
  67. width: 80px
  68. height: 80px
  69. margin: 0
  70. border: none
  71. position: absolute;
  72. top: 50%
  73. left: 50%
  74. margin-right: -50%
  75. transform: translate(-50%, -50%)
  76. .product-price
  77. width: 100%
  78. height: 30px
  79. padding-top: 5px
  80. text-align: center
  81. font-size: 10pt
  82. font-weight: bold
  83. background: #7c7bad
  84. color: #fff
  85. position: absolute
  86. bottom: 0
  87. </style>