ProductLeft.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <div class="product-left">
  3. <div class="media">
  4. <div
  5. class="big"
  6. v-show="bigShow">
  7. <img
  8. :src="
  9. $utils.generateResizedImageUrl(
  10. comInfo.mergeImages[currentPre],
  11. 1800
  12. )
  13. "
  14. alt=""
  15. ref="big" />
  16. </div>
  17. <el-carousel
  18. :interval="5000"
  19. arrow="always"
  20. height="578px"
  21. indicator-position="none"
  22. :autoplay="false"
  23. ref="carousel"
  24. @change="changeCarousel">
  25. <el-carousel-item
  26. v-for="item in comInfo.mergeImages"
  27. :key="item">
  28. <!-- <div class="banner" :style="{backgroundImage: 'url(' + item + ')'}"></div> -->
  29. <zoom
  30. :imgUrl="
  31. $utils.generateResizedImageUrl(
  32. comInfo.mergeImages[currentPre],
  33. 1800
  34. )
  35. "
  36. @sendStyle="getStyle"
  37. @handleViwer="handleViwer"></zoom>
  38. </el-carousel-item>
  39. <el-carousel-item v-if="comInfo.video">
  40. <video
  41. controls
  42. width="100%"
  43. height="100%"
  44. ref="video">
  45. <source :src="comInfo.video" />
  46. Your browser does not support the video tag.
  47. </video>
  48. </el-carousel-item>
  49. </el-carousel>
  50. </div>
  51. <div class="smImgUl">
  52. <ul>
  53. <li
  54. @click="changeCarousel(index)"
  55. :class="currentPre == index ? 'slip' : ''"
  56. v-for="(item, index) of comInfo.mergeImages"
  57. :key="index"
  58. class="banner">
  59. <el-image
  60. :src="$utils.generateResizedImageUrl(item, 100)"
  61. class="card-img-1"
  62. fit="cover"
  63. style="width: 100%; height: 100%"></el-image>
  64. </li>
  65. <li
  66. @click="changeCarousel(comInfo.mergeImages?.length)"
  67. :class="currentPre == comInfo.mergeImages?.length ? 'slip' : ''"
  68. v-if="comInfo.video">
  69. <video
  70. width="100%"
  71. height="100%"
  72. :src="comInfo.video" />
  73. <div class="playMask">
  74. <img
  75. src="@/assets/img/play.png"
  76. alt="" />
  77. </div>
  78. </li>
  79. </ul>
  80. </div>
  81. <ElImageViewer
  82. v-if="showViewer"
  83. :initial-index="currentPre"
  84. :on-close="closeViewer"
  85. :url-list="comS3Img" />
  86. </div>
  87. </template>
  88. <script>
  89. import { mapMutations } from 'vuex'
  90. import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
  91. import Zoom from '@/components/Zoom'
  92. export default {
  93. components: { Zoom, ElImageViewer },
  94. props: {
  95. pageData: {
  96. type: Object,
  97. default: () => {
  98. return {}
  99. },
  100. },
  101. id: {
  102. type: Number,
  103. default: 0,
  104. },
  105. },
  106. data() {
  107. return {
  108. indexBanner: [],
  109. btnObj: ['View larger', '3D Preview'],
  110. current3D: 0, // 3D图序号
  111. btnShow: true, // 所有按钮显示
  112. bigShow: false,
  113. showViewer: false,
  114. }
  115. },
  116. computed: {
  117. currentPre() {
  118. return this.$store.state.product.smImgUlIdx
  119. },
  120. comInfo() {
  121. const { main } = this.pageData
  122. const images = main.image_color.map(i => i.image)
  123. if (main.image) {
  124. images.unshift(main.image)
  125. }
  126. main.mergeImages = images
  127. return main
  128. },
  129. comS3Img() {
  130. return this.comInfo.mergeImages.map(url => this.$utils.repaceDomain(url))
  131. },
  132. },
  133. watch: {
  134. currentPre(newVal) {
  135. this.$refs.carousel.setActiveItem(newVal)
  136. },
  137. },
  138. mounted() {
  139. if (this.comInfo.video) {
  140. this.$refs.video.volume = 0.5
  141. }
  142. },
  143. methods: {
  144. ...mapMutations({ setSmImgUlIdx: 'product/setSmImgUlIdx' }),
  145. changeCarousel(val) {
  146. this.setSmImgUlIdx(val)
  147. if (val === this.comInfo.mergeImages?.length) {
  148. this.btnShow = false
  149. this.comInfo.video && this.$refs.video.play()
  150. } else {
  151. this.btnShow = true
  152. this.comInfo.video && this.$refs.video.pause()
  153. }
  154. },
  155. selectCurrent3D(val) {
  156. this.current3D = val
  157. },
  158. getStyle(val) {
  159. const bigImg = this.$refs.big
  160. bigImg.style.left = -2 * val.left + 'px'
  161. bigImg.style.top = -2 * val.top + 'px'
  162. this.bigShow = val.bigShow
  163. },
  164. closeViewer() {
  165. this.showViewer = false
  166. },
  167. handleViwer() {
  168. this.showViewer = true
  169. },
  170. },
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .product-left {
  175. padding-right: 20px;
  176. .media {
  177. border: 1px solid rgba(74, 89, 108, 0.2);
  178. position: relative;
  179. width: 578px;
  180. height: 578px;
  181. .banner {
  182. width: 100%;
  183. height: 100%;
  184. background-size: cover;
  185. background-repeat: no-repeat;
  186. background-position: center;
  187. }
  188. video {
  189. object-fit: contain;
  190. }
  191. .design_list_img {
  192. padding: 10px;
  193. // display: flex;
  194. // flex-wrap: wrap;
  195. // justify-content:space-around;
  196. display: grid;
  197. grid-template-columns: repeat(4, 1fr);
  198. gap: 10px;
  199. li {
  200. cursor: pointer;
  201. // width: 192px;
  202. // height:192px;
  203. }
  204. }
  205. .switch-wrap {
  206. position: absolute;
  207. left: 50%;
  208. bottom: 20px;
  209. transform: translate(-50%, 0);
  210. z-index: 2;
  211. font-family: ProximaNova-Regular;
  212. }
  213. .switch-btn {
  214. text-align: center;
  215. &:nth-child(1) {
  216. margin-bottom: 20px;
  217. }
  218. .primary_button {
  219. display: inline-block;
  220. cursor: pointer;
  221. width: 140px;
  222. background: rgba(255, 255, 255);
  223. box-shadow: 0 2px 4px 1px rgba(0, 0, 0, 0.2);
  224. padding: 10px 0;
  225. color: #00213b;
  226. transition: all 0.2s ease-out 0s;
  227. }
  228. .primary_checked {
  229. background: #00213b !important;
  230. color: #fff !important;
  231. }
  232. }
  233. }
  234. .smImgUl {
  235. ul {
  236. margin-top: 10px;
  237. display: inline-grid;
  238. grid-template-columns: repeat(8, 68px);
  239. gap: 5px;
  240. li {
  241. box-sizing: border-box;
  242. border: 1px solid #eee;
  243. cursor: pointer;
  244. width: 100%;
  245. height: 68px;
  246. background-size: cover;
  247. background-repeat: no-repeat;
  248. background-position: center;
  249. position: relative;
  250. }
  251. .slip {
  252. border-color: #4a596c !important;
  253. }
  254. .playMask {
  255. position: absolute;
  256. top: 0;
  257. width: 100%;
  258. height: 100%;
  259. background-color: rgba(0, 0, 0, 0.3);
  260. display: flex;
  261. align-items: center;
  262. justify-content: center;
  263. }
  264. }
  265. }
  266. }
  267. .big {
  268. width: 100%;
  269. height: 100%;
  270. position: absolute;
  271. top: -1px;
  272. left: 100%;
  273. border: 1px solid rgba(74, 89, 108, 0.2);
  274. overflow: hidden;
  275. z-index: 3;
  276. // display: block;
  277. background: white;
  278. // box-sizing: border-box;
  279. img {
  280. width: 200%;
  281. max-width: 200%;
  282. height: 200%;
  283. position: absolute;
  284. left: 0;
  285. top: 0;
  286. object-fit: cover;
  287. }
  288. }
  289. </style>