index.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Icon, Image } from 'vant'
  2. import { defineComponent } from 'vue'
  3. import styles from './index.module.less'
  4. import iconAddCart from '../../images/icon-add-cart.png'
  5. import iconSellOut from '../../images/icon-sell-out.png'
  6. import { moneyFormat } from '@/helpers/utils'
  7. export default defineComponent({
  8. name: 'goods',
  9. props: {
  10. showAdd: {
  11. type: Boolean,
  12. default: true
  13. },
  14. item: {
  15. type: Object,
  16. default: {}
  17. },
  18. onItemClick: {
  19. type: Function,
  20. default: (item: any) => {}
  21. },
  22. onBuyClick: {
  23. type: Function,
  24. default: (item: any) => {}
  25. }
  26. },
  27. render() {
  28. const item = this.item
  29. return (
  30. <div class={styles.goods} onClick={() => this.onItemClick(item)}>
  31. <div class={styles.goodsSection}>
  32. <Image src={item.pic} fit="cover" class={styles.goodsImg} />
  33. {item.stock <= 0 && (
  34. <div class={styles.sellOut}>
  35. <Image src={iconSellOut} fit="cover" class={styles.sellOutImg} />
  36. </div>
  37. )}
  38. </div>
  39. <div class={styles.goodsInfo}>
  40. <div class={[styles.goodsName, 'van-ellipsis']}>{item.name}</div>
  41. <div class={styles.goodsBuy}>
  42. {/* <del class={styles.goodsSale}>
  43. ¥{moneyFormat(item.originalPrice)}
  44. </del> */}
  45. <p class={styles.goodsPrice}><span class={styles.pre}>¥</span>{moneyFormat(item.price)}</p>
  46. {this.showAdd && (
  47. <Icon
  48. class={[
  49. styles.addCart,
  50. item.stock <= 0 && styles.addCartDisabled
  51. ]}
  52. name={iconAddCart}
  53. size={22}
  54. onClick={(e: MouseEvent) => {
  55. e.stopPropagation()
  56. item.stock > 0 && this.onBuyClick(item)
  57. }}
  58. />
  59. )}
  60. </div>
  61. </div>
  62. </div>
  63. )
  64. }
  65. })