金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

289 lines
8.0 KiB

  1. <template>
  2. <view id="point_index">
  3. <!--point-top开始-->
  4. <view class="point-top" :style="'background: ' + config.mainColor">
  5. <view class="point-current">
  6. <view>当前可用积分</view>
  7. <view class="point-num">{{point.pointValid}}</view>
  8. <view>冻结积分 {{point.pointFrozen}}</view>
  9. </view>
  10. <view class="point-frozen">
  11. <view class="point-mall" @tap="jump">积分商城</view>
  12. </view>
  13. </view>
  14. <!--point-top结束-->
  15. <!--point-content开始-->
  16. <view class="point-content">
  17. <view class="navbar mx-1px-bottom">
  18. <block v-for="(item, index) in tabList" :key="index" >
  19. <view :id="index" class="navbar-item activity" :hidden="activeIndex != index" :style="'color: ' + config.mainColor" @tap="tabClick">
  20. <view class="navbar-title">{{item.title}}</view>
  21. </view>
  22. <view :id="index" :hidden="activeIndex == index" class="navbar-item" @tap="tabClick">
  23. <view class="navbar-title">{{item.title}}</view>
  24. </view>
  25. </block>
  26. <view class="navbar-slider" :style="'width: ' + width + 'px; transform: translateX(' + sliderOffset + 'px); -webkit-transform: translateX(' + sliderOffset + 'px); background: ' + config.mainColor"></view>
  27. </view>
  28. <view class="tab-panel">
  29. <view class="tab-content" :hidden="activeIndex != 0">
  30. <view class="point-item mx-1px-top">
  31. <view v-for="(item, idx) in dataList[0]" :key="idx">
  32. <view class="point-info mx-1px-bottom" v-for="(point, index) in dataList[0][idx]" :key="index" >
  33. <view class="info-left">
  34. <view class="store-title">{{point.note}}</view>
  35. <view class="up-time">{{point.updated_at}}</view>
  36. </view>
  37. <view class="info-right">
  38. <view class="up-money">{{point.value}}</view>
  39. <view class="point-status">{{point.status_text}}</view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="tab-content" :hidden="activeIndex != 1">
  46. <view class="point-item mx-1px-top">
  47. <view v-for="(item, idx) in dataList[1]" :key="idx" >
  48. <view class="point-info mx-1px-bottom" v-for="(point, index) in dataList[1][idx]" :key="index">
  49. <view class="info-left">
  50. <view class="store-title">{{point.note}}</view>
  51. <view class="up-time">{{point.updated_at}}</view>
  52. </view>
  53. <view class="slow-money">{{point.value}}</view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <!--point-content结束-->
  61. </view>
  62. </template>
  63. <script>
  64. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  65. export default {
  66. data() {
  67. return {
  68. activeIndex: 0,
  69. sliderOffset: 0,
  70. sliderLeft: 0,
  71. width: 0,
  72. tabList: [{
  73. title: "收入",
  74. init: false,
  75. page: 0,
  76. more: true
  77. }, {
  78. title: "支出",
  79. init: false,
  80. page: 0,
  81. more: true
  82. }],
  83. dataList: {
  84. 0: [],
  85. 1: []
  86. },
  87. point: {},
  88. config: ''
  89. };
  90. },
  91. onReachBottom(e) {
  92. var status = this.activeIndex;
  93. var page = this.tabList[status].page + 1;
  94. var tabList = `tabList[${status}]`;
  95. if (this.tabList[status].more) {
  96. this.queryPointListBalance(status, page);
  97. } else {
  98. wx.showToast({
  99. image: '../../../static/error.png',
  100. title: '再拉也没有啦'
  101. });
  102. }
  103. },
  104. onShow(e) {
  105. wx.getSystemInfo({
  106. success: res => {
  107. this.setData({
  108. width: res.windowWidth / this.tabList.length,
  109. sliderOffset: res.windowWidth / this.tabList.length * this.activeIndex
  110. });
  111. }
  112. });
  113. },
  114. onLoad(e) {
  115. // 第三方平台配置颜色
  116. var config = this.$cookieStorage.get('globalConfig') || '';
  117. this.setData({
  118. config: config
  119. });
  120. if (e.type) {
  121. this.setData({
  122. activeIndex: e.type
  123. });
  124. }
  125. this.queryPointListBalance(this.activeIndex);
  126. this.queryUserPoint('default');
  127. },
  128. components: {},
  129. props: {},
  130. methods: {
  131. // 点击切换
  132. tabClick(e) {
  133. var status = e.currentTarget.id;
  134. this.setData({
  135. sliderOffset: e.currentTarget.offsetLeft,
  136. activeIndex: status
  137. });
  138. if (!this.tabList[status].init) {
  139. // wx.showLoading({
  140. // title: "加载中",
  141. // mask: true
  142. // });
  143. this.queryPointListBalance(status);
  144. }
  145. },
  146. // 查询积分列表
  147. queryPointListBalance(status = 0, page = 1) {
  148. var token = this.$cookieStorage.get('user_token');
  149. wx.showLoading({
  150. title: "加载中",
  151. mask: true
  152. });
  153. var balance = status ? 'out' : 'in';
  154. var params = balance ? {
  155. balance
  156. } : {};
  157. params.page = page;
  158. params.type = 'default';
  159. this.$http.get({
  160. api: 'api/users/point/list',
  161. header: {
  162. Authorization: token
  163. },
  164. data: params
  165. }).then(res => {
  166. if (res.statusCode == 200) {
  167. res = res.data;
  168. if (res.status) {
  169. var pages = res.meta.pagination;
  170. var current_page = pages.current_page;
  171. var total_pages = pages.total_pages;
  172. var tabList = `tabList[${status}]`;
  173. // this.setData({
  174. // [`dataList.${status}[${page - 1}]`]: res.data,
  175. // [`${tabList}.init`]: true,
  176. // [`${tabList}.page`]: current_page,
  177. // [`${tabList}.more`]: current_page < total_pages,
  178. // [`${tabList}.show`]: false
  179. // });
  180. this.dataList[status][page - 1]=res.data;
  181. this.tabList[status].init=true;
  182. this.tabList[status].page=current_page;
  183. this.tabList[status].more=current_page < total_pages;
  184. this.tabList[status].show=false;
  185. } else {
  186. wx.showModal({
  187. content: res.message || '请求失败',
  188. showCancel: false
  189. });
  190. }
  191. } else {
  192. wx.showModal({
  193. content: '请求失败',
  194. showCancel: false
  195. });
  196. }
  197. wx.hideLoading();
  198. }).catch(rej => {
  199. wx.hideLoading();
  200. wx.showModal({
  201. content: '请求失败',
  202. showCancel: false
  203. });
  204. });
  205. },
  206. // 查询用户积分
  207. queryUserPoint(type) {
  208. var token = this.$cookieStorage.get('user_token');
  209. this.$http.get({
  210. api: 'api/users/point',
  211. header: {
  212. Authorization: token
  213. },
  214. data: {
  215. type: type
  216. }
  217. }).then(res => {
  218. if (res.statusCode == 200) {
  219. res = res.data;
  220. this.setData({
  221. point: res.data
  222. });
  223. } else {
  224. wx.showModal({
  225. content: '请求失败',
  226. showCancel: false
  227. });
  228. }
  229. });
  230. },
  231. jump() {
  232. wx.navigateTo({
  233. url: '/pages/pointStore/index/index'
  234. });
  235. },
  236. setData: function (obj) {
  237. let that = this;
  238. let keys = [];
  239. let val, data;
  240. Object.keys(obj).forEach(function (key) {
  241. keys = key.split('.');
  242. val = obj[key];
  243. data = that.$data;
  244. keys.forEach(function (key2, index) {
  245. if (index + 1 == keys.length) {
  246. that.$set(data, key2, val);
  247. } else {
  248. if (!data[key2]) {
  249. that.$set(data, key2, {});
  250. }
  251. }
  252. data = data[key2];
  253. });
  254. });
  255. }
  256. },
  257. computed: {},
  258. watch: {}
  259. };
  260. </script>
  261. <style rel="stylesheet/less" lang="less">
  262. @import "index";
  263. </style>