index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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="https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/search.png" mode=""></image>
  11. <input type="text" disabled confirm-type="搜索" @click="toSearch" placeholder="输入药品名称" placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  12. </view>
  13. </view>
  14. </view>
  15. <view :style="{height: divHeight}" class="medic-box">
  16. <view class="cate-list">
  17. <view
  18. v-for="(item,index) in cates"
  19. :key="index"
  20. :class="cateSelect == item.cateId?'item active':'item'"
  21. @click="choseCate(item)"
  22. >{{item.cateName }}</view>
  23. </view>
  24. <view class="medic">
  25. <!-- 轮播图 -->
  26. <view class="banner-box">
  27. <swiper
  28. class="swiper"
  29. :indicator-dots="true"
  30. :circular="true"
  31. :autoplay="true"
  32. :interval="3000"
  33. :duration="1000"
  34. indicator-color="rgba(255, 255, 255, 0.6)"
  35. indicator-active-color="#ffffff">
  36. <swiper-item class="swiper-item" v-for="(item,index) in advs" :key="index" @click="handleAdvClick(item)">
  37. <image :src="item.imageUrl" mode=""></image>
  38. </swiper-item>
  39. </swiper>
  40. </view>
  41. <!-- 药品列表 -->
  42. <view class="medic-list">
  43. <!-- <view class="item" v-for="(item,index) in subCates" :key="index">
  44. <view class="title">{{item.cateName}}</view> -->
  45. <view class="inner-list">
  46. <view class="definite"v-for="(subItem,index) in subCates" @click="showProductList(subItem)">
  47. <view class="img-box">
  48. <image :src="subItem.pic" mode="aspectFit"></image>
  49. </view>
  50. <view class="name ellipsis">{{subItem.cateName}}</view>
  51. </view>
  52. </view>
  53. <!-- </view> -->
  54. </view>
  55. </view>
  56. </view>
  57. <!-- <tabbar :actindex="3"></tabbar> -->
  58. </view>
  59. </template>
  60. <script>
  61. import {getProductCate} from '@/api/product'
  62. import {getAdv} from '@/api/adv'
  63. export default {
  64. data() {
  65. return {
  66. divHeight:'0px',
  67. allCates:[],
  68. cates:[],
  69. subCates:[],
  70. // 状态栏的高度
  71. statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
  72. // 选中药品分类
  73. cateSelect: 0,
  74. // 轮播图
  75. advs: [],
  76. isshow:false
  77. };
  78. },
  79. onLoad() {
  80. uni.showShareMenu({
  81. withShareTicket:true,
  82. //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  83. menus:["shareAppMessage","shareTimeline"] //不设置默认发送给朋友
  84. })
  85. this.getProductCate();
  86. },
  87. onShow() {
  88. var that=this;
  89. setTimeout(function(){
  90. let info = uni.createSelectorQuery().select(".top-content");
  91.     info.boundingClientRect(function(data) { //data - 各种参数
  92. //       console.log(data.height) // 获取元素宽度
  93. // console.log(uni.upx2px(10))
  94. that.divHeight="calc(100% - "+data.height+"px)"
  95.    }).exec()
  96. },500);
  97. this.getAdv();
  98. },
  99. methods:{
  100. divHeight1(){
  101. return 'height:calc(100% - ${this.top}px);'
  102. },
  103. toSearch() {
  104. uni.navigateTo({
  105. url: '../home/productSearch'
  106. })
  107. },
  108. handleAdvClick(item){
  109. console.log(item);
  110. if(item.showType==1){
  111. uni.setStorageSync('url',item.advUrl);
  112. uni.navigateTo({
  113. url:"../home/h5"
  114. })
  115. }
  116. else if(item.showType==2){
  117. uni.navigateTo({
  118. url:item.advUrl
  119. })
  120. }
  121. else if(item.showType==3){
  122. uni.setStorageSync('content',item.content);
  123. uni.navigateTo({
  124. url:"../home/content"
  125. })
  126. }
  127. },
  128. getAdv(){
  129. let data = {advType:2};
  130. getAdv(data).then(
  131. res => {
  132. if(res.code==200){
  133. this.advs=res.data;
  134. }
  135. },
  136. rej => {}
  137. );
  138. },
  139. getProductCate(){
  140. let data = {};
  141. getProductCate(data).then(
  142. res => {
  143. if(res.code==200){
  144. this.allCates=res.data;
  145. this.cates = this.allCates.filter(function (item) {
  146. return item.pid==0
  147. });
  148. if(this.cates!=null&&this.cates.length>0){
  149. this.cateSelect=this.cates[0].cateId;
  150. this.getSubCate()
  151. }
  152. }else{
  153. uni.showToast({
  154. icon:'none',
  155. title: "请求失败",
  156. });
  157. }
  158. },
  159. rej => {}
  160. );
  161. },
  162. // 药品分类选择
  163. choseCate(item) {
  164. this.cateSelect = item.cateId;
  165. this.getSubCate()
  166. },
  167. getSubCate(){
  168. var that=this;
  169. this.subCates = this.allCates.filter(function (item) {
  170. // let subList = that.allCates.filter(child => {
  171. // //返回每一项的子级数组
  172. // return child.pid === item.cateId
  173. // });
  174. // subList.length > 0 ? item.children = subList : [];
  175. return item.pid==that.cateSelect
  176. });
  177. console.log(this.subCates);
  178. },
  179. // 查看药品详情
  180. showProductList(item) {
  181. uni.navigateTo({
  182. url: '/pages_shopping/shopping/productList?cateId='+item.cateId+"&pid="+item.pid
  183. })
  184. },
  185. goSearch(e) {
  186. if(e.detail.value!=null&&e.detail.value!=""){
  187. this.utils.addHisSearch(e.detail.value);
  188. }
  189. uni.navigateTo({
  190. url: '../home/productList?searchValue=' + e.detail.value
  191. })
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="scss">
  197. page{
  198. height: 100%;
  199. background-color: #fff;
  200. }
  201. .content{
  202. height: 100%;
  203. display: flex;
  204. flex-direction: column;
  205. .top-content{
  206. width: 100%;
  207. z-index: 10;
  208. .top-title{
  209. height: 88upx;
  210. line-height: 88upx;
  211. font-size: 42upx;
  212. font-family: Source Han Sans CN;
  213. font-weight: bold;
  214. color: #222222;
  215. padding-left: 41upx;
  216. background-color: #FFFFFF;
  217. }
  218. .search-cont{
  219. padding: 16upx 30upx;
  220. background-color: #FFFFFF;
  221. .inner{
  222. box-sizing: border-box;
  223. width: 100%;
  224. height: 72upx;
  225. background: #F7F7F7;
  226. border-radius: 36upx;
  227. display: flex;
  228. align-items: center;
  229. padding: 0 30upx;
  230. .icon-search{
  231. width: 28upx;
  232. height: 28upx;
  233. margin-right: 20upx;
  234. }
  235. input{
  236. height: 60upx;
  237. line-height: 60upx;
  238. flex: 1;
  239. }
  240. }
  241. }
  242. }
  243. .medic-box{
  244. display: flex;
  245. .cate-list{
  246. box-sizing: border-box;
  247. width: 200upx;
  248. background: #F2F5F9;
  249. display: flex;
  250. flex-direction: column;
  251. padding: 20upx 0;
  252. overflow-y: scroll;
  253. .item{
  254. height: 100upx;
  255. line-height: 100upx;
  256. padding-left: 30upx;
  257. font-size: 28upx;
  258. font-family: PingFang SC;
  259. font-weight: 500;
  260. color: #333333;
  261. position: relative;
  262. &.active{
  263. color: #2BC7B9;
  264. &::after{
  265. content: "";
  266. width: 8upx;
  267. height: 50upx;
  268. background: #2BC7B9;
  269. position: absolute;
  270. top: 25upx;
  271. left: 0;
  272. }
  273. }
  274. }
  275. }
  276. .medic{
  277. box-sizing: border-box;
  278. width: calc(100% - 200upx);
  279. height: 100%;
  280. padding: 0 30upx;
  281. .banner-box{
  282. margin-top: 30rpx;
  283. width: 100%;
  284. height: 160upx;
  285. border-radius: 10upx;
  286. overflow: hidden;
  287. .swiper,
  288. .swiper-item,
  289. .swiper-item image{
  290. width: 100%;
  291. height: 100%;
  292. }
  293. }
  294. .medic-list{
  295. box-sizing: border-box;
  296. padding: 30upx 0;
  297. overflow-y: auto;
  298. height: calc(100% - 220upx);
  299. position: relative;
  300. // .item{
  301. // .title{
  302. // font-size: 28upx;
  303. // font-family: PingFang SC;
  304. // font-weight: bold;
  305. // color: #333333;
  306. // padding-top: 20upx;
  307. // margin-bottom: 30upx;
  308. // }
  309. // }
  310. .inner-list{
  311. display: flex;
  312. flex-wrap: wrap;
  313. .definite{
  314. width: calc(33% - 20upx);
  315. margin-right: 30upx;
  316. margin-bottom: 30upx;
  317. .img-box{
  318. width: 100%;
  319. height: 144upx;
  320. background: #F5F5F5;
  321. border-radius: 8upx;
  322. overflow: hidden;
  323. display: flex;
  324. align-items: center;
  325. image{
  326. max-width: 100%;
  327. }
  328. }
  329. .name{
  330. width: 100%;
  331. margin-top: 20upx;
  332. font-size: 24upx;
  333. font-family: PingFang SC;
  334. font-weight: 500;
  335. color: #666666;
  336. text-align: center;
  337. }
  338. &:nth-child(3n) {
  339. margin-right: 0;
  340. }
  341. }
  342. }
  343. }
  344. }
  345. }
  346. }
  347. </style>