productList.vue 6.1 KB

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