index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. Component({
  2. options: {
  3. addGlobalClass: true,
  4. multipleSlots: true, // 在组件定义时的选项中启用多slot支持
  5. },
  6. externalClasses: [
  7. 'title-class',
  8. 'desc-class',
  9. 'num-class',
  10. 'thumb-class',
  11. 'specs-class',
  12. 'price-class',
  13. 'origin-price-class',
  14. 'price-prefix-class',
  15. ],
  16. relations: {
  17. '../order-card/index': {
  18. type: 'ancestor',
  19. linked(target) {
  20. this.parent = target;
  21. },
  22. },
  23. },
  24. properties: {
  25. id: String,
  26. hidden: {
  27. // 设置为null代表不做类型转换
  28. type: null,
  29. observer(hidden) {
  30. // null就是代表没有设置,没有设置的话不setData,防止祖先组件触发的setHidden操作被覆盖
  31. if (hidden !== null) {
  32. this.setHidden(!!hidden);
  33. }
  34. },
  35. },
  36. data: Object,
  37. layout: {
  38. type: String,
  39. value: 'horizontal',
  40. },
  41. thumbMode: {
  42. type: String,
  43. value: 'aspectFill',
  44. },
  45. thumbWidth: Number,
  46. thumbHeight: Number,
  47. thumbWidthInPopup: Number,
  48. thumbHeightInPopup: Number,
  49. priceFill: {
  50. type: Boolean,
  51. value: true,
  52. },
  53. currency: {
  54. type: String,
  55. value: '¥',
  56. },
  57. lazyLoad: Boolean,
  58. centered: Boolean,
  59. showCart: Boolean,
  60. pricePrefix: String,
  61. cartSize: {
  62. type: Number,
  63. value: 48,
  64. },
  65. cartColor: {
  66. type: String,
  67. value: '#FA550F',
  68. },
  69. disablePopup: Boolean,
  70. },
  71. data: {
  72. hiddenInData: false,
  73. specsPopup: {
  74. insert: false,
  75. show: false,
  76. },
  77. },
  78. currentInTapSpecs: false,
  79. lifetimes: {
  80. ready() {
  81. const { hidden } = this.properties;
  82. if (hidden !== null) {
  83. this.setHidden(!!hidden);
  84. }
  85. },
  86. },
  87. methods: {
  88. closeSpecsPopup() {
  89. this.setData({
  90. 'specsPopup.show': false,
  91. });
  92. this.triggerEvent('specsclose', { good: this.properties.data });
  93. },
  94. removeSpecsPopup() {
  95. this.setData({
  96. 'specsPopup.insert': false,
  97. });
  98. },
  99. onClick(e) {
  100. if (this.currentInTapSpecs) {
  101. this.currentInTapSpecs = false;
  102. return;
  103. }
  104. this.triggerEvent('click', e.detail);
  105. },
  106. onClickThumb(e) {
  107. this.triggerEvent('thumb', e.detail);
  108. },
  109. onClickTag(e) {
  110. this.triggerEvent('tag', e.detail);
  111. },
  112. onClickCart(e) {
  113. this.triggerEvent('add-cart', e.detail);
  114. },
  115. setHidden(hidden) {
  116. this.setData({ hiddenInData: !!hidden });
  117. },
  118. },
  119. });