index.vue 8.3 KB

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