index.vue 8.4 KB

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