index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <view class="content" >
  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. defaultOrder:'desc',
  84. page: {
  85. num: 1, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  86. size: 10 // 每页数据的数量,默认10
  87. },
  88. titname:'',
  89. isEnabled: true,
  90. triggered: false,
  91. status:'loadmore'
  92. };
  93. },
  94. onLoad() {
  95. uni.showShareMenu({
  96. withShareTicket: true,
  97. //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  98. menus: ["shareAppMessage", "shareTimeline"] //不设置默认发送给朋友
  99. })
  100. this.getProductCate();
  101. setTimeout(()=>{
  102. this.cateSelect=this.allCates[0].cateId
  103. this.getproduct()
  104. },200)
  105. },
  106. onShow() {
  107. var that = this;
  108. setTimeout(function() {
  109. let info = uni.createSelectorQuery().select(".top-content");
  110. info.boundingClientRect(function(data) { //data - 各种参数
  111. console.log(data.height) // 获取元素宽度
  112. // console.log(uni.upx2px(10))
  113. that.divHeight = "calc(100% - " + data.height + "px)"
  114. }).exec()
  115. }, 500);
  116. this.getAdv();
  117. },
  118. methods: {
  119. // divHeight(){
  120. // return 'height:calc(100% - ${this.top}px);'
  121. // },
  122. pullDownRefresh(){
  123. // 下拉
  124. this.triggered = true; //下拉了状态为true
  125. setTimeout(() => {
  126. this.triggered = false;
  127. uni.stopPullDownRefresh()
  128. this.page.num= 1;
  129. this.getproduct('refresh') //触底 不穿执行else
  130. // 请求接口里面需要判断是不是最后一页 是最后一页 status赋值为‘loadmore’没有更多了
  131. // 请求接口
  132. }, 1000)
  133. },
  134. reachBottom(){
  135. //上拉
  136. // status这个是加载状态
  137. if (this.status === 'loadmore') {
  138. this.status = 'loading'
  139. uni.showNavigationBarLoading()
  140. setTimeout(() => {
  141. this.page.num++
  142. this.getproduct() //触底 不穿执行else
  143. uni.hideNavigationBarLoading()
  144. }, 1000);
  145. }
  146. },
  147. toSearch() {
  148. uni.navigateTo({
  149. url: '../home/productSearch'
  150. })
  151. },
  152. handleAdvClick(item) {
  153. console.log(item);
  154. if (item.showType == 1) {
  155. uni.setStorageSync('url', item.advUrl);
  156. uni.navigateTo({
  157. url: "../home/h5"
  158. })
  159. } else if (item.showType == 2) {
  160. uni.navigateTo({
  161. url: item.advUrl
  162. })
  163. } else if (item.showType == 3) {
  164. uni.setStorageSync('content', item.content);
  165. uni.navigateTo({
  166. url: "../home/content"
  167. })
  168. }
  169. },
  170. getAdv() {
  171. let data = {
  172. advType: 2
  173. };
  174. getAdv(data).then(
  175. res => {
  176. if (res.code == 200) {
  177. this.advs = res.data;
  178. }
  179. },
  180. rej => {}
  181. );
  182. },
  183. getProductCate() {
  184. let data = {};
  185. getProductCate(data).then(
  186. res => {
  187. if (res.code == 200) {
  188. this.allCates = res.data;
  189. this.cates = this.allCates.filter(function(item) {
  190. return item.pid == 0
  191. });
  192. console.log(this.allCates,111)
  193. console.log(this.cates)
  194. if (this.cates != null && this.cates.length > 0) {
  195. this.cateSelect = this.cates[0].cateId;
  196. this.getSubCate()
  197. }
  198. } else {
  199. uni.showToast({
  200. icon: 'none',
  201. title: "请求失败",
  202. });
  203. }
  204. },
  205. rej => {}
  206. );
  207. },
  208. // 商品分类选择
  209. choseCate(item) {
  210. this.subCates=[]
  211. this.cateSelect = item.cateId;
  212. console.log(item)
  213. this.titname=item.cateName
  214. // this.getSubCate()
  215. this.getproduct()
  216. },
  217. getproduct(type){
  218. var data = {
  219. cateId:this.cateSelect,
  220. defaultOrder:this.defaultOrder,
  221. page: this.page.num,
  222. pageSize: this.page.size,
  223. productName: "",
  224. storeId: ""
  225. };
  226. getProducts(data).then(res=>{
  227. if(res.code==200){
  228. console.log(res)
  229. if (type == 'refresh') {
  230. this.subCates=res.data.list
  231. } else {
  232. // 加载更多 当前页和下一页合并
  233. this.subCates = [...this.subCates, ...res.data.list]
  234. }
  235. if (this.page.num >= res.data.prePage) {
  236. //是否有下一页
  237. this.status = 'nomore'
  238. } else {
  239. this.status = 'loadmore'
  240. }
  241. }
  242. })
  243. },
  244. getSubCate() {
  245. var that = this;
  246. // this.subCates = this.allCates.filter(function(item) {
  247. // let subList = that.allCates.filter(child => {
  248. // //返回每一项的子级数组
  249. // return child.pid === item.cateId
  250. // });
  251. // subList.length > 0 ? item.children = subList : [];
  252. // return item.pid == that.cateSelect
  253. // });
  254. // this.getProductCate()
  255. console.log(this.subCates);
  256. },
  257. // 查看商品详情
  258. showProductList(item) {
  259. uni.navigateTo({
  260. // url: './productList?cateId=' + item.cateId + "&pid=" + 0
  261. url: '/pages/shopping/productDetails?productId=' + item.productId
  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% - 100upx);
  378. height: 100%;
  379. position: relative;
  380. // .item{
  381. // .title{
  382. // font-size: 28upx;
  383. // font-family: PingFang SC;
  384. // font-weight: bold;
  385. // color: #333333;
  386. // padding-top: 20upx;
  387. // margin-bottom: 30upx;
  388. // }
  389. // }
  390. .inner-list {
  391. display: flex;
  392. flex-wrap: wrap;
  393. .definite {
  394. width: calc(50% - 30upx);
  395. margin-right: 30upx;
  396. margin-bottom: 30upx;
  397. .img-box {
  398. width: 100%;
  399. height: 220upx;
  400. background: #F5F5F5;
  401. border-radius: 8upx;
  402. overflow: hidden;
  403. display: flex;
  404. align-items: center;
  405. image {
  406. max-width: 100%;
  407. }
  408. }
  409. .name {
  410. width: 100%;
  411. margin-top: 20upx;
  412. font-size: 24upx;
  413. font-family: PingFang SC;
  414. font-weight: 500;
  415. color: #666666;
  416. text-align: center;
  417. }
  418. &:nth-child(2n) {
  419. margin-right: 0;
  420. }
  421. }
  422. }
  423. }
  424. }
  425. }
  426. }
  427. </style>