preview.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template id="group-goods-preview">
  2. <div class="group-goods-preview">
  3. <components
  4. :is="styleName"
  5. :goods-list="goodsList"
  6. :active-item="activeItem"
  7. :title-style="titleStyle"
  8. :show-title="isShowTitle"
  9. :title="comData.title"
  10. :group-box="groupBox"
  11. :goods-style="goodsStyle"
  12. :btn-style="btnStyle"
  13. :bg-color="computedStyle.bgColor"
  14. ></components>
  15. </div>
  16. </template>
  17. <script>
  18. /**
  19. * @descriptions
  20. * 1. 组件名字必须对应模板形式 - 递归组件name
  21. * 2. 样式内容方法尽量内部维护 - 前端方便通用
  22. * 3. 父级组件会传预览数据 - activeItem
  23. */
  24. Vue.component('group-goods-preview', {
  25. name: "group-goods-preview",
  26. props: {
  27. activeItem: {
  28. type: Object,
  29. default () {
  30. return {}
  31. }
  32. }
  33. },
  34. template: '#group-goods-preview',
  35. computed: {
  36. computedStyle() {
  37. console.log(this.activeItem, 'this.activeItem.computedStyle')
  38. return this.activeItem.computedStyle
  39. },
  40. comData() {
  41. return this.activeItem.data
  42. },
  43. styleName() {
  44. var styleItem = this.activeItem.data.groupStyle || {}
  45. var name = {
  46. 1: "group-goods-style1",
  47. 2: "group-goods-style2",
  48. 3: "group-goods-style3"
  49. }
  50. var index = styleItem.type || 1
  51. return name[index]
  52. },
  53. titleStyle() {
  54. let {
  55. paddingTop,
  56. paddingBottom
  57. } = this.comData
  58. let style = {
  59. 'padding-top': paddingTop >= 0 ? `${paddingTop}px` : '10px',
  60. 'padding-bottom': paddingBottom >= 0 ? `${paddingBottom}px` : '10px'
  61. }
  62. return style
  63. },
  64. isShowTitle() {
  65. return this.comData.titleRadio || 0
  66. },
  67. groupBox() {
  68. let {
  69. marginTop,
  70. marginBottom,
  71. aroundMargin
  72. } = this.computedStyle
  73. return {
  74. margin: `${marginTop} ${aroundMargin} ${marginBottom}`,
  75. overflow: 'hidden'
  76. }
  77. },
  78. goodsStyle() {
  79. let {
  80. tabItem,
  81. searchIpts
  82. } = this.computedStyle
  83. let style = {
  84. 'margin-top': this.computedStyle.spacing,
  85. ...searchIpts
  86. }
  87. if (tabItem && tabItem.value == 'border') style.border = '1px solid ' + (tabItem ? tabItem.color : 'transparent')
  88. if (tabItem && tabItem.value == 'shandow') style.boxShadow = tabItem ? '0 0 10px ' + tabItem.color : '0 0 10px rgba(226, 231, 244, 0.7)'
  89. return style
  90. },
  91. btnStyle() {
  92. return {
  93. color: this.computedStyle.btnTextColor,
  94. background: this.computedStyle.btnBackground
  95. }
  96. },
  97. },
  98. watch: {
  99. "activeItem.data.goods": {
  100. handler(newVal, oldVal) {
  101. if (newVal && !deepEqual(newVal, oldVal)) {
  102. const ids = newVal.map(item => {
  103. return item.params.id
  104. })
  105. console.log(ids)
  106. this.getGoodsList(ids)
  107. }
  108. },
  109. immediate: true
  110. },
  111. goodsList: {
  112. handler(val) {
  113. if (val.length == 0) {
  114. this.goodsList = this.defaultList
  115. }
  116. },
  117. immediate: true
  118. }
  119. },
  120. data() {
  121. return {
  122. defaultList: [{
  123. cover_pic: "/resources/img/decorate/default_picture.png",
  124. end_at: 1640880000,
  125. goods_id: 0,
  126. goods_name: "商品名称",
  127. group_buy_price: 100,
  128. group_size: 3,
  129. group_status: 1,
  130. id: 22,
  131. price: 300,
  132. sheng: 200,
  133. start_at: 1639238400,
  134. total_num: 14
  135. }],
  136. goodsList: []
  137. }
  138. },
  139. methods: {
  140. getGoodsList(ids) {
  141. request({
  142. params: {
  143. r: '/group-buy/default/check-active-list',
  144. active_id: JSON.stringify(ids)
  145. },
  146. method: 'get'
  147. }).then(res => {
  148. this.goodsList = res.data.data
  149. })
  150. }
  151. }
  152. });
  153. </script>
  154. <style>
  155. </style>