productList.vue 9.5 KB

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