credits.vue 7.5 KB

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