index.vue 8.1 KB

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