index.vue 16 KB

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