supermarket.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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}).then(res=>{
  149. // console.log('getTypeList',res.data.rows);
  150. this.hasTypeId = true;
  151. this.tabsList = res.data.rows;
  152. this.typeId =res.data.rows[0].id;
  153. this.mescroll.resetUpScroll()
  154. }).catch(err=>{
  155. console.log('goodsTypeList',err);
  156. })
  157. },
  158. tabsClick(item){
  159. this.typeId = item.id;
  160. this.reloadList()
  161. // console.log('item',item);
  162. },
  163. getCredit(){
  164. this.$u.api.memberCredit().then(res=>{
  165. this.credit = res.data.credit;
  166. // console.log('memberCredit',res.data);
  167. }).catch(err=>{
  168. console.log('memberCredit',err);
  169. })
  170. },
  171. goDetails(id){
  172. // if(!this.hasAddr){
  173. // uni.showModal({
  174. // title: '温馨提示',
  175. // content: '请先设置地址!',
  176. // success: res => {
  177. // if (res.confirm) {
  178. // uni.$u.route('/center/addrlist', {
  179. // from: 'cart',
  180. // backUrl:'/credits/credits'
  181. // });
  182. // }
  183. // }
  184. // })
  185. // return
  186. // }
  187. uni.$u.route('/shopping/productdetails', {
  188. id: id
  189. });
  190. },
  191. getAddrList(){
  192. this.$u.api.addrList().then(res=>{
  193. // this.dataList = res.data.rows;
  194. if( res.data.total>0){
  195. this.hasAddr = true;
  196. }else{
  197. this.hasAddr = false;
  198. }
  199. }).catch(err=>{
  200. console.log('getAddrList',err.data);
  201. })
  202. },
  203. }
  204. }
  205. </script>
  206. <style>
  207. page{
  208. background-color: #F5F9FC;
  209. }
  210. </style>
  211. <style lang="scss" scoped>
  212. .header{
  213. color: #fff;
  214. position: relative;
  215. height: 260rpx;
  216. margin-bottom: 30rpx;
  217. background: url(../static/img/supermarket-top.png) no-repeat;
  218. .inner{
  219. padding: 40rpx;
  220. .top{
  221. font-size: 26rpx;
  222. text{margin-left: 10rpx;}
  223. margin-bottom: 30rpx;
  224. }
  225. .num{
  226. font-size: 50rpx;
  227. font-weight: 600;
  228. color: #FFFFFF;
  229. line-height: 58rpx;
  230. }
  231. .bottom{
  232. text-align: right;
  233. text{
  234. display: inline-block;
  235. padding: 4rpx 20rpx;
  236. background: rgba(0,0,0,0.2);
  237. color: #fff;
  238. border-radius: 23rpx;
  239. font-size: 22rpx;
  240. }
  241. }
  242. }
  243. }
  244. .tabs-wrap{
  245. background-color: #fff;
  246. margin-bottom: 10rpx;
  247. }
  248. .credit-product{
  249. margin-top: 20rpx;
  250. &-item{
  251. width: 47%;
  252. background-color: #fff;
  253. margin-bottom: 30rpx;
  254. border-radius: 24rpx;
  255. &:nth-child(even){
  256. margin-left: 6%;
  257. }
  258. .til{
  259. font-size: 32rpx;
  260. height: 80rpx;
  261. }
  262. .text{
  263. padding: 20rpx;
  264. .price{
  265. margin-top: 17rpx;
  266. font-size: 36rpx;
  267. font-weight: 600;
  268. color: #FFB100;
  269. line-height: 50rpx;
  270. }
  271. }
  272. .bottom{
  273. font-size: 30rpx;
  274. font-weight: 600;
  275. color: #00A447;
  276. line-height: 42rpx;
  277. .btn{
  278. font-size: 22rpx;
  279. font-weight: 400;
  280. color: #FFFFFF;
  281. padding: 5rpx 18rpx;
  282. background: #00A447;
  283. border-radius: 4px;
  284. }
  285. }
  286. }
  287. }
  288. </style>