preview.php 5.2 KB

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