goods.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <view class="goods">
  3. <scroll-view class="scroll-y" @scroll="handleScroll" :scroll-into-view="topItem" scroll-with-animation
  4. scroll-y="true">
  5. <view id="top"></view>
  6. <!-- 背景图 -->
  7. <view class="goods-img">
  8. <image v-if="bannerImg" style="width: 100%; height: 450rpx;" :src="bannerImg" mode=""></image>
  9. </view>
  10. <!-- 内容 -->
  11. <view class="main">
  12. <view class="search">
  13. <u-input placeholder="搜索" border='none' v-model="search" @input="searchText">
  14. <template slot="suffix" style='margin-right:40rpx;'>
  15. <u-image :showLoading="true" :showError='true' src="/static/icon/search.png" width="40rpx"
  16. height="32rpx"></u-image>
  17. </template>
  18. </u-input>
  19. </view>
  20. <view class="tab_nav">
  21. <view class="navTitle" v-for="(item,index) in items" :key="index">
  22. <view class="navTitle-item">
  23. <view :class="{'active':isActive === index}" @click="checked(index,item.id)">
  24. {{item.name}}
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="content">
  31. <view class="home-hotel-img-content">
  32. <view @click="goGoodsDetail(item.id)" class="home-hotel-img-content-item" v-for="(item,index) in goodsList" :key="index"
  33. :style="{marginTop:item.marginTop || 0 }">
  34. <image class="home-hotel-img-content-item-img"
  35. :class="item.short?'home-hotel-img-content-item-img': 'home-hotel-img-content-item-img-long' "
  36. :src="item.cover_img" mode=""></image>
  37. <view class="text">
  38. <text class="text-top">{{item.name}}</text>
  39. <text class="text-main">{{item.hotel.name}}</text>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 触底 -->
  44. <view class="home-bottom">
  45. <uni-load-more :status="status" color="#CCCCCC" :content-text="contentText" />
  46. </view>
  47. <!-- <text @click="goGoodsDetail">商品</text>
  48. <text @click="goGoodsDetailImg">转盘</text> -->
  49. </view>
  50. </scroll-view>
  51. <view class="return-btn" v-if="isShow" @click="handleBackTop">
  52. <image style="width: 128rpx;height: 128rpx;" src="/static/icon/returntop.png" mode=""></image>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import util from '@/utils/util.js'
  58. export default {
  59. data() {
  60. return {
  61. //搜索
  62. search:'',
  63. //背景图
  64. bannerImg:'',
  65. // 返回的按钮是否显示
  66. isShow: false,
  67. topItem: '', //返回顶部的标记点
  68. goodsList: [{
  69. img: 'http://t9.9026.com/imgs/goodsimg01.png',
  70. text: '中秋佳节五仁月饼,惊喜特供,限时抢购',
  71. title: '环球洲际',
  72. short: '',
  73. }],
  74. status: 'noMore',
  75. contentText: {
  76. contentdown: '查看更多',
  77. contentrefresh: '加载中',
  78. contentnomore: '—— 已经到底啦 ——'
  79. },
  80. //分段器
  81. items: [],
  82. //激活指定table菜单
  83. isActive: 0,
  84. //第三方产品分类categoryId
  85. categoryId:'',
  86. };
  87. },
  88. onLoad() {
  89. this.shortLong()
  90. this.getCategoryList()
  91. //获取产品活动列表背景图
  92. this.bannerImg = this.$store.getters.allset.activity_page.value.cover
  93. },
  94. methods: {
  95. // 获取分类列表
  96. getCategoryList(){
  97. this.$api.category.getCategoryList({
  98. page:1,
  99. type:2
  100. }).then(res=>{
  101. if(res.code==0){
  102. this.items=res.data.data
  103. this.categoryId = this.items[0].id
  104. console.log(this.categoryId,'--->this.categoryId');
  105. this.getGoodsList(this.categoryId)
  106. }
  107. })
  108. },
  109. //菜单index切换
  110. checked(index,id) {
  111. this.isActive = index
  112. this.getGoodsList(id)
  113. },
  114. //产品列表type:1,第三方购买产品
  115. getGoodsList(category_id) {
  116. this.$api.product.getProducts({
  117. type: 1,
  118. page: 0,
  119. keyword:'',
  120. category_id:`${category_id}`
  121. }).then(res => {
  122. this.goodsList = res.data.data
  123. this.shortLong()
  124. console.log(this.goodsList,'------>产品图');
  125. })
  126. },
  127. handleScroll(e) {
  128. //只有scrollTop有用,先拿scrollTop
  129. let {
  130. scrollTop
  131. } = e.detail
  132. //滑动大于500让按钮显示
  133. this.isShow = scrollTop > 500
  134. //因为点第二次不行,这里记得重置清空一下
  135. this.topItem = ''
  136. },
  137. handleBackTop() {
  138. this.topItem = 'top'
  139. },
  140. shortLong() {
  141. this.goodsList.forEach((item, index, arr) => {
  142. if (index % 4 === 0) {
  143. item.short = true
  144. }
  145. if (index % 4 === 1) {
  146. item.long = true
  147. }
  148. if (index % 4 === 2) {
  149. item.long = true
  150. item.marginTop = -68 + "rpx"
  151. }
  152. if (index % 4 === 3) {
  153. item.short = true
  154. }
  155. })
  156. console.log(this.goodsList);
  157. },
  158. // //去大转盘
  159. // goGoodsDetailImg() {
  160. // uni.navigateTo({
  161. // url: '/pages/goods/goods-lucky/index'
  162. // })
  163. // },
  164. //去产品详情
  165. goGoodsDetail(id) {
  166. uni.navigateTo({
  167. url:`/pages/goods/goods-detail/index?id=${id}&type=1`
  168. })
  169. },
  170. // 搜索防抖
  171. searchText:util.debounce(function(){
  172. if(this.search !=''){
  173. this.goSearch()
  174. }else{
  175. this.getGoodsList(this.categoryId)
  176. }
  177. },1000),
  178. //搜索
  179. goSearch(){
  180. uni.showLoading({
  181. title:'加载中'
  182. })
  183. this.$api.product.getProducts({
  184. type: 1,
  185. page: 0,
  186. name:this.search,
  187. category_id:''
  188. }).then(res=>{
  189. if(res.code==0){
  190. uni.hideLoading()
  191. this.goodsList=res.data.data
  192. }
  193. })
  194. },
  195. }
  196. }
  197. </script>
  198. <style lang="scss" scoped>
  199. .goods {
  200. height: 100%;
  201. }
  202. .tab_nav {
  203. width: 100%;
  204. height: 100rpx;
  205. display: flex;
  206. align-items: center;
  207. font-family: PingFang-SC-Heavy, PingFang-SC;
  208. overflow-x: scroll;
  209. }
  210. .scroll-y {
  211. height: 100vh;
  212. }
  213. .content {
  214. background-color: #FFF;
  215. padding: 20rpx 30rpx;
  216. .home-hotel-img-content {
  217. display: flex;
  218. align-items: flex-start;
  219. justify-content: space-between;
  220. flex-wrap: wrap;
  221. .home-hotel-img-content-item {
  222. width: 332rpx;
  223. background: #FFFFFF;
  224. box-shadow: 0px 4rpx 8rpx 0px rgba(0, 0, 0, 0.04);
  225. border-radius: 12rpx;
  226. margin-bottom: 26rpx;
  227. .home-hotel-img-content-item-img {
  228. width: 332rpx;
  229. height: 332rpx;
  230. object-fit: cover;
  231. object-position: center;
  232. }
  233. .home-hotel-img-content-item-img-long {
  234. width: 332rpx;
  235. height: 400rpx;
  236. object-fit: cover;
  237. object-position: center;
  238. }
  239. .text {
  240. display: flex;
  241. flex-direction: column;
  242. align-items: flex-start;
  243. justify-content: center;
  244. padding: 18rpx 22rpx 32rpx;
  245. .text-top {
  246. font-size: 28rpx;
  247. font-weight: bold;
  248. color: #333;
  249. }
  250. .text-main {
  251. margin-top: 20rpx;
  252. font-size: 24rpx;
  253. color: #999999;
  254. }
  255. }
  256. }
  257. }
  258. }
  259. .return-btn {
  260. position: fixed;
  261. bottom: 140rpx;
  262. right: 14rpx;
  263. }
  264. .home-bottom {
  265. background-color: #FFF;
  266. padding-bottom: 84rpx;
  267. }
  268. .tab_nav .navTitle {
  269. width: 154rpx;
  270. flex: none;
  271. height: 28rpx;
  272. font-size: 32rpx;
  273. color: #666;
  274. position: relative;
  275. display: flex;
  276. align-items: center;
  277. justify-content: center;
  278. margin-right: 16rpx;
  279. }
  280. .navTitle-item {
  281. width: 154rpx;
  282. flex: none;
  283. height: 28rpx;
  284. font-size: 32rpx;
  285. color: #666;
  286. position: relative;
  287. display: flex;
  288. align-items: center;
  289. justify-content: center;
  290. }
  291. .active {
  292. color: #D9A94D;
  293. font-weight: bold;
  294. &::after {
  295. display: inline-block;
  296. content: '';
  297. width: 48rpx;
  298. height: 12rpx;
  299. background: linear-gradient(90deg, #F3D69F 0%, #D9A94D 100%);
  300. border-radius: 6px;
  301. position: absolute;
  302. bottom: -32rpx;
  303. left: 51rpx;
  304. }
  305. }
  306. .search {
  307. ::v-deep .u-input {
  308. width: 690rpx !important;
  309. height: 68rpx !important;
  310. background: #F1F1F1;
  311. border-radius: 74rpx;
  312. }
  313. ::v-deep .u-input__content__field-wrapper {
  314. padding-left: 36rpx;
  315. }
  316. ::v-deep .u-input__content__field-wrapper__field {
  317. color: #999999 !important;
  318. font-size: 28rpx !important;
  319. }
  320. }
  321. .goods-img {
  322. width: 100%;
  323. height: 450rpx;
  324. }
  325. .main {
  326. position: relative;
  327. top: -36rpx;
  328. padding: 48rpx 30rpx 0;
  329. border-radius: 16rpx 16rpx 0px 0px;
  330. height: 238rpx;
  331. background: #FFFFFF;
  332. box-shadow: 0px 4rpx 8rpx 0px rgba(0, 0, 0, 0.04);
  333. }
  334. </style>