preview.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template id="store-preview">
  2. <div class="store-preview" :style="containerStyle">
  3. <div class="store-preview__header" v-if="diyData.titleRadio" :style="headerStyle">
  4. <div class="store-preview__title">{{ diyData.title || '推荐商品' }}</div>
  5. <div class="store-preview__more">
  6. <div class="store-preview__more--text">
  7. 更多 >
  8. </div>
  9. </div>
  10. </div>
  11. <div class="store-preview__content hide-scrollbar" :style="contentStyle">
  12. <div class="store-preview__store-item" :style="storeItemStyle" v-for="(item, index) in goodsList" :key="index">
  13. <div class="store-preview__store-logo">
  14. <el-image style="width: 100%;height: 100%;" :src="item.logo_img" draggable="false" />
  15. </div>
  16. <div class="store-preview__store-name">
  17. {{item.store_name}}
  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('store-preview', {
  31. name: "store-preview",
  32. props: {
  33. activeItem: {
  34. type: Object,
  35. default () {
  36. return {}
  37. }
  38. }
  39. },
  40. template: '#store-preview',
  41. computed: {
  42. computedStyle() {
  43. return this.activeItem.computedStyle || {}
  44. },
  45. diyData() {
  46. console.log('store-preview 装修数据',this.activeItem.data)
  47. return this.activeItem.data || {}
  48. },
  49. // 容器内容动态样式
  50. containerStyle() {
  51. let {
  52. marginTop,
  53. marginBottom,
  54. aroundMargin,
  55. boxBg,
  56. searchIpts,
  57. tabItem
  58. } = this.computedStyle
  59. let style = {
  60. margin: `${marginTop} ${aroundMargin} ${marginBottom}`,
  61. background: boxBg,
  62. ...searchIpts
  63. }
  64. if (tabItem) {
  65. if (tabItem.value === 'border') {
  66. style.border = `1px solid ${tabItem.color || 'transparent'}`;
  67. }
  68. if (tabItem.value === 'shandow') {
  69. style.boxShadow = `0 0 10px ${tabItem.color || 'rgba(226, 231, 244, 0.7)'}`;
  70. }
  71. }
  72. return style
  73. },
  74. // 头部内容动态样式
  75. headerStyle() {
  76. const { paddingTop = 10, paddingBottom = 10 } = this.diyData;
  77. return {
  78. paddingTop: `${paddingTop}px`,
  79. paddingBottom: `${paddingBottom}px`
  80. };
  81. },
  82. // 内容动态样式
  83. contentStyle() {
  84. return {
  85. background: this.computedStyle.goodsBg
  86. }
  87. },
  88. // 内容项间距动态样式
  89. storeItemStyle() {
  90. return {
  91. marginRight: this.computedStyle.spacing || "12px"
  92. }
  93. }
  94. },
  95. watch: {
  96. "activeItem.data.goods": {
  97. handler(newVal, oldVal) {
  98. if (newVal && !deepEqual(newVal, oldVal)) {
  99. const ids = newVal.map(item => {
  100. return item.params.id
  101. })
  102. console.log("ids",ids)
  103. this.getGoodsList(ids)
  104. }
  105. },
  106. immediate: true
  107. },
  108. goodsList: {
  109. handler(val) {
  110. if (val.length == 0) {
  111. this.goodsList = this.defaultList
  112. }
  113. },
  114. immediate: true
  115. }
  116. },
  117. data() {
  118. return {
  119. defaultList: [{
  120. logo_img:'',
  121. store_name:'商店名称'
  122. }],
  123. goodsList: []
  124. }
  125. },
  126. methods: {
  127. getGoodsList(ids) {
  128. request({
  129. params: {
  130. r: '/store/diy/store-list',
  131. store_ids:ids,
  132. },
  133. method: 'get'
  134. }).then(res => {
  135. this.goodsList = res.data.data
  136. })
  137. }
  138. }
  139. });
  140. </script>
  141. <style>
  142. .store-preview {
  143. position: relative;
  144. overflow: hidden;
  145. padding: 16px;
  146. }
  147. .store-preview__header{
  148. display: flex;
  149. align-items: center;
  150. justify-content: space-between;
  151. padding-bottom: 12px;
  152. }
  153. .store-preview__title{
  154. font-size: 14px;
  155. font-weight: 800;
  156. color: #333333;
  157. }
  158. .store-preview__more{
  159. font-size: 12px;
  160. font-weight: 400;
  161. color: #666666;
  162. }
  163. .store-preview__content{
  164. display: flex;
  165. width: 100%;
  166. background-color: #fff;
  167. overflow-x: auto;
  168. }
  169. .store-preview__store-item{
  170. display: flex;
  171. flex-direction: column;
  172. justify-content: center;
  173. align-items: center;
  174. width: 80px;
  175. margin-right: 12px;
  176. }
  177. .store-preview__store-logo{
  178. width: 80px;
  179. height: 80px;
  180. border-radius: 10px;
  181. overflow: hidden;
  182. }
  183. .store-preview__store-name{
  184. margin-top: 6px;
  185. font-weight: bold;
  186. font-size: 12px;
  187. color: #333333;
  188. text-align: center;
  189. /* 单行溢出显示省略号 */
  190. overflow: hidden;
  191. text-overflow: ellipsis;
  192. white-space: nowrap;
  193. display: block;
  194. width: 100%;
  195. }
  196. .hide-scrollbar {
  197. overflow: -moz-scrollbars-none;
  198. -ms-overflow-style: none;
  199. scrollbar-width: none; /* Firefox */
  200. }
  201. .hide-scrollbar::-webkit-scrollbar {
  202. display: none; /* Safari 和 Chrome */
  203. }
  204. </style>