goods.vue 8.1 KB

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