addApply.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <template>
  2. <view>
  3. <view class="content">
  4. <view class="withdraw y-c">
  5. <view class="title">提现金额</view>
  6. <view class="amount">
  7. <text class="unit">¥</text>
  8. <input class="amount-input" v-model="amount" type="digit" @input="handleAmountInput" />
  9. <image class="clear" v-if="showClearIcon" @click="clearIcon"
  10. src="@/static/image/healthRecords/input_close_icon.png" mode="aspectFill"></image>
  11. </view>
  12. <view class="tips">当前可以提现金额{{availableAmount}}元,<view class="all" @click="withdrawAll">全部提现</view>
  13. </view>
  14. </view>
  15. <view class="info-item">
  16. <view class="label">提现至</view>
  17. <view class="right" @click="selectAccount" v-if="payType==0">
  18. <view class="text">请选择提现账户</view>
  19. <image src="@/static/image/hall/my_right_arrow_right_icon.png"></image>
  20. </view>
  21. <view class="right y-bc" @click="selectAccount" v-if="payType==1">
  22. <view class="weixin x-c">
  23. <image src="@/static/images/wallet/order_wechat.png" mode=""></image>
  24. <view class="way">微信</view>
  25. <image src="@/static/image/hall/my_right_arrow_right_icon.png"></image>
  26. </view>
  27. <view class="text">立即到账</view>
  28. </view>
  29. </view>
  30. <u-popup :show="show" mode="bottom" @close="close" :round="16">
  31. <view class="pay-list">
  32. <view class="title x-bc">
  33. <view style="width: 48rpx;"></view>
  34. 请选择提现账户
  35. <image class="close" @click="close" src="@/static/image/hall/close_icon.png"></image>
  36. </view>
  37. <view class="pay-box">
  38. <radio-group @change="payTypeChange">
  39. <view class="item-box x-bc">
  40. <image src="@/static/images/wallet/order_wechat.png" mode=""></image>
  41. <view class="right x-bc">
  42. <text class="text">微信支付</text>
  43. <label>
  44. <radio :value="1" :checked="payType==1" activeBackgroundColor="#FF5C03" />
  45. </label>
  46. </view>
  47. </view>
  48. </radio-group>
  49. </view>
  50. </view>
  51. </u-popup>
  52. </view>
  53. <view class="btn-box">
  54. <view class="sub-btn" :class="{ disabled: !canSubmit }" @click="submit()">立即提现</view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import {
  60. setPwd,
  61. setHeadImg,
  62. setUserInfo,
  63. getUserInfo,
  64. withDrawal,
  65. getWallet
  66. } from '@/api/user.js';
  67. import {
  68. getRedPacketLogByCode
  69. } from '@/api/integral.js'
  70. import {
  71. premissionCheck
  72. } from "@/js_sdk/wa-permission/permission.js"
  73. export default {
  74. data() {
  75. return {
  76. payType: 1,
  77. show: false,
  78. showClearIcon: false,
  79. amount: null,
  80. availableAmount: '0.00', // 可提现金额
  81. nickName: "",
  82. deptName: "",
  83. postNames: "",
  84. phonenumber: "",
  85. email: "",
  86. sexPicker: ['男', '女', '未知'],
  87. sex: 0, // 性别
  88. headImg: '/static/images/detault_head.jpg', // 头像,
  89. headImgUrl: '',
  90. wxMerchantTransfer:null,
  91. }
  92. },
  93. computed: {
  94. // 是否可以提交提现
  95. canSubmit() {
  96. const amount = parseFloat(this.amount) || 0;
  97. const available = parseFloat(this.availableAmount) || 0;
  98. const minAmount = 0.1; // 最低提现金额
  99. return amount >= minAmount && amount <= available && this.payType > 0;
  100. }
  101. },
  102. onLoad() {
  103. this.getUserInfo();
  104. // 在调用插件之前添加
  105. console.log('当前运行基座类型:', plus.runtime.isCustomKernel ? '自定义基座' : '标准基座');
  106. // 获取插件
  107. this.wxMerchantTransfer = uni.requireNativePlugin('wxMerchantTransfer');
  108. console.log('插件对象:', this.wxMerchantTransfer);
  109. if (!this.wxMerchantTransfer) {
  110. console.error('插件加载失败!请确认是否正在运行自定义基座,且插件已正确打包。');
  111. }
  112. },
  113. onShow() {
  114. // 返回时清空提现金额
  115. this.amount = null;
  116. this.showClearIcon = false;
  117. this.getWalletInfo();
  118. },
  119. methods: {
  120. selectAccount() {
  121. this.show = true
  122. },
  123. close() {
  124. this.show = false
  125. },
  126. payTypeChange(e) {
  127. this.payType = e.detail.value
  128. },
  129. // 金额输入处理
  130. handleAmountInput(e) {
  131. const value = e.detail.value;
  132. this.amount = value;
  133. this.showClearIcon = value && value.length > 0;
  134. // 验证输入金额
  135. const inputAmount = parseFloat(value) || 0;
  136. const maxAmount = parseFloat(this.availableAmount) || 0;
  137. const minAmount = 0.1; // 最低提现金额
  138. // 如果输入了有效数字且小于最低金额,给出提示
  139. if (value && !isNaN(inputAmount) && inputAmount > 0 && inputAmount < minAmount) {
  140. uni.showToast({
  141. title: `最低提现金额为${minAmount}元`,
  142. icon: 'none',
  143. duration: 2000
  144. });
  145. }
  146. // 限制输入金额不超过可提现金额
  147. if (inputAmount > maxAmount) {
  148. this.amount = maxAmount;
  149. uni.showToast({
  150. title: `最多可提现${maxAmount}元`,
  151. icon: 'none'
  152. });
  153. }
  154. },
  155. // 全部提现
  156. withdrawAll() {
  157. const availableAmount = parseFloat(this.availableAmount) || 0;
  158. const minAmount = 0.1; // 最低提现金额
  159. if (availableAmount < minAmount) {
  160. uni.showToast({
  161. title: `可提现金额不足${minAmount}元,无法提现`,
  162. icon: 'none',
  163. duration: 2000
  164. });
  165. return;
  166. }
  167. this.amount = this.availableAmount;
  168. this.showClearIcon = true;
  169. },
  170. bindUser(data) {
  171. var that = this;
  172. that.nickName = data.user.nickName;
  173. that.posts = data.post;
  174. that.phonenumber = data.user.phone;
  175. that.email = data.user.email;
  176. if (data.user.sex != undefined) {
  177. that.sex = data.user.sex;
  178. }
  179. if (data.post != null && data.post.length > 0) {
  180. var postNameStr = "";
  181. data.post.forEach((v, i) => {
  182. postNameStr += v + ",";
  183. }, this);
  184. that.postNames = postNameStr.substr(0, postNameStr.length - 1);
  185. }
  186. if (!that.$isEmpty(data.user.avatar)) {
  187. //this.headImg=uni.getStorageSync('requestPath')+data.user.avatar;
  188. this.headImg = data.user.avatar;
  189. this.headImgUrl = data.user.avatar;
  190. }
  191. },
  192. getUserInfo() {
  193. var data = {};
  194. var that = this;
  195. getUserInfo(data).then(
  196. res => {
  197. that.bindUser(res);
  198. },
  199. rej => {}
  200. );
  201. },
  202. // 获取钱包信息,获取可提现金额
  203. getWalletInfo() {
  204. const user = this.$getUserInfo();
  205. if (!user || !user.userId) {
  206. return;
  207. }
  208. getWallet({
  209. userId: user.userId
  210. }).then(
  211. res => {
  212. if (res.code == 200 && res.data) {
  213. // 使用 mayWithdraw 作为可提现金额
  214. this.availableAmount = (res.data.mayWithdraw || 0);
  215. }
  216. },
  217. err => {
  218. console.error('获取钱包信息失败', err);
  219. }
  220. );
  221. },
  222. clearIcon() {
  223. this.amount = null;
  224. this.showClearIcon = false;
  225. },
  226. submit() {
  227. // 验证金额
  228. const amount = parseFloat(this.amount) || 0;
  229. const maxAmount = parseFloat(this.availableAmount) || 0;
  230. const minAmount = 0.1; // 最低提现金额
  231. if (amount < minAmount) {
  232. uni.showToast({
  233. title: `最低提现金额为${minAmount}元`,
  234. icon: 'none'
  235. });
  236. return;
  237. }
  238. if (amount > maxAmount) {
  239. uni.showToast({
  240. title: `提现金额不能超过${maxAmount}元`,
  241. icon: 'none'
  242. });
  243. return;
  244. }
  245. // 验证提现账户
  246. if (this.payType === 0) {
  247. uni.showToast({
  248. title: "请选择提现账户",
  249. icon: 'none'
  250. });
  251. return;
  252. }
  253. var data = {
  254. applicationAmount: amount,
  255. appId: 'wx703c4bd07bbd1695',
  256. source: 3,
  257. };
  258. uni.showLoading({
  259. title: '处理中...'
  260. });
  261. withDrawal(data).then(
  262. res => {
  263. uni.hideLoading();
  264. console.log('提现API返回:', res);
  265. if (res.code == 200) {
  266. const orderCode = res.orderCode
  267. const params = {
  268. appId: res.appId, // 您的微信 AppID
  269. mchId: res.mchId, // 您的商户号
  270. package: res.package // 服务端返回的 package 字符串
  271. };
  272. this.wxMerchantTransfer.open(params, (res) => {
  273. console.log('回调结果:', res);
  274. if (res.code === 0) {
  275. // 跳转到成功页面,传递orderCode用于查询订单状态
  276. setTimeout(() => {
  277. uni.navigateTo({
  278. url: '/pages/user/wallet/success?orderCode=' +
  279. orderCode
  280. });
  281. }, 1500);
  282. } else if (res.code === -3) {
  283. // 微信版本过低,插件已弹出 Toast 提示,此处可记录日志
  284. console.warn('用户微信版本过低');
  285. } else {
  286. console.log('回调结果:', res);
  287. uni.showModal({
  288. title: '错误',
  289. content: res.message,
  290. showCancel: false
  291. });
  292. }
  293. });
  294. } else {
  295. uni.showToast({
  296. icon: 'none',
  297. title: res.msg || '提现失败',
  298. });
  299. }
  300. },
  301. err => {
  302. uni.hideLoading();
  303. console.error('提现API错误:', err);
  304. uni.showToast({
  305. icon: 'none',
  306. title: err.msg || '网络错误,请稍后重试',
  307. });
  308. }
  309. );
  310. }
  311. }
  312. }
  313. </script>
  314. <style scoped lang="scss">
  315. page {
  316. background: #F5F7FA;
  317. }
  318. .content {
  319. padding: 24rpx;
  320. //border-top: 1px solid #F5F6FA;
  321. }
  322. .withdraw {
  323. background: #FFFFFF;
  324. padding: 32rpx;
  325. border-radius: 16rpx 16rpx 16rpx 16rpx;
  326. margin-bottom: 20rpx;
  327. .title {
  328. font-family: PingFang SC, PingFang SC;
  329. font-weight: 500;
  330. font-size: 32rpx;
  331. color: #222222;
  332. line-height: 56rpx;
  333. }
  334. .amount {
  335. margin-top: 48rpx;
  336. margin-bottom: 48rpx;
  337. display: flex;
  338. align-items: center;
  339. justify-content: space-between;
  340. .unit {
  341. font-family: PingFang SC, PingFang SC;
  342. font-weight: 600;
  343. font-size: 60rpx;
  344. color: #222222;
  345. }
  346. .amount-input {
  347. height: 88rpx;
  348. font-family: DIN, DIN;
  349. font-weight: 500;
  350. font-size: 72rpx;
  351. color: #222222;
  352. line-height: 88rpx;
  353. }
  354. .clear {
  355. width: 48rpx;
  356. height: 32rpx;
  357. }
  358. }
  359. .tips {
  360. display: flex;
  361. align-items: center;
  362. font-family: PingFang SC, PingFang SC;
  363. font-weight: 400;
  364. font-size: 24rpx;
  365. color: #999999;
  366. .all {
  367. color: #E69A22;
  368. }
  369. }
  370. }
  371. .info-item {
  372. height: 120rpx;
  373. background: #FFFFFF;
  374. padding: 0 32rpx;
  375. display: flex;
  376. align-items: center;
  377. justify-content: space-between;
  378. border-radius: 16rpx 16rpx 16rpx 16rpx;
  379. .label {
  380. font-family: PingFang SC, PingFang SC;
  381. font-weight: 500;
  382. font-size: 32rpx;
  383. color: #222222;
  384. line-height: 56rpx;
  385. }
  386. .right {
  387. display: flex;
  388. align-items: center;
  389. justify-content: center;
  390. .text {
  391. font-family: PingFang SC, PingFang SC;
  392. font-weight: 400;
  393. font-size: 28rpx;
  394. color: #999999;
  395. }
  396. .way {
  397. margin-left: 16rpx;
  398. font-family: PingFang SC, PingFang SC;
  399. font-weight: 400;
  400. font-size: 28rpx;
  401. color: #222222;
  402. }
  403. image {
  404. margin-left: 10rpx;
  405. width: 48rpx;
  406. height: 48rpx;
  407. }
  408. }
  409. .head {
  410. border-radius: 50%;
  411. width: 80rpx;
  412. height: 80rpx;
  413. }
  414. .arrow {
  415. width: 30rpx;
  416. height: 30rpx;
  417. }
  418. .text {
  419. font-size: 30rpx;
  420. font-family: PingFang SC;
  421. font-weight: 400;
  422. color: #0F1826;
  423. }
  424. .input {
  425. text-align: right;
  426. font-size: 30rpx;
  427. font-family: PingFang SC;
  428. font-weight: 400;
  429. color: #0F1826;
  430. }
  431. &.password {
  432. margin-top: 20rpx;
  433. .right {
  434. display: flex;
  435. align-items: center;
  436. .text {
  437. font-size: 30rpx;
  438. font-family: PingFang SC;
  439. font-weight: 400;
  440. color: #0F1826;
  441. margin-right: 15rpx;
  442. }
  443. }
  444. }
  445. }
  446. .pay-list {
  447. background-color: #F5F7FA;
  448. padding: 24rpx;
  449. min-height: 400rpx;
  450. .title {
  451. height: 96rpx;
  452. line-height: 96rpx;
  453. padding-bottom: 24rpx;
  454. font-family: PingFang SC, PingFang SC;
  455. font-weight: 500;
  456. font-size: 36rpx;
  457. color: #222222;
  458. .close {
  459. width: 48rpx;
  460. height: 48rpx;
  461. }
  462. }
  463. .pay-box {
  464. padding: 0 32rpx;
  465. background: #FFFFFF;
  466. border-radius: 16rpx 16rpx 16rpx 16rpx;
  467. .item-box {
  468. image {
  469. margin-right: 24rpx;
  470. width: 48rpx;
  471. height: 48rpx;
  472. }
  473. .right {
  474. flex: 1;
  475. padding: 36rpx 0;
  476. border-bottom: 1px solid #ECECEC;
  477. .text {
  478. font-family: PingFang SC, PingFang SC;
  479. font-weight: 400;
  480. font-size: 28rpx;
  481. color: #222222;
  482. }
  483. }
  484. &:last-child {
  485. .right {
  486. border-bottom: none;
  487. }
  488. }
  489. }
  490. }
  491. }
  492. .btn-box {
  493. margin-top: 15rpx;
  494. height: 120rpx;
  495. padding: 0 30rpx;
  496. display: flex;
  497. align-items: center;
  498. justify-content: center;
  499. .sub-btn {
  500. width: 100%;
  501. height: 98rpx;
  502. line-height: 98rpx;
  503. text-align: center;
  504. font-size: 32rpx;
  505. font-family: PingFang SC;
  506. font-weight: bold;
  507. color: #FFFFFF;
  508. background: #FF5C03;
  509. border-radius: 16rpx;
  510. &.disabled {
  511. background: #FDAB8D;
  512. pointer-events: none;
  513. }
  514. }
  515. }
  516. </style>