鸿宇研学生前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
6.8 KiB

  1. <template>
  2. <view class="page__view">
  3. <navbar title="提现" leftClick @leftClick="$utils.navigateBack" color="#191919" bgColor="#FFFFFF" />
  4. <view class="main">
  5. <view class="flex card row">
  6. <view class="row-label">余额</view>
  7. <view class="row-content">{{ `¥${userCenterData.balance}` }}</view>
  8. </view>
  9. <view class="card">
  10. <view class="card-header">微信提现</view>
  11. <view class="form">
  12. <uv-form
  13. ref="form"
  14. :model="form"
  15. :rules="rules"
  16. errorType="toast"
  17. >
  18. <view class="form-item">
  19. <uv-form-item prop="userName" :customStyle="formItemStyle">
  20. <view class="form-item-label">真实姓名</view>
  21. <view class="form-item-content">
  22. <formInput v-model="form.userName"></formInput>
  23. </view>
  24. </uv-form-item>
  25. </view>
  26. <view class="form-item">
  27. <uv-form-item prop="transferAmount" :customStyle="formItemStyle">
  28. <view class="form-item-label">提现金额</view>
  29. <view class="form-item-content">
  30. <formInput v-model="form.transferAmount"></formInput>
  31. </view>
  32. </uv-form-item>
  33. </view>
  34. </uv-form>
  35. </view>
  36. </view>
  37. <view class="notice">
  38. 请仔细检查并确认相关信息因用户个人疏忽导致的充值错误需由用户自行承担
  39. <text class="highlight" @click="$refs.modal.open('withdrawal_instructions', '提现须知')">提现须知</text>
  40. </view>
  41. <agreementModal ref="modal"></agreementModal>
  42. </view>
  43. <view class="bottom">
  44. <button class="btn" @click="onSubmit">提现</button>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import { mapState } from 'vuex'
  50. import formInput from '@/pages_order/components/formInput.vue'
  51. import agreementModal from '@/pages_order/components/agreementModal.vue'
  52. export default {
  53. components: {
  54. formInput,
  55. agreementModal,
  56. },
  57. data() {
  58. return {
  59. form: {
  60. userName: null,
  61. transferAmount: null,
  62. },
  63. rules: {
  64. 'userName': {
  65. type: 'string',
  66. required: true,
  67. message: '请输入真实姓名',
  68. },
  69. 'transferAmount': {
  70. type: 'string',
  71. required: true,
  72. message: '请输入提现金额',
  73. },
  74. },
  75. formItemStyle: { padding: 0 },
  76. }
  77. },
  78. computed: {
  79. ...mapState(['userCenterData']),
  80. },
  81. methods: {
  82. async onSubmit() {
  83. try {
  84. await this.$refs.form.validate()
  85. const {
  86. userName,
  87. transferAmount,
  88. } = this.form
  89. const params = {
  90. userName,
  91. transferAmount,
  92. }
  93. const result = await this.$fetch('cashout', params)
  94. console.log('cashout', result)
  95. // 拉起微信收款确认页面
  96. if (!wx.canIUse('requestMerchantTransfer')) {
  97. wx.showModal({
  98. content: '你的微信版本过低,请更新至最新版本。',
  99. showCancel: false,
  100. });
  101. return
  102. }
  103. // 在真机环境中,调用API
  104. wx.requestMerchantTransfer({
  105. mchId: this.$config.mchId,
  106. appId: wx.getAccountInfoSync().miniProgram.appId,
  107. package: result.packageInfo,
  108. success: (res) => {
  109. uni.showToast({
  110. title: '提现申请已提交',
  111. icon: 'success'
  112. })
  113. this.form.transferAmount = null
  114. this.form.userName = null
  115. this.$api('getMoney', {
  116. id : result.outBillNo,
  117. }).then(res => {
  118. this.$store.commit('getUserInfo')
  119. this.$store.commit('getUserCenterData')
  120. })
  121. },
  122. fail: (res) => {
  123. console.log('fail:', res);
  124. uni.showToast({
  125. title: '提现失败,请稍后再试',
  126. icon: 'none'
  127. })
  128. },
  129. complete: (res) => {
  130. console.log('requestMerchantTransfer完成:', res);
  131. }
  132. });
  133. // uni.showToast({
  134. // icon: 'success',
  135. // title: '提交成功',
  136. // });
  137. setTimeout(() => {
  138. this.$utils.navigateBack()
  139. }, 800)
  140. } catch (err) {
  141. console.log('cashout err', err)
  142. const { message } = err
  143. message && uni.showToast({
  144. icon: 'none',
  145. title: message,
  146. });
  147. }
  148. },
  149. },
  150. }
  151. </script>
  152. <style lang="scss" scoped>
  153. .page__view {
  154. width: 100vw;
  155. min-height: 100vh;
  156. background: $uni-bg-color;
  157. position: relative;
  158. /deep/ .nav-bar__view {
  159. position: fixed;
  160. top: 0;
  161. left: 0;
  162. }
  163. }
  164. .main {
  165. padding: calc(var(--status-bar-height) + 144rpx) 32rpx 224rpx 32rpx;
  166. }
  167. .card {
  168. padding: 32rpx;
  169. background: #FFFFFF;
  170. border: 2rpx solid #FFFFFF;
  171. border-radius: 32rpx;
  172. & + & {
  173. margin-top: 40rpx;
  174. }
  175. &-header {
  176. font-family: PingFang SC;
  177. font-weight: 500;
  178. font-size: 36rpx;
  179. line-height: 1.4;
  180. color: #252545;
  181. margin-bottom: 32rpx;
  182. }
  183. }
  184. .row {
  185. justify-content: flex-start;
  186. column-gap: 16rpx;
  187. font-family: PingFang SC;
  188. font-weight: 400;
  189. font-size: 36rpx;
  190. line-height: 1.4;
  191. color: #181818;
  192. &-label {
  193. font-weight: 500;
  194. }
  195. &-content {
  196. }
  197. }
  198. .form {
  199. padding: 8rpx 0 0 0;
  200. &-item {
  201. border-bottom: 2rpx solid #EEEEEE;
  202. &:last-child {
  203. border: none;
  204. }
  205. & + & {
  206. margin-top: 40rpx;
  207. }
  208. &-label {
  209. font-family: PingFang SC;
  210. font-weight: 400;
  211. font-size: 26rpx;
  212. line-height: 1.4;
  213. color: #181818;
  214. }
  215. &-content {
  216. margin-top: 14rpx;
  217. padding: 6rpx 0;
  218. .text {
  219. padding: 2rpx 0;
  220. font-family: PingFang SC;
  221. font-weight: 400;
  222. font-size: 32rpx;
  223. line-height: 1.4;
  224. &.placeholder {
  225. color: #C6C6C6;
  226. }
  227. }
  228. }
  229. }
  230. }
  231. .notice {
  232. margin-top: 40rpx;
  233. font-size: 24rpx;
  234. line-height: 1.4;
  235. color: #BABABA;
  236. .highlight {
  237. color: #F79400;
  238. }
  239. }
  240. .bottom {
  241. position: fixed;
  242. left: 0;
  243. bottom: 0;
  244. width: 100vw;
  245. // height: 200rpx;
  246. padding: 24rpx 40rpx;
  247. padding-bottom: calc(env(safe-area-inset-bottom) + 24rpx);
  248. background: #FFFFFF;
  249. box-sizing: border-box;
  250. .btn {
  251. width: 100%;
  252. padding: 14rpx 0;
  253. box-sizing: border-box;
  254. font-family: PingFang SC;
  255. font-weight: 500;
  256. font-size: 36rpx;
  257. line-height: 1.4;
  258. color: #FFFFFF;
  259. background: linear-gradient(to right, #21FEEC, #019AF9);
  260. border: 2rpx solid #00A9FF;
  261. border-radius: 41rpx;
  262. }
  263. }
  264. </style>