scrollHotel.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <scroll-view id="scroll-container" class="scroll-hotel"
  3. @touchcancel="touchEnd"
  4. @touchend="touchEnd"
  5. @scroll="scroll"
  6. :scroll-left="scrolls.scrollX"
  7. :scroll-with-animation="true"
  8. :scroll-x="true"
  9. :scroll-into-view="index"
  10. >
  11. <view style="width: 16rpx;display: inline-block;"></view>
  12. <view :id="`i${index}`" class="address-detail" v-for="(item,index) in hotelList" :key="index">
  13. <view :class="{mark:true, on:index == scrolls.activeIndex}" style="overflow: hidden;">
  14. <image :src="item.bg_img" mode="aspectFill"></image>
  15. </view>
  16. <view class="inner">
  17. <view class="address-detail-main">
  18. <view class="address-detail-main-left">
  19. <text class="title">{{item.name}}</text>
  20. <view class="content" :style="{opacity: item.label?1:0}">
  21. <template v-if="item.label">
  22. <text v-for="(v,k) in item.label.split(',')" :key="k">{{v}}</text>
  23. </template>
  24. </view>
  25. <view class="bottom" :style="{opacity: item.min_price?1:0}">
  26. <text class="bottom-left">¥</text>
  27. <text class="bottom-right">{{item.min_price}}起</text>
  28. </view>
  29. </view>
  30. <view class="address-detail-main-right" @click="$emit('goBook',index)">
  31. <text>预订</text>
  32. </view>
  33. </view>
  34. <view class="address-detail-position" v-if="item.distanceToMe">
  35. <image style="width: 18rpx;height: 22rpx;" src="/static/icon/address02.png" mode="">
  36. </image>
  37. <text style="margin-left:4rpx ;">{{item.distanceToMe}}km</text>
  38. </view>
  39. </view>
  40. </view>
  41. <view style="width: 16rpx;display: inline-block;"></view>
  42. </scroll-view>
  43. </template>
  44. <script>
  45. export default {
  46. name:"scroll-hotel",
  47. props:{
  48. hotelList:{
  49. type: Array,
  50. required: true
  51. },
  52. speed: {
  53. type: Number,
  54. default:2
  55. }
  56. },
  57. data(){
  58. return {
  59. target:"",
  60. scrolls:{
  61. r: 0,
  62. compensate: 0,
  63. screenWidth: 750,
  64. scrollX: -1,
  65. itemWidth: 512,
  66. isAppend: false,
  67. activeIndex:0,
  68. },
  69. move:{
  70. oldX: 0,
  71. direct: 0,
  72. isMove: false
  73. },
  74. }
  75. },
  76. computed:{
  77. scrollX(){
  78. return `translateX(${this.scrolls.scrollX}rpx)`;
  79. },
  80. totalWidth(){
  81. return this.hotelList.length*this.scrolls.itemWidth;
  82. },
  83. maxRight(){
  84. return -this.totalWidth + this.scrolls.itemWidth
  85. },
  86. activeIndex(){
  87. return Math.floor(this.scrolls.scrollX / this.scrolls.itemWidth)
  88. },
  89. },
  90. onReady(){
  91. uni.getSystemInfo({
  92. success: (res)=>{
  93. const r = res.screenWidth / 750;
  94. this.scrolls.r = r
  95. const rs = Math.ceil(r * 10)/10;
  96. this.scrolls.compensate = Math.abs(Math.floor((r - rs) * 100)/2);
  97. }
  98. });
  99. },
  100. methods:{
  101. touchStart(e){
  102. // this.move.oldX = e.touches[0].clientX;
  103. },
  104. scroll(e){
  105. const newScrollX = e.detail.scrollLeft / this.scrolls.r;
  106. const newIndex = Math.floor(((newScrollX + 750 + 50) / this.scrolls.itemWidth) - 1)
  107. if(this.scrolls.activeIndex == newIndex) return;
  108. this.scrolls.activeIndex = newIndex
  109. this.$emit('updateIndex', this.scrolls.activeIndex);
  110. },
  111. touchEnd(isUpdate){
  112. // this.scrolls.scrollX =( this.scrolls.activeIndex * this.scrolls.itemWidth - (750 - this.scrolls.itemWidth) / 2 ) + 'rpx'
  113. // if(current > 0){
  114. // this.scrolls.scrollX = 0;
  115. // }else if(this.hotelList.length<=1 && current < this.maxRight){
  116. // this.scrolls.scrollX = this.maxRight;
  117. // }else if(this.hotelList.length>1 && current < this.maxRight + (this.scrolls.screenWidth - this.scrolls.itemWidth-16)){
  118. // this.scrolls.scrollX = this.maxRight + (this.scrolls.screenWidth - this.scrolls.itemWidth-16)
  119. // }else{
  120. // if(this.activeIndex == 0){
  121. // this.scrolls.scrollX = 0;
  122. // }else if(this.activeIndex == -(this.hotelList.length - 1)){
  123. // this.scrolls.scrollX = this.maxRight + (this.scrolls.screenWidth - this.scrolls.itemWidth -16)
  124. // }else{
  125. // this.scrolls.scrollX = this.activeIndex * this.scrolls.itemWidth + (this.scrolls.screenWidth - this.scrolls.itemWidth)/2 - this.activeIndex*this.scrolls.compensate;
  126. // }
  127. // }
  128. // console.log(this.scrolls.scrollX)
  129. // isUpdate && this.$emit('updateIndex', -this.activeIndex);
  130. },
  131. setActiveIndex(index){
  132. this.scrolls.scrollX = ( index * this.scrolls.itemWidth - (750 - this.scrolls.itemWidth) / 2 ) + 'rpx'
  133. // this.touchEnd(false);
  134. },
  135. goBook(){
  136. }
  137. },
  138. }
  139. </script>
  140. <style scoped lang="scss">
  141. .scroll-hotel{
  142. width: 100%;
  143. height:318rpx;white-space: nowrap;
  144. transition: transform 5ms linear;
  145. .address-detail {
  146. display: inline-block;
  147. position: relative;
  148. flex: none;
  149. width:496rpx;
  150. height: 318rpx;
  151. border-radius: 10rpx;
  152. margin-right: 16rpx;
  153. overflow: hidden;
  154. &:last-child {
  155. margin-right: 0rpx;
  156. }
  157. .mark{
  158. height: inherit;
  159. width: inherit;
  160. overflow: hidden;
  161. border-radius: 10rpx;
  162. filter: contrast(0.5);
  163. transition: 0.3s all;
  164. image{
  165. // width: 100%;
  166. height: 318rpx;
  167. width: 690rpx;
  168. border-radius: 10rpx;
  169. }
  170. &.on{
  171. filter: contrast(1.2)!important;
  172. }
  173. }
  174. .inner {
  175. width: 100%;
  176. height: inherit;
  177. border-radius: 10rpx;
  178. position: absolute;
  179. z-index: 2;
  180. top: 0;
  181. left: 0;
  182. .address-detail-main {
  183. position: absolute;
  184. left: 0;
  185. bottom: 30rpx;
  186. width: 100%;
  187. display: flex;
  188. align-items: flex-end;
  189. justify-content: space-between;
  190. .address-detail-main-left {
  191. position: absolute;
  192. left: 20rpx;
  193. .title {
  194. font-size: 32rpx;
  195. font-weight: bold;
  196. color: #FFFFFF;
  197. }
  198. .content {
  199. width: 100%;
  200. height: 64rpx;
  201. display: flex;
  202. align-items: center;
  203. justify-content: flex-start;
  204. flex-wrap: nowrap;
  205. overflow: hidden;
  206. text{
  207. line-height: 36rpx;
  208. height: 36rpx;
  209. padding: 0 10rpx;
  210. /* padding: 4rpx 6rpx; */
  211. font-size: 22rpx;
  212. color: #ffffff;
  213. background: rgba(142, 160, 166, 0.6);
  214. border-radius: 17rpx;
  215. margin-right: 10rpx;
  216. }
  217. }
  218. .bottom {
  219. display: flex;
  220. align-items: center;
  221. justify-content: flex-start;
  222. .bottom-left {
  223. font-size: 24rpx;
  224. font-weight: bold;
  225. color: #ffffff;
  226. margin-right: 6rpx;
  227. }
  228. .bottom-right {
  229. font-size: 32rpx;
  230. font-weight: bold;
  231. color: #ffffff;
  232. }
  233. }
  234. }
  235. .address-detail-main-right {
  236. position: absolute;
  237. right: 24rpx;
  238. width: 120rpx;
  239. height: 44rpx;
  240. background: #FF6300;
  241. box-shadow: 0px 4rpx 8rpx 0px rgba(0, 0, 0, 0.08);
  242. border-radius: 22rpx;
  243. display: flex;
  244. align-items: center;
  245. justify-content: center;
  246. color: #ffffff;
  247. font-size: 28rpx;
  248. }
  249. }
  250. .address-detail-position {
  251. position: absolute;
  252. top: 22rpx;
  253. right: 24rpx;
  254. display: flex;
  255. align-items: center;
  256. justify-content: center;
  257. font-weight: 500;
  258. color: #FFFFFF;
  259. font-size: 20rpx;
  260. }
  261. }
  262. }
  263. }
  264. </style>