index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template>
  2. <view class="content" >
  3. <view class="top-content">
  4. <!-- 这里是状态栏 -->
  5. <!-- #ifdef APP -->
  6. <view style="height: 80rpx;"></view>
  7. <view class="top-title">健康产品</view>
  8. <!-- #endif -->
  9. <!-- #ifndef APP -->
  10. <view class="status_bar" :style="{height: statusBarHeight}"></view>
  11. <view class="top-title">健康产品 </view>
  12. <!-- #endif -->
  13. <!-- 搜索框 -->
  14. <view class="search-cont">
  15. <view class="inner">
  16. <image class="icon-search" src="../../static/images/search.png" mode=""></image>
  17. <input type="text" confirm-type="搜索" @click="toSearch" placeholder="输入商品名称"
  18. placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  19. </view>
  20. </view>
  21. </view>
  22. <view :style="{height: divHeight}" class="medic-box">
  23. <view class="cate-list" >
  24. <view v-for="(item,index) in cates" :key="item.cateId" :class="cateSelect == item.cateId?'item active':'item'"
  25. @click="choseCate(item)">{{item.cateName }}</view>
  26. </view>
  27. <view class="medic">
  28. <!-- 轮播图 -->
  29. <view class="banner-box">
  30. <swiper class="swiper" :indicator-dots="true" :circular="true" :autoplay="true" :interval="3000"
  31. :duration="1000" indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#ffffff">
  32. <swiper-item class="swiper-item" v-for="(item,index) in advs" :key="index"
  33. @click="handleAdvClick(item)">
  34. <image :src="item.imageUrl" mode=""></image>
  35. </swiper-item>
  36. </swiper>
  37. </view>
  38. <!-- 商品列表 -->
  39. <view class="medic-list">
  40. <!-- <view class="item" v-for="(item,index) in subCates" :key="index">
  41. <view class="title">{{item.cateName}}</view> -->
  42. <scroll-view scroll-y="true" class="hb" :refresher-enabled="isEnabled" :refresher-triggered="triggered"
  43. refresher-background="rgba(0,0,0,0)" @refresherrefresh="pullDownRefresh"
  44. @refresherrestore="triggered = false" :upper-threshold="100" :lower-threshold="100"
  45. @refresherabort="triggered = false" @scrolltolower="reachBottom">
  46. <view class="inner-list">
  47. <view class="definite" v-for="(subItem,index) in subCates" @click="showProductList(subItem)">
  48. <view class="img-box">
  49. <image :src="subItem.image" mode="aspectFit"></image>
  50. </view>
  51. <view class="name ellipsis">{{subItem.productName}}</view>
  52. </view>
  53. </view>
  54. <u-loadmore :status="status" />
  55. </scroll-view>
  56. <!-- <view v-if="subCates.length==0" class="center mt20 column">
  57. <image src="../../static/images/no_data.png"
  58. style="width: 200rpx;height: 150rpx;"></image>
  59. <text class="fs24">暂无商品</text>
  60. </view> -->
  61. <!-- </view> -->
  62. </view>
  63. </view>
  64. </view>
  65. <tabbar :actindex="3"></tabbar>
  66. </view>
  67. </template>
  68. <script>
  69. import {
  70. getProductCate,
  71. getProducts
  72. } from '@/api/product'
  73. import {
  74. getAdv
  75. } from '@/api/adv'
  76. export default {
  77. data() {
  78. return {
  79. divHeight: '0px',
  80. allCates: [],
  81. cates: [],
  82. subCates: [],
  83. // 状态栏的高度
  84. statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
  85. // 选中商品分类
  86. cateSelect: 183,
  87. // 轮播图
  88. advs: [],
  89. theme:"beiliyou",
  90. defaultOrder:'desc',
  91. page: {
  92. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  93. size: 10 // 每页数据的数量,默认10
  94. },
  95. titname:'',
  96. isEnabled: true,
  97. triggered: false,
  98. status:'loadmore'
  99. };
  100. },
  101. onLoad() {
  102. uni.showShareMenu({
  103. withShareTicket: true,
  104. //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  105. menus: ["shareAppMessage", "shareTimeline"] //不设置默认发送给朋友
  106. })
  107. this.getProductCate();
  108. // setTimeout(()=>{
  109. this.cateSelect=this.allCates[0].cateId
  110. this.getproduct()
  111. // },100)
  112. },
  113. onShow() {
  114. var that = this;
  115. setTimeout(function() {
  116. let info = uni.createSelectorQuery().select(".top-content");
  117. info.boundingClientRect(function(data) { //data - 各种参数
  118. console.log(data.height) // 获取元素宽度
  119. // console.log(uni.upx2px(10))
  120. that.divHeight = "calc(100% - " + data.height + "px)"
  121. }).exec()
  122. }, 500);
  123. this.getAdv();
  124. },
  125. methods: {
  126. // divHeight(){
  127. // return 'height:calc(100% - ${this.top}px);'
  128. // },
  129. pullDownRefresh(){
  130. // 下拉
  131. this.triggered = true; //下拉了状态为true
  132. setTimeout(() => {
  133. this.triggered = false;
  134. uni.stopPullDownRefresh()
  135. this.page.num= 1;
  136. this.getproduct('refresh') //触底 不穿执行else
  137. // 请求接口里面需要判断是不是最后一页 是最后一页 status赋值为‘loadmore’没有更多了
  138. // 请求接口
  139. }, 1000)
  140. },
  141. reachBottom(){
  142. //上拉
  143. // status这个是加载状态
  144. if (this.status === 'loadmore') {
  145. this.status = 'loading'
  146. uni.showNavigationBarLoading()
  147. setTimeout(() => {
  148. this.page.num++
  149. this.getproduct() //触底 不穿执行else
  150. uni.hideNavigationBarLoading()
  151. }, 1000);
  152. }
  153. },
  154. toSearch() {
  155. uni.navigateTo({
  156. url: '../home/productSearch'
  157. })
  158. },
  159. handleAdvClick(item) {
  160. console.log(item);
  161. if (item.showType == 1) {
  162. uni.setStorageSync('url', item.advUrl);
  163. uni.navigateTo({
  164. url: "../home/h5"
  165. })
  166. } else if (item.showType == 2) {
  167. uni.navigateTo({
  168. url: item.advUrl
  169. })
  170. } else if (item.showType == 3) {
  171. uni.setStorageSync('content', item.content);
  172. uni.navigateTo({
  173. url: "../home/content"
  174. })
  175. }
  176. },
  177. getAdv() {
  178. let data = {
  179. advType: 2
  180. };
  181. getAdv(data).then(
  182. res => {
  183. if (res.code == 200) {
  184. this.advs = res.data;
  185. }
  186. },
  187. rej => {}
  188. );
  189. },
  190. getProductCate() {
  191. let data = {};
  192. getProductCate(data).then(
  193. res => {
  194. if (res.code == 200) {
  195. this.allCates = res.data;
  196. this.cates = this.allCates.filter(function(item) {
  197. return item.pid == 0
  198. });
  199. console.log(111,this.allCates,)
  200. if (this.cates != null && this.cates.length > 0) {
  201. this.cateSelect = this.cates[0].cateId;
  202. this.getproduct()
  203. }
  204. } else {
  205. uni.showToast({
  206. icon: 'none',
  207. title: "请求失败",
  208. });
  209. }
  210. },
  211. rej => {}
  212. );
  213. },
  214. // 商品分类选择
  215. choseCate(item) {
  216. this.subCates=[]
  217. this.cateSelect = item.cateId;
  218. console.log(item)
  219. this.titname=item.cateName
  220. // this.getSubCate()
  221. this.getproduct()
  222. },
  223. getproduct(type){
  224. var data = {
  225. cateId:this.cateSelect,
  226. defaultOrder:this.defaultOrder,
  227. page: this.page.num,
  228. pageSize: this.page.size,
  229. productName: "",
  230. storeId: ""
  231. };
  232. getProducts(data).then(res=>{
  233. if(res.code==200){
  234. console.log(res)
  235. if (type == 'refresh') {
  236. this.subCates=res.data.list
  237. } else {
  238. // 加载更多 当前页和下一页合并
  239. this.subCates = [...this.subCates, ...res.data.list]
  240. }
  241. if (this.page.num >= res.data.prePage) {
  242. //是否有下一页
  243. this.status = 'nomore'
  244. } else {
  245. this.status = 'loadmore'
  246. }
  247. }
  248. })
  249. },
  250. getSubCate() {
  251. var that = this;
  252. // this.subCates = this.allCates.filter(function(item) {
  253. // let subList = that.allCates.filter(child => {
  254. // //返回每一项的子级数组
  255. // return child.pid === item.cateId
  256. // });
  257. // subList.length > 0 ? item.children = subList : [];
  258. // return item.pid == that.cateSelect
  259. // });
  260. // this.getProductCate()
  261. console.log(this.subCates);
  262. },
  263. // 查看商品详情
  264. showProductList(item) {
  265. uni.navigateTo({
  266. url: './productList?cateId=' + item.cateId + "&pid=" + 0
  267. })
  268. },
  269. goSearch(e) {
  270. if (e.detail.value != null && e.detail.value != "") {
  271. this.utils.addHisSearch(e.detail.value);
  272. }
  273. console.log(e)
  274. // uni.navigateTo({
  275. // url: '../home/productList?searchValue=' + e.detail.value+
  276. // })
  277. }
  278. }
  279. }
  280. </script>
  281. <style lang="scss">
  282. page {
  283. height: 100%;
  284. background-color: #fff;
  285. }
  286. .content {
  287. height: 100%;
  288. display: flex;
  289. flex-direction: column;
  290. .top-content {
  291. width: 100%;
  292. z-index: 10;
  293. .top-title {
  294. height: 88upx;
  295. line-height: 88upx;
  296. font-size: 42upx;
  297. font-family: Source Han Sans CN;
  298. font-weight: bold;
  299. color: #222222;
  300. padding-left: 41upx;
  301. background-color: #FFFFFF;
  302. }
  303. .search-cont {
  304. padding: 16upx 30upx;
  305. background-color: #FFFFFF;
  306. .inner {
  307. box-sizing: border-box;
  308. width: 100%;
  309. height: 72upx;
  310. background: #F7F7F7;
  311. border-radius: 36upx;
  312. display: flex;
  313. align-items: center;
  314. padding: 0 30upx;
  315. .icon-search {
  316. width: 28upx;
  317. height: 28upx;
  318. margin-right: 20upx;
  319. }
  320. input {
  321. height: 60upx;
  322. line-height: 60upx;
  323. flex: 1;
  324. }
  325. }
  326. }
  327. }
  328. .medic-box {
  329. display: flex;
  330. .cate-list {
  331. box-sizing: border-box;
  332. width: 200upx;
  333. background: #F2F5F9;
  334. display: flex;
  335. flex-direction: column;
  336. padding: 20upx 0;
  337. overflow-y: scroll;
  338. .item {
  339. height: 100upx;
  340. line-height: 100upx;
  341. padding-left: 30upx;
  342. font-size: 28upx;
  343. font-family: PingFang SC;
  344. font-weight: 500;
  345. color: #333333;
  346. position: relative;
  347. &.active {
  348. color: #018C39;
  349. &::after {
  350. content: "";
  351. width: 8upx;
  352. height: 50upx;
  353. background: #018C39;
  354. position: absolute;
  355. top: 25upx;
  356. left: 0;
  357. }
  358. }
  359. }
  360. }
  361. .medic {
  362. box-sizing: border-box;
  363. width: calc(100% - 200upx);
  364. height: 100%;
  365. padding: 0 30upx;
  366. .banner-box {
  367. margin-top: 30rpx;
  368. width: 100%;
  369. height: 160upx;
  370. border-radius: 10upx;
  371. overflow: hidden;
  372. .swiper,
  373. .swiper-item,
  374. .swiper-item image {
  375. width: 100%;
  376. height: 100%;
  377. }
  378. }
  379. .medic-list {
  380. box-sizing: border-box;
  381. padding: 30upx 0;
  382. overflow-y: auto;
  383. height: calc(100% - 220upx);
  384. position: relative;
  385. // .item{
  386. // .title{
  387. // font-size: 28upx;
  388. // font-family: PingFang SC;
  389. // font-weight: bold;
  390. // color: #333333;
  391. // padding-top: 20upx;
  392. // margin-bottom: 30upx;
  393. // }
  394. // }
  395. .inner-list {
  396. display: flex;
  397. flex-wrap: wrap;
  398. .definite {
  399. width: calc(33% - 20upx);
  400. margin-right: 30upx;
  401. margin-bottom: 30upx;
  402. .img-box {
  403. width: 100%;
  404. height: 144upx;
  405. background: #F5F5F5;
  406. border-radius: 8upx;
  407. overflow: hidden;
  408. display: flex;
  409. align-items: center;
  410. image {
  411. max-width: 100%;
  412. }
  413. }
  414. .name {
  415. width: 100%;
  416. margin-top: 20upx;
  417. font-size: 24upx;
  418. font-family: PingFang SC;
  419. font-weight: 500;
  420. color: #666666;
  421. text-align: center;
  422. }
  423. &:nth-child(3n) {
  424. margin-right: 0;
  425. }
  426. }
  427. }
  428. }
  429. }
  430. }
  431. }
  432. </style>