huodai.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <view class="content">
  3. <view class="row-box">
  4. <view class="money-box">
  5. <view class="money">{{ userInfo.now_money * 1 }}</view>
  6. <view class="money-text">我的货款</view>
  7. </view>
  8. <!-- <view class="chong">充值记录</view> -->
  9. </view>
  10. <view class="main-box">
  11. <view class="main-top flex">
  12. <view @click="change(item)" class="main-item" v-for="(item, index) in numList" :class="{ check: money === item }" :key="index">
  13. <view class="item-top">
  14. <view class="bg"><image src="../../static/icon/candy.png" mode=""></image></view>
  15. <view class="item-name" :class="{ checks: money === item.price }">{{ item.price * 1 }}货款</view>
  16. </view>
  17. <view class="item-price" :class="{ checks: money === item.price }">
  18. <text>{{ item.price * 1 }}元</text>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="list">
  23. <radio-group @change="tabRadio">
  24. <!-- #ifdef APP-PLUS -->
  25. <label>
  26. <view class="box">
  27. <view class="icon iconfont iconzhifubao"></view>
  28. <view class="title-box">
  29. <view class="title"><text>支付宝充值</text></view>
  30. </view>
  31. <view class="right"><radio value="ali" color="#EB001C" :checked="type == 'ali'" /></view>
  32. </view>
  33. </label>
  34. <!-- #endif -->
  35. <label>
  36. <view class="box">
  37. <view class="icon iconfont iconweixin1"></view>
  38. <view class="title-box">
  39. <view class="title"><text>微信充值</text></view>
  40. </view>
  41. <view class="right"><radio value="weixin" color=" #EB001C" :checked="type == 'weixin'" /></view>
  42. </view>
  43. </label>
  44. </radio-group>
  45. </view>
  46. <button class="add-btn up" :class="{ 'active-bg': payLoding }" @click="!payLoding ? confirm() : ''">确认充值</button>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import { wallet } from '@/api/finance.js';
  52. // #ifdef H5
  53. import { rechargeWechat, moneyChong } from '@/api/wallet.js';
  54. // #endif
  55. // #ifdef MP
  56. import { rechargeRoutine, moneyChong } from '@/api/wallet.js';
  57. // #endif
  58. // #ifdef APP-PLUS
  59. import { rechargeApp, rechargeAli, moneyChong } from '@/api/wallet.js';
  60. // #endif
  61. import { mapState } from 'vuex';
  62. export default {
  63. filters: {
  64. rule(i) {
  65. console.log(i);
  66. let j = Math.floor(i * 100) / 100;
  67. return j;
  68. }
  69. },
  70. data() {
  71. return {
  72. type: 'weixin',
  73. numList: [],
  74. money: 10, //充值金额
  75. payLoding: false, //是否加载中
  76. myMoney: 0, //我的糖果数
  77. all: '' //糖果的具体情况
  78. };
  79. },
  80. onLoad(options) {
  81. moneyChong({}).then(({ data }) => {
  82. this.numList = data.recharge_quota;
  83. this.money = data.recharge_quota[0].price;
  84. console.log(data);
  85. });
  86. wallet({}).then(({ data }) => {
  87. const obj = this;
  88. const arr = Object.keys(data.back);
  89. arr.forEach(e => {
  90. if (e == 'LALA') {
  91. obj.myMoney = (data.back[e].money.money * 1).toFixed(0);
  92. obj.all = data.back[e];
  93. }
  94. });
  95. });
  96. },
  97. computed: {
  98. // #ifdef H5
  99. ...mapState(['weichatObj']),
  100. // #endif
  101. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
  102. },
  103. methods: {
  104. // 跳转
  105. navTo(url) {
  106. uni.navigateTo({
  107. url: url
  108. });
  109. },
  110. change(item) {
  111. this.money = item.price;
  112. },
  113. // 切换选中对象
  114. tabRadio(e) {
  115. this.type = e;
  116. },
  117. // 提交
  118. confirm() {
  119. let obj = this;
  120. obj.payLoding = true;
  121. console.log(this.money);
  122. // #ifdef H5
  123. rechargeWechat({ price: this.money, from: this.type })
  124. .then(e => {
  125. let da = e.data.data;
  126. obj.weichatObj.chooseWXPay({
  127. timestamp: da.timestamp,
  128. nonceStr: da.nonceStr,
  129. package: da.package,
  130. signType: da.signType,
  131. paySign: da.paySign,
  132. success: function(res) {
  133. uni.showToast({
  134. title: '充值成功',
  135. duration: 2000,
  136. position: 'top'
  137. });
  138. }
  139. });
  140. obj.payLoding = false;
  141. })
  142. .catch(e => {
  143. obj.payLoding = false;
  144. console.log(e);
  145. });
  146. // #endif
  147. // #ifdef MP
  148. rechargeRoutine({ price: this.money })
  149. .then(e => {
  150. let da = e.data;
  151. wx.requestPayment({
  152. timeStamp: da.timestamp,
  153. nonceStr: da.nonceStr,
  154. package: da.package,
  155. signType: da.signType,
  156. paySign: da.paySign,
  157. success: function(res) {
  158. uni.redirectTo({
  159. url: '/pages/money/paySuccess'
  160. });
  161. }
  162. });
  163. obj.payLoding = false;
  164. })
  165. .catch(e => {
  166. obj.payLoding = false;
  167. console.log(e);
  168. });
  169. // #endif
  170. // #ifdef APP-PLUS
  171. if (this.type == 'weixin') {
  172. rechargeApp({ price: this.money })
  173. .then(e => {
  174. let da = e.data;
  175. let data = {
  176. appid: da.appid,
  177. noncestr: da.noncestr,
  178. package: da.package,
  179. partnerid: da.partnerid,
  180. prepayid: da.prepayid,
  181. timestamp: da.timestamp,
  182. sign: da.sign
  183. };
  184. uni.requestPayment({
  185. provider: 'wxpay',
  186. orderInfo: data,
  187. success(res) {
  188. console.log(res);
  189. },
  190. fail(res) {
  191. console.log('微信掉起失败');
  192. console.log(res, '失败');
  193. }
  194. });
  195. obj.payLoding = false;
  196. })
  197. .catch(e => {
  198. obj.payLoding = false;
  199. console.log(e);
  200. });
  201. } else {
  202. rechargeAli({ price: this.money }).then(e => {
  203. console.log(e, 'url');
  204. const url = e.msg;
  205. uni.requestPayment({
  206. provider: 'alipay',
  207. orderInfo: url,
  208. success: res => {
  209. console.log(res);
  210. uni.showToast({
  211. title: '支付成功',
  212. duration: 2000
  213. });
  214. },
  215. fail: e => {
  216. console.log(e);
  217. },
  218. complete: () => {}
  219. });
  220. obj.payLoding = false;
  221. });
  222. }
  223. // #endif
  224. },
  225. //获取订单列表
  226. loadData(source) {
  227. console.log(source);
  228. //这里是将订单挂载到tab列表下
  229. let index = this.tabCurrentIndex;
  230. let navItem = this.navList[index];
  231. let state = navItem.state;
  232. if (source === 'tabChange' && navItem.loaded === true) {
  233. //tab切换只有第一次需要加载数据
  234. return;
  235. }
  236. if (navItem.loadingType === 'loading') {
  237. //防止重复加载
  238. return;
  239. }
  240. navItem.loadingType = 'loading';
  241. setTimeout(() => {
  242. let orderList = [];
  243. orderList.forEach(item => {
  244. navItem.orderList.push(item);
  245. });
  246. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  247. this.$set(navItem, 'loaded', true);
  248. //判断是否还有数据, 有改为 more, 没有改为noMore
  249. navItem.loadingType = 'more';
  250. }, 600);
  251. }
  252. }
  253. };
  254. </script>
  255. <style lang="scss">
  256. page {
  257. height: 100%;
  258. background: #ffffff;
  259. }
  260. .add-btn {
  261. &.modified {
  262. color: $base-color;
  263. }
  264. &.up {
  265. background-color: $base-color;
  266. color: #fff;
  267. }
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. width: 690rpx;
  272. height: 80rpx;
  273. margin: 0 auto;
  274. margin-top: 30rpx;
  275. font-size: $font-lg;
  276. border-radius: 10rpx;
  277. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  278. }
  279. .row-box {
  280. width: 750rpx;
  281. height: 354rpx;
  282. background: linear-gradient(0deg, #2e58ff, #32c6ff);
  283. .money-box {
  284. padding-top: 80rpx;
  285. margin: 0 auto;
  286. text-align: center;
  287. position: relative;
  288. .money {
  289. font-size: 74rpx;
  290. font-family: PingFang SC;
  291. font-weight: 500;
  292. color: #ffffff;
  293. }
  294. .money-text {
  295. font-size: 30rpx;
  296. font-family: PingFang SC;
  297. font-weight: 500;
  298. color: #ffffff;
  299. }
  300. }
  301. .chong {
  302. position: absolute;
  303. top: 36rpx;
  304. right: 0;
  305. width: 128rpx;
  306. height: 45rpx;
  307. line-height: 45rpx;
  308. background: #2e58ff;
  309. border-radius: 23rpx 0px 0px 23rpx;
  310. font-size: 25rpx;
  311. font-family: PingFang SC;
  312. font-weight: 500;
  313. color: #ffffff;
  314. text-align: center;
  315. }
  316. }
  317. .main-box {
  318. margin-top: -100rpx;
  319. width: 750rpx;
  320. background: #ffffff;
  321. border-radius: 50rpx;
  322. padding-top: 46rpx;
  323. .main-top {
  324. flex-wrap: wrap;
  325. justify-content: flex-start;
  326. align-items: center;
  327. .check {
  328. background: #fff6f6 !important;
  329. border: 1px solid #d7272b;
  330. }
  331. .main-item {
  332. text-align: center;
  333. margin: 30rpx 14rpx 0;
  334. width: 220rpx;
  335. background: #ffffff;
  336. box-shadow: 0px 2rpx 20rpx 0px rgba(215, 39, 43, 0.12);
  337. border-radius: 20rpx;
  338. padding: 46rpx 0 52rpx;
  339. .item-top {
  340. display: flex;
  341. justify-content: center;
  342. .bg {
  343. width: 42rpx;
  344. height: 42rpx;
  345. image {
  346. width: 42rpx;
  347. height: 42rpx;
  348. }
  349. }
  350. .item-name {
  351. padding-left: 6rpx;
  352. font-size: 28rpx;
  353. font-family: PingFang SC;
  354. font-weight: bold;
  355. color: #333333;
  356. }
  357. }
  358. .checks {
  359. color: #d7272b !important;
  360. }
  361. .item-price {
  362. padding-top: 14rpx;
  363. font-size: 20rpx;
  364. font-family: PingFang SC;
  365. font-weight: bold;
  366. color: #999999;
  367. text {
  368. font-size: 28rpx;
  369. }
  370. }
  371. }
  372. }
  373. }
  374. .list {
  375. padding-left: 30rpx;
  376. margin-top: 30rpx;
  377. background-color: #ffffff;
  378. .box {
  379. display: flex;
  380. align-items: center;
  381. width: 100%;
  382. height: 120rpx;
  383. border-bottom: 1px solid $border-color-light;
  384. .icon {
  385. font-size: 48rpx;
  386. padding-right: 20rpx;
  387. }
  388. .iconweixin1 {
  389. color: #18bf16;
  390. }
  391. .iconzhifubao {
  392. color: #08aaec;
  393. }
  394. .title-box {
  395. flex-grow: 1;
  396. text-align: left;
  397. .title {
  398. font-size: $font-base + 2rpx;
  399. color: $font-color-base;
  400. }
  401. .node {
  402. font-size: $font-sm;
  403. color: $font-color-light;
  404. }
  405. }
  406. }
  407. }
  408. /deep/ .uni-radio-input {
  409. width: 45rpx;
  410. height: 45rpx;
  411. }
  412. .active-bg {
  413. background-color: $color-gray !important;
  414. }
  415. </style>