index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. Component({
  2. externalClasses: ['wr-class', 'header-class', 'title-class'],
  3. options: {
  4. multipleSlots: true,
  5. },
  6. relations: {
  7. '../order-goods-card/index': {
  8. type: 'descendant',
  9. linked(target) {
  10. this.children.push(target);
  11. this.setHidden();
  12. },
  13. unlinked(target) {
  14. this.children = this.children.filter((item) => item !== target);
  15. },
  16. },
  17. '../goods-card/index': {
  18. type: 'descendant',
  19. linked(target) {
  20. this.children.push(target);
  21. this.setHidden();
  22. },
  23. unlinked(target) {
  24. this.children = this.children.filter((item) => item !== target);
  25. },
  26. },
  27. '../specs-goods-card/index': {
  28. type: 'descendant',
  29. linked(target) {
  30. this.children.push(target);
  31. this.setHidden();
  32. },
  33. unlinked(target) {
  34. this.children = this.children.filter((item) => item !== target);
  35. },
  36. },
  37. },
  38. created() {
  39. this.children = [];
  40. },
  41. properties: {
  42. order: {
  43. type: Object,
  44. observer(order) {
  45. if (!order?.goodsList) return;
  46. const goodsCount = order.goodsList.length;
  47. this.setData({
  48. goodsCount,
  49. });
  50. },
  51. },
  52. useTopRightSlot: Boolean,
  53. // 初始显示的商品数量,超出部分会隐藏。
  54. defaultShowNum: {
  55. type: null,
  56. value: 10,
  57. },
  58. useLogoSlot: {
  59. type: Boolean,
  60. value: false,
  61. },
  62. },
  63. data: {
  64. showAll: true, // 是否展示所有商品,设置为false,可以使用展开更多功能
  65. goodsCount: 0,
  66. },
  67. methods: {
  68. setHidden() {
  69. const isHidden = !this.data.showAll;
  70. this.children.forEach(
  71. (c, i) => i >= this.properties.defaultShowNum && c.setHidden(isHidden),
  72. );
  73. },
  74. onOrderCardTap() {
  75. this.triggerEvent('cardtap');
  76. },
  77. onShowMoreTap() {
  78. this.setData({ showAll: true }, () => this.setHidden());
  79. this.triggerEvent('showall');
  80. },
  81. },
  82. });