鸿宇研学生前端代码
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.

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