goods.vue 8.6 KB

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