M_purchase.vue 11 KB

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