productList.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="">
  3. <u-navbar
  4. :title="typeName"
  5. :placeholder="true"
  6. :autoBack="true"
  7. :safeAreaInsetTop="true"
  8. >
  9. </u-navbar>
  10. <view class="search-wrap">
  11. <u--input
  12. placeholder="输入搜索内容"
  13. prefixIcon="search"
  14. shape="circle"
  15. v-model="params.goodsName"
  16. @confirm="search"
  17. :customStyle="{'border-color':'#00A447!important'}"
  18. prefixIconStyle="font-size: 22px;color: #333"></u--input>
  19. </view>
  20. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  21. <view class="page-wrap" >
  22. <view class="" v-for="item in dataList" :key="item.id" @click="$u.route('/shopping/productdetails',{id:item.id})">
  23. <view class="product u-flex">
  24. <u--image :showLoading="true" :src="item.mainImg" width="180rpx" height="180rpx"></u--image>
  25. <view class="text">
  26. <view class="name ellipsis-2">{{item.goodsName}}</view>
  27. <view class="u-flex u-row-between">
  28. <view class="left">
  29. <view class="up">
  30. <view class="u-flex" >
  31. <text class="price">¥ <text class="price-num">{{item.vipPrice}}</text></text>
  32. <!-- <text class="vip-icon">VIP</text> -->
  33. <text class="price-type">会员价</text>
  34. </view>
  35. <!-- <view class="" v-else>
  36. <text class="price">¥ <text class="price-num">{{item.salePrice}}</text></text>
  37. </view> -->
  38. </view>
  39. <view class="down">
  40. <!-- <text class="discount">8.8折</text> -->
  41. <text class="original-price gray line-through">¥ {{item.salePrice}}</text>
  42. <text class="sales gray">
  43. <text v-if="typeName=='特价专区'">抢购量</text>
  44. <text v-else>销量</text>
  45. {{item.saleCount}}</text>
  46. </view>
  47. </view>
  48. <u--image :showLoading="false" @click.native.stop="addCart(item.id)" :src="staticUrl+'/img/add.png'" width="48rpx" height="48rpx"></u--image>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </mescroll-body>
  55. <cartfixed ref="cartfixed" @getCartList="getCartList" />
  56. <u-toast ref="uToast"></u-toast>
  57. </view>
  58. </template>
  59. <script>
  60. // 引入mescroll-mixins.js
  61. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  62. import cartfixed from "../components/cartfixed.vue"
  63. export default {
  64. mixins: [MescrollMixin], // 使用mixin
  65. components: {
  66. cartfixed
  67. },
  68. data() {
  69. return {
  70. staticUrl:this.$commonConfig.staticUrl,
  71. downOption: {},
  72. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  73. upOption: {
  74. page: {
  75. size: 10 // 每页数据的数量,默认10
  76. },
  77. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  78. empty: {
  79. tip: '暂无相关数据'
  80. }
  81. },
  82. typeName:'产品',
  83. params:{
  84. goodsName:'',
  85. typeId:'',
  86. // isExplode:0,//是否爆款 0不是,1是
  87. },
  88. // 列表数据
  89. dataList: []
  90. }
  91. },
  92. onLoad(page) {
  93. this.params.typeId = page.typeId;
  94. this.typeName = page.typeName||'产品';
  95. },
  96. onShow() {
  97. this.$refs.cartfixed.getCartList();
  98. },
  99. methods: {
  100. /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
  101. downCallback(){
  102. this.mescroll.resetUpScroll();
  103. },
  104. /*上拉加载的回调*/
  105. upCallback(page) {
  106. // 此处可以继续请求其他接口
  107. // if(page.num == 1){
  108. // // 请求其他接口...
  109. // }
  110. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  111. let nameSearchArr = ['特价专区','爆款专区'];
  112. if(!this.params.typeId && !nameSearchArr.includes(this.typeName)){
  113. this.mescroll.endErr()
  114. return // 此处return,先获取xx
  115. }
  116. let pageNum = page.num; // 页码, 默认从1开始
  117. let pageSize = page.size; // 页长, 默认每页10条
  118. if(this.typeName=='特价专区'){
  119. this.params.typeId = '';
  120. this.params.isSpecial = 1;
  121. }else if(this.typeName=='爆款专区'){
  122. this.params.typeId = '';
  123. this.params.isExplode = 1;
  124. }
  125. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  126. console.log('this.params',this.params);
  127. this.$u.api.memberGoodList(this.params).then(data => {
  128. console.log('data',JSON.parse(JSON.stringify(data)));
  129. // 接口返回的当前页数据列表 (数组)
  130. let curPageData = data.data.rows;
  131. console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  132. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  133. let curPageLen = curPageData.length;
  134. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  135. // let totalPage = data.data.data.totalPage;
  136. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  137. let totalSize = data.data.total;
  138. // 接口返回的是否有下一页 (true/false)
  139. // let hasNext = data.xxx;
  140. // console.log('totalPage',totalPage,'curPageLen',curPageLen);
  141. //设置列表数据
  142. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  143. this.dataList = this.dataList.concat(curPageData); //追加新数据
  144. // 请求成功,隐藏加载状态
  145. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  146. // this.mescroll.endByPage(curPageLen, totalPage);
  147. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  148. this.mescroll.endBySize(curPageLen, totalSize);
  149. }).catch(err => {
  150. this.mescroll.endErr()
  151. console.log(err)
  152. });
  153. },
  154. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  155. reloadList() {
  156. this.mescroll.resetUpScroll();
  157. },
  158. search(e){
  159. this.mescroll.resetUpScroll();
  160. // this.reloadList();
  161. console.log('search',e)
  162. },
  163. addCart(id){
  164. // console.log('addCart',id);
  165. this.$u.api.addCart({goodsId:id}).then(res=>{
  166. this.$refs.cartfixed.getCartList('isAdd');
  167. console.log('res',res);
  168. }).catch(err=>{
  169. console.log('addCart',err.data);
  170. })
  171. }
  172. }
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. .product{}
  177. </style>