productList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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://bjczwh.oss-cn-beijing.aliyuncs.com/app/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://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/search1.png" mode=""></image>
  12. <image @click="showChange(1)" v-if="showType==2" src="https://bjczwh.oss-cn-beijing.aliyuncs.com/app/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://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/price_arrow_up.png" mode="" @click="priceUp(true)"></image>
  24. <image v-if="form.priceOrder=='asc'" src="https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/price_arrow_up2.png" mode="" @click="priceUp(false)"></image>
  25. <image v-if="form.priceOrder==null||form.priceOrder=='asc'" src="https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/price_arrow_down.png" mode="" @click="priceDown(true)"></image>
  26. <image v-if="form.priceOrder=='desc'" src="https://bjczwh.oss-cn-beijing.aliyuncs.com/app/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://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/price_arrow_up.png" mode="" @click="saleUp(true)"></image>
  33. <image v-if="form.salesOrder=='asc'" src="https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/price_arrow_up2.png" mode="" @click="saleUp(false)"></image>
  34. <image v-if="form.salesOrder==null||form.salesOrder=='asc'" src="https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/price_arrow_down.png" mode="" @click="saleDown(true)"></image>
  35. <image v-if="form.salesOrder=='desc'" src="https://bjczwh.oss-cn-beijing.aliyuncs.com/app/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. <text class="old">¥{{item.otPrice.toFixed(2)}} </text>
  58. </view>
  59. <view class="cart-img" @click="navgetTo('../shopping/cart')">
  60. <view class="sale">已售 {{item.sales}} {{item.unitName}}</view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="goods-list" v-if="showType==2">
  67. <view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
  68. <view class="img-box">
  69. <image :src="item.image" mode="aspectFill"></image>
  70. </view>
  71. <view class="info-box">
  72. <view class="title ellipsis2">{{item.productName}}</view>
  73. <view class="price-box">
  74. <view class="now">
  75. <text class="unit">¥</text>
  76. <text class="num">{{item.price.toFixed(2)}}</text>
  77. </view>
  78. <view class="old">¥{{item.otPrice.toFixed(2)}}</view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </mescroll-body>
  84. </view>
  85. </template>
  86. <script>
  87. import {getProducts} from '@/api/product'
  88. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  89. export default {
  90. mixins: [MescrollMixin],
  91. data() {
  92. return {
  93. showType:1,
  94. form:{
  95. defaultOrder:'desc',
  96. newOrder:null,
  97. priceOrder:null,
  98. salesOrder:null,
  99. productName:"",
  100. },
  101. mescroll:null,
  102. // 上拉加载的配置
  103. upOption: {
  104. onScroll:true,
  105. use: true, // 是否启用上拉加载; 默认true
  106. page: {
  107. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  108. size: 10 // 每页数据的数量,默认10
  109. },
  110. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  111. empty: {
  112. icon:'https://bjczwh.oss-cn-beijing.aliyuncs.com/app/shop/images/no_data.png',
  113. tip: '暂无数据'
  114. },
  115. textNoMore:"已经到底了",
  116. },
  117. // 列表数据
  118. dataList: [],
  119. };
  120. },
  121. onLoad(option) {
  122. if(option.key!=undefined){
  123. this.form.productName = option.key
  124. }
  125. },
  126. methods:{
  127. goSearch(e) {
  128. this.form.productName=e.detail.value;
  129. this.mescroll.resetUpScroll();
  130. },
  131. searchChange(type){
  132. if(type==1){
  133. this.form.defaultOrder="desc";
  134. this.form.priceOrder=null;
  135. this.form.salesOrder=null;
  136. this.form.newOrder=null;
  137. }
  138. else if(type==2){
  139. this.form.defaultOrder=null;
  140. if(this.form.priceOrder==null){
  141. this.form.priceOrder="asc"
  142. }
  143. else if(this.form.priceOrder=="asc"){
  144. this.form.priceOrder="desc"
  145. }
  146. else if(this.form.priceOrder=="desc"){
  147. this.form.priceOrder=null;
  148. }
  149. this.form.salesOrder=null;
  150. this.form.newOrder=null;
  151. }
  152. else if(type==3){
  153. this.form.defaultOrder=null;
  154. this.form.priceOrder=null;
  155. if(this.form.salesOrder==null){
  156. this.form.salesOrder="asc"
  157. }
  158. else if(this.form.salesOrder=="asc"){
  159. this.form.salesOrder="desc"
  160. }
  161. else if(this.form.salesOrder=="desc"){
  162. this.form.salesOrder=null;
  163. }
  164. this.form.newOrder=null;
  165. }
  166. else if(type==4){
  167. this.form.newOrder="desc";
  168. this.form.defaultOrder=null;
  169. this.form.priceOrder=null;
  170. this.form.salesOrder=null;
  171. }
  172. this.mescroll.resetUpScroll();
  173. },
  174. showChange(type){
  175. this.showType=type;
  176. },
  177. mescrollInit(mescroll) {
  178. this.mescroll = mescroll;
  179. },
  180. /*下拉刷新的回调 */
  181. downCallback(mescroll) {
  182. mescroll.resetUpScroll()
  183. },
  184. upCallback(page) {
  185. //联网加载数据
  186. var that = this;
  187. this.form.page=page.num;
  188. this.form.pageSize=page.size;
  189. getProducts(this.form).then(res => {
  190. if(res.code==200){
  191. //设置列表数据
  192. if (page.num == 1) {
  193. that.dataList = res.data.list;
  194. } else {
  195. that.dataList = that.dataList.concat(res.data.list);
  196. }
  197. that.mescroll.endBySize(res.data.list.length, res.data.total);
  198. }else{
  199. uni.showToast({
  200. icon:'none',
  201. title: "请求失败",
  202. });
  203. that.dataList = null;
  204. that.mescroll.endErr();
  205. }
  206. });
  207. },
  208. // 价格升序是否选中
  209. priceUp(value) {
  210. this.priceIsUp = value
  211. this.priceIsDown = false
  212. },
  213. // 价格降序是否选中
  214. priceDown(value) {
  215. this.priceIsDown = value
  216. this.priceIsUp = false
  217. },
  218. // 销量升序是否选中
  219. saleUp(value) {
  220. this.saleIsUp = value
  221. this.saleIsDown = false
  222. },
  223. // 销量降序是否选中
  224. saleDown(value) {
  225. this.saleIsDown = value
  226. this.saleIsUp = false
  227. },
  228. // 查看详情
  229. showDetail(item) {
  230. uni.navigateTo({
  231. url: '../shopping/productDetails?productId='+item.productId
  232. })
  233. }
  234. }
  235. }
  236. </script>
  237. <style lang="scss">
  238. .top-fixed{
  239. width: 100%;
  240. position: fixed;
  241. top: 0;
  242. left: 0;
  243. z-index: 10;
  244. }
  245. .search-cont{
  246. padding: 16upx 30upx;
  247. background-color: #FFFFFF;
  248. display:flex;
  249. align-items: center;
  250. justify-content: space-between;
  251. .inner{
  252. box-sizing: border-box;
  253. width: 100%;
  254. height: 72upx;
  255. background: #F7F7F7;
  256. border-radius: 36upx;
  257. display: flex;
  258. align-items: center;
  259. padding: 0 30upx;
  260. .icon-search{
  261. width: 28upx;
  262. height: 28upx;
  263. margin-right: 20upx;
  264. }
  265. input{
  266. height: 60upx;
  267. line-height: 60upx;
  268. flex: 1;
  269. }
  270. }
  271. .icon-search{
  272. margin-left: 10upx;
  273. width: 40upx;
  274. height: 40upx;
  275. image{
  276. width: 40upx;
  277. height: 40upx;
  278. }
  279. }
  280. }
  281. .sort-box{
  282. height: 88upx;
  283. background: #FFFFFF;
  284. padding: 0 100upx;
  285. display: flex;
  286. align-items: center;
  287. justify-content: space-between;
  288. .item{
  289. display: flex;
  290. align-items: center;
  291. justify-content: center;
  292. &.active .label{
  293. color: #2BC7B9;
  294. }
  295. .label{
  296. font-size: 26upx;
  297. font-family: PingFang SC;
  298. font-weight: 500;
  299. color: #666666;
  300. line-height: 1;
  301. }
  302. .sort-img{
  303. height: 20upx;
  304. display: flex;
  305. flex-direction: column;
  306. justify-content: space-between;
  307. margin: 3upx 0 0 10upx;
  308. image{
  309. width: 12upx;
  310. height: 8upx;
  311. }
  312. }
  313. }
  314. }
  315. .medic-list{
  316. padding: 20upx;
  317. .item{
  318. box-sizing: border-box;
  319. min-height: 285upx;
  320. background: #FFFFFF;
  321. border: 4upx solid #FFFFFF;
  322. border-radius: 16upx;
  323. margin-bottom: 20upx;
  324. padding: 40upx 30upx;
  325. display: flex;
  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. }
  449. }
  450. }
  451. }
  452. .old{
  453. font-size: 24upx;
  454. font-family: PingFang SC;
  455. font-weight: 500;
  456. text-decoration: line-through;
  457. color: #BBBBBB;
  458. line-height: 1.1;
  459. margin-left: 16rpx;
  460. }
  461. </style>