preview.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <template id="store-cate-recommend-preview">
  2. <div class="store-cate-container">
  3. <!--搜索-->
  4. <div class="search-box" :style="{background: searchData.searchBox}" v-if="searchData && searchData.show && searchData.show == 1">
  5. <div class="search-ipt" flex="cross:center" :style="{...searchData.inputStyle}">
  6. <i class="el-icon-search search-icons" :style="{color: searchData.iconsStyle}"></i>
  7. <div class="placeholder" :style="{color: searchData.textStyle}">{{ searchData.name || '请输入关键字' }}</div>
  8. </div>
  9. </div>
  10. <div class="diy-store-cate-recommend" :style="{background: computedStyle.searchBox}">
  11. <div class="store-cate-recommend-boxs" :style="{...inputStyle}">
  12. <!-- 按钮位置 -->
  13. <div flex="cross:center" :class="'store-cate-recommend-' + pattern">
  14. <div class="btn-group-list"
  15. :class="'col-' + (btn_data.buttonData && btn_data.buttonData.single_line)"
  16. flex="dir:top main:center cross:center"
  17. v-for="(item, index) in (pattern == 'swiper' ? swiperList : iconList)" :key="index"
  18. >
  19. <div class="btn-group-image"
  20. flex="main:center cross:center"
  21. :style="{borderRadius: borderRadius}"
  22. v-if="btn_data.buttonData && btn_data.buttonData.style != 3"
  23. >
  24. <el-image style="width: 100%; height: 100%" :src="item.img || default_bg"></el-image>
  25. </div>
  26. <div class="btn-group-text"
  27. v-if="btn_data.buttonData && btn_data.buttonData.style != 2"
  28. :style="{color: computedStyle.textStyle}"
  29. >{{ item.btnText }}</div>
  30. <!-- <div class="btn-group-tags" -->
  31. <!-- v-if="is_show_tags && item.is_show_tag"-->
  32. <!-- :style="{background: item.tagsBgColor, color: item.tagsTextColor}"-->
  33. <!-- >{{ item.tags }}</div>-->
  34. </div>
  35. </div>
  36. <!-- 左右箭头 -->
  37. <!-- :class="{'showArrow': is_show_arrow}" -->
  38. <div class="swiper-arrow left" @click.stop="toggleHandle('left')" v-if="pattern == 'swiper'">
  39. <i class="el-icon-arrow-left"></i>
  40. </div>
  41. <div class="swiper-arrow right" @click.stop="toggleHandle('right')" v-if="pattern == 'swiper'">
  42. <i class="el-icon-arrow-right"></i>
  43. </div>
  44. <!-- 轮播点 -->
  45. <div class="swiper-dots" v-if="pattern == 'swiper'">
  46. <div class="dot-item" v-for="(it, i) in list" :class="i == current ? 'active' : ''" @click.stop="dotClick(i)"></div>
  47. </div>
  48. </div>
  49. <div style="height:5px;width:100%;" :style="{background: computedStyle.gapStyle}">
  50. </div>
  51. <store-recommend-list-preview :active-item="goods_item"></store-recommend-list-preview>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. /**
  57. * @descriptions
  58. * 1. 组件名字必须对应模板形式 - 递归组件name
  59. * 2. 样式内容方法尽量内部维护 - 前端方便通用
  60. * 3. 父级组件会传预览数据 - activeItem
  61. */
  62. Vue.component('store-cate-recommend-preview', {
  63. name: "store-cate-recommend-preview",
  64. props: {
  65. activeItem: {
  66. type: Object,
  67. default () {
  68. return {}
  69. }
  70. }
  71. },
  72. template: '#store-cate-recommend-preview',
  73. computed: {
  74. searchData(){
  75. // this.activeItem.data.
  76. // inputStyle:{
  77. // let tabItem = this.computedStyle.tabItem
  78. // let style = {
  79. // 'background': this.computedStyle.iptBg,
  80. // ...this.computedStyle.searchIpts
  81. // }
  82. // if (tabItem && tabItem.value == 'border') style.border = '1px solid ' + (tabItem ? tabItem.color : 'transparent')
  83. // if (tabItem && tabItem.value == 'shandow') style.boxShadow = tabItem ? '0 0 10px ' + tabItem.color : '0 0 10px rgba(226, 231, 244, 0.7)'
  84. // return style
  85. // }
  86. let data = {}
  87. return this.activeItem.data.searchStyle
  88. },
  89. btn_data() {
  90. return this.activeItem.data
  91. },
  92. computedStyle() {
  93. return this.activeItem.computedStyle
  94. },
  95. borderRadius() {
  96. let data = this.btn_data.buttonData.shape
  97. return data == 'square' ? '0px' : data == 'round' ? '8px' : '50%'
  98. },
  99. inputStyle() {
  100. let tabItem = this.computedStyle.tabItem
  101. let style = {
  102. 'background': this.computedStyle.iptBg,
  103. ...this.activeItem.computedStyle.searchIpts
  104. }
  105. if (tabItem && tabItem.value == 'border') style.border = '1px solid ' + (tabItem ? tabItem.color : 'transparent')
  106. if (tabItem && tabItem.value == 'shandow') style.boxShadow = tabItem ? '0 0 10px ' + tabItem.color : '0 0 10px rgba(226, 231, 244, 0.7)'
  107. return style
  108. },
  109. is_show_tags() {
  110. return this.btn_data.buttonData && (this.btn_data.buttonData.style != 3 && this.btn_data.buttonData.type == 1)
  111. },
  112. pattern() {
  113. return this.btn_data.buttonData && this.btn_data.buttonData.pattern
  114. },
  115. goods_item() {
  116. var initData = {
  117. computedStyle: {},
  118. data: {}
  119. }
  120. try {
  121. var index = this.activeItem.data.activeIndex || 0
  122. var item = this.activeItem.data.goodList[index]
  123. if (item) {
  124. return item
  125. } else {
  126. return initData
  127. }
  128. } catch (error) {
  129. return initData
  130. }
  131. },
  132. },
  133. watch: {
  134. activeItem: {
  135. deep:true,
  136. immediate: true,
  137. handler(val) {
  138. console.log('装修数据',val)
  139. let pattern = val.data.buttonData && val.data.buttonData.pattern
  140. this.iconList = val.data.iconList
  141. if (pattern == 'swiper') {
  142. this.toggleHandle()
  143. }
  144. }
  145. }
  146. },
  147. data() {
  148. return {
  149. default_bg: 'resources/img/decorate/default_picture.png',
  150. iconList: [],
  151. swiperList: [],
  152. current: 0,
  153. list: [],
  154. }
  155. },
  156. mounted() {
  157. },
  158. methods: {
  159. toggleHandle(name) {
  160. let n = this.current
  161. // 每页行数
  162. let line_num = this.btn_data.buttonData && this.btn_data.buttonData.line_num
  163. // 单行数量
  164. let single_line = this.btn_data.buttonData && this.btn_data.buttonData.single_line
  165. this.list = this.swiperHandle(line_num, single_line)
  166. let arr = []
  167. if (name == 'right' && n < this.list.length - 1) {
  168. n++
  169. } else if (name == 'left' && n > 0) {
  170. n--
  171. }
  172. this.current = n
  173. this.swiperList = this.iconList.slice(single_line * line_num * n, single_line* line_num * (n + 1))
  174. },
  175. dotClick(i) {
  176. this.current = i
  177. this.toggleHandle()
  178. },
  179. swiperHandle(line_num, single_line) {
  180. const arr = deepClone(this.iconList)
  181. let len = Math.ceil((arr && arr.length) / (line_num * single_line))
  182. let newArr = []
  183. for(var i = 0; i < len; i++) {
  184. newArr[i] = arr.splice(0, line_num * single_line)
  185. }
  186. return newArr
  187. },
  188. }
  189. });
  190. </script>
  191. <?php
  192. use common\helpers\ComponentHelper;
  193. use common\helpers\AddonHelper;
  194. ComponentHelper::loadComponentView('preview', AddonHelper::getAddonRootPath('Store') . 'backend/views/components/diy/store-recommend-list');
  195. ComponentHelper::loadComponentView('preview', AddonHelper::getAddonRootPath('Store') . 'backend/views/components/diy/store-search');
  196. ?>
  197. <style>
  198. .diy-store-cate-recommend {
  199. position: relative;
  200. overflow: hidden;
  201. }
  202. .store-cate-recommend-boxs {
  203. position: relative;
  204. padding: 4px 0;
  205. overflow: hidden;
  206. }
  207. .store-cate-recommend-scroll {
  208. overflow-x: auto;
  209. width: 100%;
  210. box-sizing: border-box;
  211. padding: 0 8px;
  212. }
  213. .store-cate-recommend-scroll::-webkit-scrollbar {
  214. height: 5px;
  215. }
  216. .store-cate-recommend-fixed {
  217. flex-wrap: wrap;
  218. }
  219. .store-cate-recommend-swiper {
  220. overflow: hidden;
  221. padding-bottom: 20px;
  222. flex-wrap: wrap;
  223. }
  224. .btn-group-list {
  225. position: relative;
  226. padding: 8px 0;
  227. flex-shrink: 0;
  228. }
  229. .btn-group-tags {
  230. position: absolute;
  231. top: -7px;
  232. left: 50%;
  233. width: 53px;
  234. height: 26px;
  235. transform: scale(.5);
  236. color: #fff;
  237. margin-left: -6px;
  238. background: #f83287;
  239. border-radius: 12px 12px 12px 0;
  240. border: 1px solid #fff;
  241. text-align: center;
  242. font-size: 14px;
  243. }
  244. .btn-group-image {
  245. width: 44px;
  246. height: 44px;
  247. background-size: cover;
  248. background-repeat: no-repeat;
  249. background-position: 50%;
  250. }
  251. .btn-group-text {
  252. font-size: 12px;
  253. margin-top: 4px;
  254. }
  255. .col-3 {
  256. width: 33.3%;
  257. }
  258. .col-4 {
  259. width: 25%;
  260. }
  261. .col-5 {
  262. width: 20%;
  263. }
  264. .btn-icon-type {
  265. font-size: 24px;
  266. color: #999;
  267. }
  268. /* 轮播图 */
  269. .swiper-arrow {
  270. position: absolute;
  271. width: 32px;
  272. height: 32px;
  273. border-radius: 50%;
  274. background: rgba(0,0,0,.4);
  275. top: 50%;
  276. z-index: 10;
  277. left: 10px;
  278. text-align: center;
  279. line-height: 32px;
  280. font-size: 20px;
  281. cursor: pointer;
  282. margin-top: -16px;
  283. color: #fff;
  284. display: none;
  285. }
  286. .store-cate-recommend-boxs:hover .swiper-arrow {
  287. display: block;
  288. }
  289. .swiper-arrow.right {
  290. left: auto;
  291. right: 10px;
  292. }
  293. .swiper-dots {
  294. position: absolute;
  295. left: 0;
  296. bottom: 0;
  297. right: 0;
  298. height: 30px;
  299. line-height: 30px;
  300. text-align: center;
  301. }
  302. .swiper-dots .dot-item {
  303. display: inline-block;
  304. width: 5px;
  305. height: 5px;
  306. border-radius: 50%;
  307. margin: 0 4px;
  308. background: rgba(0,0,0,.2);
  309. cursor: pointer;
  310. }
  311. .swiper-dots .dot-item.active {
  312. background: #000;
  313. }
  314. .store-cate-container .search-ipt{
  315. border-radius:10px;
  316. }
  317. </style>