鸿宇研学生前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
4.6 KiB

  1. <template>
  2. <view class="product"
  3. @touchstart="onTouchstart"
  4. @touchmove="onTouchmove"
  5. @touchend="onTouchend"
  6. >
  7. <image class="product-img" :src="data.image" mode="aspectFill"></image>
  8. <view class="flex flex-column product-info">
  9. <view class="product-info-top">
  10. <view class="product-name text-ellipsis-2">{{ data.name }}</view>
  11. <view class="product-desc text-ellipsis">{{ data.desc }}</view>
  12. </view>
  13. <view class="flex product-info-bottom">
  14. <view class="product-detail">
  15. <view class="flex product-price">
  16. <view class="product-price-val">
  17. <text>¥</text>
  18. <text class="highlight">{{ priceInt }}</text>
  19. <text>{{ `${priceFrac}` }}</text>
  20. </view>
  21. <view class="product-price-bef" v-if="data.originalPrice">
  22. {{ `¥${data.originalPrice}` }}
  23. </view>
  24. </view>
  25. <view class="product-registered">
  26. {{ `${data.registered}人已报名` }}
  27. </view>
  28. </view>
  29. <button class="btn" @click="onRegistrate">报名</button>
  30. </view>
  31. </view>
  32. <button class="flex btn-collect"
  33. :style="collectBtnStyle"
  34. @click.stop="onCollect"
  35. @touchstart.stop="() => {}"
  36. >
  37. <view>收藏</view>
  38. </button>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. props: {
  44. data: {
  45. type: Object,
  46. default() {
  47. return {}
  48. }
  49. }
  50. },
  51. data() {
  52. return {
  53. isMove: false,
  54. startClientX: null,
  55. displayX: 0,
  56. }
  57. },
  58. computed: {
  59. priceInt() {
  60. return parseInt(this.data.currentPrice)
  61. },
  62. priceFrac() {
  63. return (this.data.currentPrice % this.priceInt).toFixed(2).slice(1)
  64. },
  65. collectBtnStyle() {
  66. let display = Math.ceil(this.displayX / 56 * 100)
  67. display > 100 && (display = 100)
  68. const translateX = 100 - display
  69. return `transform: translateX(${translateX}%);`
  70. }
  71. },
  72. methods: {
  73. onTouchstart(e) {
  74. const clientX = e.changedTouches[0].clientX
  75. this.isMove = false
  76. this.startClientX = clientX
  77. this.displayX = 0
  78. },
  79. onTouchmove(e) {
  80. const clientX = e.changedTouches[0].clientX
  81. if (clientX < this.startClientX) {
  82. this.displayX = this.startClientX - clientX
  83. } else {
  84. this.displayX = 0
  85. }
  86. this.isMove = true
  87. },
  88. onTouchend() {
  89. if (this.displayX < 100) {
  90. this.displayX = 0
  91. }
  92. this.isMove = false
  93. },
  94. showCollectBtn() {
  95. this.displayX = 100
  96. },
  97. hiddenCollectBtn() {
  98. this.displayX = 0
  99. },
  100. onCollect() {
  101. console.log('onCollect')
  102. // todo: fetch collect
  103. uni.showToast({
  104. icon: 'success',
  105. title: '已收藏',
  106. });
  107. this.hiddenCollectBtn()
  108. },
  109. onRegistrate() {
  110. this.$utils.navigateTo(`/pages_order/product/productDetail?id=${this.data.id}`)
  111. },
  112. },
  113. }
  114. </script>
  115. <style scoped lang="scss">
  116. .product {
  117. position: relative;
  118. height: 464rpx;
  119. background: #FFFFFF;
  120. border: 2rpx solid #FFFFFF;
  121. border-radius: 32rpx;
  122. overflow: hidden;
  123. font-size: 0;
  124. &-img {
  125. width: 100%;
  126. height: 220rpx;
  127. }
  128. &-info {
  129. height: 244rpx;
  130. padding: 16rpx 16rpx 24rpx 16rpx;
  131. box-sizing: border-box;
  132. justify-content: space-between;
  133. &-top {
  134. }
  135. &-bottom {
  136. width: 100%;
  137. justify-content: space-between;
  138. }
  139. }
  140. &-name {
  141. font-size: 28rpx;
  142. font-weight: 500;
  143. color: #000000;
  144. }
  145. &-desc {
  146. margin-top: 8rpx;
  147. font-size: 24rpx;
  148. color: #8B8B8B;
  149. }
  150. &-detail {
  151. }
  152. &-price {
  153. justify-content: flex-start;
  154. align-items: baseline;
  155. column-gap: 12rpx;
  156. &-val {
  157. font-size: 24rpx;
  158. font-weight: 500;
  159. color: #FF4800;
  160. .highlight {
  161. font-size: 32rpx;
  162. }
  163. }
  164. &-bef {
  165. text-decoration: line-through;
  166. font-size: 24rpx;
  167. color: #8B8B8B;
  168. }
  169. }
  170. &-registered {
  171. font-size: 24rpx;
  172. color: #8B8B8B;
  173. }
  174. .btn {
  175. padding: 11rpx 16rpx;
  176. font-size: 26rpx;
  177. font-weight: 500;
  178. color: #FFFFFF;
  179. background: #00A9FF;
  180. border-radius: 24rpx;
  181. }
  182. }
  183. .btn-collect {
  184. position: absolute;
  185. top: 0;
  186. right: 0;
  187. row-gap: 8rpx;
  188. width: 112rpx;
  189. height: 100%;
  190. font-size: 24rpx;
  191. line-height: 1;
  192. color: #FFFFFF;
  193. background: #FF9035;
  194. }
  195. </style>