productList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/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="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/search1.png" mode=""></image>
  12. <image @click="showChange(1)" v-if="showType==2" src="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/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="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/price_arrow_up.png" mode="" @click="priceUp(true)"></image>
  24. <image v-if="form.priceOrder=='asc'" src="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/price_arrow_up2.png" mode="" @click="priceUp(false)"></image>
  25. <image v-if="form.priceOrder==null||form.priceOrder=='asc'" src="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/price_arrow_down.png" mode="" @click="priceDown(true)"></image>
  26. <image v-if="form.priceOrder=='desc'" src="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/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="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/price_arrow_up.png" mode="" @click="saleUp(true)"></image>
  33. <image v-if="form.salesOrder=='asc'" src="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/price_arrow_up2.png" mode="" @click="saleUp(false)"></image>
  34. <image v-if="form.salesOrder==null||form.salesOrder=='asc'" src="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/price_arrow_down.png" mode="" @click="saleDown(true)"></image>
  35. <image v-if="form.salesOrder=='desc'" src="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/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||'0'}} {{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:'https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/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: #2BC7B9;
  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. align-items: center;
  326. .img-box{
  327. width: 200upx;
  328. height: 200upx;
  329. margin-right: 30upx;
  330. image{
  331. width: 100%;
  332. height: 100%;
  333. }
  334. }
  335. .info-box{
  336. width: calc(100% - 210upx);
  337. .title{
  338. font-size: 32upx;
  339. font-family: PingFang SC;
  340. font-weight: 500;
  341. color: #111111;
  342. line-height: 40rpx;
  343. height: 80rpx;
  344. }
  345. .intro{
  346. font-size: 26upx;
  347. font-family: PingFang SC;
  348. font-weight: 500;
  349. color: #999999;
  350. line-height: 1;
  351. margin-top: 26upx;
  352. }
  353. .prce-num{
  354. display: flex;
  355. align-items: center;
  356. justify-content: space-between;
  357. margin-top: 30upx;
  358. .price{
  359. display: flex;
  360. align-items: flex-end;
  361. .unit{
  362. font-size: 24upx;
  363. font-family: PingFang SC;
  364. font-weight: 500;
  365. color: #FF6633;
  366. line-height: 1.2;
  367. margin-right: 4upx;
  368. }
  369. .num{
  370. font-size: 36upx;
  371. font-family: PingFang SC;
  372. font-weight: bold;
  373. color: #FF6633;
  374. line-height: 1;
  375. }
  376. }
  377. .cart-img{
  378. .sale{
  379. font-size: 20upx;
  380. font-family: PingFang SC;
  381. color: #999999;
  382. }
  383. }
  384. }
  385. }
  386. }
  387. }
  388. .goods-list{
  389. padding: 20upx;
  390. display: flex;
  391. flex-wrap: wrap;
  392. .item{
  393. margin-right: 20rpx;
  394. margin-bottom: 20rpx;
  395. width: 345rpx;
  396. background: #FFFFFF;
  397. box-shadow: 0px 0px 10rpx 4rpx rgba(199, 199, 199, 0.22);
  398. border-radius: 20rpx;
  399. overflow: hidden;
  400. &:nth-child(2n) {
  401. margin-right: 0;
  402. }
  403. .img-box{
  404. width: 100%;
  405. height: 334upx;
  406. image{
  407. width: 100%;
  408. height: 100%;
  409. }
  410. }
  411. .info-box{
  412. box-sizing: border-box;
  413. height: 182upx;
  414. padding: 20upx 20upx 30upx;
  415. display: flex;
  416. flex-direction: column;
  417. justify-content: space-between;
  418. .title{
  419. font-size: 26upx;
  420. font-family: PingFang SC;
  421. font-weight: 500;
  422. color: #111111;
  423. line-height: 40upx;
  424. }
  425. .price-box{
  426. display: flex;
  427. align-items: flex-end;
  428. .now{
  429. display: flex;
  430. align-items: flex-end;
  431. margin-right: 20upx;
  432. .unit{
  433. font-size: 24upx;
  434. font-family: PingFang SC;
  435. font-weight: 500;
  436. color: #FF6633;
  437. line-height: 1.2;
  438. margin-right: 4upx;
  439. }
  440. .num{
  441. font-size: 36upx;
  442. font-family: PingFang SC;
  443. font-weight: bold;
  444. color: #FF6633;
  445. line-height: 1;
  446. }
  447. }
  448. .old{
  449. font-size: 26upx;
  450. font-family: PingFang SC;
  451. font-weight: 500;
  452. text-decoration: line-through;
  453. color: #BBBBBB;
  454. line-height: 1.1;
  455. }
  456. }
  457. }
  458. }
  459. }
  460. </style>