productList.vue 11 KB

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