recharge.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <template>
  2. <view class="content">
  3. <view class="yue">
  4. <view class="font">
  5. 当前余额
  6. </view>
  7. <view class="money">
  8. {{ nowmoney | getMoneyStyle }}
  9. </view>
  10. </view>
  11. <view class="row-box">
  12. <view class="title">充值金额</view>
  13. <view class="row">
  14. <text class="tit">¥</text>
  15. <input class="input" type="number" v-model="money" placeholder="请输入充值金额" placeholder-class="placeholder" />
  16. </view>
  17. <view class="xian"></view>
  18. <view class="moneyBtn-box">
  19. <view class="moneyBtn" v-for="(item,index) in moneyList" :class="{'current' : choose == index}" :key="index" @click="changemoney(item,index)">
  20. {{ item }}元
  21. </view>
  22. </view>
  23. </view>
  24. <view class="list">
  25. <radio-group @change="tabRadio">
  26. <!-- #ifndef APP-PLUS -->
  27. <label>
  28. <view class="box">
  29. <view class="icon iconfont iconweixin1"></view>
  30. <view class="title-box">
  31. <view class="title"><text>微信充值</text></view>
  32. </view>
  33. <view class="right"><radio value="weixin" color="#FF4343" :checked="type == 'weixin'" /></view>
  34. </view>
  35. </label>
  36. <!-- #endif -->
  37. <!-- <label>
  38. <view class="box">
  39. <view class="icon iconfont"><image class="yongjing" src="http://xmpt.liuniu946.com/img/yongjing.png"></image></view>
  40. <view class="title-box">
  41. <view class="title"><text>佣金充值</text></view>
  42. <view class="node">可用佣金¥{{ yongMoney }}</view>
  43. </view>
  44. <view class="right"><radio value="yongjing" color=" #5dbc7c" :checked="type == 'yongjing'" /></view>
  45. </view>
  46. </label> -->
  47. </radio-group>
  48. </view>
  49. <button class="add-btn up" :class="{ 'active-bg': payLoding }" @click="!payLoding ? confirm() : ''">确认充值</button>
  50. </view>
  51. </template>
  52. <script>
  53. import { getMoneyStyle } from '@/utils/rocessor.js';
  54. import { userBalance,extractBank } from '@/api/wallet.js'
  55. // #ifdef H5
  56. import { rechargeWechat } from '@/api/wallet.js';
  57. // #endif
  58. // #ifdef MP
  59. import { rechargeRoutine } from '@/api/wallet.js';
  60. // #endif
  61. import { mapState } from 'vuex';
  62. // #ifdef H5
  63. import weixinObj from '@/plugin/jweixin-module/index.js';
  64. // #endif
  65. export default {
  66. filters: {
  67. getMoneyStyle
  68. },
  69. data() {
  70. return {
  71. // #ifndef APP-PLUS
  72. typeText: 0,
  73. type: 'weixin',
  74. // #endif
  75. // #ifdef APP-PLUS
  76. typeText: 1,
  77. type: 'yongjing',
  78. // #endif
  79. money: '', //充值金额
  80. payLoding: false, //是否加载中
  81. moneyList: [300,200,150,100,50],
  82. nowmoney: '',
  83. choose: -1,
  84. yongMoney:'',
  85. };
  86. },
  87. onLoad(options) {
  88. const obj = this;
  89. if(options.type == '1'){
  90. obj.type = 'yongjing',
  91. obj.typeText = 1
  92. }
  93. },
  94. onShow() {
  95. userBalance({}).then(({ data }) => {
  96. console.log(data)
  97. this.nowmoney = data.now_money;
  98. });
  99. extractBank({}).then(({ data }) => {
  100. this.yongMoney = (data.commissionCount*1).toFixed(2);//累积佣金
  101. });
  102. },
  103. computed: {
  104. // #ifdef H5
  105. ...mapState(['weichatObj'])
  106. // #endif
  107. },
  108. methods: {
  109. // 跳转
  110. navTo(url) {
  111. uni.navigateTo({
  112. url: url
  113. });
  114. },
  115. // 切换选中对象
  116. tabRadio(e) {
  117. console.log(e)
  118. if ( e.detail.value == 'weixin' ) {
  119. this.typeText = 0
  120. }
  121. else {
  122. this.typeText = 1
  123. }
  124. this.type = e;
  125. console.log(this.typeText);
  126. },
  127. // 提交
  128. confirm() {
  129. let obj = this;
  130. obj.payLoding = true;
  131. if( obj.money == ''){
  132. obj.$api.msg('请输入充值金额');
  133. obj.payLoding = false;
  134. return;
  135. }
  136. if( obj.type == 'yongjin' && obj.money > parseInt(obj.yongMoney) ) {
  137. obj.$api.msg('佣金不足');
  138. obj.payLoding = false;
  139. return;
  140. }
  141. // #ifdef H5
  142. // rechargeWechat({ price: this.money, from: this.type })
  143. rechargeWechat({ price: this.money, from: 'weixin',
  144. type: this.typeText})
  145. .then(e => {
  146. console.log(e)
  147. if ( obj.type == 'weixin' ){
  148. let da = e.data.data;
  149. console.log(weixinObj,"weixin")
  150. weixinObj.chooseWXPay({
  151. timestamp: da.timestamp,
  152. nonceStr: da.nonceStr,
  153. package: da.package,
  154. signType: da.signType,
  155. paySign: da.paySign,
  156. success: function(res) {
  157. uni.showToast({
  158. title: '充值成功',
  159. duration: 2000,
  160. position: 'top'
  161. });
  162. }
  163. });
  164. obj.payLoding = false;
  165. }else {
  166. uni.navigateTo({
  167. url: '/pages/money/rechargeSuccess'
  168. })
  169. obj.payLoding = false;
  170. console.log(e, '佣金');
  171. }
  172. })
  173. .catch(e => {
  174. obj.payLoding = false;
  175. console.log(e);
  176. });
  177. // #endif
  178. // #ifdef MP
  179. rechargeRoutine({ price: this.money})
  180. .then(e => {
  181. let da = e.data;
  182. wx.requestPayment({
  183. timeStamp: da.timestamp,
  184. nonceStr: da.nonceStr,
  185. package: da.package,
  186. signType: da.signType,
  187. paySign: da.paySign,
  188. success: function(res) {
  189. uni.redirectTo({
  190. url: '/pages/money/paySuccess'
  191. });
  192. },
  193. })
  194. obj.payLoding = false;
  195. })
  196. .catch(e => {
  197. obj.payLoding = false;
  198. console.log(e);
  199. });
  200. // #endif
  201. },
  202. //获取订单列表
  203. loadData(source) {
  204. console.log(source);
  205. //这里是将订单挂载到tab列表下
  206. let index = this.tabCurrentIndex;
  207. let navItem = this.navList[index];
  208. let state = navItem.state;
  209. if (source === 'tabChange' && navItem.loaded === true) {
  210. //tab切换只有第一次需要加载数据
  211. return;
  212. }
  213. if (navItem.loadingType === 'loading') {
  214. //防止重复加载
  215. return;
  216. }
  217. navItem.loadingType = 'loading';
  218. setTimeout(() => {
  219. let orderList = [];
  220. orderList.forEach(item => {
  221. navItem.orderList.push(item);
  222. });
  223. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  224. this.$set(navItem, 'loaded', true);
  225. //判断是否还有数据, 有改为 more, 没有改为noMore
  226. navItem.loadingType = 'more';
  227. }, 600);
  228. },
  229. changemoney(item,index){
  230. this.choose = index;
  231. this.money = item
  232. }
  233. }
  234. };
  235. </script>
  236. <style lang="scss">
  237. page {
  238. height: 100%;
  239. }
  240. .add-btn {
  241. &.modified {
  242. color: $base-color;
  243. }
  244. &.up {
  245. background: linear-gradient(-35deg, #FF4343, #FF4343);
  246. color: #fff;
  247. }
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. width: 604rpx;
  252. height: 80rpx;
  253. margin: 0 auto;
  254. margin-top: 30rpx;
  255. font-size: $font-lg;
  256. border-radius: 10rpx;
  257. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  258. }
  259. .row-box {
  260. margin-top: 30rpx;
  261. padding: 20rpx 0rpx 20rpx 30rpx;
  262. background: #fff;
  263. .title {
  264. font-size: $font-base + 2rpx;
  265. color: $font-color-dark;
  266. }
  267. .row {
  268. display: flex;
  269. align-items: center;
  270. position: relative;
  271. height: 80rpx;
  272. .tit {
  273. flex-shrink: 0;
  274. width: 40rpx;
  275. font-size: 30rpx;
  276. color: $font-color-dark;
  277. }
  278. .input {
  279. flex: 1;
  280. font-size: 30rpx;
  281. color: $font-color-dark;
  282. }
  283. .iconlocation {
  284. font-size: 36rpx;
  285. color: $font-color-light;
  286. }
  287. .buttom {
  288. color: $font-color;
  289. font-size: $font-base;
  290. }
  291. }
  292. .xian {
  293. width: 700rpx;
  294. height: 1rpx;
  295. background: #E6E6E6;
  296. margin-bottom: 16rpx;
  297. }
  298. .moneyBtn-box {
  299. display: flex;
  300. justify-content: flex-start;
  301. flex-wrap: wrap;
  302. .moneyBtn {
  303. margin-right: 30rpx;
  304. width: 210rpx;
  305. height: 70rpx;
  306. background: #F0F0F0;
  307. border-radius: 4px;
  308. margin-top: 30rpx;
  309. text-align: center;
  310. line-height: 70rpx;
  311. }
  312. }
  313. }
  314. .list {
  315. padding-left: 30rpx;
  316. margin-top: 30rpx;
  317. background-color: #ffffff;
  318. .box {
  319. display: flex;
  320. align-items: center;
  321. width: 100%;
  322. height: 120rpx;
  323. border-bottom: 1px solid $border-color-light;
  324. .icon {
  325. font-size: 48rpx;
  326. padding-right: 20rpx;
  327. }
  328. .yongjing {
  329. width: 48rpx;
  330. height: 48rpx;
  331. }
  332. .iconweixin1 {
  333. color: #18bf16;
  334. }
  335. .iconzhifubao {
  336. color: #08aaec;
  337. }
  338. .title-box {
  339. flex-grow: 1;
  340. text-align: left;
  341. .title {
  342. font-size: $font-base + 2rpx;
  343. color: $font-color-base;
  344. }
  345. .node {
  346. font-size: $font-sm;
  347. color: $font-color-light;
  348. }
  349. }
  350. }
  351. }
  352. /deep/ .uni-radio-input {
  353. width: 45rpx;
  354. height: 45rpx;
  355. }
  356. .active-bg {
  357. background-color: $color-gray !important;
  358. }
  359. .yue {
  360. display: flex;
  361. justify-content: space-between;
  362. padding: 30rpx 48rpx 30rpx 26rpx;
  363. background: #FFFFFF;
  364. .font{
  365. font-size: 28rpx;
  366. font-family: PingFang SC;
  367. font-weight: 500;
  368. color: #333333;
  369. }
  370. .money{
  371. font-size: 30rpx;
  372. font-family: PingFang SC;
  373. font-weight: bold;
  374. color: #EF041F;
  375. }
  376. }
  377. .current {
  378. background: linear-gradient(-35deg, #F8DD4F, #FBEB77) !important;
  379. }
  380. </style>