Txmoney.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <view>
  3. <!-- <view class="flex text-center text-white text-lg bg">
  4. <view class="title_btn flex-sub bg" @click="cut(1)" :class="title_color==1?'bgCol2': ''">我的余额
  5. </view>
  6. <view class="title_btn flex-sub bg" @click="cut(2)" :class="title_color==2?'bgCol2': ''">我的收益
  7. </view>
  8. </view> -->
  9. <view class="padding">
  10. <view class="flex justify-between radius bg ">
  11. <view class=" u-flex u-p-l-30 u-p-t-30 u-p-b-30">
  12. <view class="u-m-r-20">
  13. <u-avatar :src="avatar" size="80"></u-avatar>
  14. </view>
  15. <view class="u-flex-1 ">
  16. <view class="u-font-16 text-bold">{{money}}元</view>
  17. <view class="u-font-14 u-m-t-10">可用于平台消费</view>
  18. </view>
  19. </view>
  20. <!-- <view class="margin-right margin-top-sm" @click="goNav('/my/wallet/moneydetail')">钱包明细
  21. </view> -->
  22. </view>
  23. <view class="margin-top radius bg flex justify-between flex-wrap padding-lr padding-bottom">
  24. <view v-for="(item,index) in wallet" :key='index'
  25. class="flex justify-between align-center padding-sm radius margin-top"
  26. style="color: #1E1F31;background-color: #F7F7F7; width: 46%;border: 1px solid #F7F7F7;"
  27. @click="active(item,index)" :class="wallIndex==index?'active':''">
  28. <view>
  29. {{item.money}}元
  30. <view class="" style="font-size: 24rpx;" v-if="item.tbCoupon">
  31. 赠送{{item.couponNum}}张{{item.tbCoupon.money}}元优惠劵
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="margin-top" style="width: 100%;padding-left: 40rpx;">
  37. 充值后仅可用于消费,不支持退款。
  38. </view>
  39. <view class="bg margin-top padding-lr radius">
  40. <view>
  41. <view style="display: flex;height: 100upx;align-items: center;padding: 20upx 0;"
  42. v-for="(item,index) in openLists" :key='index'>
  43. <image :src="item.image" style="width: 55upx;height: 55upx;border-radius: 50upx;"></image>
  44. <view style="font-size: 30upx;margin-left: 20upx;width: 70%;">{{item.text}}
  45. </view>
  46. <radio-group name="openWay" style="margin-left: 20upx;" @tap='selectWay(item)'>
  47. <label class="tui-radio">
  48. <radio color="#0278FE" :checked="openWay === item.id ? true : false" />
  49. </label>
  50. </radio-group>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="btn" @click="pay">确认支付</view>
  55. </view>
  56. <view class="flex justify-around margin-top text-white">
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import { waitForGlobalImages } from '@/utils/globalImageLoader'
  62. export default {
  63. data() {
  64. return {
  65. title_color: 1,
  66. money: 0,
  67. avatar: '',
  68. Profit: 0,
  69. openLists: [{
  70. image: '../../static/image/zhifubao.png',
  71. text: '支付宝',
  72. id: 1
  73. }, {
  74. image: '../../static/image/icon_weixin.png',
  75. text: '微信',
  76. id: 2
  77. }],
  78. openWay: 1,
  79. wallet: [],
  80. wallIndex: 0,
  81. price: 0,
  82. moneyNum: null,
  83. charge: 0, //提现手续费
  84. maxMoney: 0, //最高提现额度
  85. minMoney: 0, //最低提现额度
  86. ratio: '', //金元比例
  87. placeholder: '',
  88. sp: 0,
  89. rechargeId: '',
  90. globalImages: ''
  91. }
  92. },
  93. onLoad() {
  94. waitForGlobalImages().then((path) => {
  95. console.log('✅ 全局图片路径:', path)
  96. this.globalImages = path
  97. })
  98. this.avatar = uni.getStorageSync('avatar')
  99. // #ifdef APP-PLUS
  100. this.openLists = [{
  101. image: '../../static/image/zhifubao.png',
  102. text: '支付宝',
  103. id: 1
  104. }, {
  105. image: '../../static/image/icon_weixin.png',
  106. text: '微信',
  107. id: 2
  108. }];
  109. this.openWay = 1;
  110. // #endif
  111. // #ifdef MP-WEIXIN
  112. this.openLists = [{
  113. image: '../../static/image/icon_weixin.png',
  114. text: '微信',
  115. id: 2
  116. }];
  117. this.openWay = 2;
  118. // #endif
  119. // #ifdef H5
  120. let ua = navigator.userAgent.toLowerCase();
  121. if (ua.indexOf('micromessenger') !== -1) {
  122. //公众号是否自动登录 443
  123. this.$Request.get('/app/common/type/443').then(res => {
  124. if (res.data && res.data.value && res.data.value == '是') {
  125. this.openLists = [{
  126. image: '../../static/image/icon_weixin.png',
  127. text: '微信',
  128. id: 2
  129. }];
  130. this.openWay = 2;
  131. } else {
  132. this.openLists = [];
  133. this.openWay = -1;
  134. }
  135. })
  136. } else {
  137. this.openLists = [{
  138. image: '../../static/image/zhifubao.png',
  139. text: '支付宝',
  140. id: 1
  141. }];
  142. this.openWay = 1;
  143. }
  144. // #endif
  145. },
  146. onShow() {
  147. this.getMoney();
  148. this.getUserInfo();
  149. this.getMoneyList();
  150. },
  151. methods: {
  152. getMoneyList() {
  153. this.$Request.getT("/app/rechargeConfig/getConfigInfoList").then(res => {
  154. if (res.code == 0) {
  155. this.wallet = res.data.records
  156. this.price = this.wallet[0].money
  157. this.rechargeId = this.wallet[0].rechargeId
  158. }
  159. });
  160. },
  161. getUserInfo() {
  162. this.$Request.getT("/app/user/selectUserById").then(res => {
  163. if (res.code == 0) {
  164. this.avatar = res.data.avatar ? res.data.avatar : this.globalImages ? this.globalImages + 'images/static/image/logo.png' : ''
  165. uni.setStorageSync('avatar', res.data.avatar)
  166. }
  167. });
  168. },
  169. cut(e) {
  170. this.title_color = e
  171. },
  172. goNav(url) {
  173. uni.navigateTo({
  174. url
  175. })
  176. },
  177. active(e, index) {
  178. this.wallIndex = index
  179. this.price = e.money
  180. this.rechargeId = e.rechargeId
  181. // this.wallet =
  182. // this.wallet.forEach(res => {
  183. // if (res.id == e.id) {
  184. // res.isSelect = true
  185. // this.thisSelect = e
  186. // } else {
  187. // res.isSelect = false
  188. // }
  189. // })
  190. },
  191. // 我的余额
  192. getMoney() {
  193. this.$Request.getT("/app/userMoney/selectMyMoney").then(res => {
  194. if (res.code == 0 && res.data) {
  195. console.log(res.data.money)
  196. this.money = res.data.money
  197. }
  198. });
  199. },
  200. selectWay: function(item) {
  201. this.openWay = item.id;
  202. },
  203. //h5支付
  204. payH5() {
  205. let that = this
  206. let data = {
  207. money: that.price,
  208. rechargeId: that.rechargeId
  209. }
  210. if (this.openWay == 1) { //h5支付宝
  211. this.$Request.postT("/app/aliPay/payH5Money", data).then(res => {
  212. if (res.code == 0) {
  213. const div = document.createElement('div')
  214. div.innerHTML = res.data //此处form就是后台返回接收到的数据
  215. document.body.appendChild(div)
  216. document.forms[0].submit()
  217. uni.hideLoading()
  218. } else {
  219. uni.showToast({
  220. icon: 'none',
  221. title: '支付失败!'
  222. });
  223. }
  224. });
  225. } else { //h5微信支付
  226. this.$Request.postT("/app/wxPay/wxPayMpMoney", data).then(res => {
  227. if (res.code == 0) {
  228. uni.hideLoading()
  229. that.callPay(res.data);
  230. } else {
  231. uni.showToast({
  232. icon: 'none',
  233. title: '支付失败!'
  234. });
  235. }
  236. });
  237. }
  238. },
  239. //app支付
  240. payApp() {
  241. let that = this
  242. let data = {
  243. money: that.price,
  244. rechargeId: that.rechargeId
  245. }
  246. if (this.openWay == 1) { //app支付宝
  247. that.$Request.postT("/app/aliPay/payAppMoney", data).then(ret => {
  248. console.log(ret)
  249. that.isCheckPay(ret.code, 'alipay', ret.data);
  250. });
  251. } else { //app微信支付
  252. that.$Request.postT("/app/wxPay/payAppMoney", data).then(ret => {
  253. console.log(ret, 'retretretretretret')
  254. that.isCheckPay(ret.code, 'wxpay', JSON.stringify(ret.data));
  255. });
  256. }
  257. },
  258. //微信支付
  259. payMP(money) {
  260. let that = this
  261. let data = {
  262. money: that.price,
  263. rechargeId: that.rechargeId
  264. }
  265. that.$Request.postT('/app/wxPay/wxPayJsApiMoney', data).then(ret => {
  266. uni.hideLoading()
  267. uni.requestPayment({
  268. provider: 'wxpay',
  269. timeStamp: ret.data.timestamp,
  270. nonceStr: ret.data.noncestr,
  271. package: ret.data.package,
  272. signType: ret.data.signType,
  273. paySign: ret.data.sign,
  274. success: function(suc) {
  275. console.log('success:' + JSON.stringify(suc));
  276. uni.showToast({
  277. title: '支付成功',
  278. icon: 'success'
  279. })
  280. setTimeout(d => {
  281. uni.navigateBack(1)
  282. }, 1000);
  283. },
  284. fail: function(err) {
  285. console.log('fail:' + JSON.stringify(err));
  286. uni.showToast({
  287. title: '支付失败',
  288. icon: 'none'
  289. })
  290. }
  291. });
  292. });
  293. },
  294. pay() {
  295. // console.log(this.thisSelect)
  296. // let data = {
  297. // }this.price
  298. uni.showLoading({
  299. title: '支付中...'
  300. });
  301. // H5
  302. // #ifdef H5
  303. this.payH5()
  304. // #endif
  305. //APP
  306. // #ifdef APP
  307. this.payApp()
  308. // #endif
  309. //小程序
  310. // #ifdef MP-WEIXIN
  311. this.payMP()
  312. // #endif
  313. },
  314. callPay: function(response) {
  315. console.log(response)
  316. if (typeof WeixinJSBridge === "undefined") {
  317. if (document.addEventListener) {
  318. document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(response), false);
  319. } else if (document.attachEvent) {
  320. document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(response));
  321. document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(response));
  322. }
  323. } else {
  324. console.log(1)
  325. this.onBridgeReady(response);
  326. }
  327. },
  328. onBridgeReady: function(response) {
  329. let that = this;
  330. if (!response.package) {
  331. return;
  332. }
  333. console.log(response, '++++++++')
  334. WeixinJSBridge.invoke(
  335. 'getBrandWCPayRequest', {
  336. "appId": response.appid, //公众号名称,由商户传入
  337. "timeStamp": response.timestamp, //时间戳,自1970年以来的秒数
  338. "nonceStr": response.noncestr, //随机串
  339. "package": response.package,
  340. "signType": response.signType, //微信签名方式:
  341. "paySign": response.sign //微信签名
  342. },
  343. function(res) {
  344. console.log(res, '/*-/*-/*-')
  345. if (res.err_msg === "get_brand_wcpay_request:ok") {
  346. // 使用以上方式判断前端返回,微信团队郑重提示:
  347. //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  348. uni.showLoading({
  349. title: '支付成功'
  350. });
  351. setTimeout(function() {
  352. uni.hideLoading();
  353. }, 1000);
  354. } else {
  355. uni.hideLoading();
  356. }
  357. WeixinJSBridge.log(response.err_msg);
  358. }
  359. );
  360. },
  361. isCheckPay(status, name, order) {
  362. if (status == 0) {
  363. this.setPayment(name, order);
  364. } else {
  365. uni.hideLoading();
  366. uni.showToast({
  367. title: '支付信息有误',
  368. icon: 'none'
  369. });
  370. }
  371. },
  372. setPayment(name, order) {
  373. console.log('*-*-*')
  374. uni.requestPayment({
  375. provider: name,
  376. orderInfo: order, //微信、支付宝订单数据
  377. success: function(res) {
  378. console.log(res)
  379. uni.hideLoading();
  380. uni.showLoading({
  381. title: '支付成功'
  382. });
  383. },
  384. fail: function(err) {
  385. console.log(err)
  386. uni.hideLoading();
  387. },
  388. complete() {
  389. uni.hideLoading();
  390. }
  391. });
  392. },
  393. }
  394. }
  395. </script>
  396. <style>
  397. page {
  398. background-color: #F7F7F7;
  399. }
  400. .bgCol2 {
  401. color: #0278FE;
  402. }
  403. .bg {
  404. background-color: #FFFFFF;
  405. }
  406. .active {
  407. border: 1px solid #0278FE !important;
  408. color: #0278FE !important;
  409. background: #FFFFFF !important;
  410. }
  411. .title_btn {
  412. height: 78upx;
  413. line-height: 78upx;
  414. /* background: #f7f7f7; */
  415. }
  416. .btn {
  417. width: 100%;
  418. height: 88upx;
  419. background: #0278FE;
  420. border-radius: 44upx;
  421. text-align: center;
  422. line-height: 88upx;
  423. margin-top: 40upx;
  424. font-size: 28upx;
  425. color: #FFF;
  426. }
  427. </style>