credits.vue 7.7 KB

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