WineListPage.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div class="wines">
  3. <div class="wine" v-for="(wine, index) in wines" :key="keys[index]" @click="detail_of(index)">
  4. <img class="wine-picture" :src="wine.picture" alt="wine-image">
  5. <h2>{{ wine.name }}</h2>
  6. <div class="info">
  7. <h3>¥<span class="price">{{ wine.price_in_yuan }}</span>/两</h3>
  8. <div class="remain">剩余:<span :style="`color: ${color_of_remain(index)};`">{{ wine.remain_in_weight }}</span> 两
  9. </div>
  10. </div>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. let Timer = null;
  16. export default {
  17. name: "WineListPage",
  18. data() {
  19. return {
  20. wines: this.$utils.Wines,
  21. keys: [10, 11, 12, 13]
  22. };
  23. },
  24. methods: {
  25. Start() {
  26. for (let i = 0; i < 4; i++) this.keys[i]++;
  27. this.clear_timer();
  28. Timer = setTimeout(() => {
  29. this.$emit("list2adv");
  30. }, this.$utils.ParamMap.ListTimeOut * 1000);
  31. },
  32. Over() {
  33. this.clear_timer();
  34. },
  35. get_icon(name) {
  36. return `${process.env.BASE_URL}icon/${name}.svg`;
  37. },
  38. color_of_remain(index) {
  39. if (this.wines[index].remain > this.$utils.ParamMap.WarnLine) return "green";
  40. else if (this.wines[index].remain > this.$utils.ParamMap.DangerLine) return "goldenrod";
  41. return "red";
  42. },
  43. clear_timer() {
  44. if (Timer !== null) clearTimeout(Timer);
  45. Timer = null;
  46. },
  47. detail_of(index) {
  48. this.$emit("list2detail", index);
  49. }
  50. }
  51. }
  52. </script>
  53. <style scoped>
  54. .wines {
  55. display: flex;
  56. justify-content: space-evenly;
  57. align-items: center;
  58. }
  59. .wine {
  60. width: 400px;
  61. height: 650px;
  62. cursor: pointer;
  63. background-color: white;
  64. border-radius: 6px;
  65. display: flex;
  66. flex-direction: column;
  67. align-items: center;
  68. justify-content: space-between;
  69. box-sizing: border-box;
  70. padding: 30px 20px;
  71. }
  72. .wine:active {
  73. transform: scale(0.99);
  74. box-shadow: 1px 2px 4px lightgray;
  75. }
  76. .wine-picture {
  77. width: 280px;
  78. height: 400px;
  79. object-fit: cover;
  80. }
  81. h2 {
  82. font-size: 30px;
  83. text-align: center;
  84. margin-block-start: 5px;
  85. margin-block-end: 10px;
  86. }
  87. .info {
  88. width: 100%;
  89. display: flex;
  90. justify-content: space-between;
  91. align-items: flex-end;
  92. }
  93. h3 {
  94. font-size: 22px;
  95. margin-block-start: 0;
  96. margin-block-end: 0;
  97. color: red;
  98. }
  99. .price {
  100. font-size: 38px;
  101. }
  102. .remain {
  103. color: rgba(0, 0, 0, .4);
  104. font-size: 20px;
  105. }
  106. </style>