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