index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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" :style="{width:`calc(100vw - 80rpx - ${menuRight} - ${menuWidth})`}">
  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="输入药品名称"
  12. placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  13. </view>
  14. </view>
  15. </view>
  16. <view :style="{height: divHeight}" class="medic-box">
  17. <view class="cate-list">
  18. <view v-for="(item,index) in cates" :key="index" :class="cateSelect == item.cateId?'item active':'item'"
  19. @click="choseCate(item)">{{item.cateName }}
  20. </view>
  21. </view>
  22. <view class="medic">
  23. <!-- 轮播图 -->
  24. <view class="banner-box">
  25. <swiper class="swiper" :indicator-dots="true" :circular="true" :autoplay="true" :interval="3000"
  26. :duration="1000" indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#ffffff">
  27. <swiper-item class="swiper-item" v-for="(item,index) in advs" :key="index"
  28. @click="handleAdvClick(item)">
  29. <image :src="item.imageUrl" mode=""></image>
  30. </swiper-item>
  31. </swiper>
  32. </view>
  33. <view class="inner-list">
  34. <!-- <view class="definite"v-for="(subItem,index) in subCates" @click="showProductList(subItem)">
  35. <view class="img-box">
  36. <image :src="subItem.pic" mode="aspectFit"></image>
  37. </view>
  38. <view class="name ellipsis">{{subItem.cateName}}</view>
  39. </view> -->
  40. <view class="definite" v-for="(subItem,index) in subCates"
  41. @click="showProductList(subItem, index)">
  42. <view class="name ellipsis" :class="{ 'select-name': activeIndex === index }">
  43. {{subItem.cateName}}
  44. </view>
  45. </view>
  46. </view>
  47. <view class="line"></view>
  48. <!-- 药品列表 -->
  49. <view class="medic-list">
  50. <!-- <view class="item" v-for="(item,index) in subCates" :key="index">
  51. <view class="title">{{item.cateName}}</view> -->
  52. <!-- <view class="product-list">
  53. <text class="product-title"> {{ activeIndex >= 0 ? subCates[activeIndex].cateName : '' }}</text>
  54. </view> -->
  55. <!-- 数据列表 -->
  56. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  57. <view class="medic-list2">
  58. <text class="product-title"> {{ activeIndex >= 0 && subCates.length>0?subCates[activeIndex].cateName : '' }}</text>
  59. <view v-for="(item,index) in dataList" :key="index" class="item" @click="showDetail(item)">
  60. <view class="img-box">
  61. <image :src="item.image" mode="aspectFit"></image>
  62. <view class="cf-box" v-if="item.productType==2">
  63. <view class="title">处方药</view>
  64. <view class="subTitle">请在医师指导下使用</view>
  65. </view>
  66. </view>
  67. <view class="info-box">
  68. <view class="title ellipsis2">{{item.productName}}</view>
  69. <view class="intro">
  70. <view class="intro-zk"><text>9.5折</text></view>
  71. <view class="intro-zk"><text>限购1份</text></view>
  72. </view>
  73. <view class="price-box">
  74. <view class="now">
  75. <!-- <text class="unit">¥</text> -->
  76. <text class="num">{{item.price.toFixed(2)}}</text>
  77. </view>
  78. <view class="old">¥{{item.otPrice.toFixed(2)}}</view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </mescroll-body>
  84. <!-- </view> -->
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. import {
  92. getProductCate,getProductCateByPid,getProducts
  93. } from '@/api/product'
  94. import {
  95. getAdv
  96. } from '@/api/adv'
  97. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  98. export default {
  99. mixins: [MescrollMixin],
  100. data() {
  101. return {
  102. activeIndex: 0,
  103. divHeight: '0px',
  104. allCates: [],
  105. cates: [],
  106. subCates: [],
  107. // 右侧的胶囊距离右侧屏幕距离-px
  108. menuRight: uni.getStorageSync('menuInfo').menuRight,
  109. // 右侧的胶囊宽度-px
  110. menuWidth: uni.getStorageSync('menuInfo').menuWidth,
  111. // 状态栏的高度
  112. statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
  113. // 选中药品分类
  114. cateSelect: 0,
  115. // 轮播图
  116. advs: [],
  117. dataList:[],
  118. cateId:null,
  119. pid:null,
  120. defaultOrder:'desc',
  121. storeId: "",
  122. //上拉加载的配置
  123. upOption: {
  124. onScroll:true,
  125. use: true, // 是否启用上拉加载; 默认true
  126. page: {
  127. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  128. size: 10 // 每页数据的数量,默认10
  129. },
  130. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  131. empty: {
  132. icon:'/static/images/no_data.png',
  133. tip: '暂无数据',
  134. },
  135. textNoMore:"已经到底了",
  136. }
  137. };
  138. },
  139. onLoad() {
  140. uni.showShareMenu({
  141. withShareTicket: true,
  142. //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  143. menus: ["shareAppMessage", "shareTimeline"] //不设置默认发送给朋友
  144. })
  145. this.getProductCate();
  146. },
  147. onShow() {
  148. var that = this;
  149. setTimeout(function() {
  150. let info = uni.createSelectorQuery().select(".top-content");
  151. info.boundingClientRect(function(data) { //data - 各种参数
  152. console.log(data.height) // 获取元素宽度
  153. // console.log(uni.upx2px(10))
  154. that.divHeight = "calc(100% - " + data.height + "px)"
  155. }).exec()
  156. }, 500);
  157. this.getAdv();
  158. },
  159. methods: {
  160. // divHeight(){
  161. // return 'height:calc(100% - ${this.top}px);'
  162. // },
  163. toSearch() {
  164. uni.navigateTo({
  165. url: '../home/productSearch'
  166. })
  167. },
  168. handleAdvClick(item) {
  169. console.log(item);
  170. if (item.showType == 1) {
  171. uni.setStorageSync('url', item.advUrl);
  172. uni.navigateTo({
  173. url: "../home/h5"
  174. })
  175. } else if (item.showType == 2) {
  176. uni.navigateTo({
  177. url: item.advUrl
  178. })
  179. } else if (item.showType == 3) {
  180. uni.setStorageSync('content', item.content);
  181. uni.navigateTo({
  182. url: "../home/content"
  183. })
  184. }
  185. },
  186. getAdv() {
  187. let data = {
  188. advType: 2
  189. };
  190. getAdv(data).then(
  191. res => {
  192. if (res.code == 200) {
  193. this.advs = res.data;
  194. }
  195. },
  196. rej => {}
  197. );
  198. },
  199. getProductCate() {
  200. let data = {};
  201. getProductCate(data).then(
  202. res => {
  203. if (res.code == 200) {
  204. this.allCates = res.data;
  205. this.cates = this.allCates.filter(function(item) {
  206. return item.pid == 0
  207. });
  208. if (this.cates != null && this.cates.length > 0) {
  209. this.cateSelect = this.cates[0].cateId ;
  210. this.getSubCate();
  211. // this.mescroll.resetUpScroll()
  212. }
  213. } else {
  214. uni.showToast({
  215. icon: 'none',
  216. title: "请求失败",
  217. });
  218. }
  219. },
  220. rej => {}
  221. );
  222. },
  223. // 药品分类选择
  224. choseCate(item) {
  225. this.activeIndex = 0
  226. this.dataList=[]
  227. this.cateSelect = item.cateId;
  228. this.getSubCate()
  229. },
  230. getSubCate() {
  231. var that = this;
  232. this.subCates = this.allCates.filter(function(item) {
  233. // let subList = that.allCates.filter(child => {
  234. // //返回每一项的子级数组
  235. // return child.pid === item.cateId
  236. // });
  237. // subList.length > 0 ? item.children = subList : [];
  238. return item.pid == that.cateSelect
  239. });
  240. if (this.subCates != null && this.subCates.length > 0) {
  241. this.cateId= this.subCates[0].cateId;
  242. this.mescroll.resetUpScroll()
  243. }
  244. },
  245. // 查看药品详情
  246. showProductList(item, index) {
  247. // console.log("item>>>>>", item)
  248. this.activeIndex = index;
  249. this.cateId = item.cateId;
  250. this.mescroll.resetUpScroll()
  251. // uni.navigateTo({
  252. // url: './productList?cateId='+item.cateId+"&pid="+item.pid
  253. // })
  254. },
  255. mescrollInit(mescroll) {
  256. this.mescroll = mescroll;
  257. },
  258. /*下拉刷新的回调 */
  259. downCallback(mescroll) {
  260. this.mescroll.resetUpScroll()
  261. },
  262. upCallback(page) {
  263. //联网加载数据
  264. var that = this;
  265. var data = {
  266. cateId:this.cateId,
  267. defaultOrder:this.defaultOrder,
  268. page: page.num,
  269. pageSize: page.size,
  270. productName: this.productName || "",
  271. storeId: this.storeId
  272. };
  273. if(this.cateId!=null){
  274. this.getProducts(page,data)
  275. }
  276. },
  277. //查询商品列表
  278. getProducts(page,data) {
  279. var that = this;
  280. getProducts(data).then(res => {
  281. if(res.code==200){
  282. //设置列表数据
  283. if (page.num == 1) {
  284. that.dataList = res.data.list;
  285. } else {
  286. that.dataList = that.dataList.concat(res.data.list);
  287. }
  288. that.mescroll.endBySize(res.data.list.length, res.data.total);
  289. }else{
  290. uni.showToast({
  291. icon:'none',
  292. title: "请求失败",
  293. });
  294. that.dataList = null;
  295. that.mescroll.endErr();
  296. }
  297. });
  298. },
  299. // 查看药品详情
  300. showDetail(item) {
  301. if(this.from == 'company') {
  302. uni.navigateTo({
  303. url: '/pages_company/order/productDetails?productId='+item.productId +`${this.storeId ? '&storeId='+this.storeId : ''}`
  304. })
  305. } else {
  306. uni.navigateTo({
  307. url: './productDetails?productId='+item.productId +`${this.storeId ? '&storeId='+this.storeId : ''}`
  308. })
  309. }
  310. },
  311. goSearch(e) {
  312. if (e.detail.value != null && e.detail.value != "") {
  313. this.utils.addHisSearch(e.detail.value);
  314. }
  315. uni.navigateTo({
  316. url: '../home/productList?searchValue=' + e.detail.value
  317. })
  318. }
  319. }
  320. }
  321. </script>
  322. <style lang="scss">
  323. page {
  324. height: 100%;
  325. background-color: #fff;
  326. }
  327. .mescroll-body{
  328. min-height: calc(100% - 330upx) !important;
  329. }
  330. .content {
  331. height: 100%;
  332. display: flex;
  333. flex-direction: column;
  334. .top-content {
  335. width: 100%;
  336. z-index: 10;
  337. .top-title {
  338. height: 88upx;
  339. line-height: 88upx;
  340. font-size: 42upx;
  341. font-family: Source Han Sans CN;
  342. font-weight: bold;
  343. color: #222222;
  344. padding-left: 41upx;
  345. background-color: #FFFFFF;
  346. }
  347. .search-cont {
  348. padding: 16upx 30upx;
  349. background-color: #FFFFFF;
  350. .inner {
  351. box-sizing: border-box;
  352. width: 100%;
  353. height: 72upx;
  354. background: #F7F7F7;
  355. border-radius: 36upx;
  356. display: flex;
  357. align-items: center;
  358. padding: 0 30upx;
  359. .icon-search {
  360. width: 28upx;
  361. height: 28upx;
  362. margin-right: 20upx;
  363. }
  364. input {
  365. height: 60upx;
  366. line-height: 60upx;
  367. flex: 1;
  368. }
  369. }
  370. }
  371. }
  372. .medic-box {
  373. display: flex;
  374. .cate-list {
  375. box-sizing: border-box;
  376. width: 200upx;
  377. background: #F2F5F9;
  378. display: flex;
  379. flex-direction: column;
  380. // padding: 20upx 0;
  381. overflow-y: scroll;
  382. margin-top: 30rpx;
  383. .item {
  384. height: 100upx;
  385. line-height: 100upx;
  386. padding-left: 30upx;
  387. font-size: 28upx;
  388. font-family: PingFang SC;
  389. font-weight: 500;
  390. color: #333333;
  391. position: relative;
  392. // overflow: hidden;
  393. &.active {
  394. background: #FFFFFF;
  395. font-weight: 600;
  396. // box-shadow: 12px 0 12px 0 #ffffff, -12px 0 12px 0 #ffffff;
  397. // border-radius: 12px 12px 0 0;
  398. &::after {
  399. content: "";
  400. width: 6upx;
  401. height: 28upx;
  402. background: #008FD3;
  403. position: absolute;
  404. top: 50%;
  405. left: 0;
  406. transform: translateY(-50%);
  407. border-radius: 0upx 6upx 6upx 0;
  408. }
  409. }
  410. }
  411. }
  412. .medic {
  413. box-sizing: border-box;
  414. width: calc(100% - 200upx);
  415. height: 100%;
  416. padding: 0 30upx;
  417. .banner-box {
  418. margin-top: 30rpx;
  419. width: 100%;
  420. height: 160upx;
  421. border-radius: 10upx;
  422. overflow: hidden;
  423. .swiper,
  424. .swiper-item,
  425. .swiper-item image {
  426. width: 100%;
  427. height: 100%;
  428. }
  429. }
  430. .inner-list {
  431. display: flex;
  432. flex-wrap: wrap;
  433. padding-top: 30upx;
  434. .definite {
  435. width: calc(33% - 20upx);
  436. margin-right: 30upx;
  437. margin-bottom: 30upx;
  438. .img-box {
  439. width: 100%;
  440. height: 144upx;
  441. background: #F5F5F5;
  442. border-radius: 8upx;
  443. overflow: hidden;
  444. display: flex;
  445. align-items: center;
  446. image {
  447. max-width: 100%;
  448. }
  449. }
  450. .name {
  451. width: 100%;
  452. margin-top: 20upx;
  453. font-size: 24upx;
  454. font-family: PingFang SC;
  455. font-weight: 500;
  456. color: #666666;
  457. text-align: center;
  458. padding: 10rpx 16rpx;
  459. }
  460. .select-name {
  461. background: #EFF3F7;
  462. color: #222426;
  463. border-radius:10upx ;
  464. }
  465. &:nth-child(3n) {
  466. margin-right: 0;
  467. }
  468. }
  469. }
  470. .line {
  471. width: 100%;
  472. height: 0rpx;
  473. border-top: 1rpx solid #ECECEC;
  474. }
  475. .medic-list {
  476. box-sizing: border-box;
  477. padding: 30upx 0;
  478. overflow-y: auto;
  479. height: calc(100% - 330upx);
  480. position: relative;
  481. // .item{
  482. // .title{
  483. // font-size: 28upx;
  484. // font-family: PingFang SC;
  485. // font-weight: bold;
  486. // color: #333333;
  487. // padding-top: 20upx;
  488. // margin-bottom: 30upx;
  489. // }
  490. // }
  491. .product-list {
  492. padding: 32rpx 0 0;
  493. .product-title {
  494. font-weight: 500;
  495. font-size: 28rpx;
  496. color: #222426;
  497. }
  498. }
  499. .medic-list2{
  500. // padding: 20upx;
  501. .product-title{
  502. font-size: 28upx;
  503. display: block;
  504. // padding-top: 30upx;
  505. }
  506. .item{
  507. box-sizing: border-box;
  508. min-height: 200upx;
  509. background: #FFFFFF;
  510. // border: 4upx solid #FFFFFF;
  511. border-radius: 20upx;
  512. // margin-bottom: 20upx;
  513. // padding: 40upx 0upx;
  514. padding-top: 30upx;
  515. display: flex;
  516. .img-box{
  517. width: 200upx;
  518. height: 200upx;
  519. margin-right: 30upx;
  520. position: relative;
  521. border-radius: 20upx;
  522. overflow: hidden;
  523. image{
  524. width: 100%;
  525. height: 100%;
  526. }
  527. }
  528. .info-box{
  529. width: calc(100% - 210upx);
  530. display: grid;
  531. justify-items: left;
  532. .title{
  533. font-size: 28upx;
  534. font-family: PingFang SC;
  535. font-weight: 500;
  536. color: #111111;
  537. line-height: 40upx;
  538. height: 80upx;
  539. }
  540. .intro{
  541. // font-size: 26upx;
  542. // font-family: PingFang SC;
  543. // font-weight: 500;
  544. // color: #999999;
  545. // line-height: 1;
  546. // margin-top: 26upx;
  547. display: flex;
  548. .intro-zk{
  549. border: 1px solid #FF4B33;
  550. padding:0 8rpx ;
  551. border-radius: 8rpx;
  552. margin-right: 10rpx;
  553. line-height: 5rpx;
  554. display: flex;
  555. text{
  556. font-size:24rpx;
  557. color:#FF4B33 ;
  558. display: flex;
  559. align-items: center;
  560. }
  561. }
  562. }
  563. .price-box{
  564. display: flex;
  565. align-items: flex-end;
  566. .now{
  567. display: flex;
  568. align-items: flex-end;
  569. margin-right: 20upx;
  570. .num{
  571. font-size: 36upx;
  572. font-family: PingFang SC;
  573. font-weight: bold;
  574. color: #FF5030;
  575. line-height: 1;
  576. }
  577. }
  578. .old{
  579. font-size: 24upx;
  580. font-family: PingFang SC;
  581. // font-weight: 500;
  582. text-decoration: line-through;
  583. color: #BBBBBB;
  584. line-height: 1.1;
  585. }
  586. }
  587. .prce-num{
  588. display: flex;
  589. align-items: center;
  590. justify-content: space-between;
  591. margin-top: 30upx;
  592. .price{
  593. display: flex;
  594. align-items: flex-end;
  595. .unit{
  596. font-size: 24upx;
  597. font-family: PingFang SC;
  598. font-weight: 500;
  599. color: #FF6633;
  600. line-height: 1.2;
  601. margin-right: 4upx;
  602. }
  603. .num{
  604. font-size: 36upx;
  605. font-family: PingFang SC;
  606. font-weight: bold;
  607. color: #FF6633;
  608. line-height: 1;
  609. }
  610. }
  611. .cart-img{
  612. .sale{
  613. font-size: 20upx;
  614. font-family: PingFang SC;
  615. color: #999999;
  616. }
  617. }
  618. }
  619. }
  620. }
  621. }
  622. }
  623. }
  624. }
  625. }
  626. </style>