productList.vue 6.2 KB

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