productList.vue 12 KB

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