productList.vue 12 KB

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