index.vue 8.9 KB

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