index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. <up-button type="error" text="提现历史" @click="onHistory" style="margin-top: 20rpx;"></up-button>
  78. </view>
  79. <up-action-sheet
  80. :show="show"
  81. @close="close"
  82. @select="select"
  83. :actions="actions"
  84. >
  85. </up-action-sheet>
  86. <up-action-sheet
  87. :show="showNumber"
  88. @close="close"
  89. @select="selectNumber"
  90. :actions="actionsProxy"
  91. ></up-action-sheet>
  92. </view>
  93. </template>
  94. <script setup>
  95. import { ref, relative } from 'vue'
  96. import {
  97. getVolunteerAccountInfo,
  98. getAccountInfo,
  99. submitAmountApply,
  100. vonTtAlipayAccountHistory,
  101. getWithdrawStatus
  102. } from '@/api/mine'
  103. import { onShow } from '@dcloudio/uni-app'
  104. import row from 'uview-plus/components/u-row/row'
  105. const actions = [
  106. {
  107. name: '支付宝账户',
  108. },
  109. ]
  110. const actionsProxy = [
  111. {
  112. name: '本人支付宝账号提现',
  113. value: 1,
  114. },
  115. {
  116. name: '他人支付宝账号提现',
  117. value: 2,
  118. },
  119. ]
  120. const userType = uni.getStorageSync('userType') //读取本地存储
  121. const w_key = ref('支付宝账户')
  122. const s_key = ref('本人支付宝账号提现')
  123. const show = ref(false)
  124. const showNumber = ref(false)
  125. const maxPrice = ref(0)
  126. const priceData = ref({
  127. // price: '0.01',
  128. // name: '搁置',
  129. // code: '18696601943'
  130. price: '',
  131. name: '',
  132. code: '',
  133. idCard: '',
  134. })
  135. const change = (e) => {
  136. console.log('change', e)
  137. const regex = /^\d*\.?\d*$/
  138. if (!regex.test(e.detail.value)) {
  139. priceData.value.price = priceData.value.price.replace(/[^\d.]/g, '')
  140. }
  141. }
  142. const openSheet = (index) => {
  143. show.value = true
  144. }
  145. const openSheetNumber = (index) => {
  146. showNumber.value = true
  147. }
  148. const close = () => {
  149. show.value = false
  150. showNumber.value = false
  151. }
  152. const select = (row) => {
  153. w_key.value = row.name
  154. console.log('select', row)
  155. }
  156. // const selectNumber = (row) => {
  157. // s_key.value = row.name
  158. // console.log('selectNumber', row)
  159. // }
  160. const errors = (e) => {
  161. uni.showToast({
  162. title: e,
  163. icon: 'none',
  164. })
  165. }
  166. const handleCheck = () => {
  167. const is =
  168. priceData.value.price &&
  169. priceData.value.price > 0 &&
  170. priceData.value.name &&
  171. priceData.value.code
  172. if (is) {
  173. return true
  174. }
  175. !priceData.value.price && errors('请输入提现金额')
  176. priceData.value.price <= 0 && errors('请输入正确的金额')
  177. !priceData.value.name && errors('请输入账户名')
  178. !priceData.value.code && errors('请输入账号')
  179. return false
  180. }
  181. const onSubmit = () => {
  182. console.log('TCL: priceData', priceData.value)
  183. // init();
  184. const type = handleCheck()
  185. type &&
  186. submitAmountApply({
  187. takeAmount: priceData.value.price,
  188. alipayName: priceData.value.name,
  189. alipayAccountNo: priceData.value.code,
  190. payType: '2',
  191. alipayAccountType: s_key.value === '本人支付宝账号提现' ? 1 : 2,
  192. idCard: priceData.value.idCard,
  193. }).then((res) => {
  194. if (res.code === 200) {
  195. uni.showToast({
  196. title: '提交成功',
  197. icon: 'success',
  198. })
  199. setTimeout(() => {
  200. uni.redirectTo({ url: `/pages_mine/pages/wallet/index` })
  201. }, 800)
  202. }
  203. })
  204. }
  205. // 进入提现历史详情
  206. const onHistory = () => {
  207. uni.navigateTo({
  208. url:'/pages_mine/pages/withdrawal/detailsList'
  209. })
  210. }
  211. const onMaxChange = () => {
  212. priceData.value.price = maxPrice.value
  213. }
  214. const init = async () => {
  215. try {
  216. uni.showLoading({
  217. title: '数据加载中...',
  218. })
  219. // 获取初始账户历史数据,alipayAccountType=1(本人)
  220. const historyRes = await vonTtAlipayAccountHistory({ alipayAccountType: 1 })
  221. if (historyRes.data) {
  222. priceData.value.name = historyRes.data.alipayName || ''
  223. priceData.value.code = historyRes.data.alipayAccountNo || ''
  224. priceData.value.idCard = historyRes.data.idCard || ''
  225. }
  226. if (userType === 2) {
  227. const res = await getVolunteerAccountInfo()
  228. maxPrice.value = res.data.balance
  229. }
  230. if (userType === 1) {
  231. const res = await getAccountInfo()
  232. maxPrice.value = res.data.balance
  233. }
  234. } catch (error) {
  235. console.log('error', error)
  236. uni.showToast({
  237. title: error.msg,
  238. icon: 'error',
  239. })
  240. } finally {
  241. uni.hideLoading()
  242. }
  243. }
  244. const selectNumber = async (row) => {
  245. s_key.value = row.name
  246. console.log('selectNumber', row)
  247. try {
  248. uni.showLoading({
  249. title: '加载数据...',
  250. mask: true
  251. })
  252. // 根据类型获取账户历史
  253. const type = row.name === '他人支付宝账号提现' ? 2 : 1
  254. const res = await vonTtAlipayAccountHistory({ alipayAccountType: type })
  255. if (row.name === '他人支付宝账号提现') {
  256. if (res.data) {
  257. priceData.value.name = res.data.alipayName || ''
  258. priceData.value.code = res.data.alipayAccountNo || ''
  259. priceData.value.idCard = res.data.idCard || ''
  260. } else {
  261. // 如果没有历史数据,获取当前状态
  262. const statusRes = await getWithdrawStatus()
  263. if (statusRes.code === 200 && statusRes.data) {
  264. priceData.value.name = statusRes.data.alipayName || ''
  265. priceData.value.code = statusRes.data.alipayAccountNo || ''
  266. priceData.value.idCard = statusRes.data.idCard || ''
  267. } else {
  268. // 如果data为null,清空相关字段
  269. priceData.value.name = ''
  270. priceData.value.code = ''
  271. priceData.value.idCard = ''
  272. }
  273. }
  274. } else {
  275. // 切换回本人时清空数据
  276. priceData.value.name = ''
  277. priceData.value.code = ''
  278. priceData.value.idCard = ''
  279. // 重新查一次本人账号历史
  280. if (res.data) {
  281. priceData.value.name = res.data.alipayName || ''
  282. priceData.value.code = res.data.alipayAccountNo || ''
  283. priceData.value.idCard = res.data.idCard || ''
  284. }
  285. }
  286. } catch (error) {
  287. console.error('获取账户信息失败:', error)
  288. uni.showToast({
  289. title: '获取账户信息失败',
  290. icon: 'none'
  291. })
  292. } finally {
  293. uni.hideLoading()
  294. }
  295. }
  296. onShow(() => {
  297. init()
  298. })
  299. </script>
  300. <style lang="scss" scoped>
  301. .withdrawal-main {
  302. position: fixed;
  303. top: 0px;
  304. left: 0px;
  305. right: 0px;
  306. bottom: 0px;
  307. background-color: #fff;
  308. padding: 0 12px;
  309. .withdrawal-item {
  310. display: flex;
  311. align-items: center;
  312. justify-content: space-between;
  313. padding: 12px 0;
  314. .withdrawal-label {
  315. font-size: 14px;
  316. font-weight: 500;
  317. line-height: 20.27px;
  318. color: rgba(153, 153, 153, 1);
  319. display: flex;
  320. align-items: center;
  321. }
  322. .withdrawal-item-right {
  323. display: flex;
  324. align-items: center;
  325. .withdrawal-text {
  326. font-size: 16px;
  327. font-weight: 700;
  328. line-height: 23.17px;
  329. color: rgba(0, 0, 0, 1);
  330. margin-right: 6px;
  331. }
  332. }
  333. }
  334. .price-box {
  335. display: flex;
  336. .price-input {
  337. flex: 1;
  338. height: 58px;
  339. padding: 0 12px;
  340. font-size: 28px;
  341. }
  342. .price-input2 {
  343. flex: 1;
  344. height: 38px;
  345. padding: 0 12px;
  346. font-size: 16px;
  347. }
  348. }
  349. }
  350. </style>