supermarket.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view class="page-wrap">
  3. <!-- <u-navbar
  4. title="积分商城"
  5. :placeholder="true"
  6. :autoBack="true"
  7. :safeAreaInsetTop="true"
  8. >
  9. </u-navbar> -->
  10. <view class="header">
  11. <view class="inner">
  12. <view class="top u-flex u-row-between">
  13. <view class="u-flex">
  14. <img src="../static/img/integral-ico.png" alt="">
  15. <text>积分余额</text>
  16. </view>
  17. <view class="right u-flex" @click="$u.route('/pages/regulation/regulation',{regulationName:'积分规则'})">
  18. <u-icon name="error-circle" color="#fff" size="34rpx"></u-icon>
  19. <text>规则</text>
  20. </view>
  21. </view>
  22. <view class="num" @click="$u.route('/center/addcredits')">{{credit}}</view>
  23. <!-- <view class="bottom">
  24. <text @click="$u.route('/credits/creditslist')">积分明细</text>
  25. </view> -->
  26. </view>
  27. </view>
  28. <view class="tabs-wrap">
  29. <u-tabs
  30. :list="tabsList"
  31. lineColor="#009AEF"
  32. :activeStyle="{color:'#333','font-weight': '600','font-size':'30rpx'}"
  33. :inactiveStyle="{color:'#999'}"
  34. @click="tabsClick"></u-tabs>
  35. </view>
  36. <view class="">
  37. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  38. <view class="credit-product u-flex u-flex-wrap">
  39. <view class="credit-product-item" @click="goDetails(item.id)" v-for="(item,index) in dataList" :key="item.id">
  40. <view class="pic">
  41. <u--image class="image" :src="item.mainImg" width="100%" height="340rpx"></u--image>
  42. </view>
  43. <view class="text">
  44. <view class="til ellipsis-2">
  45. {{item.goodsName}}
  46. </view>
  47. <view class="price u-flex">
  48. <img style="margin-right: 10rpx;" src="../static/img/integral-ico-y.png" alt="">
  49. {{item.exchangeCredit}}积分
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </mescroll-body>
  55. </view>
  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. export default {
  62. mixins: [MescrollMixin], // 使用mixin
  63. data() {
  64. return {
  65. downOption: {},
  66. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  67. upOption: {
  68. page: {
  69. size: 10 // 每页数据的数量,默认10
  70. },
  71. noMoreSize: 3, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  72. empty: {
  73. tip: '暂无相关数据'
  74. }
  75. },
  76. hasAddr:false,
  77. staticUrl:this.$commonConfig.staticUrl,
  78. tabsList:[],
  79. credit:'',
  80. hasTypeId:false,
  81. typeId:'',
  82. dataList:[],
  83. }
  84. },
  85. onShow() {
  86. this.getCredit();//积分
  87. // this.getAddrList();
  88. },
  89. onLoad() {
  90. // this.getTypeList();
  91. },
  92. methods: {
  93. /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
  94. downCallback(){
  95. this.mescroll.resetUpScroll();
  96. },
  97. /*上拉加载的回调*/
  98. upCallback(page) {
  99. // 此处可以继续请求其他接口
  100. // if(page.num == 1){
  101. // // 请求其他接口...
  102. // }
  103. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  104. if(!this.hasTypeId){
  105. this.getTypeList();
  106. return // 此处return,先获取xx
  107. }
  108. let pageNum = page.num; // 页码, 默认从1开始
  109. let pageSize = page.size; // 页长, 默认每页10条
  110. let params = {
  111. pageNum : page.num,
  112. pageSize : page.size,
  113. classifyId : this.typeId
  114. }
  115. // console.log('this.params',params);
  116. this.$u.api.memberGoodList(params).then(data => {
  117. // console.log('data',JSON.parse(JSON.stringify(data)));
  118. // 接口返回的当前页数据列表 (数组)
  119. let curPageData = data.data.rows;
  120. // console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  121. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  122. let curPageLen = curPageData.length;
  123. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  124. // let totalPage = data.data.data.totalPage;
  125. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  126. let totalSize = data.data.total;
  127. // 接口返回的是否有下一页 (true/false)
  128. // let hasNext = data.xxx;
  129. // console.log('totalPage',totalPage,'curPageLen',curPageLen);
  130. //设置列表数据
  131. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  132. this.dataList = this.dataList.concat(curPageData); //追加新数据
  133. // 请求成功,隐藏加载状态
  134. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  135. // this.mescroll.endByPage(curPageLen, totalPage);
  136. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  137. this.mescroll.endBySize(curPageLen, totalSize);
  138. }).catch(err => {
  139. this.mescroll.endErr()
  140. console.log(err)
  141. });
  142. },
  143. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  144. reloadList() {
  145. this.mescroll.resetUpScroll();
  146. },
  147. getTypeList(){
  148. this.$u.api.goodsTypeList({parentId:0,pageNum:1,pageSize:200}).then(res=>{
  149. // console.log('getTypeList',res.data.rows);
  150. this.hasTypeId = true;
  151. this.tabsList = res.data.rows;
  152. this.tabsList.unshift({name:'全部',id:null});
  153. this.typeId =res.data.rows[0].id;
  154. this.mescroll.resetUpScroll()
  155. }).catch(err=>{
  156. console.log('goodsTypeList',err);
  157. })
  158. },
  159. tabsClick(item){
  160. this.typeId = item.id;
  161. this.reloadList()
  162. // console.log('item',item);
  163. },
  164. getCredit(){
  165. this.$u.api.memberCredit().then(res=>{
  166. this.credit = res.data.credit;
  167. // console.log('memberCredit',res.data);
  168. }).catch(err=>{
  169. console.log('memberCredit',err);
  170. })
  171. },
  172. goDetails(id){
  173. // if(!this.hasAddr){
  174. // uni.showModal({
  175. // title: '温馨提示',
  176. // content: '请先设置地址!',
  177. // success: res => {
  178. // if (res.confirm) {
  179. // uni.$u.route('/center/addrlist', {
  180. // from: 'cart',
  181. // backUrl:'/credits/credits'
  182. // });
  183. // }
  184. // }
  185. // })
  186. // return
  187. // }
  188. uni.$u.route('/shopping/productdetails', {
  189. id: id
  190. });
  191. },
  192. getAddrList(){
  193. this.$u.api.addrList().then(res=>{
  194. // this.dataList = res.data.rows;
  195. if( res.data.total>0){
  196. this.hasAddr = true;
  197. }else{
  198. this.hasAddr = false;
  199. }
  200. }).catch(err=>{
  201. console.log('getAddrList',err.data);
  202. })
  203. },
  204. }
  205. }
  206. </script>
  207. <style>
  208. page{
  209. background-color: #F5F9FC;
  210. }
  211. </style>
  212. <style lang="scss" scoped>
  213. .header{
  214. color: #fff;
  215. position: relative;
  216. height: 260rpx;
  217. margin-bottom: 30rpx;
  218. background: url(../static/img/supermarket-top.png) no-repeat;
  219. background-size: 100% 100%;
  220. .inner{
  221. padding: 40rpx;
  222. .top{
  223. font-size: 26rpx;
  224. text{margin-left: 10rpx;}
  225. margin-bottom: 30rpx;
  226. }
  227. .num{
  228. font-size: 50rpx;
  229. font-weight: 600;
  230. color: #FFFFFF;
  231. line-height: 58rpx;
  232. }
  233. .bottom{
  234. text-align: right;
  235. text{
  236. display: inline-block;
  237. padding: 4rpx 20rpx;
  238. background: rgba(0,0,0,0.2);
  239. color: #fff;
  240. border-radius: 23rpx;
  241. font-size: 22rpx;
  242. }
  243. }
  244. }
  245. }
  246. .tabs-wrap{
  247. background-color: #fff;
  248. margin-bottom: 10rpx;
  249. }
  250. .credit-product{
  251. margin-top: 20rpx;
  252. &-item{
  253. width: 47%;
  254. background-color: #fff;
  255. margin-bottom: 30rpx;
  256. border-radius: 24rpx;
  257. &:nth-child(even){
  258. margin-left: 6%;
  259. }
  260. .til{
  261. font-size: 32rpx;
  262. height: 80rpx;
  263. }
  264. .text{
  265. padding: 20rpx;
  266. .price{
  267. margin-top: 17rpx;
  268. font-size: 36rpx;
  269. font-weight: 600;
  270. color: #FFB100;
  271. line-height: 50rpx;
  272. }
  273. }
  274. .bottom{
  275. font-size: 30rpx;
  276. font-weight: 600;
  277. color: #00A447;
  278. line-height: 42rpx;
  279. .btn{
  280. font-size: 22rpx;
  281. font-weight: 400;
  282. color: #FFFFFF;
  283. padding: 5rpx 18rpx;
  284. background: #00A447;
  285. border-radius: 4px;
  286. }
  287. }
  288. }
  289. }
  290. </style>