金诚优选前端代码
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.

283 lines
9.2 KiB

4 years ago
  1. <template>
  2. <view id="recharge-balance">
  3. <view class="content">
  4. <!-- 我在类名里面写了样式但是并不起作用先用行内样式-->
  5. <view class="balance-top" style="background:#FB5054 ">
  6. <view class="title">
  7. 账户余额
  8. </view>
  9. <view class="recharge-box">
  10. <view class="money">
  11. {{num/100}}
  12. </view>
  13. <view class="recharge" @tap="jump" style="display: flex;
  14. justify-content: center;
  15. align-items: center;
  16. width:50px;
  17. height:24px;
  18. border-radius:2px;
  19. border:1px solid rgba(255,255,255,1);">
  20. 充值 >
  21. </view>
  22. </view>
  23. </view>
  24. <view class="tab-panel">
  25. <block v-for="(item, index) in tabList" :key="index">
  26. <view :id="index" :hidden="activeIndex != index" :style="'color: ' + config.mainColor + '; border-color: ' + config.mainColor + ' '" class="tab-title active" @tap="tabClick">{{item.name}}</view>
  27. <view :id="index" :hidden="activeIndex == index" class="tab-title" @tap="tabClick">{{item.name}}</view>
  28. </block>
  29. </view>
  30. <view class="tab-content">
  31. <view class="tab-item" :hidden="activeIndex!=0">
  32. <block v-for="(items, idx) in dataList[0]" :key="idx">
  33. <view class="tab-item-content" v-for="(item, index) in dataList[0][idx]" :key="index">
  34. <view class="text">
  35. <view style="font-size: 14px; text-overflow:ellipsis;overflow:hidden;">{{item.note}}</view>
  36. <view style="font-size: 10px;color: #A3A3A3">{{item.updated_at}}</view>
  37. </view>
  38. <view class="num">
  39. +{{item.value/100}}
  40. </view>
  41. </view>
  42. </block>
  43. <view class="loadingbox" :hidden="!tabList[0].show">
  44. {{showText}}
  45. </view>
  46. </view>
  47. <view class="tab-item" :hidden="activeIndex!=1">
  48. <block v-for="(item, idx) in dataList[1]" :key="idx" >
  49. <view class="tab-item-content" v-for="(item, index) in dataList[1][idx]" :key="index">
  50. <view class="text">
  51. <view style="font-size: 14px; text-overflow:ellipsis;overflow:hidden;">{{item.note}}</view>
  52. <view style="font-size: 10px;color: #A3A3A3">{{item.updated_at}}</view>
  53. </view>
  54. <view class="num">
  55. {{item.value/100}}
  56. </view>
  57. </view>
  58. </block>
  59. <view class="loadingbox" :hidden="!tabList[1].show">
  60. {{showText}}
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  69. export default {
  70. data() {
  71. return {
  72. activeIndex: 0,
  73. tabList: [{
  74. id: 0,
  75. name: "收入",
  76. init: false,
  77. page: 0,
  78. more: true,
  79. show: false
  80. }, {
  81. id: 1,
  82. name: "支出",
  83. init: false,
  84. page: 0,
  85. more: true,
  86. show: false
  87. }],
  88. token: "",
  89. dataList: {
  90. 0: [],
  91. 1: []
  92. },
  93. num: "",
  94. showText: '正在加载下一页数据',
  95. config: ''
  96. };
  97. },
  98. onReachBottom(e) {
  99. var status = this.activeIndex;
  100. var page = this.tabList[status].page + 1;
  101. var tabList = `tabList[${status}]`;
  102. if (this.tabList[status].more) {
  103. this.setData({
  104. [`${tabList}.show`]: true
  105. });
  106. var token = this.token;
  107. this.queryBalanceList(token, status, page);
  108. } else {
  109. wx.showToast({
  110. icon: 'error',
  111. title: '再拉也没有啦'
  112. });
  113. }
  114. },
  115. onShow() {// let app =getApp();
  116. // app.isBirthday().then(()=>{
  117. // if(this.$cookieStorage.get("birthday_gift")){
  118. // var giftData=this.$cookieStorage.get("birthday_gift").data;
  119. // new app.ToastPannel().__page.showText(giftData);
  120. // }
  121. // });
  122. },
  123. onLoad(e) {
  124. // 第三方平台配置颜色
  125. var bgConfig = this.$cookieStorage.get('globalConfig') || '';
  126. this.setData({
  127. config: bgConfig
  128. }); // var status=0,page=1;
  129. // this.queryBalanceList(token);
  130. var status = e.type ? e.type : 0;
  131. var page = this.tabList[status].page;
  132. pageLogin(getUrl(), token => {
  133. this.setData({
  134. 'token': token
  135. });
  136. this.queryBalanceList(token, status, page);
  137. this.queryUserSum(token);
  138. });
  139. },
  140. components: {},
  141. props: {},
  142. methods: {
  143. jump() {
  144. wx.navigateTo({
  145. url: '/pages/recharge/index/index'
  146. });
  147. },
  148. tabClick(e) {
  149. // console.log(e.currentTarget.id);
  150. var status = e.currentTarget.id;
  151. this.setData({
  152. activeIndex: status
  153. });
  154. if (!this.tabList[status].init) {
  155. var page = this.tabList[status].page;
  156. wx.showLoading({
  157. title: "加载中",
  158. mask: true
  159. });
  160. this.queryBalanceList(this.token, status, page);
  161. }
  162. },
  163. result(res, status) {
  164. if (res.status) {
  165. var list;
  166. var page = res.meta.pagination;
  167. var current_page = page.current_page;
  168. var total_pages = page.total_pages;
  169. var tabList = `tabList[${status}]`;
  170. list = res.data;
  171. // this.setData({
  172. // [`dataList.${status}[${current_page - 1}]`]: list,
  173. // [`${tabList}.init`]: true,
  174. // [`${tabList}.page`]: current_page,
  175. // [`${tabList}.more`]: current_page < total_pages,
  176. // [`${tabList}.show`]: false
  177. // });
  178. this.dataList[status][current_page - 1]=res.data;
  179. this.tabList[status].init=true;
  180. this.tabList[status].page=current_page;
  181. this.tabList[status].more=current_page < total_pages;
  182. this.tabList[status].show=false;
  183. }
  184. },
  185. queryBalanceList(token, status, page) {
  186. var type = status ? 'consume' : 'recharge';
  187. var params = type ? {
  188. type
  189. } : {};
  190. params.page = page;
  191. this.$http.get({
  192. api: 'api/users/balance/list',
  193. header: {
  194. Authorization: token
  195. },
  196. data: params
  197. }).then(res => {
  198. if (res.statusCode == 200) {
  199. res = res.data;
  200. this.result(res, status);
  201. } else {
  202. wx.showModal({
  203. title: '提示',
  204. content: '数据请求失败',
  205. success: res => {}
  206. });
  207. }
  208. wx.hideLoading();
  209. }).catch(rej => {
  210. wx.showToast({
  211. title: "请求失败",
  212. image: '../../../static/error.png'
  213. });
  214. wx.hideLoading();
  215. });
  216. },
  217. queryUserSum(token) {
  218. this.$http.get({
  219. api: "api/users/balance/sum",
  220. header: {
  221. Authorization: token
  222. }
  223. }).then(res => {
  224. if (res.statusCode == 200) {
  225. res = res.data;
  226. this.setData({
  227. "num": res.data.sum
  228. });
  229. } else {
  230. wx.showModal({
  231. title: '提示',
  232. content: '数据请求失败',
  233. success: res => {}
  234. });
  235. }
  236. });
  237. },
  238. setData: function (obj) {
  239. let that = this;
  240. let keys = [];
  241. let val, data;
  242. Object.keys(obj).forEach(function (key) {
  243. keys = key.split('.');
  244. val = obj[key];
  245. data = that.$data;
  246. keys.forEach(function (key2, index) {
  247. if (index + 1 == keys.length) {
  248. that.$set(data, key2, val);
  249. } else {
  250. if (!data[key2]) {
  251. that.$set(data, key2, {});
  252. }
  253. }
  254. data = data[key2];
  255. });
  256. });
  257. }
  258. },
  259. computed: {},
  260. watch: {}
  261. };
  262. </script>
  263. <style>
  264. #recharge-balance .content{height:100%;overflow:auto;box-sizing:border-box}#recharge-balance .content .balance-top{color:#FFF;padding:20px 15px;background:#CDA76E}#recharge-balance .content .balance-top .title{font-size:12px}#recharge-balance .content .balance-top .recharge-box{display:flex;align-items:center;margin-top:20px;font-size:14px}#recharge-balance .content .tab-content,#recharge-balance .content .tab-panel{margin-top:10px;background-color:#FFF}#recharge-balance .content .balance-top .recharge-box .money{flex:1;font-size:30px}#recharge-balance .content .tab-panel{display:flex;box-sizing:border-box}#recharge-balance .content .tab-panel .tab-title{height:44px;width:50%;line-height:44px;text-align:center;box-sizing:border-box}#recharge-balance .content .tab-panel .tab-title.active{color:#CDA76E;border-bottom:2px solid #CDA76E}#recharge-balance .content .tab-content .tab-item-content{box-sizing:border-box;padding-left:12px;padding-right:12px;display:flex;line-height:60px;height:60px;border-bottom:1px solid #d9d9d9;justify-content:space-between}#recharge-balance .content .tab-content .tab-item-content .num{color:#ff2741}#recharge-balance .content .tab-content .tab-item-content .text{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;line-height:30px;flex:1}#recharge-balance .loadingbox{text-align:center;padding:5px 0}
  265. </style>