index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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="ellipsis" :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: 1, // 当前页码,默认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. computed:{
  108. isDrug() {
  109. return this.$store.state.isDrug
  110. },
  111. },
  112. onShow() {
  113. var that = this;
  114. setTimeout(function() {
  115. let info = uni.createSelectorQuery().select(".top-content");
  116. info.boundingClientRect(function(data) { //data - 各种参数
  117. console.log(data.height) // 获取元素宽度
  118. // console.log(uni.upx2px(10))
  119. that.divHeight = "calc(100% - " + data.height + "px)"
  120. }).exec()
  121. }, 500);
  122. this.getAdv();
  123. },
  124. methods: {
  125. // divHeight(){
  126. // return 'height:calc(100% - ${this.top}px);'
  127. // },
  128. pullDownRefresh(){
  129. // 下拉
  130. this.triggered = true; //下拉了状态为true
  131. setTimeout(() => {
  132. this.triggered = false;
  133. uni.stopPullDownRefresh()
  134. this.page.num= 1;
  135. this.getproduct('refresh') //触底 不穿执行else
  136. // 请求接口里面需要判断是不是最后一页 是最后一页 status赋值为‘loadmore’没有更多了
  137. // 请求接口
  138. }, 1000)
  139. },
  140. reachBottom(){
  141. //上拉
  142. // status这个是加载状态
  143. if (this.status === 'loadmore') {
  144. this.status = 'loading'
  145. uni.showNavigationBarLoading()
  146. setTimeout(() => {
  147. this.page.num++
  148. this.getproduct() //触底 不穿执行else
  149. uni.hideNavigationBarLoading()
  150. }, 1000);
  151. }
  152. },
  153. toSearch() {
  154. uni.navigateTo({
  155. url: '../home/productSearch'
  156. })
  157. },
  158. handleAdvClick(item) {
  159. console.log(item);
  160. if (item.showType == 1) {
  161. uni.setStorageSync('url', item.advUrl);
  162. uni.navigateTo({
  163. url: "../home/h5"
  164. })
  165. } else if (item.showType == 2) {
  166. uni.navigateTo({
  167. url: item.advUrl
  168. })
  169. } else if (item.showType == 3) {
  170. uni.setStorageSync('content', item.content);
  171. uni.navigateTo({
  172. url: "../home/content"
  173. })
  174. }
  175. },
  176. getAdv() {
  177. let data = {
  178. advType: 2
  179. };
  180. getAdv(data).then(
  181. res => {
  182. if (res.code == 200) {
  183. this.advs = res.data;
  184. }
  185. },
  186. rej => {}
  187. );
  188. },
  189. getProductCate() {
  190. let data = {
  191. isDrug:this.isDrug
  192. };
  193. getProductCate(data).then(
  194. res => {
  195. if (res.code == 200) {
  196. this.allCates = res.data;
  197. this.cates = this.allCates.filter(function(item) {
  198. return item.pid == 0
  199. });
  200. console.log(this.allCates,111)
  201. console.log(this.cates)
  202. if (this.cates != null && this.cates.length > 0) {
  203. this.cateSelect = this.cates[0].cateId;
  204. this.getSubCate()
  205. }
  206. } else {
  207. uni.showToast({
  208. icon: 'none',
  209. title: "请求失败",
  210. });
  211. }
  212. },
  213. rej => {}
  214. );
  215. },
  216. // 商品分类选择
  217. choseCate(item) {
  218. this.page.num=1
  219. this.subCates=[]
  220. this.cateSelect = item.cateId;
  221. console.log(item)
  222. this.titname=item.cateName
  223. // this.getSubCate()
  224. this.getproduct()
  225. },
  226. getproduct(type){
  227. var data = {
  228. cateId:this.cateSelect,
  229. defaultOrder:this.defaultOrder,
  230. page: this.page.num,
  231. pageSize: this.page.size,
  232. productName: "",
  233. storeId: "",
  234. isDrug:this.isDrug
  235. };
  236. getProducts(data).then(res=>{
  237. if(res.code==200){
  238. console.log(res)
  239. if (type == 'refresh') {
  240. this.subCates=res.data.list
  241. } else {
  242. // 加载更多 当前页和下一页合并
  243. this.subCates = [...this.subCates, ...res.data.list]
  244. }
  245. if (this.page.num >= res.data.pages) {
  246. //是否有下一页
  247. this.status = 'nomore'
  248. } else {
  249. this.status = 'loadmore'
  250. }
  251. }
  252. })
  253. },
  254. getSubCate() {
  255. var that = this;
  256. // this.subCates = this.allCates.filter(function(item) {
  257. // let subList = that.allCates.filter(child => {
  258. // //返回每一项的子级数组
  259. // return child.pid === item.cateId
  260. // });
  261. // subList.length > 0 ? item.children = subList : [];
  262. // return item.pid == that.cateSelect
  263. // });
  264. // this.getProductCate()
  265. console.log(this.subCates);
  266. },
  267. // 查看商品详情
  268. showProductList(item) {
  269. uni.navigateTo({
  270. // url: './productList?cateId=' + item.cateId + "&pid=" + 0
  271. url: '/pages/shopping/productDetails?productId=' + item.productId
  272. })
  273. },
  274. goSearch(e) {
  275. if (e.detail.value != null && e.detail.value != "") {
  276. this.utils.addHisSearch(e.detail.value);
  277. }
  278. uni.navigateTo({
  279. url: '../home/productList?searchValue=' + e.detail.value
  280. })
  281. }
  282. }
  283. }
  284. </script>
  285. <style lang="scss">
  286. page {
  287. height: 100%;
  288. background-color: #fff;
  289. }
  290. .content {
  291. height: 100%;
  292. display: flex;
  293. flex-direction: column;
  294. .top-content {
  295. width: 100%;
  296. z-index: 10;
  297. .top-title {
  298. height: 88upx;
  299. line-height: 88upx;
  300. font-size: 42upx;
  301. font-family: Source Han Sans CN;
  302. font-weight: bold;
  303. color: #222222;
  304. padding-left: 41upx;
  305. background-color: #FFFFFF;
  306. }
  307. .search-cont {
  308. padding: 16upx 30upx;
  309. background-color: #FFFFFF;
  310. .inner {
  311. box-sizing: border-box;
  312. width: 100%;
  313. height: 72upx;
  314. background: #F7F7F7;
  315. border-radius: 36upx;
  316. display: flex;
  317. align-items: center;
  318. padding: 0 30upx;
  319. .icon-search {
  320. width: 28upx;
  321. height: 28upx;
  322. margin-right: 20upx;
  323. }
  324. input {
  325. height: 60upx;
  326. line-height: 60upx;
  327. flex: 1;
  328. }
  329. }
  330. }
  331. }
  332. .medic-box {
  333. display: flex;
  334. .cate-list {
  335. box-sizing: border-box;
  336. width: 200upx;
  337. background: #F2F5F9;
  338. display: flex;
  339. flex-direction: column;
  340. padding: 20upx 0;
  341. overflow-y: scroll;
  342. .item {
  343. height: 100upx;
  344. line-height: 100upx;
  345. padding-left: 30upx;
  346. font-size: 28upx;
  347. font-family: PingFang SC;
  348. font-weight: 500;
  349. color: #333333;
  350. position: relative;
  351. &.active {
  352. color: #4C49E9;
  353. &::after {
  354. content: "";
  355. width: 8upx;
  356. height: 50upx;
  357. background: #4C49E9;
  358. position: absolute;
  359. top: 25upx;
  360. left: 0;
  361. }
  362. }
  363. }
  364. }
  365. .medic {
  366. box-sizing: border-box;
  367. width: calc(100% - 200upx);
  368. height: 100%;
  369. padding: 0 30upx;
  370. .banner-box {
  371. margin-top: 30rpx;
  372. width: 100%;
  373. height: 160upx;
  374. border-radius: 10upx;
  375. overflow: hidden;
  376. .swiper,
  377. .swiper-item,
  378. .swiper-item image {
  379. width: 100%;
  380. height: 100%;
  381. }
  382. }
  383. .medic-list {
  384. box-sizing: border-box;
  385. padding: 30upx 0;
  386. overflow-y: auto;
  387. // height: calc(100% - 100upx);
  388. height: 100%;
  389. position: relative;
  390. // .item{
  391. // .title{
  392. // font-size: 28upx;
  393. // font-family: PingFang SC;
  394. // font-weight: bold;
  395. // color: #333333;
  396. // padding-top: 20upx;
  397. // margin-bottom: 30upx;
  398. // }
  399. // }
  400. .inner-list {
  401. display: flex;
  402. flex-wrap: wrap;
  403. .definite {
  404. width: calc(50% - 30upx);
  405. margin-right: 30upx;
  406. margin-bottom: 30upx;
  407. .img-box {
  408. width: 100%;
  409. height: 220upx;
  410. background: #F5F5F5;
  411. border-radius: 8upx;
  412. overflow: hidden;
  413. display: flex;
  414. align-items: center;
  415. image {
  416. max-width: 100%;
  417. }
  418. }
  419. .name {
  420. width: 100%;
  421. margin-top: 20upx;
  422. font-size: 24upx;
  423. font-family: PingFang SC;
  424. font-weight: 500;
  425. color: #666666;
  426. text-align: center;
  427. }
  428. &:nth-child(2n) {
  429. margin-right: 0;
  430. }
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }
  437. </style>