index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <view>
  3. <view class="padding">
  4. <view class=" radius bg padding">
  5. <view>充值钻石</view>
  6. <view class="padding-tb-xs" style="border-bottom: 1rpx solid rgba(0, 221, 154, 0.1);">
  7. <u-input v-model="money" type="number" placeholder="0钻石" placeholder-style="color:#000;"
  8. inputAlign="text-align:left" @input="input" />
  9. </view>
  10. </view>
  11. <view class="margin-top radius bg flex justify-between flex-wrap padding-lr padding-bottom">
  12. <view v-for="(item,index) in wallet" :key='index'
  13. class="flex padding-sm radius margin-top justify-center"
  14. style="background: rgba(0, 221, 154, 0.1);color: #00B88F; width: 48%;" @click="active(item,index)"
  15. :class="tabIndex==index?'active':''">
  16. <view style="font-size: 34upx;" class="flex align-center">
  17. <!-- <text style="font-size: 22upx;margin-right: 5upx;"></text> -->
  18. <image src="../static/jifenss.png" style="width: 32upx;height: 34upx;margin-right: 5upx;">
  19. </image>
  20. {{item.price}}
  21. </view>
  22. </view>
  23. </view>
  24. <view class="bg margin-top padding-lr radius">
  25. <view>
  26. <view style="display: flex;height: 100upx;align-items: center;padding: 20upx 0;"
  27. v-for="(item,index) in openLists" :key='index'>
  28. <image :src="item.image" style="width: 55upx;height: 55upx;border-radius: 50upx;"></image>
  29. <view style="font-size: 30upx;margin-left: 20upx;width: 70%;">{{item.text}}
  30. </view>
  31. <radio-group name="openWay" style="margin-left: 20upx;" @tap='selectWay(item)'>
  32. <label class="tui-radio">
  33. <radio color="#00B88F" :checked="openWay === item.id ? true : false" />
  34. </label>
  35. </radio-group>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="btn" @click="pay">确认支付</view>
  40. <view class="" style="margin-top: 20rpx;">
  41. 如需开具发票请<span style="color: red;padding-left: 5rpx;" @click="goChat">联系客服</span>!
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. openLists: [],
  51. openWay: 1,
  52. wallet: [],
  53. tabIndex: -1,
  54. money: '',
  55. placeholder: '',
  56. }
  57. },
  58. onLoad() {
  59. this.getwalletList() //获取充值列表
  60. // #ifdef APP-PLUS
  61. this.openLists = [{
  62. image: '../../static/images/my/zhifubao.png',
  63. text: '支付宝',
  64. id: 1
  65. }, {
  66. image: '../../static/images/my/icon_weixin.png',
  67. text: '微信',
  68. id: 2
  69. }];
  70. this.openWay = 1;
  71. // #endif
  72. // #ifdef MP-WEIXIN
  73. this.openLists = [{
  74. image: '../../static/share/icon_weixin.png',
  75. text: '微信',
  76. id: 2
  77. }];
  78. this.openWay = 2;
  79. // #endif
  80. // #ifdef H5
  81. let ua = navigator.userAgent.toLowerCase();
  82. if (ua.indexOf('micromessenger') !== -1) {
  83. this.openLists = [{
  84. image: '../../static/images/my/zhifubao.png',
  85. text: '支付宝',
  86. id: 1
  87. }, {
  88. image: '../../static/share/icon_weixin.png',
  89. text: '微信',
  90. id: 2
  91. }];
  92. } else {
  93. this.openLists = [{
  94. image: '../../static/images/my/zhifubao.png',
  95. text: '支付宝',
  96. id: 1
  97. }];
  98. }
  99. this.openWay = 1;
  100. // #endif
  101. },
  102. onShow() {
  103. this.getCharge()
  104. this.getMinMoney()
  105. this.getMaxMoney()
  106. this.getRatio()
  107. },
  108. methods: {
  109. goChat() {
  110. let that = this
  111. if (uni.getStorageSync('userType') == 1) { //用户端
  112. // #ifdef MP-WEIXIN
  113. wx.openCustomerServiceChat({
  114. extInfo: {
  115. url: that.$queue.getData('kefu')
  116. },
  117. corpId: that.$queue.getData('kefuAppid'),
  118. success(res) {
  119. console.log(res)
  120. },
  121. })
  122. // #endif
  123. // #ifdef H5
  124. window.location.href = that.$queue.getData('kefu');
  125. // #endif
  126. // #ifdef APP
  127. let kefu = that.$queue.getData('kefu')
  128. console.log(kefu)
  129. plus.runtime.openURL(kefu, function(res) {});
  130. // #endif
  131. } else { //企业端
  132. // #ifdef MP-WEIXIN
  133. wx.openCustomerServiceChat({
  134. extInfo: {
  135. url: that.$queue.getData('kefuq')
  136. },
  137. corpId: that.$queue.getData('kefuAppidq'),
  138. success(res) {
  139. console.log(res)
  140. },
  141. })
  142. // #endif
  143. // #ifdef H5
  144. window.location.href = that.$queue.getData('kefuq');
  145. // #endif
  146. // #ifdef APP
  147. let kefu = that.$queue.getData('kefuq')
  148. console.log(kefu)
  149. plus.runtime.openURL(kefu, function(res) {});
  150. // #endif
  151. }
  152. },
  153. input(e) {
  154. console.log(e)
  155. this.tabIndex = -1
  156. this.money = e
  157. },
  158. //获取充值列表
  159. getwalletList() {
  160. this.$Request.get("/app/payClassify/selectPayClassifyList").then(res => {
  161. if (res.code == 0) {
  162. this.wallet = res.data
  163. }
  164. });
  165. },
  166. // 提现手续费
  167. getCharge() {
  168. this.$Request.get("/app/common/type/152").then(res => {
  169. if (res.code == 0) {
  170. this.charge = res.data.value
  171. this.placeholder = '服务费:' + this.charge * 100 + '%' + ',最低提现:' +
  172. this.minMoney * 1 + ',最高提现:' + this.maxMoney * 1
  173. }
  174. });
  175. },
  176. // 最低提现额度
  177. getMinMoney() {
  178. this.$Request.get("/app/common/type/112").then(res => {
  179. if (res.code == 0) {
  180. this.minMoney = res.data.value
  181. this.placeholder = '服务费:' + this.charge * 100 + '%' + ',最低提现:' +
  182. this.minMoney * 1 + ',最高提现:' + this.maxMoney * 1
  183. }
  184. });
  185. },
  186. // 最高提现额度
  187. getMaxMoney() {
  188. this.$Request.get("/app/common/type/153").then(res => {
  189. if (res.code == 0) {
  190. this.maxMoney = res.data.value
  191. this.placeholder = '服务费:' + this.charge * 100 + '%' + ',最低提现:' +
  192. this.minMoney * 1 + ',最高提现:' + this.maxMoney * 1
  193. }
  194. });
  195. },
  196. // 金元比例
  197. getRatio() {
  198. this.$Request.get("/app/common/type/154").then(res => {
  199. if (res.code == 0) {
  200. this.ratio = res.data.value
  201. this.placeholder = '服务费:' + this.charge * 100 + '%' + ',最低提现:' +
  202. this.minMoney * 1 + ',最高提现:' + this.maxMoney * 1
  203. this.wallet.forEach(re => {
  204. re.num = re.price * res.data.value
  205. })
  206. }
  207. });
  208. },
  209. cut(e) {
  210. this.title_color = e
  211. },
  212. goNav(url) {
  213. uni.navigateTo({
  214. url
  215. })
  216. },
  217. active(e, index) {
  218. this.tabIndex = index
  219. this.money = e.price
  220. },
  221. selectWay: function(item) {
  222. this.openWay = item.id;
  223. },
  224. pay() {
  225. if (!this.money) {
  226. uni.showToast({
  227. title: '请选择或输入充值的金额',
  228. icon: 'none'
  229. })
  230. return
  231. }
  232. if (this.openWay == 2) {
  233. // #ifdef APP-PLUS
  234. // 微信APP支付 根据订单id获取支付信息
  235. this.$Request.post("/app/wxPay/wxPayOrder", {
  236. classify: 1,
  237. money: this.money,
  238. type: 1,
  239. }).then(ret => {
  240. this.isCheckPay(ret.code, 'wxpay', JSON.stringify(ret.data));
  241. });
  242. // #endif
  243. // #ifdef MP-WEIXIN
  244. // 微信小程序支付
  245. this.$Request.post('/app/wxPay/wxPayOrder', {
  246. classify: 3,
  247. money: this.money,
  248. type: 1,
  249. }).then(ret => {
  250. uni.hideLoading()
  251. console.log(ret.data)
  252. uni.requestPayment({
  253. provider: 'wxpay',
  254. timeStamp: ret.data.timestamp,
  255. nonceStr: ret.data.noncestr,
  256. package: ret.data.package,
  257. signType: ret.data.signType,
  258. paySign: ret.data.sign,
  259. success: function(suc) {
  260. console.log('success:' + JSON.stringify(suc));
  261. uni.showToast({
  262. title: '支付成功',
  263. icon: 'success'
  264. })
  265. setTimeout(d => {
  266. uni.navigateBack(1)
  267. }, 1000);
  268. },
  269. fail: function(err) {
  270. console.log('fail:' + JSON.stringify(err));
  271. uni.showToast({
  272. title: '支付失败',
  273. icon: 'none'
  274. })
  275. }
  276. });
  277. });
  278. // #endif
  279. // #ifdef H5
  280. let ua = navigator.userAgent.toLowerCase();
  281. if (ua.indexOf('micromessenger') !== -1) {
  282. let data = {
  283. classify: 2,
  284. money: this.money,
  285. type: 1,
  286. }
  287. this.$Request.post('/app/wxPay/wxPayOrder', data).then(res => {
  288. if (res.code == 0) {
  289. this.callPay(res.data);
  290. } else {
  291. uni.showToast({
  292. icon: 'none',
  293. title: '支付失败!'
  294. });
  295. }
  296. });
  297. }
  298. // #endif
  299. } else {
  300. // APP支付宝支付
  301. // #ifdef APP
  302. this.$Request.post("/app/aliPay/payMoneyOrder", {
  303. classify: 4,
  304. money: this.money,
  305. type: 1,
  306. }).then(ret => {
  307. console.log(ret)
  308. this.isCheckPay(ret.code, 'alipay', ret.data);
  309. });
  310. // #endif
  311. // #ifdef H5
  312. let data = {
  313. classify: 5,
  314. money: this.money,
  315. type: 1,
  316. }
  317. this.$Request.post('/app/aliPay/payMoneyOrder', data).then(
  318. res => {
  319. if (res.code === 0) {
  320. const div = document.createElement('div')
  321. div.innerHTML = res.data //此处form就是后台返回接收到的数据
  322. document.body.appendChild(div)
  323. document.forms[0].submit()
  324. } else {
  325. uni.showToast({
  326. icon: 'none',
  327. title: '支付失败!'
  328. });
  329. }
  330. });
  331. // #endif
  332. }
  333. },
  334. callPay: function(response) {
  335. if (typeof WeixinJSBridge === "undefined") {
  336. if (document.addEventListener) {
  337. document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(response), false);
  338. } else if (document.attachEvent) {
  339. document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(response));
  340. document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(response));
  341. }
  342. } else {
  343. this.onBridgeReady(response);
  344. }
  345. },
  346. onBridgeReady: function(response) {
  347. let that = this;
  348. if (!response.package) {
  349. return;
  350. }
  351. console.log(response, '++++++++')
  352. WeixinJSBridge.invoke(
  353. 'getBrandWCPayRequest', {
  354. "appId": response.appid, //公众号名称,由商户传入
  355. "timeStamp": response.timestamp, //时间戳,自1970年以来的秒数
  356. "nonceStr": response.noncestr, //随机串
  357. "package": response.package,
  358. "signType": response.signType, //微信签名方式:
  359. "paySign": response.sign //微信签名
  360. },
  361. function(res) {
  362. console.log(res, '/*-/*-/*-')
  363. if (res.err_msg === "get_brand_wcpay_request:ok") {
  364. // 使用以上方式判断前端返回,微信团队郑重提示:
  365. //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  366. uni.showLoading({
  367. title: '支付成功'
  368. });
  369. setTimeout(function() {
  370. uni.hideLoading();
  371. uni.navigateBack(1)
  372. }, 1000);
  373. } else {
  374. uni.hideLoading();
  375. }
  376. WeixinJSBridge.log(response.err_msg);
  377. }
  378. );
  379. },
  380. isCheckPay(status, name, order) {
  381. if (status == 0) {
  382. this.setPayment(name, order);
  383. } else {
  384. uni.hideLoading();
  385. uni.showToast({
  386. title: '支付信息有误',
  387. icon: 'none'
  388. });
  389. }
  390. },
  391. setPayment(name, order) {
  392. console.log('*-*-*')
  393. uni.requestPayment({
  394. provider: name,
  395. orderInfo: order, //微信、支付宝订单数据
  396. success: function(res) {
  397. console.log(res)
  398. uni.hideLoading();
  399. uni.showLoading({
  400. title: '支付成功'
  401. });
  402. uni.navigateBack(1)
  403. },
  404. fail: function(err) {
  405. console.log(err)
  406. uni.hideLoading();
  407. },
  408. complete() {
  409. uni.hideLoading();
  410. }
  411. });
  412. },
  413. // 提现
  414. cashMoney() {
  415. if (!this.moneyNum) {
  416. uni.showToast({
  417. icon: 'none',
  418. title: '请输入提现金额'
  419. })
  420. return
  421. }
  422. if (this.moneyNum > this.money * 1) {
  423. uni.showToast({
  424. icon: 'none',
  425. title: '您的余额不足'
  426. })
  427. return
  428. }
  429. // if (this.moneyNum*1+this.charge*this.moneyNum > this.money*1) {
  430. // uni.showToast({
  431. // icon: 'none',
  432. // title: '您的手续费不足'
  433. // })
  434. // return
  435. // }
  436. let zhiFuBao = uni.getStorageSync('zhiFuBao')
  437. let zhiFuBaoName = uni.getStorageSync('zhiFuBaoName')
  438. if (!zhiFuBao && !zhiFuBaoName) {
  439. uni.navigateTo({
  440. url: '/my/wallet/zhifubao'
  441. })
  442. return
  443. }
  444. let that = this
  445. that.sp = (that.moneyNum * this.charge).toFixed(2)
  446. uni.showModal({
  447. title: '提示',
  448. content: '本次提现' + that.moneyNum + '元,服务费' + this.sp + '元,是否确认提现?',
  449. success: function(res) {
  450. if (res.confirm) {
  451. that.$Request.get("/app/cash/cashMoney", {
  452. money: that.moneyNum
  453. }).then(res => {
  454. if (res.code == 0) {
  455. uni.showToast({
  456. icon: 'none',
  457. title: res.msg
  458. })
  459. that.moneyNum = null
  460. } else {
  461. uni.showToast({
  462. icon: 'none',
  463. title: res.msg
  464. })
  465. }
  466. that.getMoney()
  467. });
  468. } else if (res.cancel) {
  469. console.log('用户点击取消');
  470. }
  471. }
  472. });
  473. }
  474. }
  475. }
  476. </script>
  477. <style>
  478. page {
  479. background-color: #F7F7F7;
  480. }
  481. .bg {
  482. background-color: #FFFFFF;
  483. }
  484. .active {
  485. border: 1px solid #00B88F !important;
  486. /* color: #557EFD !important; */
  487. /* background: #00B88F !important;
  488. color: #FFFFFF !important; */
  489. }
  490. .title_btn {
  491. height: 78upx;
  492. line-height: 78upx;
  493. /* background: #f7f7f7; */
  494. }
  495. .btn {
  496. width: 100%;
  497. height: 88upx;
  498. background: #00B88F;
  499. border-radius: 44upx;
  500. text-align: center;
  501. line-height: 88upx;
  502. margin-top: 40upx;
  503. font-size: 28upx;
  504. color: #FFF;
  505. }
  506. </style>