index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. console.log(1123)
  208. uni.navigateTo({
  209. url:'/pages_mine/pages/withdrawal/details'
  210. })
  211. }
  212. const onMaxChange = () => {
  213. priceData.value.price = maxPrice.value
  214. }
  215. const init = async () => {
  216. try {
  217. uni.showLoading({
  218. title: '数据加载中...',
  219. })
  220. if (userType === 2) {
  221. const res = await getVolunteerAccountInfo()
  222. maxPrice.value = res.data.balance
  223. }
  224. if (userType === 1) {
  225. const res = await getAccountInfo()
  226. maxPrice.value = res.data.balance
  227. }
  228. } catch (error) {
  229. console.log('error', error)
  230. uni.showToast({
  231. title: error.msg,
  232. icon: 'error',
  233. })
  234. } finally {
  235. uni.hideLoading()
  236. }
  237. }
  238. const selectNumber = (row) => {
  239. s_key.value = row.name
  240. console.log('selectNumber', row)
  241. // if (row.name === '他人支付宝账号提现') {
  242. // try {
  243. // uni.showLoading({
  244. // title: '加载历史数据...',
  245. // mask: true
  246. // })
  247. // // 首先尝试获取历史支付宝账户信息
  248. // const res = await vonTtAlipayAccountHistory()
  249. // if (res.data === null ) {
  250. // // 获取当前提现状态的数据
  251. // const statusRes = await getWithdrawStatus()
  252. // if (statusRes.code === 200 && statusRes.data) {
  253. // priceData.value.name = statusRes.data.alipayName || ''
  254. // priceData.value.code = statusRes.data.alipayAccountNo || ''
  255. // priceData.value.idCard = statusRes.data.takeIdCard || ''
  256. // }
  257. // }
  258. // } catch (error) {
  259. // console.error('获取账户信息失败:', error)
  260. // uni.showToast({
  261. // title: '获取账户信息失败',
  262. // icon: 'none'
  263. // })
  264. // } finally {
  265. // uni.hideLoading()
  266. // }
  267. // } else {
  268. // // 切回本人时清空第三方账号信息
  269. // priceData.value.name = ''
  270. // priceData.value.code = ''
  271. // priceData.value.idCard = ''
  272. // }
  273. }
  274. onShow(() => {
  275. init()
  276. })
  277. </script>
  278. <style lang="scss" scoped>
  279. .withdrawal-main {
  280. position: fixed;
  281. top: 0px;
  282. left: 0px;
  283. right: 0px;
  284. bottom: 0px;
  285. background-color: #fff;
  286. padding: 0 12px;
  287. .withdrawal-item {
  288. display: flex;
  289. align-items: center;
  290. justify-content: space-between;
  291. padding: 12px 0;
  292. .withdrawal-label {
  293. font-size: 14px;
  294. font-weight: 500;
  295. line-height: 20.27px;
  296. color: rgba(153, 153, 153, 1);
  297. display: flex;
  298. align-items: center;
  299. }
  300. .withdrawal-item-right {
  301. display: flex;
  302. align-items: center;
  303. .withdrawal-text {
  304. font-size: 16px;
  305. font-weight: 700;
  306. line-height: 23.17px;
  307. color: rgba(0, 0, 0, 1);
  308. margin-right: 6px;
  309. }
  310. }
  311. }
  312. .price-box {
  313. display: flex;
  314. .price-input {
  315. flex: 1;
  316. height: 58px;
  317. padding: 0 12px;
  318. font-size: 28px;
  319. }
  320. .price-input2 {
  321. flex: 1;
  322. height: 38px;
  323. padding: 0 12px;
  324. font-size: 16px;
  325. }
  326. }
  327. }
  328. </style>