index.vue 7.6 KB

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