index.vue 18 KB

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