index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class="zs-banner">
  3. <!-- <view class="position-box" :style="{height:navBareight +'px',top:statusBarHeight+'px'}" v-if="position"> -->
  4. <view class="position-box" :style="{height:navBareight +'px',background:background?'#fff':''}" v-if="position">
  5. <view class="position" @click="handlePosition">
  6. <image class="position-icon" src="../../static/black-position.png" mode=""></image>
  7. <text class="city">{{city}}</text>
  8. </view>
  9. <view class="search-box" @click="handleSearch">
  10. <input class="search" :style="{height:height+'px'}" type="text" placeholder="搜索" v-model="search" />
  11. <image class="icon" src="../../static/search.png" mode=""></image>
  12. </view>
  13. </view>
  14. <view class="top-box" :style="{'--bg':theme}">
  15. <swiper class="swiper" @change="swiperChange" :indicator-dots="true" circular :autoplay="true"
  16. :interval="3000" :duration="1000">
  17. <swiper-item v-for="(item,index) in bannerList" :key="index">
  18. <image class="swiper-item" mode="" :src="item.bannerImg">
  19. </image>
  20. </swiper-item>
  21. </swiper>
  22. </view>
  23. <u-notice-bar bgColor="none" icon="volume-fill" color="#6F4F23" direction="column" :fontSize='26' :text="textList"></u-notice-bar>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. getNotification,
  29. getBanner
  30. } from '@/api/common.js'
  31. export default {
  32. options:{
  33. styleIsolation:'shared'
  34. },
  35. props: {
  36. position: {
  37. type: Boolean,
  38. default: false
  39. },
  40. city:{
  41. type: String,
  42. default: '定位中'
  43. },
  44. background: {
  45. type: Boolean,
  46. default: false
  47. }
  48. },
  49. data() {
  50. return {
  51. navBareight:0,
  52. height:0,
  53. search:'',
  54. theme: '#FD9E59', //顶部颜色
  55. textList: [], //通知列表
  56. bannerList: [
  57. // {
  58. // src:'http://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/LasLcHe8z6F9c7c569e98cf778f866ac466404589d03.png/1.png',
  59. // theme: '#FD9E59'
  60. // },
  61. // {
  62. // src:'http://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/QdulVZUZ9HYH190ae2e9392281ee1b845573e68ece1e.png/1.png',
  63. // theme: '#FDD34C'
  64. // },
  65. // {
  66. // src:'http://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/N7kknVWzDPKLbb7e15025599a818bbf11e3b030b6765.png/1.png',
  67. // theme: '#B0ACF9'
  68. // },
  69. // {
  70. // src:'http://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/rJ1Crwfuf0if0e3285089cb737285b7583c890a905db.png/1.png',
  71. // theme: '#85DCF4'
  72. // },
  73. // {
  74. // src:'http://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/WBcUUqzpi50Dd1012af5dd52b6e28758a49e79e3fd07.png/1.png',
  75. // theme: '#FE6646'
  76. // }
  77. ],
  78. };
  79. },
  80. methods: {
  81. // swiper变动
  82. swiperChange(val) {
  83. this.theme = this.bannerList[val.detail.current].colour
  84. },
  85. // 获取通知列表
  86. getNotification() {
  87. // this.loading = true
  88. getNotification({
  89. page: 1,
  90. pageSize: 10
  91. }).then(res => {
  92. if(res.state == 'Success'){
  93. this.textList = []
  94. res.content.records.map(item => {
  95. this.textList.push(`用户${item.phoneNum}注册成功,本月累计节省${item.economizeTheMoney||0}元`)
  96. })
  97. }
  98. }).catch(e=>{
  99. console.log(3,e);
  100. })
  101. },
  102. getBanner(){
  103. getBanner({currentPage:1,pageSize:10,belongType:2}).then(res=>{
  104. if(res.state == 'Success'){
  105. this.bannerList = res.content.records
  106. this.theme = this.bannerList[0].colour
  107. }
  108. })
  109. },
  110. jump(){
  111. uni.navigateTo({
  112. url:'../../pages/index/position'
  113. })
  114. },
  115. handleSearch(){
  116. this.$emit('search',this.search)
  117. },
  118. handlePosition(){
  119. this.$emit('handlePosition','')
  120. },
  121. getNavHeight(){
  122. //去除
  123. //#ifndef H5 || MP-ALIPAY ||APP-PLUS
  124. //获取小程序胶囊的高度
  125. let {
  126. bottom,
  127. height
  128. } = uni.getMenuButtonBoundingClientRect()
  129. this.height = height
  130. this.navBareight = bottom
  131. //#endif
  132. }
  133. },
  134. created() {
  135. this.getNotification()
  136. this.getBanner()
  137. this.getNavHeight()
  138. }
  139. }
  140. </script>
  141. <style lang="scss" >
  142. // 通知喇叭样式
  143. .zs-banner ::v-deep .u-notice .u-icon__icon{
  144. font-size: 32rpx!important;
  145. }
  146. .zs-banner{
  147. position: relative;
  148. height: 584rpx;
  149. .position-box{
  150. position: fixed;
  151. width: 100%;
  152. top: 0;
  153. left: 0;
  154. z-index: 2;
  155. display: flex;
  156. align-items: flex-end;
  157. justify-content: center;
  158. box-sizing: border-box;
  159. // padding-bottom: 6rpx;
  160. .position{
  161. position: absolute;
  162. // top: 50%;
  163. left: 30rpx;
  164. // transform: translateY(-50%);
  165. color: #222;
  166. display: flex;
  167. align-items: center;
  168. font-size: 24rpx;
  169. .position-icon{
  170. width: 40rpx;
  171. height: 40rpx;
  172. }
  173. .city{
  174. margin-left: 6rpx;
  175. line-height: 60rpx;
  176. }
  177. }
  178. .search-box {
  179. width: 380rpx;
  180. // height: 60rpx;
  181. background: #FFFFFF;
  182. border-radius: 30rpx;
  183. position: absolute;
  184. left: 160rpx;
  185. box-shadow: 0rpx 0rpx 20rpx 2rpx rgba(0,0,0,0.1);
  186. .icon {
  187. width: 34rpx;
  188. height: 34rpx;
  189. position: absolute;
  190. top: 50%;
  191. left: 22rpx;
  192. transform: translateY(-50%);
  193. }
  194. .search {
  195. // line-height: 60rpx;
  196. // height: 60rpx;
  197. padding-left: 80rpx;
  198. }
  199. }
  200. }
  201. .top-box {
  202. background: linear-gradient(180deg, var(--bg) 0%, #FFF 100%);
  203. // padding: 100rpx 32rpx 0;
  204. height: 536rpx;
  205. box-sizing: border-box;
  206. display: flex;
  207. flex-direction: column;
  208. justify-content: flex-end;
  209. .swiper {
  210. height: 584rpx;
  211. border-radius: 16rpx;
  212. .swiper-item {
  213. width: 100%;
  214. height: 100%;
  215. // border-radius: 16rpx;
  216. object-fit: cover;
  217. }
  218. }
  219. }
  220. }
  221. </style>