index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <view class="withdrawal-main">
  3. <view class="withdrawal-item">
  4. <label class="withdrawal-label">提现到账</label>
  5. <view class="withdrawal-item-right" @click="openSheet">
  6. <view class="withdrawal-text">{{ w_key }}</view>
  7. <up-icon name="arrow-right"></up-icon>
  8. </view>
  9. </view>
  10. <view class="withdrawal-item">
  11. <label class="withdrawal-label">本人支付宝账号提现</label>
  12. <view class="withdrawal-item-right" @click="openSheetNumber">
  13. <view class="withdrawal-text">{{ s_key }}</view>
  14. <up-icon name="arrow-right"></up-icon>
  15. </view>
  16. </view>
  17. <view v-if="w_key === '支付宝账户'">
  18. <view class="withdrawal-item">
  19. <label class="withdrawal-label">支付宝姓名</label>
  20. </view>
  21. <view class="price-box">
  22. <input
  23. class="price-input2"
  24. placeholder="请输入支付宝姓名"
  25. border="none"
  26. v-model="priceData.name"
  27. />
  28. </view>
  29. <view class="withdrawal-item">
  30. <label class="withdrawal-label">支付宝户名</label>
  31. </view>
  32. <view class="price-box">
  33. <input
  34. class="price-input2"
  35. placeholder="请输入支付宝户名"
  36. border="none"
  37. v-model="priceData.code"
  38. />
  39. </view>
  40. <view v-show="s_key === '他人支付宝账号提现'">
  41. <view class="withdrawal-item">
  42. <label class="withdrawal-label">身份证号</label>
  43. </view>
  44. <view class="price-box">
  45. <input
  46. class="price-input2"
  47. placeholder="请输入身份证号"
  48. border="none"
  49. v-model="priceData.idCard"
  50. />
  51. </view>
  52. </view>
  53. </view>
  54. <view class="withdrawal-item">
  55. <label class="withdrawal-label">提现金额</label>
  56. </view>
  57. <view class="price-box">
  58. <up-icon name="rmb" size="28" color="rgba(0, 0, 0, 1)"></up-icon>
  59. <input
  60. class="price-input"
  61. placeholder="请输入提现金额"
  62. border="none"
  63. v-model="priceData.price"
  64. @change="change"
  65. />
  66. </view>
  67. <view class="withdrawal-item">
  68. <label class="withdrawal-label"
  69. >可提现余额 <up-icon name="rmb"></up-icon>{{ maxPrice }}</label
  70. >
  71. <view class="withdrawal-item-right" @click="onMaxChange">
  72. <view class="withdrawal-text">全部提现</view>
  73. </view>
  74. </view>
  75. <view style="margin-top: 45px">
  76. <up-button type="primary" text="确定提现" @click="onSubmit"></up-button>
  77. </view>
  78. <up-action-sheet
  79. :show="show"
  80. @close="close"
  81. @select="select"
  82. :actions="actions"
  83. >
  84. </up-action-sheet>
  85. <up-action-sheet
  86. :show="showNumber"
  87. @close="close"
  88. @select="selectNumber"
  89. :actions="actionsProxy"
  90. ></up-action-sheet>
  91. </view>
  92. </template>
  93. <script setup>
  94. import { ref, relative } from 'vue'
  95. import {
  96. getVolunteerAccountInfo,
  97. getAccountInfo,
  98. submitAmountApply,
  99. } from '@/api/mine'
  100. import { onShow } from '@dcloudio/uni-app'
  101. import row from 'uview-plus/components/u-row/row'
  102. const actions = [
  103. {
  104. name: '支付宝账户',
  105. },
  106. ]
  107. const actionsProxy = [
  108. {
  109. name: '本人支付宝账号提现',
  110. value: 1,
  111. },
  112. {
  113. name: '他人支付宝账号提现',
  114. value: 2,
  115. },
  116. ]
  117. const userType = uni.getStorageSync('userType') //读取本地存储
  118. const w_key = ref('支付宝账户')
  119. const s_key = ref('本人支付宝账号提现')
  120. const show = ref(false)
  121. const showNumber = ref(false)
  122. const maxPrice = ref(0)
  123. const priceData = ref({
  124. // price: '0.01',
  125. // name: '搁置',
  126. // code: '18696601943'
  127. price: '',
  128. name: '',
  129. code: '',
  130. idCard: '',
  131. })
  132. const change = (e) => {
  133. console.log('change', e)
  134. const regex = /^\d*\.?\d*$/
  135. if (!regex.test(e.detail.value)) {
  136. priceData.value.price = priceData.value.price.replace(/[^\d.]/g, '')
  137. }
  138. }
  139. const openSheet = (index) => {
  140. show.value = true
  141. }
  142. const openSheetNumber = (index) => {
  143. showNumber.value = true
  144. }
  145. const close = () => {
  146. show.value = false
  147. showNumber.value = false
  148. }
  149. const select = (row) => {
  150. w_key.value = row.name
  151. console.log('select', row)
  152. }
  153. const selectNumber = (row) => {
  154. s_key.value = row.name
  155. console.log('selectNumber', row)
  156. }
  157. const errors = (e) => {
  158. uni.showToast({
  159. title: e,
  160. icon: 'none',
  161. })
  162. }
  163. const handleCheck = () => {
  164. const is =
  165. priceData.value.price &&
  166. priceData.value.price > 0 &&
  167. priceData.value.name &&
  168. priceData.value.code
  169. if (is) {
  170. return true
  171. }
  172. !priceData.value.price && errors('请输入提现金额')
  173. priceData.value.price <= 0 && errors('请输入正确的金额')
  174. !priceData.value.name && errors('请输入账户名')
  175. !priceData.value.code && errors('请输入账号')
  176. return false
  177. }
  178. const onSubmit = () => {
  179. console.log('TCL: priceData', priceData.value)
  180. // init();
  181. const type = handleCheck()
  182. type &&
  183. submitAmountApply({
  184. takeAmount: priceData.value.price,
  185. alipayName: priceData.value.name,
  186. alipayAccountNo: priceData.value.code,
  187. payType: '2',
  188. alipayAccountType: s_key.value === '本人支付宝账号提现' ? 1 : 2,
  189. idCard: priceData.value.idCard,
  190. }).then((res) => {
  191. if (res.code === 200) {
  192. uni.showToast({
  193. title: '提交成功',
  194. icon: 'success',
  195. })
  196. setTimeout(() => {
  197. uni.redirectTo({ url: `/pages_mine/pages/wallet/index` })
  198. }, 800)
  199. }
  200. })
  201. }
  202. const onMaxChange = () => {
  203. priceData.value.price = maxPrice.value
  204. }
  205. const init = async () => {
  206. try {
  207. uni.showLoading({
  208. title: '数据加载中...',
  209. })
  210. if (userType === 2) {
  211. const res = await getVolunteerAccountInfo()
  212. maxPrice.value = res.data.balance
  213. }
  214. if (userType === 1) {
  215. const res = await getAccountInfo()
  216. maxPrice.value = res.data.balance
  217. }
  218. } catch (error) {
  219. console.log('error', error)
  220. uni.showToast({
  221. title: error.msg,
  222. icon: 'error',
  223. })
  224. } finally {
  225. uni.hideLoading()
  226. }
  227. }
  228. onShow(() => {
  229. init()
  230. })
  231. </script>
  232. <style lang="scss" scoped>
  233. .withdrawal-main {
  234. position: fixed;
  235. top: 0px;
  236. left: 0px;
  237. right: 0px;
  238. bottom: 0px;
  239. background-color: #fff;
  240. padding: 0 12px;
  241. .withdrawal-item {
  242. display: flex;
  243. align-items: center;
  244. justify-content: space-between;
  245. padding: 12px 0;
  246. .withdrawal-label {
  247. font-size: 14px;
  248. font-weight: 500;
  249. line-height: 20.27px;
  250. color: rgba(153, 153, 153, 1);
  251. display: flex;
  252. align-items: center;
  253. }
  254. .withdrawal-item-right {
  255. display: flex;
  256. align-items: center;
  257. .withdrawal-text {
  258. font-size: 16px;
  259. font-weight: 700;
  260. line-height: 23.17px;
  261. color: rgba(0, 0, 0, 1);
  262. margin-right: 6px;
  263. }
  264. }
  265. }
  266. .price-box {
  267. display: flex;
  268. .price-input {
  269. flex: 1;
  270. height: 58px;
  271. padding: 0 12px;
  272. font-size: 28px;
  273. }
  274. .price-input2 {
  275. flex: 1;
  276. height: 38px;
  277. padding: 0 12px;
  278. font-size: 16px;
  279. }
  280. }
  281. }
  282. </style>