index.vue 9.5 KB

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