index.vue 8.5 KB

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