preview.php 4.8 KB

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