lunbobox.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="lunbobox-container">
  3. <template v-for="(lunbobox, index) in lunboboxList">
  4. <view :key="index" :class="['lunbobox', showIndex == index && 'show', nextIndex == index && 'next']" @click="toDetail">
  5. <view class="left-info">
  6. <view class="avatar">
  7. <image :src="'/static/def-avatar.png'" mode="heightFix"></image>
  8. </view>
  9. <view class="user">{{ lunbobox.nickname }}</view>
  10. <view class="goods-name">获得{{ lunbobox.goods_name }}</view>
  11. </view>
  12. <view class="goods-img">
  13. <image :src="lunbobox.goods_image" mode="widthFix"></image>
  14. </view>
  15. </view>
  16. </template>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name:"lunbobox",
  22. data() {
  23. return {
  24. lunboboxList: [],
  25. showIndex: 0
  26. };
  27. },
  28. computed:{
  29. nextIndex(){
  30. if(this.showIndex < this.lunboboxList.length - 1){
  31. return this.showIndex + 1
  32. } else {
  33. return 0
  34. }
  35. },
  36. cueeShowBox(){
  37. return this.lunboboxList[this.showIndex]
  38. }
  39. },
  40. created() {
  41. this.getLunboBoxList()
  42. setInterval(() => {
  43. this.showIndex = this.nextIndex
  44. }, 3000)
  45. },
  46. methods: {
  47. getLunboBoxList(){
  48. this.$api.lunbobox().then( ({code, data}) => {
  49. if(code == 1){
  50. this.lunboboxList = this.dataHandler(data)
  51. }
  52. })
  53. },
  54. dataHandler(data){
  55. let dataList = data.map(item => {
  56. item.nickname = this.nicknameHandler(item.nickname)
  57. item.goods_name = this.goodsNameHandler(item.goods_name)
  58. return item
  59. })
  60. return dataList
  61. },
  62. nicknameHandler(nickname){
  63. let left = nickname.substring(0, 1)
  64. let right = nickname.substring(nickname.length - 2, nickname.length - 1)
  65. return `${left}***${right}`
  66. },
  67. goodsNameHandler(goodsName){
  68. let len = 4
  69. if(goodsName.length <= len){
  70. return goodsName
  71. }
  72. return goodsName.substring(0, len)
  73. },
  74. toDetail(){
  75. const boxId = this.cueeShowBox.box_id
  76. console.log(this.cueeShowBox)
  77. if(boxId){
  78. uni.navigateTo({url:'/pages/index/details?id=' + boxId + '&type=0'})
  79. }
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. .user,.goods-name{
  86. color: #FFFFFF;
  87. }
  88. .lunbobox-container{
  89. padding: 10rpx 10rpx;
  90. margin-top: 5rpx;
  91. .lunbobox{
  92. transition: .5s;
  93. opacity: 0;
  94. display: flex;
  95. height: 0;
  96. background-image: url('@/static/lunbo.png');
  97. background-repeat: no-repeat;
  98. background-size: auto 100%;
  99. width: 205px;
  100. $height: 35px;
  101. $avatar-size: 28px;
  102. position: relative;
  103. .avatar{
  104. width: $avatar-size;
  105. height: $avatar-size;
  106. border: solid 1px #fff;
  107. border-radius: 50px;
  108. display: flex;
  109. justify-content: center;
  110. align-items: center;
  111. overflow: hidden;
  112. margin-left: 5px;
  113. margin-right: 10px;
  114. }
  115. &.show{
  116. opacity: 1;
  117. height: $height;
  118. }
  119. &.next{
  120. height: $height;
  121. opacity: .5;
  122. transform: scale(0.7) translateX(-20%);
  123. }
  124. .left-info{
  125. height: 100%;
  126. display: flex;
  127. width: 162px;
  128. align-items: center;
  129. >view{
  130. font-size: 13px;
  131. font-weight: 500;
  132. }
  133. }
  134. .goods-img{
  135. height: 83%;
  136. transform: translateY(4px);
  137. flex: 1;
  138. display: flex;
  139. align-items: center;
  140. overflow: hidden;
  141. justify-content: center;
  142. image{
  143. width: 45%;
  144. }
  145. }
  146. }
  147. }
  148. </style>