M_purchase.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <template>
  2. <view class="page">
  3. <view class="topBody">
  4. <PageHeader title="M币充值" class="PageHeader">
  5. <template v-slot:right>
  6. <DropdownMenu
  7. :options="dropdownOptions"
  8. @select="handleDropdownSelect"
  9. />
  10. </template>
  11. </PageHeader>
  12. <view class="reserveASeat"></view>
  13. <view class="myGoldCoin-box">
  14. <view>我的M币</view>
  15. <view class="myGoldCoin-box-content">
  16. <image src="../../static/icon/coin_m.png" mode="widthFix" />
  17. <text>{{ myGoldCoin }}</text>
  18. </view>
  19. </view>
  20. <view class="myinfo">
  21. <view class="purchaseList" style="margin-top: 32rpx">
  22. <view
  23. class="item"
  24. :class="index == sel ? 'itemSel' : ''"
  25. v-for="(item, index) in list"
  26. @click="selTA(item, index)"
  27. :key="index"
  28. >
  29. <view class="num1">
  30. <image src="../../static/icon/coin_m.png" mode="widthFix" />
  31. <view class="name">{{ item.num_gmm| formatNumberToK }} </view>
  32. </view>
  33. <view class="num2">
  34. <view class="name">{{ $t("txt.¥") }}{{ item.money }}</view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="jinchu">
  39. <text>{{ $t("txt.支付方式") }}</text>
  40. </view>
  41. <view v-if="isWeChatPay" class="mingxiList" @click="selPay('wechat')">
  42. <view class="left">
  43. <image
  44. class="icon"
  45. src="../../static/me/icon_wechat.png"
  46. mode="widthFix"
  47. />
  48. <text style="font-size: 28rpx; margin-left: 20rpx">{{
  49. $t("txt.微信支付")
  50. }}</text>
  51. </view>
  52. <view class="right">
  53. <image
  54. class="icon"
  55. :src="
  56. payType != 'wechat'
  57. ? '../../static/icon/wd_icon_gouxuan04.png'
  58. : '../../static/icon/wd_icon_gouxuan05.png'
  59. "
  60. />
  61. </view>
  62. </view>
  63. <!-- <view class="line"></view> -->
  64. <view class="mingxiList" @click="selPay('alipay')">
  65. <view class="left">
  66. <image
  67. class="icon"
  68. src="../../static/me/icon_alipay.png"
  69. mode="widthFix"
  70. />
  71. <text style="font-size: 28rpx; margin-left: 20rpx">{{
  72. $t("txt.支付宝支付")
  73. }}</text>
  74. </view>
  75. <view class="right">
  76. <image
  77. class="icon"
  78. :src="
  79. payType != 'alipay'
  80. ? '../../static/icon/wd_icon_gouxuan04.png'
  81. : '../../static/icon/wd_icon_gouxuan05.png'
  82. "
  83. />
  84. </view>
  85. </view>
  86. <!-- <view class="line"></view> -->
  87. </view>
  88. <view class="agree">
  89. <view class="agree2" @click="agreeChk()">
  90. <image
  91. src="../../static/icon/wd_icon_gouxuan04.png"
  92. v-if="is_agree == 0"
  93. ></image>
  94. <image
  95. src="../../static/icon/wd_icon_gouxuan05.png"
  96. v-if="is_agree == 1"
  97. ></image>
  98. </view>
  99. <view>
  100. 同意
  101. <text class="xy" @click="goPage('/pages/AboutUs/pay_xy')">
  102. 《充值服务协议》 </text
  103. >,充值M币仅【萌创星球】使用,点击查看
  104. <text class="xy" @click="goPage('/pages/vip/record?type=coin')"> 充值记录 </text>
  105. </view>
  106. </view>
  107. <view class="btn_submit" :class="{'btn-loading': isSubmitting}" @click="submitData">
  108. <text v-if="!isSubmitting">¥{{ money }}</text>
  109. <text v-if="!isSubmitting">确认充值</text>
  110. <view v-if="isSubmitting" class="loading-spinner"></view>
  111. </view>
  112. <view class="blankHeight"></view>
  113. </view>
  114. <!-- 提示框 -->
  115. <DialogBox ref="DialogBox"></DialogBox>
  116. </view>
  117. </template>
  118. <script>
  119. import DropdownMenu from '@/components/DropdownMenu.vue'
  120. import { mapState } from 'vuex'
  121. export default {
  122. components: {
  123. DropdownMenu
  124. },
  125. computed: {
  126. ...mapState('hideModule', ['isWeChatPay'])
  127. },
  128. data() {
  129. return {
  130. title: "",
  131. sel: 1,
  132. payType: "wechat",
  133. list: [],
  134. money: 0,
  135. tid: 0,
  136. linkid: "",
  137. is_agree: 0,
  138. myGoldCoin: 0,
  139. dropdownOptions: [
  140. { label: '购买记录', type: 'vipRecord' }
  141. ],
  142. isSubmitting: false,
  143. lastClickTime: 0
  144. };
  145. },
  146. onLoad() {
  147. // setTimeout(function() {
  148. // uni.setNavigationBarColor({
  149. // frontColor: '#ffffff',
  150. // backgroundColor: '#00000000',
  151. // animation: {
  152. // duration: 400,
  153. // timingFunc: 'easeIn'
  154. // }
  155. // })
  156. // }, 200);
  157. },
  158. onShow() {
  159. this.loadData();
  160. let that = this;
  161. },
  162. methods: {
  163. onBack() {},
  164. goPage(page) {
  165. uni.navigateTo({
  166. url: page,
  167. });
  168. },
  169. selTA(item, se) {
  170. this.tid = item.id;
  171. this.sel = se;
  172. if (this.list != null && this.list != undefined) {
  173. this.money = this.list[se]["money"];
  174. }
  175. },
  176. selPay(se) {
  177. this.payType = se;
  178. },
  179. chkSel() {
  180. if (this.sel == 1) {
  181. this.sel = 0;
  182. } else {
  183. this.sel = 1;
  184. }
  185. },
  186. submitData() {
  187. const now = Date.now();
  188. if (now - this.lastClickTime < 3000) {
  189. uni.showToast({
  190. title: "请勿频繁点击",
  191. icon: "none"
  192. });
  193. return;
  194. }
  195. this.lastClickTime = now;
  196. if (this.isSubmitting) return;
  197. if (this.is_agree == 0) {
  198. uni.showToast({
  199. title: "请确认并选择协议",
  200. icon: "none",
  201. });
  202. return;
  203. }
  204. this.isSubmitting = true;
  205. let that = this;
  206. uni.request({
  207. url: this.$apiHost + "/Order/submit",
  208. data: {
  209. uuid: getApp().globalData.uuid,
  210. product_id: this.tid,
  211. type: "buyM",
  212. payType: this.payType,
  213. },
  214. header: {
  215. "content-type": "application/json",
  216. },
  217. success: (res) => {
  218. console.log("res-pay", res.data);
  219. if (res.data.success == "yes") {
  220. this.linkid = res.data.linkid;
  221. // 微信支付逻辑
  222. if (this.payType === "wechat") {
  223. uni.requestPayment({
  224. provider: "wxpay",
  225. orderInfo: {
  226. appid: res.data.wepay.appid,
  227. partnerid: res.data.wepay.partnerid,
  228. prepayid: res.data.wepay.prepayid,
  229. package: "Sign=WXPay",
  230. noncestr: res.data.wepay.noncestr,
  231. timestamp: res.data.wepay.timestamp,
  232. sign: res.data.wepay.sign
  233. },
  234. success(res) {
  235. console.log("微信支付成功:", res);
  236. setTimeout(function () {
  237. that.showPayCall();
  238. }, 1000);
  239. },
  240. fail(e) {
  241. console.log("微信支付失败:", e);
  242. uni.showToast({
  243. title: "支付失败,请重试",
  244. icon: "none"
  245. });
  246. }
  247. });
  248. }
  249. // 支付宝支付逻辑
  250. else if (this.payType === "alipay") {
  251. uni.requestPayment({
  252. provider: "alipay",
  253. orderInfo: res.data.ali_pay, // 直接使用后端返回的支付宝支付参数
  254. success(res) {
  255. console.log("支付宝支付成功:", res);
  256. setTimeout(function () {
  257. that.showPayCall();
  258. }, 1000);
  259. },
  260. fail(e) {
  261. console.log("支付宝支付失败:", e);
  262. uni.showToast({
  263. title: "支付失败,请重试",
  264. icon: "none"
  265. });
  266. }
  267. });
  268. }
  269. } else {
  270. uni.showToast({
  271. title: "创建订单失败,请联系客服",
  272. icon: "none",
  273. });
  274. }
  275. },
  276. fail: (err) => {
  277. console.log("请求失败:", err);
  278. uni.showToast({
  279. title: "网络错误,请重试",
  280. icon: "none"
  281. });
  282. },
  283. complete: () => {
  284. that.isSubmitting = false;
  285. }
  286. });
  287. },
  288. showPayCall() {
  289. let that = this;
  290. this.$refs["DialogBox"]
  291. .confirm({
  292. title: "提示",
  293. content: "我已经支付完成",
  294. DialogType: "inquiry",
  295. btn1: "否",
  296. btn2: "是",
  297. animation: 0,
  298. })
  299. .then((res) => {
  300. uni.request({
  301. url: this.$apiHost + "/Order/getstatus",
  302. data: {
  303. uuid: getApp().globalData.uuid,
  304. linkid: that.linkid,
  305. },
  306. header: {
  307. "content-type": "application/json",
  308. },
  309. success: (res) => {
  310. if (res.data.success == "yes") {
  311. uni.showToast({
  312. title: "充值成功",
  313. icon: "none",
  314. });
  315. } else {
  316. uni.showToast({
  317. title: "还未检测到充值状态,请稍后再试",
  318. icon: "none",
  319. });
  320. setTimeout(function () {
  321. that.showPayCall();
  322. }, 1000);
  323. }
  324. },
  325. complete: (com) => {},
  326. });
  327. });
  328. },
  329. loadData() {
  330. // 获取M币数量
  331. uni.request({
  332. url: this.$apiHost + '/My/getnum',
  333. method: 'GET',
  334. header: {
  335. 'content-type': 'application/json',
  336. 'sign': getApp().globalData.headerSign
  337. },
  338. data: {
  339. uuid: getApp().globalData.uuid
  340. },
  341. success: (res) => {
  342. console.log("获取用户M币数量:", res.data);
  343. if (res.data && res.data.num_gmm) {
  344. this.myGoldCoin = res.data.num_gmm;
  345. }
  346. }
  347. });
  348. // 获取充值列表
  349. uni.request({
  350. url: this.$apiHost + "/User/getCzList",
  351. data: {
  352. uuid: getApp().globalData.uuid,
  353. },
  354. header: {
  355. "content-type": "application/json",
  356. },
  357. success: (res) => {
  358. console.log("res", res.data);
  359. this.num = res.data.num;
  360. if (res.data.list != null && res.data.list != undefined) {
  361. this.list = res.data.list;
  362. this.tid = this.list[1]["id"];
  363. this.sel = 1;
  364. this.money = this.list[1]["money"];
  365. }
  366. },
  367. });
  368. },
  369. handleDropdownSelect(item) {
  370. switch (item.type) {
  371. case "vipRecord":
  372. uni.navigateTo({
  373. url: "/pages/vip/record?type=coin",
  374. });
  375. break;
  376. }
  377. },
  378. agreeChk() {
  379. if (this.is_agree == 0) {
  380. this.is_agree = 1;
  381. } else {
  382. this.is_agree = 0;
  383. }
  384. },
  385. },
  386. };
  387. </script>
  388. <style scoped lang="scss">
  389. @import "M_purchase.scss";
  390. .agree {
  391. width: 90%;
  392. margin: 0 auto;
  393. color: #666666;
  394. font-size: 24rpx;
  395. display: flex;
  396. align-items: center;
  397. text-align: left;
  398. line-height: 32rpx;
  399. position: absolute;
  400. bottom: 215rpx;
  401. left: 50%;
  402. transform: translateX(-50%);
  403. .agree2 {
  404. display: flex;
  405. flex-direction: row;
  406. justify-content: flex-start;
  407. align-items: center;
  408. padding-right: 8rpx;
  409. flex-shrink: 0;
  410. padding-bottom: 34rpx;
  411. }
  412. .xy {
  413. color: #0084ff;
  414. display: inline;
  415. }
  416. image {
  417. width: 32rpx;
  418. height: 32rpx;
  419. }
  420. }
  421. .btn_submit {
  422. width: 626rpx;
  423. height: 88rpx;
  424. background: linear-gradient(to left, #1f1f1f , #444444 );
  425. border-radius: 76rpx;
  426. margin: 0 auto;
  427. margin-top: 70rpx;
  428. color: #acf934;
  429. display: flex;
  430. align-items: center;
  431. justify-content: center;
  432. font-size: 32rpx;
  433. line-height: 0;
  434. position: relative;
  435. overflow: hidden;
  436. transition: all 0.3s ease;
  437. position: absolute;
  438. bottom: 100rpx;
  439. left: 50%;
  440. transform: translateX(-50%);
  441. &.btn-loading {
  442. opacity: 0.7;
  443. pointer-events: none;
  444. }
  445. .loading-spinner {
  446. width: 40rpx;
  447. height: 40rpx;
  448. border: 4rpx solid rgba(255, 255, 255, 0.3);
  449. border-radius: 50%;
  450. border-top-color: #fff;
  451. animation: spin 1s linear infinite;
  452. }
  453. text {
  454. display: inline-block;
  455. margin-right: 10rpx;
  456. }
  457. }
  458. @keyframes spin {
  459. to {
  460. transform: rotate(360deg);
  461. }
  462. }
  463. </style>