index.vue 11 KB

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