index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. <template>
  2. <view class="content">
  3. <view class="top-content">
  4. <image class="bg" src="/static/images/classification-bg.png"></image>
  5. <view class="status_bar" :style="{height: statusBarHeight}"></view>
  6. <!-- 这里是状态栏 -->
  7. <!-- <view class="top-title">健康商城</view> -->
  8. <!-- 搜索框 -->
  9. <view class="search-cont">
  10. <image class="back" src="../../static/images/back_black.png" mode=""></image>
  11. <view class="inner">
  12. <image class="icon-search" src="../../static/images/search.png" mode=""></image>
  13. <input type="text" disabled confirm-type="搜索" @click="toSearch" placeholder="搜索您喜欢的商品"
  14. placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  15. </view>
  16. </view>
  17. <!-- 栏目 -->
  18. <view class="column-box" :class="isExpand?'column-box2':''">
  19. <!-- <view class="column-list" :class="isExpand?'column-list2':''">
  20. <view class="item" v-for="(item,index) in columnList" :key="index" @click="selectColumn(item)">
  21. <view class="img-item" :class="index===activeIndex?'active':''">
  22. <image class="img" src="../../static/images/img.png" mode=""></image>
  23. </view>
  24. <view class="name" :class="index===activeIndex?'active':''">{{item.name}}</view>
  25. </view>
  26. </view> -->
  27. <scroll-view class="column-list-scroll" :class="isExpand?'column-list2':''" scroll-x="true"
  28. :scroll-with-animation="true" :show-scrollbar="false" :enable-flex="true">
  29. <view class="column-list" :class="isExpand?'column-list2':''">
  30. <view class="item" v-for="(item,index) in columnList" :key="index" @click="selectColumn(item)">
  31. <view class="img-item" :class="index===activeIndex?'active':''">
  32. <image class="img" src="../../static/images/img.png" mode=""></image>
  33. </view>
  34. <view class="name" :class="index===activeIndex?'active':''">{{item.name}}</view>
  35. </view>
  36. </view>
  37. </scroll-view>
  38. <view class="expand" @click="expand" :class="{'expand2': isExpand}">
  39. <view>{{isExpand ? '收起' : '展开'}}</view>
  40. <image class="expand-icon"
  41. :src="isExpand ? '../../static/images/retract.png' : '../../static/images/expand.png'" mode="">
  42. </image>
  43. </view>
  44. </view>
  45. </view>
  46. <view :style="{height: divHeight}" class="medic-box">
  47. <view class="cate-list">
  48. <view v-for="(item,index) in cates" :key="index" :class="cateSelect == item.cateId?'item active':'item'"
  49. @click="choseCate(item)">
  50. <image class="line" v-if="cateSelect == item.cateId" src="/static/images/select_hover_line.png"
  51. mode=""></image>
  52. {{item.cateName }}
  53. </view>
  54. </view>
  55. <view class="medic">
  56. <view class="tab-inner">
  57. <view v-for="(item,index) in selectList" :key="index"
  58. :class="selectIndex == item.value?'item active':'item'" @click="onSelect(item)">
  59. <view class="text">
  60. <text>{{ item.name }}</text>
  61. <image v-if="item.value==2" class="tab-bg" :src=`/static/images/shaixuan_moren${number}.png` mode="">
  62. </image>
  63. </view>
  64. </view>
  65. <view class="icon-search">
  66. <image @click="showChange(2)" v-if="showType==1" src="../../static/images/demonstrations1.png"
  67. mode="">
  68. </image>
  69. <image @click="showChange(1)" v-if="showType==2" src="../../static/images/demonstrations2.png"
  70. mode="">
  71. </image>
  72. <view class="filter">
  73. <text>筛选</text>
  74. <image class="ml8" @click="toFilter" src="../../static/images/filter_icon.png" mode="">
  75. </view>
  76. </view>
  77. </view>
  78. <view class="medic-list">
  79. <view v-for="(item,index) in dataList" :key="index" class="item" @click="showDetail(item)">
  80. <view class="img-box">
  81. <image :src="item.image" mode="aspectFit"></image>
  82. </view>
  83. <view class="info-box">
  84. <view class="title ellipsis2">{{item.productName}}</view>
  85. <view class="intro ellipsis">{{item.productInfo}}</view>
  86. <view class="sale">已售 {{item.sales}} {{item.unitName}} | 惊艳度98%</view>
  87. <view class="lable-group">
  88. <view class="lable-item">9.5折</view>
  89. <view class="lable-item">限购1份</view>
  90. </view>
  91. <view class="prce-num">
  92. <view class="price">
  93. <text class="unit">¥</text><text
  94. class="bold">{{splitPrice(item.price).integer}}</text>.{{splitPrice(item.price).decimal}}
  95. </view>
  96. <view class="cart-img" @click="navgetTo('../shopping/cart')">
  97. <image class="w40 h40" src="/static/images/add_car.png"></image>
  98. </view>
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. <!-- 轮播图 -->
  104. <!-- <view class="banner-box">
  105. <swiper class="swiper" :indicator-dots="true" :circular="true" :autoplay="true" :interval="3000"
  106. :duration="1000" indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#ffffff">
  107. <swiper-item class="swiper-item" v-for="(item,index) in advs" :key="index"
  108. @click="handleAdvClick(item)">
  109. <image :src="item.imageUrl" mode=""></image>
  110. </swiper-item>
  111. </swiper>
  112. </view> -->
  113. <!-- 药品列表 -->
  114. <!-- <view class="medic-list">
  115. <view class="inner-list">
  116. <view class="definite" v-for="(subItem,index) in subCates" @click="showProductList(subItem)">
  117. <view class="img-box">
  118. <image :src="subItem.pic" mode="aspectFit"></image>
  119. </view>
  120. <view class="name ellipsis">{{subItem.cateName}}</view>
  121. </view>
  122. </view>
  123. </view> -->
  124. </view>
  125. </view>
  126. </view>
  127. </template>
  128. <script>
  129. import {
  130. getProductCate
  131. } from '@/api/product'
  132. import {
  133. getAdv
  134. } from '@/api/adv'
  135. export default {
  136. data() {
  137. return {
  138. number:0,
  139. selectIndex: 0,
  140. selectList: [{
  141. name: '综合',
  142. value: 0
  143. }, {
  144. name: '销量',
  145. value: 1
  146. }, {
  147. name: '价格',
  148. value: 2
  149. }, {
  150. name: '惊艳度',
  151. value: 3
  152. }],
  153. isExpand: false, //是否展开
  154. activeIndex: 0,
  155. columnList: [{
  156. name: "中秋佳礼",
  157. img: "/static/images/img.png",
  158. value: 0
  159. }, {
  160. name: "中秋佳礼",
  161. img: "/static/images/img.png",
  162. value: 1
  163. }, {
  164. name: "中秋佳礼",
  165. img: "/static/images/img.png",
  166. value: 2
  167. }, {
  168. name: "中秋佳礼",
  169. img: "/static/images/img.png",
  170. value: 3
  171. }, {
  172. name: "中秋佳礼",
  173. img: "/static/images/img.png",
  174. value: 4
  175. }, {
  176. name: "中秋佳礼",
  177. img: "/static/images/img.png",
  178. value: 5
  179. }, {
  180. name: "中秋佳礼",
  181. img: "/static/images/img.png",
  182. value: 6
  183. }, {
  184. name: "中秋佳礼",
  185. img: "/static/images/img.png",
  186. value: 7
  187. }],
  188. dataList: [{
  189. cateId: 364,
  190. image: "https://hos-1309931967.cos.ap-chongqing.myqcloud.com/fs/20251216/6a3c96bd3fc44b15b760871670302e9a.jpg",
  191. otPrice: 268,
  192. price: 98,
  193. productId: 66050,
  194. productInfo: "电肌肉刺激(EMS),又称神经肌肉电刺激,是利用电脉冲诱发多发性肌肉收缩;中枢神经系统使肌肉收缩;EMS被证明是一种积极的肌肉强化工具。↵EMS的用途:肌肉强化,预防废肌萎缩,肌肉松弛,缓解酸痛,放松肌肉,美容肌肉调理。",
  195. productName: "佟络宝®健步器",
  196. sales: 1026,
  197. unitName: "个",
  198. warehouseCode: "JST001",
  199. warehouseId: 3,
  200. }, {
  201. cateId: 364,
  202. image: "https://hos-1309931967.cos.ap-chongqing.myqcloud.com/fs/20251204/c53bb29cf794468ba59ee2d60983b92f.jpg",
  203. otPrice: 298,
  204. price: 138,
  205. productId: 65920,
  206. productInfo: "1、取本品1包放入脚盆,倒入适量沸水浸泡搅拌,约5-10分钟,再加入适量温水或冷水调至适宜水温即可足浴,泡脚15- 25分钟。↵2、取本品1包放入锅内煮约5分钟,将煮好的水倒入脚盆,再加入适量温水或冷水调至适宜温度即可足浴,泡脚15-25分钟。",
  207. productName: "[九仙汤]除痹通络汤 30克x30包",
  208. sales: 6042,
  209. unitName: "盒",
  210. warehouseCode: "JST001",
  211. warehouseId: 3,
  212. }],
  213. divHeight: '0px',
  214. allCates: [],
  215. cates: [],
  216. subCates: [],
  217. // 状态栏的高度
  218. statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
  219. // 选中药品分类
  220. cateSelect: 0,
  221. // 轮播图
  222. advs: [],
  223. };
  224. },
  225. onLoad() {
  226. uni.showShareMenu({
  227. withShareTicket: true,
  228. //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  229. menus: ["shareAppMessage", "shareTimeline"] //不设置默认发送给朋友
  230. })
  231. this.getProductCate();
  232. },
  233. onShow() {
  234. var that = this;
  235. setTimeout(function() {
  236. let info = uni.createSelectorQuery().select(".top-content");
  237. info.boundingClientRect(function(data) { //data - 各种参数
  238. console.log(data.height) // 获取元素宽度
  239. // console.log(uni.rpx2px(10))
  240. that.divHeight = "calc(100% - " + data.height + "px)"
  241. }).exec()
  242. }, 500);
  243. this.getAdv();
  244. },
  245. methods: {
  246. onSelect(item) {
  247. console.log("item", item)
  248. this.selectIndex = item.value
  249. if(item.value==2){
  250. if(number<2){
  251. this.number++
  252. }else{
  253. this.number=0
  254. }
  255. }
  256. },
  257. splitPrice(price) {
  258. const priceStr = parseFloat(price).toFixed(2).toString();
  259. return {
  260. integer: priceStr.split('.')[0],
  261. decimal: priceStr.split('.')[1]
  262. };
  263. },
  264. // 展开
  265. expand() {
  266. this.isExpand = !this.isExpand;
  267. },
  268. // 选择栏目
  269. selectColumn(item) {
  270. console.log("打印item", item.value);
  271. this.activeIndex = item.value;
  272. },
  273. // divHeight() {
  274. // return 'height:calc(100% - ${this.top}px);'
  275. // },
  276. toSearch() {
  277. uni.navigateTo({
  278. url: '../home/productSearch'
  279. })
  280. },
  281. handleAdvClick(item) {
  282. console.log(item);
  283. if (item.showType == 1) {
  284. uni.setStorageSync('url', item.advUrl);
  285. uni.navigateTo({
  286. url: "../home/h5"
  287. })
  288. } else if (item.showType == 2) {
  289. uni.navigateTo({
  290. url: item.advUrl
  291. })
  292. } else if (item.showType == 3) {
  293. uni.setStorageSync('content', item.content);
  294. uni.navigateTo({
  295. url: "../home/content"
  296. })
  297. }
  298. },
  299. getAdv() {
  300. let data = {
  301. advType: 2
  302. };
  303. getAdv(data).then(
  304. res => {
  305. if (res.code == 200) {
  306. this.advs = res.data;
  307. }
  308. },
  309. rej => {}
  310. );
  311. },
  312. getProductCate() {
  313. let data = {};
  314. getProductCate(data).then(
  315. res => {
  316. if (res.code == 200) {
  317. this.allCates = res.data;
  318. this.cates = this.allCates.filter(function(item) {
  319. return item.pid == 0
  320. });
  321. if (this.cates != null && this.cates.length > 0) {
  322. this.cateSelect = this.cates[0].cateId;
  323. this.getSubCate()
  324. }
  325. } else {
  326. uni.showToast({
  327. icon: 'none',
  328. title: "请求失败",
  329. });
  330. }
  331. },
  332. rej => {}
  333. );
  334. },
  335. // 药品分类选择
  336. choseCate(item) {
  337. this.cateSelect = item.cateId;
  338. this.getSubCate()
  339. },
  340. getSubCate() {
  341. var that = this;
  342. this.subCates = this.allCates.filter(function(item) {
  343. // let subList = that.allCates.filter(child => {
  344. // //返回每一项的子级数组
  345. // return child.pid === item.cateId
  346. // });
  347. // subList.length > 0 ? item.children = subList : [];
  348. return item.pid == that.cateSelect
  349. });
  350. console.log(this.subCates);
  351. },
  352. // 查看药品详情
  353. showProductList(item) {
  354. uni.navigateTo({
  355. url: '/pages_shopping/shopping/productList?cateId=' + item.cateId + "&pid=" + item.pid
  356. })
  357. },
  358. goSearch(e) {
  359. if (e.detail.value != null && e.detail.value != "") {
  360. this.utils.addHisSearch(e.detail.value);
  361. }
  362. uni.navigateTo({
  363. url: '../home/productList?searchValue=' + e.detail.value
  364. })
  365. }
  366. }
  367. }
  368. </script>
  369. <style lang="scss">
  370. page {
  371. height: 100%;
  372. background-color: #fff;
  373. }
  374. .content {
  375. height: 100%;
  376. display: flex;
  377. flex-direction: column;
  378. .top-content {
  379. background: linear-gradient(180deg, #E1FAEF 0%, #FFFFFF 100%);
  380. box-shadow: 0rpx 6rpx 8rpx 0rpx rgba(187, 187, 187, 0.15);
  381. width: 100%;
  382. z-index: 10;
  383. position: relative;
  384. .bg {
  385. position: absolute;
  386. top: 0;
  387. z-index: -1;
  388. width: 100%;
  389. height: 372rpx;
  390. }
  391. .top-title {
  392. height: 88rpx;
  393. line-height: 88rpx;
  394. font-size: 42rpx;
  395. font-family: Source Han Sans CN;
  396. font-weight: bold;
  397. color: #222222;
  398. padding-left: 41rpx;
  399. background-color: #FFFFFF;
  400. }
  401. .search-cont {
  402. display: flex;
  403. padding: 6rpx 30rpx;
  404. .back {
  405. width: 64rpx;
  406. height: 64rpx;
  407. }
  408. .inner {
  409. box-sizing: border-box;
  410. width: 436rpx;
  411. height: 64rpx;
  412. background: #ffffff;
  413. border-radius: 32rpx;
  414. display: flex;
  415. align-items: center;
  416. padding: 0 24rpx;
  417. .icon-search {
  418. width: 28rpx;
  419. height: 28rpx;
  420. margin-left: 42rpx;
  421. }
  422. input {
  423. height: 60rpx;
  424. line-height: 60rpx;
  425. flex: 1;
  426. }
  427. }
  428. }
  429. .column-box {
  430. display: flex;
  431. padding-left: 16rpx;
  432. margin: 16rpx 0 24rpx;
  433. &.column-box2 {
  434. display: flex;
  435. flex-direction: column;
  436. }
  437. .column-list-scroll {
  438. flex: 1;
  439. overflow: hidden;
  440. white-space: nowrap;
  441. &.column-list2 {
  442. flex-wrap: wrap;
  443. height: auto;
  444. }
  445. .column-list {
  446. display: inline-flex; // 改为行内flex
  447. align-items: center;
  448. padding-bottom: 10rpx; // 增加底部padding,防止滚动条遮挡
  449. &.column-list2 {
  450. display: flex;
  451. flex-wrap: wrap;
  452. width: 100%;
  453. }
  454. .item {
  455. display: inline-flex; // 改为行内flex
  456. flex-direction: column;
  457. align-items: center;
  458. margin-right: 16rpx;
  459. margin-bottom: 20rpx;
  460. flex-shrink: 0; // 防止收缩
  461. .img-item {
  462. width: 88rpx;
  463. height: 88rpx;
  464. flex-shrink: 0;
  465. &.active {
  466. border: 3rpx solid #02B176;
  467. box-sizing: border-box;
  468. border-radius: 44rpx;
  469. }
  470. .img {
  471. width: 100%;
  472. height: 100%;
  473. border-radius: 44rpx;
  474. }
  475. }
  476. .name {
  477. width: 128rpx;
  478. height: 44rpx;
  479. font-size: 24rpx;
  480. color: #333333;
  481. text-align: center;
  482. line-height: 44rpx;
  483. margin-top: 16rpx;
  484. white-space: nowrap;
  485. overflow: hidden;
  486. text-overflow: ellipsis;
  487. &.active {
  488. font-weight: 500;
  489. color: #FFFFFF;
  490. background: #02B176;
  491. border-radius: 22rpx;
  492. }
  493. }
  494. }
  495. }
  496. }
  497. .expand {
  498. margin: 0 20rpx;
  499. font-size: 24rpx;
  500. color: #000000;
  501. width: 24rpx;
  502. display: flex;
  503. flex-direction: column;
  504. align-items: center;
  505. flex-shrink: 0; // 防止收缩
  506. .expand-icon {
  507. width: 24rpx;
  508. height: 24rpx;
  509. margin-top: 6rpx;
  510. }
  511. }
  512. .expand2 {
  513. margin-top: 8rpx;
  514. width: 100%;
  515. justify-content: center;
  516. flex-direction: row;
  517. align-items: center;
  518. .expand-icon {
  519. margin-left: 12rpx;
  520. }
  521. }
  522. }
  523. }
  524. .medic-box {
  525. display: flex;
  526. .cate-list {
  527. box-sizing: border-box;
  528. width: 200rpx;
  529. background: #F5F7FA;
  530. display: flex;
  531. flex-direction: column;
  532. padding: 20rpx 0;
  533. overflow-y: scroll;
  534. position: relative;
  535. .line {
  536. position: absolute;
  537. left: 0;
  538. top: 50%;
  539. transform: translateY(-50%);
  540. width: 6rpx;
  541. height: 28rpx;
  542. }
  543. .item {
  544. height: 112rpx;
  545. line-height: 112rpx;
  546. padding-left: 28rpx;
  547. font-size: 28rpx;
  548. font-family: PingFang SC;
  549. color: #666666;
  550. position: relative;
  551. &.active {
  552. color: #02B176;
  553. background: #FFFFFF;
  554. font-weight: 500;
  555. }
  556. }
  557. }
  558. .medic {
  559. box-sizing: border-box;
  560. width: calc(100% - 200rpx);
  561. height: 100%;
  562. .tab-inner {
  563. height: 88upx;
  564. line-height: 88upx;
  565. display: flex;
  566. overflow-x: auto;
  567. align-items: center;
  568. font-size: 26rpx;
  569. color: #666666;
  570. margin-left: 24rpx;
  571. .item {
  572. font-size: 24rpx;
  573. white-space: nowrap;
  574. line-height: 1;
  575. font-family: PingFang SC;
  576. background: #F5F7FA;
  577. border-radius: 8rpx 8rpx 8rpx 8rpx;
  578. padding: 12rpx 12rpx 10rpx;
  579. margin-right: 20upx;
  580. display: flex;
  581. align-items: center;
  582. justify-content: center;
  583. &:last-child {
  584. margin-right: 0;
  585. }
  586. &.active {
  587. font-weight: 600;
  588. color: #02B176;
  589. background: #EBFAF6;
  590. }
  591. .text {
  592. position: relative;
  593. z-index: 1;
  594. display: flex;
  595. align-items: center;
  596. }
  597. .tab-bg {
  598. width: 24upx;
  599. height: 24upx;
  600. margin-left: 8rpx;
  601. }
  602. }
  603. .icon-search {
  604. display: flex;
  605. align-items: center;
  606. image {
  607. width: 32upx;
  608. height: 32upx;
  609. }
  610. .filter {
  611. display: flex;
  612. align-items: center;
  613. }
  614. }
  615. }
  616. .medic-list {
  617. .item {
  618. box-sizing: border-box;
  619. min-height: 296upx;
  620. background: #FFFFFF;
  621. border: 4upx solid #FFFFFF;
  622. border-radius: 16upx;
  623. margin-bottom: 18upx;
  624. padding: 24rpx;
  625. display: flex;
  626. .img-box {
  627. flex-shrink: 0;
  628. width: 188rpx;
  629. height: 188rpx;
  630. margin-right: 20upx;
  631. border-radius: 16upx;
  632. overflow: hidden;
  633. image {
  634. width: 100%;
  635. height: 100%;
  636. }
  637. }
  638. .info-box {
  639. flex: 1;
  640. min-width: 0;
  641. .title {
  642. font-size: 28upx;
  643. font-family: PingFang SC;
  644. font-weight: 500;
  645. color: #333333;
  646. margin-bottom: 4rpx;
  647. }
  648. .intro {
  649. font-weight: 400;
  650. font-size: 22rpx;
  651. color: #D46C0D;
  652. margin-bottom: 8upx;
  653. }
  654. .sale {
  655. font-size: 21rpx;
  656. color: #999999;
  657. }
  658. .lable-group {
  659. display: flex;
  660. margin-top: 8rpx;
  661. .lable-item {
  662. margin-right: 8rpx;
  663. height: 30rpx;
  664. padding: 0 8rpx;
  665. border-radius: 4rpx 4rpx 4rpx 4rpx;
  666. border: 1rpx solid #FFA599;
  667. font-size: 21rpx;
  668. color: #FF4B33;
  669. }
  670. }
  671. .prce-num {
  672. display: flex;
  673. align-items: center;
  674. justify-content: space-between;
  675. margin-top: 8upx;
  676. .price {
  677. font-weight: 600;
  678. font-size: 26rpx;
  679. color: #FA341E;
  680. font-size: 26rpx;
  681. .unit {
  682. font-size: 20upx;
  683. }
  684. .bold {
  685. font-size: 36upx;
  686. }
  687. }
  688. }
  689. }
  690. }
  691. }
  692. }
  693. }
  694. }
  695. </style>