preview.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template id="best-sellers-preview">
  2. <div class="best-sellers-preview">
  3. <div class="sellers-box" :style="[bestSellerBox]">
  4. <div class="sellers-title" v-if="bestSellerData.titleRadio" :style="[titleStyle]">
  5. <div >{{ bestSellerData.title || '全城热卖' }}</div>
  6. <div class="best-more">
  7. 更多
  8. <i class="el-icon-arrow-right"></i>
  9. </div>
  10. </div>
  11. <div class="shop-box" :style="[goodsStyle]">
  12. <!-- -->
  13. <div class="shop-list" v-for="(it, i) in (goodsList.length > 0 ? goodsList : defaultList)" :key="i" @tap="navToGroup(it)">
  14. <div class="shop-image">
  15. <el-image style="width: 100%;height: 100%;" :src="it.cover_pic" draggable="false">></el-image>
  16. </div>
  17. <div class="shop-name over2">
  18. {{it.goods_name}}
  19. </div>
  20. <div class="shop-price">
  21. ¥{{it.price}}
  22. </div>
  23. <div class="shop-disarea">
  24. <span>
  25. 已抵扣{{it.discount}}元
  26. </span>
  27. </div>
  28. <div class="shop-sales">
  29. <div class="origin-price">¥{{it.original_price}}</div>
  30. <div>销量:{{it.sales_num}}</div>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. /**
  39. * @descriptions
  40. * 1. 组件名字必须对应模板形式 - 递归组件name
  41. * 2. 样式内容方法尽量内部维护 - 前端方便通用
  42. * 3. 父级组件会传预览数据 - activeItem
  43. */
  44. Vue.component('best-sellers-preview', {
  45. name: "best-sellers-preview",
  46. props: {
  47. activeItem: {
  48. type: Object,
  49. default () {
  50. return {}
  51. }
  52. }
  53. },
  54. template: '#best-sellers-preview',
  55. computed: {
  56. computedStyle() {
  57. return this.activeItem.computedStyle
  58. },
  59. bestSellerData() {
  60. console.log('标题装修数据',this.activeItem.data)
  61. return this.activeItem.data
  62. },
  63. titleStyle() {
  64. let {
  65. paddingTop,
  66. paddingBottom
  67. } = this.bestSellerData
  68. let style = {
  69. 'padding-top': paddingTop >= 0 ? `${paddingTop}px` : '10px',
  70. 'padding-bottom': paddingBottom >= 0 ? `${paddingBottom}px` : '10px'
  71. }
  72. return style
  73. },
  74. goodsStyle() {
  75. let {
  76. tabItem,
  77. searchIpts,
  78. goodsBg
  79. } = this.computedStyle
  80. let style = {
  81. 'margin-bottom': this.computedStyle.spacing,
  82. background: goodsBg,
  83. ...searchIpts
  84. }
  85. if (tabItem && tabItem.value == 'border') style.border = '1px solid ' + (tabItem ? tabItem.color : 'transparent')
  86. if (tabItem && tabItem.value == 'shandow') style.boxShadow = tabItem ? '0 0 10px ' + tabItem.color : '0 0 10px rgba(226, 231, 244, 0.7)'
  87. return style
  88. },
  89. bestSellerBox() {
  90. let {
  91. marginTop,
  92. marginBottom,
  93. aroundMargin,
  94. boxBg
  95. } = this.computedStyle
  96. return {
  97. padding: `${marginTop} ${aroundMargin} ${marginBottom}`,
  98. background: boxBg
  99. }
  100. },
  101. },
  102. watch: {
  103. "activeItem.data.goods": {
  104. handler(newVal, oldVal) {
  105. if (newVal && !deepEqual(newVal, oldVal)) {
  106. const ids = newVal.map(item => {
  107. return item.params.id
  108. })
  109. this.getGoodsList(ids)
  110. }
  111. },
  112. immediate: true
  113. },
  114. goodsList: {
  115. handler(val) {
  116. if (val.length == 0) {
  117. this.goodsList = this.defaultList
  118. }
  119. },
  120. immediate: true
  121. }
  122. },
  123. data() {
  124. return {
  125. defaultList: [
  126. {
  127. cover_pic:'https://n.sinaimg.cn/sinacn10111/183/w640h343/20190410/27e2-hvntnkq0878753.bmp',
  128. goods_name:'【广东省东莞市.蛋糕】 198元起抢购麦莎蒂斯烘培套餐,口感细腻,造型精致,甜蜜好滋味!',
  129. original_price:30,
  130. discount:10,
  131. price:20,
  132. sales_num:66,
  133. },
  134. {
  135. cover_pic:'https://n.sinaimg.cn/sinacn10111/183/w640h343/20190410/27e2-hvntnkq0878753.bmp',
  136. goods_name:'【广东省东莞市.蛋糕】 198元起抢购麦莎蒂斯烘培套餐,口感细腻,造型精致,甜蜜好滋味!',
  137. original_price:30,
  138. discount:10,
  139. price:20,
  140. sales_num:66,
  141. },
  142. {
  143. cover_pic:'https://n.sinaimg.cn/sinacn10111/183/w640h343/20190410/27e2-hvntnkq0878753.bmp',
  144. goods_name:'【广东省东莞市.蛋糕】 198元起抢购麦莎蒂斯烘培套餐,口感细腻,造型精致,甜蜜好滋味!',
  145. original_price:30,
  146. discount:10,
  147. price:20,
  148. sales_num:66,
  149. },
  150. ],
  151. goodsList: []
  152. }
  153. },
  154. methods: {
  155. getGoodsList(ids) {
  156. request({
  157. params: {
  158. r: '/store/diy/good-list',
  159. good_ids:ids,
  160. },
  161. method: 'get'
  162. }).then(res => {
  163. this.goodsList = res.data.data
  164. })
  165. }
  166. }
  167. });
  168. </script>
  169. <style >
  170. .sellers-title{
  171. color:rgb(75,75,75);
  172. font-weight:700;
  173. padding-left:12px;
  174. display: flex;
  175. justify-content: space-between;
  176. font-size: 16px;
  177. }
  178. .shop-name{
  179. margin-top:10px;
  180. font-weight: 500 !important;
  181. }
  182. .shop-price{
  183. color: #eb3d30;
  184. font-size: 13px;
  185. margin-top: 10px;
  186. font-weight: 700;
  187. padding: 0 5px;
  188. }
  189. .shop-disarea{
  190. font-size: 12px;
  191. color: rgb(152,84,0);
  192. margin: 8px 5px;
  193. }
  194. .shop-disarea span{
  195. background: rgb(255,243,213);
  196. border-radius: 10px;
  197. padding: 2px 8px;
  198. }
  199. .shop-sales{
  200. display: flex;
  201. justify-content: space-between;
  202. color: #9d9d9d;
  203. padding: 0 5px;
  204. font-size: 12px;
  205. }
  206. .shop-sales .origin-price{
  207. text-decoration: line-through;
  208. }
  209. .best-more{
  210. padding-right: 12px;
  211. color: #aaaaaa;
  212. font-size: 13px;
  213. font-weight:500;
  214. }
  215. .best-sellers-preview {
  216. position: relative;
  217. overflow: hidden;
  218. }
  219. .shop-box {
  220. display: flex;
  221. position: relative;
  222. width: 100%;
  223. padding: 12px;
  224. box-sizing: border-box;
  225. background-color: #fff;
  226. overflow: scroll;
  227. }
  228. .shop-list{
  229. margin-right: 12px;
  230. position: relative;
  231. border-radius: 0 0 8px 8px;
  232. }
  233. .shop-image {
  234. width: 160px;
  235. height: 160px !important;
  236. border-radius: 8px 8px 0 0;
  237. }
  238. .shop-image img{
  239. border-radius: 8px 8px 0 0;
  240. }
  241. @-webkit-keyframes animate-positive {
  242. 0% {
  243. width: 0;
  244. }
  245. }
  246. @keyframes animate-positive {
  247. 0% {
  248. width: 0;
  249. }
  250. }
  251. </style>