productList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. <template>
  2. <view>
  3. <view class="top-fixed">
  4. <view class="search-cont">
  5. <view class="inner">
  6. <image class="icon-search" src="https://cqtyt-2025.oss-cn-beijing.aliyuncs.com/shop/images/search.png" mode=""></image>
  7. <input type="text" :value="searchValue" placeholder="输入商品名称" @confirm="goSearch"
  8. placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  9. </view>
  10. <view class="icon-search">
  11. <image @click="showChange(2)" v-if="showType==1" src="https://cqtyt-2025.oss-cn-beijing.aliyuncs.com/shop/images/search1.png" mode=""></image>
  12. <image @click="showChange(1)" v-if="showType==2" src="https://cqtyt-2025.oss-cn-beijing.aliyuncs.com/shop/images/search2.png" mode=""></image>
  13. </view>
  14. </view>
  15. <!-- tab切换 -->
  16. <view class="pub-tab-box">
  17. <view class="tab-inner">
  18. <view
  19. v-for="(item,index) in cates"
  20. :key="index"
  21. :class="cateId == item.cateId?'item active':'item'"
  22. @click="cateChange(item)">
  23. <view class="text">
  24. {{ item.cateName }}
  25. <image v-show="cateId == item.cateId" class="tab-bg" src="https://cqtyt-2025.oss-cn-beijing.aliyuncs.com/shop/images/tab_bg.png" mode=""></image>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 数据列表 -->
  32. <mescroll-body top="190upx" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  33. <view class="medic-list" v-if="showType==1">
  34. <view v-for="(item,index) in dataList" :key="index" class="item" @click="showDetail(item)">
  35. <view class="img-box">
  36. <image :src="item.image" mode="aspectFit"></image>
  37. <view class="cf-box" v-if="item.productType==2">
  38. <view class="title">处方药</view>
  39. <view class="subTitle">请在医师指导下使用</view>
  40. </view>
  41. </view>
  42. <view class="info-box">
  43. <view class="title ellipsis2">{{item.productName}}</view>
  44. <view class="intro ellipsis">{{item.productInfo}}</view>
  45. <view class="prce-num">
  46. <view class="price">
  47. <text class="unit">¥</text>
  48. <text class="num">{{item.price.toFixed(2)}} </text>
  49. </view>
  50. <view class="cart-img" @click="navgetTo('../shopping/cart')">
  51. <view class="sale">已售 {{item.sales}} {{item.unitName}}</view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="goods-list" v-if="showType==2">
  58. <view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
  59. <view class="img-box">
  60. <image :src="item.image" mode="aspectFit"></image>
  61. <view class="cf-box" v-if="item.productType==2">
  62. <view class="title">处方药</view>
  63. <view class="subTitle">请在医师指导下使用</view>
  64. </view>
  65. </view>
  66. <view class="info-box">
  67. <view class="title ellipsis2">{{item.productName}}</view>
  68. <view class="price-box">
  69. <view class="now" v-if="userinfo.isShow==1&&isuser==false">
  70. <text class="unit">¥</text>
  71. <text class="num">{{item.price.toFixed(2)}}</text>
  72. </view>
  73. <view class="now" v-else>
  74. <text class="unit">¥</text>
  75. <text class="num">{{item.otPrice.toFixed(2)}}</text>
  76. </view>
  77. <view class="old" v-if="userinfo.isShow==0&&isuser==true">¥{{item.otPrice.toFixed(2)}}</view>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </mescroll-body>
  83. </view>
  84. </template>
  85. <script>
  86. import {getProductCateByPid,getProducts} from '@/api/product'
  87. import {getUserInfo} from '@/api/user'
  88. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  89. export default {
  90. mixins: [MescrollMixin],
  91. data() {
  92. return {
  93. showType:2,
  94. cates:[],
  95. cateId:null,
  96. defaultOrder:'desc',
  97. pid:null,
  98. //上拉加载的配置
  99. upOption: {
  100. onScroll:true,
  101. use: true, // 是否启用上拉加载; 默认true
  102. page: {
  103. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  104. size: 10 // 每页数据的数量,默认10
  105. },
  106. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  107. empty: {
  108. icon:'https://cqtyt-2025.oss-cn-beijing.aliyuncs.com/shop/images/no_data.png',
  109. tip: '暂无数据',
  110. },
  111. textNoMore:"已经到底了",
  112. },
  113. // 列表数据
  114. dataList: [],
  115. userinfo:[],
  116. isuser:false
  117. };
  118. },
  119. onLoad(options) {
  120. this.cateId = options.cateId;
  121. this.pid=options.pid;
  122. console.log(this.cateId)
  123. //获取分类列表
  124. this.getProductCateByPid();
  125. },
  126. onShow() {
  127. if(uni.getStorageSync('AppToken')){
  128. this.getuser()
  129. }else{
  130. this.isuser=true
  131. }
  132. },
  133. methods: {
  134. goSearch(e) {
  135. if(e.detail.value!=null&&e.detail.value!=""){
  136. // this.utils.addHisSearch(e.detail.value);
  137. this.$addHisSearch(e.detail.value);
  138. }
  139. uni.navigateTo({
  140. url: '/pages_shopping/productListAll?key=' + e.detail.value
  141. })
  142. },
  143. getuser(){
  144. getUserInfo().then(
  145. res => {
  146. if (res.code == 200) {
  147. if (res.user != null) {
  148. this.userinfo = res.user;
  149. console.log(this.userinfo)
  150. }
  151. } else {
  152. uni.showToast({
  153. icon: 'none',
  154. title: "请求失败",
  155. });
  156. }
  157. },
  158. rej => {}
  159. );
  160. },
  161. showChange(type){
  162. this.showType=type;
  163. },
  164. getProductCateByPid(){
  165. let data = {pid:this.pid};
  166. getProductCateByPid(data).then(
  167. res => {
  168. if(res.code==200){
  169. this.cates=res.data;
  170. }else{
  171. uni.showToast({
  172. icon:'none',
  173. title: "请求失败",
  174. });
  175. }
  176. },
  177. rej => {}
  178. );
  179. },
  180. // tab切换
  181. cateChange(item) {
  182. this.cateId = item.cateId;
  183. this.mescroll.resetUpScroll()
  184. },
  185. mescrollInit(mescroll) {
  186. this.mescroll = mescroll;
  187. },
  188. upCallback(page) {
  189. //联网加载数据
  190. var that = this;
  191. var data = {
  192. cateId:this.cateId,
  193. defaultOrder:this.defaultOrder,
  194. page: page.num,
  195. pageSize: page.size
  196. };
  197. getProducts(data).then(res => {
  198. if(res.code==200){
  199. //设置列表数据
  200. if (page.num == 1) {
  201. that.dataList = res.data.list;
  202. } else {
  203. that.dataList = that.dataList.concat(res.data.list);
  204. }
  205. that.mescroll.endBySize(res.data.list.length, res.data.total);
  206. }else{
  207. uni.showToast({
  208. icon:'none',
  209. title: "请求失败",
  210. });
  211. that.dataList = null;
  212. mescroll.endErr();
  213. }
  214. });
  215. },
  216. // 查看药品详情
  217. showDetail(item) {
  218. console.log("item.productId",item.productId)
  219. uni.navigateTo({
  220. url: '/pages_shopping/productDetails?productId='+item.productId
  221. })
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss">
  227. .top-fixed{
  228. width: 100%;
  229. position: fixed;
  230. top: 0;
  231. left: 0;
  232. z-index: 10;
  233. }
  234. .pub-tab-box{
  235. box-sizing: border-box;
  236. width: 100%;
  237. padding: 0 33upx;
  238. background-color: #FFFFFF;
  239. .tab-inner{
  240. height: 88upx;
  241. line-height: 88upx;
  242. display: flex;
  243. overflow-x: auto;
  244. justify-content: flex-start;
  245. align-items: center;
  246. }
  247. .item{
  248. font-size: 28upx;
  249. white-space: nowrap;
  250. line-height: 1;
  251. font-family: PingFang SC;
  252. font-weight: 500;
  253. color: #666666;
  254. margin-right: 60upx;
  255. display: flex;
  256. align-items: center;
  257. justify-content: center;
  258. &:last-child{
  259. margin-right: 0;
  260. }
  261. &.active{
  262. font-weight: bold;
  263. color: #333333;
  264. }
  265. .text{
  266. position: relative;
  267. z-index: 1;
  268. }
  269. .tab-bg{
  270. width: 72upx;
  271. height: 28upx;
  272. position: absolute;
  273. top: 17upx;
  274. left: 50%;
  275. transform: translateX(-36upx);
  276. z-index: -1;
  277. }
  278. }
  279. }
  280. .medic-list{
  281. padding: 20upx;
  282. .item{
  283. box-sizing: border-box;
  284. min-height: 285upx;
  285. background: #FFFFFF;
  286. border: 4upx solid #FFFFFF;
  287. border-radius: 16upx;
  288. margin-bottom: 20upx;
  289. padding: 40upx 30upx;
  290. display: flex;
  291. .img-box{
  292. width: 200upx;
  293. height: 200upx;
  294. margin-right: 30upx;
  295. position: relative;
  296. image{
  297. width: 100%;
  298. height: 100%;
  299. }
  300. }
  301. .info-box{
  302. width: calc(100% - 210upx);
  303. .title{
  304. font-size: 32upx;
  305. font-family: PingFang SC;
  306. font-weight: 500;
  307. color: #111111;
  308. line-height: 40rpx;
  309. height: 80rpx;
  310. }
  311. .intro{
  312. font-size: 26upx;
  313. font-family: PingFang SC;
  314. font-weight: 500;
  315. color: #999999;
  316. line-height: 1;
  317. margin-top: 26upx;
  318. }
  319. .prce-num{
  320. display: flex;
  321. align-items: center;
  322. justify-content: space-between;
  323. margin-top: 30upx;
  324. .price{
  325. display: flex;
  326. align-items: flex-end;
  327. .unit{
  328. font-size: 24upx;
  329. font-family: PingFang SC;
  330. font-weight: 500;
  331. color: #FF6633;
  332. line-height: 1.2;
  333. margin-right: 4upx;
  334. }
  335. .num{
  336. font-size: 36upx;
  337. font-family: PingFang SC;
  338. font-weight: bold;
  339. color: #FF6633;
  340. line-height: 1;
  341. }
  342. }
  343. .cart-img{
  344. .sale{
  345. font-size: 20upx;
  346. font-family: PingFang SC;
  347. color: #999999;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }
  354. .goods-list{
  355. padding: 20upx;
  356. display: flex;
  357. flex-wrap: wrap;
  358. .item{
  359. margin-right: 20rpx;
  360. margin-bottom: 20rpx;
  361. width: 345rpx;
  362. background: #FFFFFF;
  363. box-shadow: 0px 0px 10rpx 4rpx rgba(199, 199, 199, 0.22);
  364. border-radius: 20rpx;
  365. overflow: hidden;
  366. &:nth-child(2n) {
  367. margin-right: 0;
  368. }
  369. .img-box{
  370. width: 100%;
  371. height: 334upx;
  372. position: relative;
  373. image{
  374. width: 100%;
  375. height: 100%;
  376. }
  377. }
  378. .info-box{
  379. box-sizing: border-box;
  380. height: 182upx;
  381. padding: 20upx 20upx 30upx;
  382. display: flex;
  383. flex-direction: column;
  384. justify-content: space-between;
  385. .title{
  386. font-size: 26upx;
  387. font-family: PingFang SC;
  388. font-weight: 500;
  389. color: #111111;
  390. line-height: 40upx;
  391. }
  392. .price-box{
  393. display: flex;
  394. align-items: flex-end;
  395. .now{
  396. display: flex;
  397. align-items: flex-end;
  398. margin-right: 20upx;
  399. .unit{
  400. font-size: 24upx;
  401. font-family: PingFang SC;
  402. font-weight: 500;
  403. color: #FF6633;
  404. line-height: 1.2;
  405. margin-right: 4upx;
  406. }
  407. .num{
  408. font-size: 36upx;
  409. font-family: PingFang SC;
  410. font-weight: bold;
  411. color: #FF6633;
  412. line-height: 1;
  413. }
  414. }
  415. .old{
  416. font-size: 26upx;
  417. font-family: PingFang SC;
  418. font-weight: 500;
  419. text-decoration: line-through;
  420. color: #BBBBBB;
  421. line-height: 1.1;
  422. }
  423. }
  424. }
  425. }
  426. }
  427. .search-cont{
  428. padding: 16upx 30upx;
  429. background-color: #FFFFFF;
  430. display:flex;
  431. align-items: center;
  432. justify-content: space-between;
  433. .inner{
  434. box-sizing: border-box;
  435. width: 100%;
  436. height: 72upx;
  437. background: #F7F7F7;
  438. border-radius: 36upx;
  439. display: flex;
  440. align-items: center;
  441. padding: 0 30upx;
  442. .icon-search{
  443. width: 28upx;
  444. height: 28upx;
  445. margin-right: 20upx;
  446. }
  447. input{
  448. height: 60upx;
  449. line-height: 60upx;
  450. flex: 1;
  451. }
  452. }
  453. .icon-search{
  454. margin-left: 10upx;
  455. width: 40upx;
  456. height: 40upx;
  457. image{
  458. width: 40upx;
  459. height: 40upx;
  460. }
  461. }
  462. }
  463. .cf-box{
  464. position: absolute;
  465. z-index: 10;
  466. left: 0;
  467. right:0;
  468. top: 0rpx;
  469. bottom: 0rpx;
  470. background-color: rgba(0,0,0, 0.3);
  471. backdrop-filter: blur(2rpx); /* 背景模糊度 */
  472. display: flex;
  473. flex-direction: column;
  474. flex: 1;
  475. justify-content: center;
  476. align-items: center;
  477. .title{
  478. font-size: 34rpx;
  479. font-weight: bold;
  480. color: #fff;
  481. }
  482. .subTitle{
  483. font-size: 28rpx;
  484. font-weight: bold;
  485. margin-top: 4rpx;
  486. color: #fff;
  487. }
  488. }
  489. </style>