preview.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <template id="store-commodity-classify-group-preview">
  2. <div class="store-commodity-classify-group-preview" :style="{background: computedStyle.searchBox }">
  3. <!-- 默认数据 -->
  4. <div class="flex-wrap" :style="{flexWrap: flexWrap}" v-if="showDefaultData">
  5. <div :class="[styleTypeClassArr, zoomComputed(index)]" v-for="(item,index) in defaultList" :key="index">
  6. <div class="diy-goods-basic" :style="goodsStyle">
  7. <div class="diy-goods-image">
  8. <el-image :src="item.cover_pic || default_src"></el-image>
  9. </div>
  10. <div class="goods-info">
  11. <div class="goods-name over2">'这是商品标题'</div>
  12. <div class="goods-price" flex>
  13. <div class="left" flex>
  14. <div class="price">
  15. <span class="size1">¥</span>
  16. <span class="size2">25</span>
  17. </div>
  18. <div class="origin-price">¥ 30</div>
  19. </div>
  20. <div class="store-address">56.975km</div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. <!-- 有数据 -->
  27. <div class="flex-wrap" :style="{flexWrap: flexWrap}" v-else>
  28. <div :class="[styleTypeClassArr, zoomComputed(index)]" v-for="(item,index) in goodsList" :key="index">
  29. <div class="diy-goods-basic" :style="goodsStyle">
  30. <div class="diy-goods-image">
  31. <el-image :src="item.cover_pic || default_src"></el-image>
  32. </div>
  33. <div class="goods-info">
  34. <div class="goods-name over2">{{item.goods_name }}</div>
  35. <div class="goods-price" flex>
  36. <div class="left" flex>
  37. <div class="price">
  38. <span class="size1">¥</span>
  39. <span class="size2">{{item.price}}</span>
  40. </div>
  41. <div class="origin-price">¥{{item.original_price }}</div>
  42. </div>
  43. <div class="store-address">56.975km</div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. Vue.component('store-commodity-classify-group-preview', {
  52. name: "store-commodity-classify-group-preview",
  53. props: {
  54. activeItem: {
  55. type: Object,
  56. default () {
  57. return {}
  58. }
  59. }
  60. },
  61. template: '#store-commodity-classify-group-preview',
  62. computed: {
  63. showDefaultData() {
  64. var boo = true
  65. if (this.activeItem.data.chooseGoods != 2) {
  66. boo = false
  67. if (!this.goodsList.length) {
  68. boo = true
  69. }
  70. }
  71. return boo
  72. },
  73. flexWrap() {
  74. let acceptArr = [6, 7]
  75. return acceptArr.indexOf(this.activeItem.data.style) != -1 ? 'nowrap' : ''
  76. },
  77. default_src() { // 默认图片
  78. var type = this.activeItem.data.style || 1
  79. return type == 1 ? 'resources/img/decorate/default_img.png' : 'resources/img/decorate/default_picture.png'
  80. },
  81. contianStyle() {
  82. var style = this.filterKey(this.computedStyle.searchIpts, ["margin"])
  83. if (!style.margin) {
  84. style.margin = "10px"
  85. }
  86. return style
  87. },
  88. goodsStyle() {
  89. let tabItem = this.computedStyle.tabItem
  90. let other = this.filterKey(this.computedStyle.searchIpts, ["border"])
  91. let style = {
  92. 'background': this.computedStyle.iptBg,
  93. ...other
  94. }
  95. if (tabItem && tabItem.value == 'border') style.border = '1px solid ' + (tabItem ? tabItem.color : 'transparent')
  96. if (tabItem && tabItem.value == 'shandow') style.boxShadow = tabItem ? '0 0 10px ' + tabItem.color : '0 0 10px rgba(226, 231, 244, 0.7)'
  97. return style
  98. },
  99. styleTypeClassArr() {
  100. var type = this.activeItem.data.style || 1
  101. var contentClass = []
  102. var result = {
  103. 1: 'diy-goods-contain-full',
  104. 2: 'diy-goods-contain',
  105. 3: 'diy-goods-contain1',
  106. 4: 'diy-goods-contain2',
  107. 5: 'diy-goods-contain3',
  108. 6: 'diy-goods-contain4',
  109. 7: 'diy-goods-contain5'
  110. }
  111. return contentClass.concat(result[type])
  112. },
  113. computedStyle() {
  114. return this.activeItem.computedStyle
  115. },
  116. searchData() {
  117. return this.activeItem.data
  118. },
  119. // 角标
  120. isShowHot() {
  121. var angleMark = this.activeItem.data.angleMark || null
  122. return angleMark && angleMark.label != 1
  123. },
  124. hotStyle() {
  125. var angleMark = this.activeItem.data.angleMark || null
  126. if (angleMark.label == 3 && angleMark.customImgUrl) {
  127. return {
  128. width: "76px",
  129. height: "76px",
  130. background: `url(${angleMark.customImgUrl}) no-repeat`,
  131. backgroundSize: "76px"
  132. }
  133. }
  134. return {}
  135. },
  136. hotClass() {
  137. var angleMark = this.activeItem.data.angleMark || null
  138. var obj = ["diy-goods-hot"]
  139. if (angleMark) {
  140. var name = ["", "diy-goods-hot3", "diy-goods-hot2", "diy-goods-hot1"]
  141. if (angleMark.label == 2 && angleMark.angleMarkStyle) {
  142. var key = name[angleMark.angleMarkStyle.label]
  143. obj.push(key)
  144. }
  145. }
  146. return obj
  147. },
  148. hotName() {
  149. var angleMark = this.activeItem.data.angleMark || null
  150. if (angleMark && !angleMark.angleMarkText && angleMark.label == 2) {
  151. return "热卖"
  152. }
  153. return angleMark.angleMarkText
  154. },
  155. // 购物车
  156. isShowGoodsBuy() { // 是否显示购物车按钮
  157. var showShopCart = this.activeItem.data.showShopCart
  158. var type = this.activeItem.data.style || 1
  159. if (type == 6) {
  160. return false
  161. }
  162. return !(showShopCart == 2)
  163. },
  164. goodsBuySrc() {
  165. var shopCartData = this.activeItem.data.shopCartStyle || {}
  166. var imgUrl = shopCartData.src
  167. if (shopCartData.label == 3 || shopCartData.label == 4) {
  168. return imgUrl
  169. }
  170. return ""
  171. },
  172. goodsBuyStyle() {
  173. var shopCartStyle = this.activeItem.computedStyle.shopCartStyle || {}
  174. var shopCartData = this.activeItem.data.shopCartStyle || {}
  175. // 类型1尺寸
  176. var size = ["", "3px 7px", "6px 10px", "10px 16px"]
  177. var small = size[shopCartStyle.sizeType] || size[1]
  178. // 类型2/3/4尺寸
  179. var size1 = ["", "22px", "28px", " 36px"]
  180. var small1 = size1[shopCartStyle.sizeType] || size1[1]
  181. var imgUrl = shopCartData.src
  182. // 1 2 3 4
  183. var handleList = [{}, {
  184. borderRadius: `${shopCartStyle.borderReduis || 0}px`,
  185. backgroundColor: `${shopCartStyle.backgroundColor || '#fd463e'}`,
  186. color: `${shopCartStyle.color || '#fff'}`,
  187. border: `1px solid ${shopCartStyle.borderColor}`,
  188. padding: small
  189. }, {
  190. borderRadius: `50%`,
  191. backgroundColor: `${shopCartStyle.backgroundColor || '#fd463e'}`,
  192. color: `${shopCartStyle.color || '#fff'}`,
  193. border: `1px solid ${shopCartStyle.borderColor}`,
  194. width: small1,
  195. height: small1,
  196. lineHeight: small1
  197. }, ]
  198. if (shopCartData.label == 3 || shopCartData.label == 4) {
  199. return {
  200. width: small1,
  201. height: small1,
  202. lineHeight: small1
  203. }
  204. }
  205. var result = handleList[shopCartData.label || 1]
  206. return result
  207. },
  208. goodsBuyText() {
  209. var shopCartStyle = this.activeItem.data.shopCartStyle || {}
  210. if (shopCartStyle.label == 2) {
  211. return '+'
  212. } else if (shopCartStyle.label == 3 || shopCartStyle.label == 4) {
  213. return ""
  214. }
  215. return shopCartStyle.text || "购买"
  216. },
  217. // 几种类型变化样式
  218. // 权限列表
  219. permession() {
  220. var obj = {
  221. showTitle: {
  222. show: true,
  223. color: ""
  224. },
  225. showSubTitle: {
  226. show: true,
  227. color: ""
  228. },
  229. goodsPrice: {
  230. show: true,
  231. color: ""
  232. },
  233. originalPrice: {
  234. show: true,
  235. color: ""
  236. },
  237. goodsSales_num: {
  238. show: true,
  239. color: ""
  240. },
  241. memberPrice: {
  242. // show: false,
  243. show: true,
  244. color: ""
  245. },
  246. }
  247. var data = this.activeItem.data.showContent || []
  248. var style = this.activeItem.data.style
  249. if (data.length) {
  250. for (const key in obj) {
  251. obj[key].show = false
  252. }
  253. }
  254. data.map(item => {
  255. var keyObj = {
  256. 1: {
  257. key: 'showTitle',
  258. filter: [1, 2, 3, 4, 5, 6, 7] // style支持的权限标识
  259. },
  260. 2: {
  261. key: 'showSubTitle',
  262. filter: [1, 2]
  263. },
  264. 3: {
  265. key: 'goodsPrice',
  266. filter: [1, 2, 3, 4, 5, 6, 7]
  267. },
  268. 4: {
  269. key: 'originalPrice',
  270. filter: [1, 2, 3]
  271. },
  272. 5: {
  273. key: 'goodsSales_num',
  274. filter: [1, 2, 3]
  275. },
  276. 6: {
  277. key: 'memberPrice',
  278. filter: [1, 2, 3]
  279. },
  280. }
  281. var target = keyObj[item.label]
  282. // 存在选中 - 继续style判断是否支持
  283. if (style) {
  284. if (target.filter.indexOf(style) != -1) {
  285. obj[target.key].show = true
  286. obj[target.key].color = item.color
  287. }
  288. }
  289. })
  290. return obj
  291. }
  292. },
  293. watch: {
  294. "activeItem.data.goods": {
  295. handler(newVal, oldVal) {
  296. if (newVal && !deepEqual(newVal, oldVal)) {
  297. const ids = newVal.map(item => {
  298. return item.params.id
  299. })
  300. this.getGoodsList(ids)
  301. }
  302. },
  303. immediate: true
  304. },
  305. 'activeItem.data': {
  306. handler(newVal, oldVal) {
  307. if (!newVal) {
  308. return false
  309. }
  310. var newCommCate = newVal && newVal.commCate
  311. var oldCommCate = oldVal && oldVal.commCate
  312. if (newVal.chooseGoods == 2 && newCommCate) {
  313. let { commCate } = newVal,count = 10;
  314. if(commCate){
  315. if(Array.isArray(commCate)){
  316. count = newVal.cateNum
  317. }else { //兼容原有逻辑
  318. count = newCommCate.count
  319. }
  320. }
  321. this.defaultList = new Array(count).fill({})
  322. console.log('this.defaultList11111',this.defaultList)
  323. } else {
  324. this.defaultList = [{}]
  325. }
  326. // 会抛出警告
  327. // if (newCommCate && newCommCate.count && (newCommCate.count == oldCommCate.count)) return false
  328. // if (newCommCate && newCommCate.count) {
  329. // this.defaultList = new Array(newCommCate.count).fill({})
  330. // } else {
  331. // this.defaultList = [{}]
  332. // }
  333. },
  334. immediate: true
  335. }
  336. },
  337. data() {
  338. return {
  339. defaultList: [
  340. {
  341. cover_pic:"https://shuzixiangdao.oss-cn-guangzhou.aliyuncs.com//images/2022/05/24/image_1653384878_YONsS7q4.png",
  342. goods_name:'【广东省东莞市-蛋糕】198元起抢购麦莎蒂斯烘焙套餐,口感细腻,造型精致,型精致',
  343. discount:2,
  344. original_price:30,
  345. price:28,
  346. sales_num:89
  347. }
  348. ],
  349. goodsList: [],
  350. goodsList1:[]
  351. }
  352. },
  353. methods: {
  354. getGoodsList(ids) {
  355. request({
  356. params: {
  357. r: '/store/diy/good-list',
  358. good_ids:ids,
  359. },
  360. method: 'get'
  361. }).then(res => {
  362. this.goodsList = res.data.data
  363. })
  364. },
  365. zoomComputed(index) {
  366. const type = this.activeItem.data.style
  367. if (type == 6) {
  368. if (index % 2 == 0) {
  369. return "zoom"
  370. }
  371. }
  372. return ""
  373. },
  374. showDetail(index) {
  375. const type = this.activeItem.data.style
  376. return !(type == 6 && index > 2)
  377. },
  378. filterKey(obj, keys) {
  379. var result = {}
  380. keys.forEach(key => {
  381. for (const k in obj) {
  382. if (k.indexOf(key) != -1) {
  383. result[k] = obj[k]
  384. }
  385. }
  386. })
  387. return result
  388. },
  389. }
  390. });
  391. </script>
  392. <style lang="scss" scoped>
  393. .store-commodity-classify-group-preview {
  394. .flex-wrap {
  395. display: flex;
  396. flex-wrap: wrap;
  397. overflow-y: auto;
  398. }
  399. .diy-goods-contain-full {
  400. width: 100%;
  401. margin: 0;
  402. border-radius: 10px;
  403. background-color: #FFF;
  404. padding: 12px;
  405. }
  406. .diy-goods-contain-full+.diy-goods-contain-full {
  407. margin-top: 9px;
  408. }
  409. .diy-goods-basic {
  410. display: flex;
  411. margin: 0;
  412. .diy-goods-image {
  413. position: relative;
  414. width: 80px;
  415. height: 80px;
  416. border-radius: 10px;
  417. overflow: hidden;
  418. }
  419. }
  420. .goods-info {
  421. display: flex;
  422. flex: 1;
  423. justify-content: space-between;
  424. flex-direction: column;
  425. padding-right: 0;
  426. padding-left: 12px;
  427. .goods-name {
  428. font-size: 14px;
  429. font-weight: bold;
  430. }
  431. .goods-price {
  432. padding: 0;
  433. display: flex;
  434. align-items: baseline;
  435. justify-content: space-between;
  436. color: #DB0505;
  437. .left {
  438. display: flex;
  439. align-items: baseline;
  440. }
  441. .price {
  442. font-weight: bold;
  443. }
  444. .size1 {
  445. font-size: 11px;
  446. }
  447. .size2 {
  448. font-size: 20px;
  449. }
  450. }
  451. .origin-price {
  452. text-decoration: line-through;
  453. color: #9a9a9a;
  454. font-size: 11px;
  455. padding-left: 6px;
  456. }
  457. .store-address {
  458. color: #a7a7a7;
  459. font-size: 11px;
  460. }
  461. }
  462. }
  463. </style>