preview.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template id="bargain-goods-preview">
  2. <div class="bargain-goods-preview" :style="{background: computedStyle.bgColor}">
  3. <div :style="[bargainBox]">
  4. <div class="bargain-goods-title" :style="[titleStyle]" v-if="showTitle">{{ comData.title || '砍价商品' }}</div>
  5. <div class="bargain-goods-item" :style="[goodsStyle]" flex="cross:center" v-for="(item, index) in goodsList" :key="index">
  6. <div class="goods-img">
  7. <el-image style="width: 100%; height: 100%" :src="item.cover_pic"></el-image>
  8. </div>
  9. <div class="goods-content">
  10. <div class="goods-name over2">{{ item.goods_name }}</div>
  11. <div flex="main:justify cross:center">
  12. <div class="goods-price">
  13. <div class="goods-origin-price">¥{{ item.price }}</div>
  14. <div class="goods-min-price">最低¥<span class="price-text" :style="{ color: computedStyle.priceColor }">{{ item.min_price }}</span></div>
  15. </div>
  16. <div class="goods-btn" :style="[btnStyle]">{{ btnName }}</div>
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. /**
  25. * @descriptions
  26. * 1. 组件名字必须对应模板形式 - 递归组件name
  27. * 2. 样式内容方法尽量内部维护 - 前端方便通用
  28. * 3. 父级组件会传预览数据 - activeItem
  29. */
  30. Vue.component('bargain-goods-preview', {
  31. name: "bargain-goods-preview",
  32. props: {
  33. activeItem: {
  34. type: Object,
  35. default () {
  36. return {}
  37. }
  38. },
  39. btnName: {
  40. type: String,
  41. default: '立即参与'
  42. }
  43. },
  44. template: '#bargain-goods-preview',
  45. computed: {
  46. computedStyle() {
  47. console.log(this.activeItem, 'this.activeItem.computedStyle')
  48. return this.activeItem.computedStyle
  49. },
  50. comData() {
  51. return this.activeItem.data
  52. },
  53. showTitle() {
  54. return this.comData.titleRadio || 0
  55. },
  56. styleName() {
  57. var styleItem = this.activeItem.data.groupStyle || {}
  58. var name = {
  59. 1: "bargain-goods-style1",
  60. 2: "bargain-goods-style2",
  61. 3: "bargain-goods-style3"
  62. }
  63. var index = styleItem.type || 1
  64. return name[index]
  65. },
  66. titleStyle() {
  67. let {
  68. paddingTop,
  69. paddingBottom
  70. } = this.comData
  71. let style = {
  72. 'padding-top': paddingTop >= 0 ? `${paddingTop}px` : '10px',
  73. 'padding-bottom': paddingBottom >= 0 ? `${paddingBottom}px` : '10px'
  74. }
  75. return style
  76. },
  77. bargainBox() {
  78. let {
  79. marginTop,
  80. marginBottom,
  81. aroundMargin
  82. } = this.computedStyle
  83. return {
  84. margin: `${marginTop} ${aroundMargin} ${marginBottom}`,
  85. overflow: 'hidden'
  86. }
  87. },
  88. goodsStyle() {
  89. let {
  90. tabItem,
  91. searchIpts
  92. } = this.computedStyle
  93. let style = {
  94. 'margin-top': this.computedStyle.spacing,
  95. ...searchIpts
  96. }
  97. if (tabItem && tabItem.value == 'border') style.border = '1px solid ' + (tabItem ? tabItem.color : 'transparent')
  98. if (tabItem && tabItem.value == 'shandow') style.boxShadow = tabItem ? '0 0 10px ' + tabItem.color : '0 0 10px rgba(226, 231, 244, 0.7)'
  99. return style
  100. },
  101. btnStyle() {
  102. return {
  103. color: this.computedStyle.btnTextColor,
  104. background: this.computedStyle.btnBackground
  105. }
  106. },
  107. },
  108. watch: {
  109. "activeItem.data.goods": {
  110. handler(newVal, oldVal) {
  111. if (newVal && !deepEqual(newVal, oldVal)) {
  112. const ids = newVal.map(item => {
  113. return item.params.id
  114. })
  115. console.log(ids)
  116. this.getGoodsList(ids)
  117. }
  118. },
  119. immediate: true
  120. },
  121. goodsList: {
  122. handler(val) {
  123. if (val.length == 0) {
  124. this.goodsList = this.defaultList
  125. }
  126. },
  127. immediate: true
  128. }
  129. },
  130. data() {
  131. return {
  132. defaultList: [{
  133. cover_pic: "/resources/img/decorate/default_picture.png",
  134. end_at: 1640880000,
  135. goods_id: 0,
  136. goods_name: "商品名称",
  137. group_buy_price: 100,
  138. group_size: 3,
  139. group_status: 1,
  140. id: 22,
  141. price: 300,
  142. sheng: 200,
  143. start_at: 1639238400,
  144. total_num: 14
  145. }],
  146. goodsList: []
  147. }
  148. },
  149. methods: {
  150. getGoodsList(ids) {
  151. request({
  152. params: {
  153. r: '/bargain/default/check-active-list',
  154. active_id: JSON.stringify(ids)
  155. },
  156. method: 'get'
  157. }).then(res => {
  158. this.goodsList = res.data.data
  159. })
  160. }
  161. }
  162. });
  163. </script>
  164. <style>
  165. .bargain-goods-preview {
  166. position: relative;
  167. overflow: hidden;
  168. }
  169. .bargain-goods-title {
  170. text-align: center;
  171. font-size: 16px;
  172. color: #0D0C0C;
  173. font-weight: 700;
  174. }
  175. .bargain-goods-item {
  176. padding: 10px;
  177. background-color: #fff;
  178. }
  179. .bargain-goods-item .goods-img {
  180. width: 80px;
  181. height: 80px;
  182. border-radius: 10px;
  183. overflow: hidden;
  184. }
  185. .bargain-goods-item .goods-content {
  186. flex: 1;
  187. margin-left: 8px;
  188. }
  189. .bargain-goods-item .goods-content .goods-name {
  190. font-size: 13px;
  191. font-weight: 500;
  192. color: #000;
  193. margin-bottom: 5px;
  194. }
  195. .goods-origin-price {
  196. font-size: 13px;
  197. text-decoration: line-through;
  198. color: #999;
  199. }
  200. .goods-min-price {
  201. font-size: 13px;
  202. font-weight: 500;
  203. color: #666;
  204. }
  205. .goods-min-price .price-text {
  206. font-size: 16px;
  207. font-weight: 700;
  208. color: #e12c2e;
  209. }
  210. .goods-btn {
  211. width: 80px;
  212. height: 25px;
  213. line-height: 25px;
  214. font-size: 13px;
  215. font-weight: 500;
  216. color: #fff;
  217. background-color: #db0505;
  218. border-radius: 14px;
  219. text-align: center;
  220. }
  221. </style>