productList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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://kntobs.jnmyunl.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://kntobs.jnmyunl.com/shop/images/search1.png" mode=""></image>
  12. <image @click="showChange(1)" v-if="showType==2" src="https://kntobs.jnmyunl.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://kntobs.jnmyunl.com/shop/images/price_arrow_up.png" mode="" @click="priceUp(true)"></image>
  24. <image v-if="form.priceOrder=='asc'" src="https://kntobs.jnmyunl.com/shop/images/price_arrow_up2.png" mode="" @click="priceUp(false)"></image>
  25. <image v-if="form.priceOrder==null||form.priceOrder=='asc'" src="https://kntobs.jnmyunl.com/shop/images/price_arrow_down.png" mode="" @click="priceDown(true)"></image>
  26. <image v-if="form.priceOrder=='desc'" src="https://kntobs.jnmyunl.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://kntobs.jnmyunl.com/shop/images/price_arrow_up.png" mode="" @click="saleUp(true)"></image>
  33. <image v-if="form.salesOrder=='asc'" src="https://kntobs.jnmyunl.com/shop/images/price_arrow_up2.png" mode="" @click="saleUp(false)"></image>
  34. <image v-if="form.salesOrder==null||form.salesOrder=='asc'" src="https://kntobs.jnmyunl.com/shop/images/price_arrow_down.png" mode="" @click="saleDown(true)"></image>
  35. <image v-if="form.salesOrder=='desc'" src="https://kntobs.jnmyunl.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}} {{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://kntobs.jnmyunl.com/shop/images/no_data.png',
  112. tip: '暂无数据'
  113. },
  114. textNoMore:"已经到底了",
  115. },
  116. // 列表数据
  117. dataList: [],
  118. };
  119. },
  120. onLoad(option) {
  121. if(option.salesOrder){
  122. this.form.salesOrder=option.salesOrder
  123. this.form.defaultOrder=null;
  124. }
  125. if(option.key!=undefined){
  126. this.form.productName = option.key
  127. }
  128. },
  129. methods:{
  130. goSearch(e) {
  131. this.form.productName=e.detail.value;
  132. this.mescroll.resetUpScroll();
  133. },
  134. searchChange(type){
  135. if(type==1){
  136. this.form.defaultOrder="desc";
  137. this.form.priceOrder=null;
  138. this.form.salesOrder=null;
  139. this.form.newOrder=null;
  140. }
  141. else if(type==2){
  142. this.form.defaultOrder=null;
  143. if(this.form.priceOrder==null){
  144. this.form.priceOrder="asc"
  145. }
  146. else if(this.form.priceOrder=="asc"){
  147. this.form.priceOrder="desc"
  148. }
  149. else if(this.form.priceOrder=="desc"){
  150. this.form.priceOrder=null;
  151. }
  152. this.form.salesOrder=null;
  153. this.form.newOrder=null;
  154. }
  155. else if(type==3){
  156. this.form.defaultOrder=null;
  157. this.form.priceOrder=null;
  158. if(this.form.salesOrder==null){
  159. this.form.salesOrder="asc"
  160. }
  161. else if(this.form.salesOrder=="asc"){
  162. this.form.salesOrder="desc"
  163. }
  164. else if(this.form.salesOrder=="desc"){
  165. this.form.salesOrder=null;
  166. }
  167. this.form.newOrder=null;
  168. }
  169. else if(type==4){
  170. this.form.newOrder="desc";
  171. this.form.defaultOrder=null;
  172. this.form.priceOrder=null;
  173. this.form.salesOrder=null;
  174. }
  175. this.mescroll.resetUpScroll();
  176. },
  177. showChange(type){
  178. this.showType=type;
  179. },
  180. mescrollInit(mescroll) {
  181. this.mescroll = mescroll;
  182. },
  183. /*下拉刷新的回调 */
  184. downCallback(mescroll) {
  185. mescroll.resetUpScroll()
  186. },
  187. upCallback(page) {
  188. //联网加载数据
  189. var that = this;
  190. this.form.page=page.num;
  191. this.form.pageSize=page.size;
  192. getProducts(this.form).then(res => {
  193. if(res.code==200){
  194. //设置列表数据
  195. if (page.num == 1) {
  196. that.dataList = res.data.list;
  197. } else {
  198. that.dataList = that.dataList.concat(res.data.list);
  199. }
  200. that.mescroll.endBySize(res.data.list.length, res.data.total);
  201. }else{
  202. uni.showToast({
  203. icon:'none',
  204. title: "请求失败",
  205. });
  206. that.dataList = null;
  207. that.mescroll.endErr();
  208. }
  209. });
  210. },
  211. // 价格升序是否选中
  212. priceUp(value) {
  213. this.priceIsUp = value
  214. this.priceIsDown = false
  215. },
  216. // 价格降序是否选中
  217. priceDown(value) {
  218. this.priceIsDown = value
  219. this.priceIsUp = false
  220. },
  221. // 销量升序是否选中
  222. saleUp(value) {
  223. this.saleIsUp = value
  224. this.saleIsDown = false
  225. },
  226. // 销量降序是否选中
  227. saleDown(value) {
  228. this.saleIsDown = value
  229. this.saleIsUp = false
  230. },
  231. // 查看详情
  232. showDetail(item) {
  233. uni.navigateTo({
  234. url: '../shopping/productDetails?productId='+item.productId
  235. })
  236. }
  237. }
  238. }
  239. </script>
  240. <style lang="scss">
  241. .top-fixed{
  242. width: 100%;
  243. position: fixed;
  244. top: 0;
  245. left: 0;
  246. z-index: 10;
  247. }
  248. .search-cont{
  249. padding: 16upx 30upx;
  250. background-color: #FFFFFF;
  251. display:flex;
  252. align-items: center;
  253. justify-content: space-between;
  254. .inner{
  255. box-sizing: border-box;
  256. width: 100%;
  257. height: 72upx;
  258. background: #F7F7F7;
  259. border-radius: 36upx;
  260. display: flex;
  261. align-items: center;
  262. padding: 0 30upx;
  263. .icon-search{
  264. width: 28upx;
  265. height: 28upx;
  266. margin-right: 20upx;
  267. }
  268. input{
  269. height: 60upx;
  270. line-height: 60upx;
  271. flex: 1;
  272. }
  273. }
  274. .icon-search{
  275. margin-left: 10upx;
  276. width: 40upx;
  277. height: 40upx;
  278. image{
  279. width: 40upx;
  280. height: 40upx;
  281. }
  282. }
  283. }
  284. .sort-box{
  285. height: 88upx;
  286. background: #FFFFFF;
  287. padding: 0 100upx;
  288. display: flex;
  289. align-items: center;
  290. justify-content: space-between;
  291. .item{
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. &.active .label{
  296. color: #2BC7B9;
  297. }
  298. .label{
  299. font-size: 26upx;
  300. font-family: PingFang SC;
  301. font-weight: 500;
  302. color: #666666;
  303. line-height: 1;
  304. }
  305. .sort-img{
  306. height: 20upx;
  307. display: flex;
  308. flex-direction: column;
  309. justify-content: space-between;
  310. margin: 3upx 0 0 10upx;
  311. image{
  312. width: 12upx;
  313. height: 8upx;
  314. }
  315. }
  316. }
  317. }
  318. .medic-list{
  319. padding: 20upx;
  320. .item{
  321. box-sizing: border-box;
  322. min-height: 285upx;
  323. background: #FFFFFF;
  324. border: 4upx solid #FFFFFF;
  325. border-radius: 16upx;
  326. margin-bottom: 20upx;
  327. padding: 40upx 30upx;
  328. display: flex;
  329. .img-box{
  330. width: 200upx;
  331. height: 200upx;
  332. margin-right: 30upx;
  333. image{
  334. width: 100%;
  335. height: 100%;
  336. }
  337. }
  338. .info-box{
  339. width: calc(100% - 210upx);
  340. .title{
  341. font-size: 32upx;
  342. font-family: PingFang SC;
  343. font-weight: 500;
  344. color: #111111;
  345. line-height: 40rpx;
  346. height: 80rpx;
  347. }
  348. .intro{
  349. font-size: 26upx;
  350. font-family: PingFang SC;
  351. font-weight: 500;
  352. color: #999999;
  353. line-height: 1;
  354. margin-top: 26upx;
  355. }
  356. .prce-num{
  357. display: flex;
  358. align-items: center;
  359. justify-content: space-between;
  360. margin-top: 30upx;
  361. .price{
  362. display: flex;
  363. align-items: flex-end;
  364. .unit{
  365. font-size: 24upx;
  366. font-family: PingFang SC;
  367. font-weight: 500;
  368. color: #FF6633;
  369. line-height: 1.2;
  370. margin-right: 4upx;
  371. }
  372. .num{
  373. font-size: 36upx;
  374. font-family: PingFang SC;
  375. font-weight: bold;
  376. color: #FF6633;
  377. line-height: 1;
  378. }
  379. }
  380. .cart-img{
  381. .sale{
  382. font-size: 20upx;
  383. font-family: PingFang SC;
  384. color: #999999;
  385. }
  386. }
  387. }
  388. }
  389. }
  390. }
  391. .goods-list{
  392. padding: 20upx;
  393. display: flex;
  394. flex-wrap: wrap;
  395. .item{
  396. margin-right: 20rpx;
  397. margin-bottom: 20rpx;
  398. width: 345rpx;
  399. background: #FFFFFF;
  400. box-shadow: 0px 0px 10rpx 4rpx rgba(199, 199, 199, 0.22);
  401. border-radius: 20rpx;
  402. overflow: hidden;
  403. &:nth-child(2n) {
  404. margin-right: 0;
  405. }
  406. .img-box{
  407. width: 100%;
  408. height: 334upx;
  409. image{
  410. width: 100%;
  411. height: 100%;
  412. }
  413. }
  414. .info-box{
  415. box-sizing: border-box;
  416. height: 182upx;
  417. padding: 20upx 20upx 30upx;
  418. display: flex;
  419. flex-direction: column;
  420. justify-content: space-between;
  421. .title{
  422. font-size: 26upx;
  423. font-family: PingFang SC;
  424. font-weight: 500;
  425. color: #111111;
  426. line-height: 40upx;
  427. }
  428. .price-box{
  429. display: flex;
  430. align-items: flex-end;
  431. .now{
  432. display: flex;
  433. align-items: flex-end;
  434. margin-right: 20upx;
  435. .unit{
  436. font-size: 24upx;
  437. font-family: PingFang SC;
  438. font-weight: 500;
  439. color: #FF6633;
  440. line-height: 1.2;
  441. margin-right: 4upx;
  442. }
  443. .num{
  444. font-size: 36upx;
  445. font-family: PingFang SC;
  446. font-weight: bold;
  447. color: #FF6633;
  448. line-height: 1;
  449. }
  450. }
  451. .old{
  452. font-size: 26upx;
  453. font-family: PingFang SC;
  454. font-weight: 500;
  455. text-decoration: line-through;
  456. color: #BBBBBB;
  457. line-height: 1.1;
  458. }
  459. }
  460. }
  461. }
  462. }
  463. </style>