huodai.vue 7.6 KB

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