index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view>
  3. <!--mine/wallet/wallet.wxml-->
  4. <view class="bodry mt20">
  5. <image src="/wallet/static/wallet/images/topbg.png" class="walletbg"></image>
  6. <view class="balance">
  7. <view class="mywallet">我的余额(元)</view>
  8. <view class="bottm dflex">
  9. <view class="money">
  10. <!-- ¥ --><text class="num">{{money.all?money.all:'0'}}</text>
  11. </view>
  12. <view class="detailed" @tap="toDetailed">余额明细</view>
  13. </view>
  14. </view>
  15. <!-- <view class="dflex top">
  16. <label style="font-size:32rpx;font-weight:bold;">我的余额</label>
  17. <view style="font-size:32rpx">
  18. <text class="qian"
  19. style="font-size:52rpx;font-weight:bold;margin-right: 10rpx;">{{money.all?money.all:'0'}}</text>元
  20. <view class="dflex yueDetaile " @tap="toDetailed">余额明细<image src="/static/pages/images/more.png" role="img"
  21. class="more"></image>
  22. </view>
  23. </view>
  24. </view> -->
  25. <!-- 充值金额 -->
  26. <view class="recharge">
  27. <view :class="'dflex rechargeId' + (isInt ? ' on' : '')">
  28. <text>¥</text>
  29. <input placeholder="点击输入充值金额" placeholder-class="placeholder" v-model="pay" @input="amount"
  30. @focus="focus" @blur="onBlur" />
  31. </view>
  32. <view class="rechargeMoney" v-if="TabList&&TabList.length>0">快捷充值</view>
  33. <view class="rechargeul dflex" v-if="TabList&&TabList.length>0">
  34. <view v-for="(item, index) in TabList" :key="index"
  35. :class="'rechargeli ' + (item.active?'active':'')" @tap="switchTab(item,index)">
  36. <view :class="'wealth ' + (item.active?'awealth':'')">充{{item.rechargeAmount}}元</view>
  37. <view :class="'give ' + (item.active?'awealth':'')" v-if="item.donationAmount>0">
  38. 送{{item.donationAmount}}元
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="kong"></view>
  45. <view class="chongzhi" @tap="remainder">立即充值</view>
  46. <view class="card" @tap="goCard">激活卡充值</view>
  47. <view class="kong"></view>
  48. </view>
  49. </template>
  50. <script>
  51. // mine/wallet/wallet.js
  52. const route = require("../../utils/route.js");
  53. const req = require("../../utils/request");
  54. const app = getApp();
  55. export default {
  56. data() {
  57. return {
  58. TabList: [],
  59. money: "",
  60. id: "",
  61. pay: "",
  62. active: false,
  63. isInt: false,
  64. };
  65. },
  66. components: {},
  67. props: {},
  68. /**
  69. * 生命周期函数--监听页面加载
  70. */
  71. onLoad: function(options) {},
  72. /**
  73. * 生命周期函数--监听页面显示
  74. */
  75. onShow: function() {
  76. this.extendNew();
  77. this.balance();
  78. },
  79. /**
  80. * 生命周期函数--监听页面隐藏
  81. */
  82. onHide: function() {},
  83. /**
  84. * 生命周期函数--监听页面卸载
  85. */
  86. onUnload: function() {},
  87. /**
  88. * 页面相关事件处理函数--监听用户下拉动作
  89. */
  90. onPullDownRefresh: function() {},
  91. /**
  92. * 页面上拉触底事件的处理函数
  93. */
  94. onReachBottom: function() {},
  95. methods: {
  96. // 查询用户余额
  97. extendNew() {
  98. route.extendNew({}, res => {
  99. this.setData({
  100. money: res
  101. });
  102. console.log(res);
  103. });
  104. },
  105. // 查询余额充值策略
  106. balance() {
  107. route.balance({}, res => {
  108. // res=res.map(it=>{
  109. // it.active=false
  110. // return it
  111. // })
  112. if (!res) {} else if (res.length > 0) {
  113. this.setData({
  114. TabList: res,
  115. // ['TabList[0].active']: true,
  116. // id: res[0].id,
  117. // pay: res[0].rechargeAmount
  118. });
  119. }
  120. console.log(this.TabList);
  121. });
  122. },
  123. switchTab(item, index) {
  124. // let index = event.currentTarget.dataset.index;
  125. // let id = event.currentTarget.dataset.id;
  126. // let money = event.currentTarget.dataset.money;
  127. let def = this.TabList.findIndex(it => it.active || it.actives);
  128. let d = {};
  129. console.log(def, index);
  130. d['TabList[' + def + '].active'] = false;
  131. d['TabList[' + def + '].actives'] = false;
  132. d['TabList[' + index + '].active'] = true;
  133. d['pageList'] = []; // this.data.form.states=this.data.TabList[index].state.toString();
  134. // this.data.form.state = this.data.TabList[index].state;
  135. console.log(item)
  136. this.setData({
  137. id: item.id,
  138. active: false,
  139. pay: item.rechargeAmount
  140. });
  141. this.setData(d);
  142. },
  143. switchTab1() {
  144. let def = this.TabList.findIndex(it => it.active);
  145. let d = {};
  146. if (def == -1) return;
  147. d['TabList[' + def + '].active'] = false;
  148. d['TabList[' + 0 + '].actives'] = true;
  149. this.setData({
  150. active: true,
  151. id: ''
  152. });
  153. this.setData(d);
  154. },
  155. // 输入金额根据输入金额获取赠送多少金额
  156. amount(e) {
  157. console.log(e.detail.value);
  158. let money = e.detail.value;
  159. this.setData({
  160. pay: money,
  161. id: ''
  162. });
  163. },
  164. focus(e) {
  165. this.setData({
  166. pay: ""
  167. })
  168. this.isInt = true;
  169. let def = this.TabList.findIndex(it => it.active);
  170. let d = {};
  171. console.log(def)
  172. if (!e.detail.value) {
  173. } else {
  174. let money = e.detail.value
  175. this.setData({
  176. pay: money
  177. })
  178. }
  179. if (def == -1) return
  180. d['TabList[' + def + '].active'] = false;
  181. d['TabList[' + 0 + '].actives'] = true;
  182. console.log(e, "111111111111", e.detail.value)
  183. this.setData(d);
  184. this.setData({
  185. id: ''
  186. })
  187. },
  188. onBlur() {
  189. this.isInt = false;
  190. },
  191. //跳充值卡
  192. goCard() {
  193. app.globalData.navigateTo('wallet/rechargeCard/index')
  194. },
  195. // 余额充值
  196. remainder(id) {
  197. let that = this;
  198. let from = {};
  199. console.log(that.pay);
  200. if (this.pay && this.pay > 0) {
  201. from.money = this.pay;
  202. } else {
  203. return req.msg('输入的充值金额需大于0');
  204. }
  205. if (this.id) {
  206. from.rulesId = this.id;
  207. delete from.money;
  208. }
  209. console.log(from);
  210. route.remainder(from, data => {
  211. if (!data) {
  212. return req.msg('创建订单失败');
  213. } else {
  214. route.balancePay(data, '4', that.pay, res => {
  215. if (res) {
  216. // app.openPage('product/pay/pay?isSuccess=true' + '&balance=' + true)
  217. that.extendNew();
  218. that.active = false;
  219. if(TabList && TabList.length > 0){
  220. that.TabList[0].active = true;
  221. that.id = that.TabList[0].id;
  222. that.pay = that.TabList[0].rechargeAmount;
  223. }
  224. // this.setData({
  225. // active: false,
  226. // ['TabList[0].active']: true,
  227. // id: this.TabList[0].id,
  228. // pay: this.TabList[0].rechargeAmount
  229. // });
  230. }
  231. });
  232. }
  233. console.log(data);
  234. });
  235. },
  236. // 跳转余额明细
  237. toDetailed() {
  238. app.globalData.navigateTo('wallet/detailed/detailed');
  239. },
  240. onHide() {
  241. this.setData({
  242. active: false
  243. })
  244. }
  245. }
  246. };
  247. </script>
  248. <style>
  249. @import "./index.css";
  250. </style>