style1.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. <template id="presale-goods-style1">
  2. <div class="presale-goods-style" :style="{background: bgColor}">
  3. <div class="flex-wrap" :style="{flexWrap: flexWrap}" style="margin:10px;">
  4. <div :class="[styleTypeClassArr, zoomComputed(i)]" v-for="(it, i) in goodsList" :key="i">
  5. <div class="diy-goods-basic" :style="[goodsStyle,groupBox,{background: goodsBgColor}]">
  6. <div class="diy-goods-image">
  7. <div :class="hotClass" v-if="isShowHot" :style="hotStyle">{{hotName}}</div>
  8. <el-image :src="it.cover_pic ? it.cover_pic : default_src"></el-image>
  9. </div>
  10. <div class="detail">
  11. <div class="name" :style="{color: permession.goodsName.color }" v-if="permession.goodsName.show">
  12. {{ it.goods_name }}
  13. </div>
  14. <div class="diy-sale-new">
  15. <div class="diy-info">
  16. <div class="diy-price">
  17. <span class="new-diy-original-price-first" :style="{color: permession.totalNum.color }" v-if="permession.totalNum.show">
  18. {{ it.total_num }}人付款
  19. </span>
  20. <span class="diy-sale-price" :style="{color: permession.price.color }" v-if="permession.price.show">
  21. &nbsp;&nbsp;&nbsp;¥{{ it.presale_price }}
  22. </span>
  23. <span class="new-diy-original-price" :style="{color: permession.presalePrice.color }" v-if="permession.presalePrice.show">
  24. 商品售价:¥{{ it.price }}
  25. </span>
  26. </div>
  27. </div>
  28. <div v-if="isShowGoodsBuy" class="goods-buy" :style="goodsBuyStyle">
  29. <span v-if="!goodsBuySrc">{{goodsBuyText}}</span>
  30. <img :src="goodsBuySrc" v-else>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. /**
  41. * @descriptions
  42. * 1. 组件名字必须对应模板形式 - 递归组件name
  43. * 2. 样式内容方法尽量内部维护 - 前端方便通用
  44. * 3. 父级组件会传预览数据 - activeItem
  45. */
  46. Vue.component('presale-goods-style1', {
  47. name: "presale-goods-style1",
  48. props: {
  49. activeItem: {
  50. type: Object,
  51. default () {
  52. return {}
  53. }
  54. },
  55. goodsList: { // 商品列表
  56. type: Array,
  57. default: () => []
  58. },
  59. showTitle: { // 是否展示标题
  60. type: Number,
  61. default: 0
  62. },
  63. title: { // 标题
  64. type: String,
  65. default: ''
  66. },
  67. titleStyle: { // 标题的样式
  68. type: Object,
  69. default: () => {}
  70. },
  71. groupBox: { // 最外层样式
  72. type: Object,
  73. default: () => {}
  74. },
  75. goodsStyle: { // 商品的样式
  76. type: Object,
  77. default: () => {}
  78. },
  79. btnStyle: { // 按钮的样式
  80. type: Object,
  81. default: () => {}
  82. },
  83. bgColor: {
  84. type: String,
  85. default: ''
  86. },
  87. goodsBgColor: {
  88. type: String,
  89. default: ''
  90. }
  91. },
  92. watch: {
  93. "activeItem.data": {
  94. handler(newVal, oldVal) {
  95. if (!newVal) {
  96. return false
  97. }
  98. var newCommCate = newVal && newVal.commCate
  99. var oldCommCate = oldVal && oldVal.commCate
  100. if (newVal.chooseGoods == 2 && newCommCate) {
  101. this.defaultList = new Array(newCommCate.count).fill({})
  102. } else {
  103. this.defaultList = [{}]
  104. }
  105. },
  106. immediate: true
  107. }
  108. },
  109. template: '#presale-goods-style1',
  110. data() {
  111. return {
  112. defaultList: [],
  113. }
  114. },
  115. computed: {
  116. hotStyle() {
  117. var angleMark = this.activeItem.data.angleMark || null
  118. if (angleMark.label == 3 && angleMark.customImgUrl) {
  119. return {
  120. width: "76px",
  121. height: "76px",
  122. background: `url(${angleMark.customImgUrl}) no-repeat`,
  123. backgroundSize: "76px"
  124. }
  125. }
  126. return {}
  127. },
  128. // 角标
  129. isShowHot() {
  130. var angleMark = this.activeItem.data.angleMark || null
  131. return angleMark && angleMark.label != 1
  132. },
  133. default_src() { // 默认图片
  134. var type = this.activeItem.data.style || 1
  135. return type == 1 ? 'resources/img/decorate/default_img.png' : 'resources/img/decorate/default_picture.png'
  136. },
  137. hotClass() {
  138. var angleMark = this.activeItem.data.angleMark || null
  139. var obj = ["diy-goods-hot"]
  140. if (angleMark) {
  141. var name = ["", "diy-goods-hot3", "diy-goods-hot2", "diy-goods-hot1"]
  142. if (angleMark.label == 2 && angleMark.angleMarkStyle) {
  143. var key = name[angleMark.angleMarkStyle.label]
  144. obj.push(key)
  145. }
  146. }
  147. return obj
  148. },
  149. hotName() {
  150. var angleMark = this.activeItem.data.angleMark || null
  151. if (angleMark && !angleMark.angleMarkText && angleMark.label == 2) {
  152. return "预售"
  153. }
  154. return angleMark.angleMarkText
  155. },
  156. // 购物车
  157. isShowGoodsBuy() { // 是否显示购物车按钮
  158. var showShopCart = this.activeItem.data.showShopCart
  159. var type = this.activeItem.data.style || 1
  160. if (type == 6) {
  161. return false
  162. }
  163. return !(showShopCart == 2)
  164. },
  165. goodsBuyText() {
  166. var shopCartStyle = this.activeItem.data.shopCartStyle || {}
  167. if (shopCartStyle.label == 2) {
  168. return '+'
  169. } else if (shopCartStyle.label == 3 || shopCartStyle.label == 4) {
  170. return ""
  171. }
  172. return shopCartStyle.text || "付定金"
  173. },
  174. goodsBuyStyle() {
  175. var shopCartStyle = this.activeItem.computedStyle.shopCartStyle || {}
  176. var shopCartData = this.activeItem.data.shopCartStyle || {}
  177. // 类型1尺寸
  178. var size = ["", "3px 7px", "6px 10px", "10px 16px"]
  179. var small = size[shopCartStyle.sizeType] || size[1]
  180. // 类型2/3/4尺寸
  181. var size1 = ["", "22px", "28px", " 36px"]
  182. var small1 = size1[shopCartStyle.sizeType] || size1[1]
  183. var imgUrl = shopCartData.src
  184. // 1 2 3 4
  185. var handleList = [{}, {
  186. borderRadius: `${shopCartStyle.borderReduis || 0}px`,
  187. backgroundColor: `${shopCartStyle.backgroundColor || '#fd463e'}`,
  188. color: `${shopCartStyle.color || '#fff'}`,
  189. border: `1px solid ${shopCartStyle.borderColor}`,
  190. padding: small
  191. }, {
  192. borderRadius: `50%`,
  193. backgroundColor: `${shopCartStyle.backgroundColor || '#fd463e'}`,
  194. color: `${shopCartStyle.color || '#fff'}`,
  195. border: `1px solid ${shopCartStyle.borderColor}`,
  196. width: small1,
  197. height: small1,
  198. lineHeight: small1
  199. }, ]
  200. if (shopCartData.label == 3 || shopCartData.label == 4) {
  201. return {
  202. width: small1,
  203. height: small1,
  204. lineHeight: small1
  205. }
  206. }
  207. var result = handleList[shopCartData.label || 1]
  208. return result
  209. },
  210. styleTypeClassArr() {
  211. var type = this.activeItem.data.style || 2
  212. var contentClass = []
  213. var result = {
  214. 1: 'diy-goods-contain-full',
  215. 2: 'diy-goods-contain',
  216. 3: 'diy-goods-contain1',
  217. 4: 'diy-goods-contain2',
  218. 5: 'diy-goods-contain3',
  219. 6: 'diy-goods-contain4',
  220. 7: 'diy-goods-contain5'
  221. }
  222. return contentClass.concat(result[type])
  223. },
  224. contianStyle() {
  225. var style = this.filterKey(this.computedStyle.searchIpts, ["margin"])
  226. if (!style.margin) {
  227. style.margin = "10px"
  228. }
  229. return style
  230. },
  231. flexWrap() {
  232. let acceptArr = [6, 7]
  233. return acceptArr.indexOf(this.activeItem.data.style) != -1 ? 'nowrap' : ''
  234. },
  235. goodsBuySrc() {
  236. var shopCartData = this.activeItem.data.shopCartStyle || {}
  237. var imgUrl = shopCartData.src
  238. if (shopCartData.label == 3 || shopCartData.label == 4) {
  239. return imgUrl
  240. }
  241. return ""
  242. },
  243. // 权限列表
  244. permession() {
  245. var obj = {
  246. goodsName: {
  247. show: true,
  248. color: ""
  249. },
  250. totalNum: {
  251. show: true,
  252. color: ""
  253. },
  254. price: {
  255. show: true,
  256. color: ""
  257. },
  258. presalePrice: {
  259. show: true,
  260. color: ""
  261. }
  262. }
  263. var data = this.activeItem.data.showContent || []
  264. var style = this.activeItem.data.style
  265. if (data.length) {
  266. for (const key in obj) {
  267. obj[key].show = false
  268. }
  269. }
  270. data.map(item => {
  271. var keyObj = {
  272. 1: {
  273. key: 'goodsName',
  274. // filter: [1, 2, 3, 4, 5, 6, 7], // style支持的权限标识
  275. filter: [1, 2, 3, 4, 5, 6, 7], // style支持的权限标识
  276. },
  277. 5: {
  278. key: 'totalNum',
  279. // filter: [1, 2],
  280. filter: [1, 2, 3, 4, 5, 6, 7],
  281. },
  282. 3: {
  283. key: 'price',
  284. // filter: [1, 2, 3, 4, 5, 6, 7],
  285. filter: [1, 2, 3, 4, 5, 6, 7],
  286. },
  287. 4: {
  288. key: 'presalePrice',
  289. // filter: [1, 2, 3],
  290. filter: [1, 2, 3, 4, 5, 6, 7],
  291. }
  292. }
  293. var target = keyObj[item.label]
  294. // 存在选中 - 继续style判断是否支持
  295. if (style) {
  296. if (target.filter.indexOf(style) != -1) {
  297. obj[target.key].show = true
  298. obj[target.key].color = item.color
  299. }
  300. }
  301. })
  302. return obj
  303. }
  304. },
  305. methods: {
  306. zoomComputed(index) {
  307. const type = this.activeItem.data.style
  308. if (type == 6) {
  309. if (index % 2 == 0) {
  310. return "zoom"
  311. }
  312. }
  313. return ""
  314. },
  315. }
  316. });
  317. </script>
  318. <style>
  319. .presale-goods-style {
  320. box-sizing: border-box;
  321. overflow: hidden;
  322. }
  323. /* .commodity-group-preview {
  324. box-sizing: border-box;
  325. overflow: hidden;
  326. } */
  327. .presale-goods-title {
  328. text-align: center;
  329. font-size: 16px;
  330. color: #0D0C0C;
  331. font-weight: 700;
  332. }
  333. .presale-goods-box {
  334. position: relative;
  335. background-color: #fff;
  336. border-radius: 8px;
  337. overflow: hidden;
  338. padding: 10px;
  339. }
  340. .group-content {
  341. flex: 1;
  342. padding-left: 8px;
  343. }
  344. .goods-tags {
  345. display: inline-block;
  346. padding: 2px 1px 2px 8px;
  347. font-size: 11px;
  348. background-color: #FFF2F2;
  349. margin: 4px 0px;
  350. border-radius: 16px;
  351. color: #DB0505;
  352. }
  353. .tags-text {
  354. background-color: #fff;
  355. padding: 1px 5px;
  356. border-radius: 0 16px 16px 0;
  357. }
  358. .goods-save {
  359. position: relative;
  360. display: inline-block;
  361. padding: 2px 8px;
  362. font-size: 11px;
  363. color: #F69E19;
  364. background-color: #FEF4E4;
  365. border-radius: 16px;
  366. }
  367. .goods-save .trnaglre {
  368. position: absolute;
  369. bottom: -13px;
  370. left: 10px;
  371. width: 0px;
  372. height: 0px;
  373. border-top: 8px solid #FEF4E4;
  374. border-left: 8px solid transparent;
  375. border-right: 8px solid transparent;
  376. border-bottom: 8px solid transparent;
  377. border-radius: 2px;
  378. }
  379. .goods-price {
  380. padding-top: 2px;
  381. font-size: 16px;
  382. color: #DB0505;
  383. }
  384. .price-origin {
  385. font-size: 11px;
  386. color: #707070;
  387. }
  388. .group-btn {
  389. position: absolute;
  390. bottom: 12px;
  391. right: 12px;
  392. width: 80px;
  393. height: 32px;
  394. background: #DB0505;
  395. border-radius: 33px;
  396. font-size: 13px;
  397. color: #fff;
  398. }
  399. .diy-goods-image {
  400. position: relative;
  401. }
  402. /* 角标 */
  403. .diy-goods-hot {
  404. position: absolute;
  405. top: 20;
  406. left: 20;
  407. transform: scale(.5);
  408. transform-origin: top left;
  409. color: #fff;
  410. font-size: 22px;
  411. z-index: 99;
  412. }
  413. .diy-goods-hot1 {
  414. width: 64px;
  415. height: 44px;
  416. line-height: 44px;
  417. padding-left: 4px;
  418. background: url("resources/img/decorate/commodity-group/common_label2_3.png") no-repeat;
  419. }
  420. .diy-goods-hot2 {
  421. width: 52px;
  422. height: 56px;
  423. line-height: 44px;
  424. text-align: center;
  425. background: url("resources/img/decorate/commodity-group/common_label2_2.png") no-repeat;
  426. background-size: 52px 56px;
  427. }
  428. .diy-goods-hot3 {
  429. top: 20;
  430. width: 60px;
  431. height: 60px;
  432. line-height: 50px;
  433. background-size: 60px;
  434. padding-left: 4px;
  435. background: url("resources/img/decorate/commodity-group/common_label2.png") no-repeat;
  436. }
  437. .goods-buy {
  438. box-sizing: border-box;
  439. display: inline-block;
  440. text-align: center;
  441. align-self: flex-end;
  442. }
  443. .goods-buy img {
  444. width: 100%;
  445. height: 100%;
  446. display: block;
  447. }
  448. /* 样式1 */
  449. .diy-goods-contain-full {
  450. width: 100%;
  451. margin: 0;
  452. }
  453. .diy-goods-contain-full .detail .name {
  454. height: 20px;
  455. max-height: 20px;
  456. margin-bottom: 4px;
  457. }
  458. /* 样式2 */
  459. .diy-goods-contain {
  460. width: 100%;
  461. }
  462. .diy-goods-contain .detail .name {
  463. height: 20px;
  464. max-height: 20px;
  465. margin-bottom: 4px;
  466. }
  467. .diy-goods-contain .diy-goods-image {
  468. float: left;
  469. width: 130px;
  470. height: 130px;
  471. }
  472. .diy-goods-contain .detail {
  473. /* margin-left: 130px; */
  474. height: 130px;
  475. padding: 10px;
  476. }
  477. .diy-goods-contain .new-diy-original-price {
  478. display: block;
  479. padding-top: 13px;
  480. }
  481. .diy-goods-contain .new-diy-original-price-first {
  482. display: block;
  483. padding-bottom: 13px;
  484. }
  485. .diy-goods-image .el-image {
  486. display: block;
  487. width: 100%;
  488. height: 100%;
  489. }
  490. /* 样式3 */
  491. .diy-goods-contain1 {
  492. width: 50%;
  493. }
  494. .diy-goods-contain1 .new-diy-original-price {
  495. display: block;
  496. padding-top: 13px;
  497. }
  498. .diy-goods-contain1 .new-diy-original-price-first {
  499. display: block;
  500. padding-bottom: 13px;
  501. }
  502. .diy-goods-contain1 .subtitle {
  503. display: none;
  504. }
  505. /* .diy-goods-contain1 .diy-sale {
  506. margin-top: 16px;
  507. } */
  508. /* 样式4 */
  509. .diy-goods-contain2 {
  510. width: 50%;
  511. }
  512. .diy-goods-contain2 .diy-goods-image {
  513. float: left;
  514. width: 80px;
  515. height: 80px;
  516. }
  517. .diy-goods-contain2 .detail {
  518. margin-left: 80px;
  519. padding: 4px;
  520. height: 80px;
  521. }
  522. .diy-goods-contain2 .detail .goods-buy {
  523. display: none;
  524. }
  525. .diy-goods-contain2 .detail .subtitle {
  526. display: none;
  527. }
  528. .diy-goods-contain2 .detail .diy-sold {
  529. display: none;
  530. }
  531. .diy-goods-contain2 .detail .new-diy-original-price {
  532. display: none;
  533. }
  534. /* 样式5 */
  535. .diy-goods-contain3 {
  536. width: 33.33%;
  537. }
  538. .diy-goods-contain3 .el-image__error {
  539. min-height: 100px;
  540. }
  541. .diy-goods-contain3 .detail .subtitle {
  542. display: none;
  543. }
  544. .diy-goods-contain3 .detail .goods-buy {
  545. display: none;
  546. }
  547. .diy-goods-contain3 .detail .diy-sold {
  548. display: none;
  549. }
  550. .diy-goods-contain3 .detail .new-diy-original-price {
  551. display: none;
  552. }
  553. /* 样式6 */
  554. .diy-goods-contain4 {
  555. width: 33.33%;
  556. flex: 0 0 33.33%;
  557. }
  558. /* 样式7 */
  559. .diy-goods-contain5 {
  560. width: 30%;
  561. flex: 0 0 30%;
  562. }
  563. .diy-goods-contain5 .name {
  564. height: 36px;
  565. }
  566. .diy-goods-contain5 .el-image__error {
  567. min-height: 100px;
  568. }
  569. .diy-goods-contain5 .detail .subtitle {
  570. display: none;
  571. }
  572. .diy-goods-contain5 .detail .diy-sold {
  573. display: none;
  574. }
  575. .diy-goods-contain5 .detail .new-diy-original-price {
  576. display: none;
  577. }
  578. /* 购物车按钮 */
  579. .diy-sale-new {
  580. box-sizing: border-box;
  581. width: 100%;
  582. display: flex;
  583. align-items: flex-end;
  584. height: 94px;
  585. }
  586. .diy-sale-new .diy-info {
  587. flex: 1;
  588. height: 80px;
  589. }
  590. .diy-info .diy-price {
  591. display: flex;
  592. flex-direction: column;
  593. }
  594. .flex-wrap {
  595. display: flex;
  596. flex-wrap: wrap;
  597. }
  598. .detail {
  599. display: flex;
  600. flex-wrap: wrap;
  601. padding: 8px 6px;
  602. }
  603. .detail .name {
  604. font-size: 14px;
  605. line-height: 18px;
  606. /* height: 36px; */
  607. margin-bottom: 4px;
  608. overflow: hidden;
  609. text-overflow: ellipsis;
  610. display: -webkit-box;
  611. -webkit-box-orient: vertical;
  612. -webkit-line-clamp: 2;
  613. }
  614. .detail .subtitle {
  615. font-size: 12px;
  616. height: 16px;
  617. line-height: 16px;
  618. width: 100%;
  619. color: #999ca7;
  620. margin-bottom: 4px;
  621. overflow: hidden;
  622. word-break: break-all;
  623. text-overflow: ellipsis;
  624. }
  625. /* 基础样式 */
  626. .diy-goods-basic {
  627. margin: 0 4px 4px 0;
  628. overflow: hidden;
  629. }
  630. .diy-goods-contain-full .diy-goods-basic,
  631. .diy-goods-contain .diy-goods-basic {
  632. margin: 0 0 6px 0;
  633. }
  634. /* 图片自适应 */
  635. .img-contain {
  636. padding-top: 100%;
  637. position: relative
  638. }
  639. .img-contain .test-img {
  640. position: absolute;
  641. top: 0;
  642. bottom: 0;
  643. left: 0;
  644. right: 0;
  645. }
  646. </style>