productList.vue 6.1 KB

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