withdraw.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <!-- 分佣提现 -->
  2. <template>
  3. <s-layout title="申请提现" class="withdraw-wrap" navbar="inner">
  4. <view class="page-bg"></view>
  5. <view
  6. class="wallet-num-box ss-flex ss-col-center ss-row-between"
  7. :style="[
  8. {
  9. marginTop: '-' + Number(statusBarHeight + 88) + 'rpx',
  10. paddingTop: Number(statusBarHeight + 108) + 'rpx',
  11. },
  12. ]"
  13. >
  14. <view class="">
  15. <view class="num-title">可提现金额(元)</view>
  16. <view class="wallet-num">{{ fen2yuan(state.brokerageInfo.brokeragePrice) }}</view>
  17. </view>
  18. <button
  19. class="ss-reset-button log-btn"
  20. @tap="sheep.$router.go('/pages/commission/wallet', { type: 2 })"
  21. >
  22. 提现记录
  23. </button>
  24. </view>
  25. <!-- 提现输入卡片-->
  26. <view class="draw-card">
  27. <view class="bank-box ss-flex ss-col-center ss-row-between ss-m-b-30">
  28. <view class="name">提现至</view>
  29. <view class="bank-list ss-flex ss-col-center" @tap="onAccountSelect(true)">
  30. <view v-if="!state.accountInfo.type" class="empty-text">请选择提现方式</view>
  31. <view v-if="state.accountInfo.type === '1'" class="empty-text">钱包余额</view>
  32. <view v-if="state.accountInfo.type === '2'" class="empty-text">银行卡转账</view>
  33. <view v-if="state.accountInfo.type === '3'" class="empty-text">微信账户</view>
  34. <view v-if="state.accountInfo.type === '4'" class="empty-text">支付宝账户</view>
  35. <view v-if="state.accountInfo.type === '5'" class="empty-text">微信零钱</view>
  36. <text class="cicon-forward" />
  37. </view>
  38. </view>
  39. <!-- 提现金额 -->
  40. <view class="card-title">提现金额</view>
  41. <view class="input-box ss-flex ss-col-center border-bottom">
  42. <view class="unit">¥</view>
  43. <uni-easyinput
  44. :inputBorder="false"
  45. class="ss-flex-1 ss-p-l-10"
  46. v-model="state.accountInfo.price"
  47. type="number"
  48. placeholder="请输入提现金额"
  49. />
  50. </view>
  51. <!-- 提现账号 -->
  52. <view class="card-title" v-show="['2', '6'].includes(state.accountInfo.type)">
  53. 提现账号
  54. </view>
  55. <view
  56. class="input-box ss-flex ss-col-center border-bottom"
  57. v-show="['2', '6'].includes(state.accountInfo.type)"
  58. >
  59. <view class="unit" />
  60. <uni-easyinput
  61. :inputBorder="false"
  62. class="ss-flex-1 ss-p-l-10"
  63. v-model="state.accountInfo.userAccount"
  64. placeholder="请输入提现账号"
  65. />
  66. </view>
  67. <!-- 收款码 -->
  68. <view class="card-title" v-show="['3', '4'].includes(state.accountInfo.type)">收款码</view>
  69. <view
  70. class="input-box ss-flex ss-col-center"
  71. v-show="['3', '4'].includes(state.accountInfo.type)"
  72. >
  73. <view class="unit" />
  74. <view class="upload-img">
  75. <s-uploader
  76. v-model:url="state.accountInfo.qrCodeUrl"
  77. fileMediatype="image"
  78. limit="1"
  79. mode="grid"
  80. :imageStyles="{ width: '168rpx', height: '168rpx' }"
  81. @success="(payload) => (state.accountInfo.qrCodeUrl = payload.tempFilePaths[0])"
  82. />
  83. </view>
  84. </view>
  85. <!-- 持卡人姓名 -->
  86. <view class="card-title" v-show="['2', '5', '6'].includes(state.accountInfo.type)">
  87. 收款真名
  88. </view>
  89. <view
  90. class="input-box ss-flex ss-col-center border-bottom"
  91. v-show="['2', '5', '6'].includes(state.accountInfo.type)"
  92. >
  93. <view class="unit" />
  94. <uni-easyinput
  95. :inputBorder="false"
  96. class="ss-flex-1 ss-p-l-10"
  97. v-model="state.accountInfo.userName"
  98. placeholder="请输入收款真名"
  99. />
  100. </view>
  101. <!-- 提现银行 -->
  102. <view class="card-title" v-show="state.accountInfo.type === '2'">提现银行</view>
  103. <view
  104. class="input-box ss-flex ss-col-center border-bottom"
  105. v-show="state.accountInfo.type === '2'"
  106. >
  107. <view class="unit" />
  108. <!--银行改为下拉选择-->
  109. <picker
  110. @change="bankChange"
  111. :value="state.bankListSelectedIndex"
  112. :range="state.bankList"
  113. range-key="label"
  114. style="width: 100%"
  115. >
  116. <uni-easyinput
  117. :inputBorder="false"
  118. :value="bankNameLabel"
  119. placeholder="请选择银行"
  120. suffixIcon="right"
  121. disabled
  122. :styles="{ disableColor: '#fff', borderColor: '#fff', color: '#333!important' }"
  123. />
  124. </picker>
  125. </view>
  126. <!-- 开户地址 -->
  127. <view class="card-title" v-show="state.accountInfo.type === '2'">开户地址</view>
  128. <view
  129. class="input-box ss-flex ss-col-center border-bottom"
  130. v-show="state.accountInfo.type === '2'"
  131. >
  132. <view class="unit" />
  133. <uni-easyinput
  134. :inputBorder="false"
  135. class="ss-flex-1 ss-p-l-10"
  136. v-model="state.accountInfo.bankAddress"
  137. placeholder="请输入开户地址"
  138. />
  139. </view>
  140. <button class="ss-reset-button save-btn ui-BG-Main-Gradient ui-Shadow-Main" @tap="onConfirm">
  141. 确认提现
  142. </button>
  143. </view>
  144. <!-- 提现说明 -->
  145. <view class="draw-notice">
  146. <view class="title ss-m-b-30">提现说明</view>
  147. <view class="draw-list"> 最低提现金额 {{ fen2yuan(state.minPrice) }} 元 </view>
  148. <view class="draw-list">
  149. 冻结佣金:<text>¥{{ fen2yuan(state.brokerageInfo.frozenPrice) }}</text>
  150. (每笔佣金的冻结期为 {{ state.frozenDays }} 天,到期后可提现)
  151. </view>
  152. </view>
  153. <!-- 选择提现账户 -->
  154. <account-type-select
  155. :show="state.accountSelect"
  156. @close="onAccountSelect(false)"
  157. round="10"
  158. v-model="state.accountInfo"
  159. :methods="state.withdrawTypes"
  160. />
  161. </s-layout>
  162. </template>
  163. <script setup>
  164. import { onBeforeMount, reactive, computed } from 'vue';
  165. import sheep from '@/sheep';
  166. import accountTypeSelect from './components/account-type-select.vue';
  167. import { fen2yuan } from '@/sheep/hooks/useGoods';
  168. import TradeConfigApi from '@/sheep/api/trade/config';
  169. import BrokerageApi from '@/sheep/api/trade/brokerage';
  170. import DictApi from '@/sheep/api/system/dict';
  171. import SLayout from '@/sheep/components/s-layout/s-layout.vue';
  172. import { getWeixinPayChannelCode, goBindWeixin } from '@/sheep/platform/pay';
  173. const headerBg = sheep.$url.css('/static/img/shop/user/withdraw_bg.png');
  174. const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
  175. const state = reactive({
  176. accountInfo: {
  177. // 提现表单
  178. type: undefined,
  179. userAccount: undefined,
  180. userName: undefined,
  181. qrCodeUrl: undefined,
  182. bankName: undefined,
  183. bankAddress: undefined,
  184. },
  185. accountSelect: false,
  186. brokerageInfo: {}, // 分销信息
  187. frozenDays: 0, // 冻结天数
  188. minPrice: 0, // 最低提现金额
  189. withdrawTypes: [], // 提现方式
  190. bankList: [], // 银行字典数据
  191. bankListSelectedIndex: '', // 选中银行 bankList 的 index
  192. });
  193. const bankNameLabel = computed(() => {
  194. if (!state.accountInfo.bankName || !state.bankList || state.bankList.length === 0) {
  195. return '';
  196. }
  197. const item = state.bankList.find((it) => it.value === state.accountInfo.bankName);
  198. return item ? item.label : '';
  199. });
  200. // 打开提现方式的弹窗
  201. const onAccountSelect = (e) => {
  202. state.accountSelect = e;
  203. };
  204. // 提交提现
  205. const onConfirm = async () => {
  206. // 参数校验
  207. if (
  208. !state.accountInfo.price ||
  209. state.accountInfo.price > state.brokerageInfo.price ||
  210. state.accountInfo.price <= 0
  211. ) {
  212. sheep.$helper.toast('请输入正确的提现金额');
  213. return;
  214. }
  215. if (!state.accountInfo.type) {
  216. sheep.$helper.toast('请选择提现方式');
  217. return;
  218. }
  219. let openid;
  220. if (state.accountInfo.type === '5') {
  221. openid = await sheep.$platform.useProvider('wechat').getOpenid();
  222. // 如果获取不到 openid,微信无法发起支付,此时需要引导
  223. if (!openid) {
  224. goBindWeixin();
  225. return;
  226. }
  227. }
  228. // 提交请求
  229. const data = {
  230. ...state.accountInfo,
  231. price: state.accountInfo.price * 100,
  232. };
  233. if (state.accountInfo.type === '5') {
  234. data.userAccount = openid;
  235. data.transferChannelCode = getWeixinPayChannelCode();
  236. } else if (state.accountInfo.type === '6' || state.accountInfo.type === '2') {
  237. delete data.transferChannelCode;
  238. } else {
  239. delete data.userAccount;
  240. delete data.transferChannelCode;
  241. }
  242. let { code } = await BrokerageApi.createBrokerageWithdraw(data);
  243. if (code !== 0) {
  244. return;
  245. }
  246. // 提示
  247. uni.showModal({
  248. title: '操作成功',
  249. content: '您的提现申请已成功提交',
  250. cancelText: '继续提现',
  251. confirmText: '查看记录',
  252. success: (res) => {
  253. if (res.confirm) {
  254. sheep.$router.go('/pages/commission/wallet', { type: 2 });
  255. return;
  256. }
  257. getBrokerageUser();
  258. state.accountInfo = {};
  259. },
  260. });
  261. };
  262. // 获得分销配置
  263. async function getWithdrawRules() {
  264. let { code, data } = await TradeConfigApi.getTradeConfig();
  265. if (code !== 0) {
  266. return;
  267. }
  268. if (data) {
  269. state.minPrice = data.brokerageWithdrawMinPrice || 0;
  270. state.frozenDays = data.brokerageFrozenDays || 0;
  271. state.withdrawTypes = data.brokerageWithdrawTypes;
  272. }
  273. }
  274. // 获得分销信息
  275. async function getBrokerageUser() {
  276. const { data, code } = await BrokerageApi.getBrokerageUser();
  277. if (code === 0) {
  278. state.brokerageInfo = data;
  279. }
  280. }
  281. // 获取提现银行配置字典
  282. async function getDictDataListByType() {
  283. let { code, data } = await DictApi.getDictDataListByType('brokerage_bank_name');
  284. if (code !== 0) {
  285. return;
  286. }
  287. if (data && data.length > 0) {
  288. state.bankList = data;
  289. }
  290. }
  291. // 银行选择
  292. function bankChange(e) {
  293. const value = e.detail.value;
  294. state.bankListSelectedIndex = value;
  295. const item = state.bankList[value];
  296. state.accountInfo.bankName = item ? item.value : undefined;
  297. }
  298. onBeforeMount(() => {
  299. getWithdrawRules();
  300. getBrokerageUser();
  301. getDictDataListByType(); //获取银行字典数据
  302. });
  303. </script>
  304. <style lang="scss" scoped>
  305. :deep() {
  306. .uni-input-input {
  307. font-family: OPPOSANS !important;
  308. }
  309. }
  310. .wallet-num-box {
  311. padding: 0 40rpx 80rpx;
  312. background: var(--ui-BG-Main) v-bind(headerBg) center/750rpx 100% no-repeat;
  313. border-radius: 0 0 5% 5%;
  314. .num-title {
  315. font-size: 26rpx;
  316. font-weight: 500;
  317. color: $white;
  318. margin-bottom: 20rpx;
  319. }
  320. .wallet-num {
  321. font-size: 60rpx;
  322. font-weight: 500;
  323. color: $white;
  324. font-family: OPPOSANS;
  325. }
  326. .log-btn {
  327. width: 170rpx;
  328. height: 60rpx;
  329. line-height: 60rpx;
  330. border: 1rpx solid $white;
  331. border-radius: 30rpx;
  332. padding: 0;
  333. font-size: 26rpx;
  334. font-weight: 500;
  335. color: $white;
  336. }
  337. }
  338. // 提现输入卡片
  339. .draw-card {
  340. background-color: $white;
  341. border-radius: 20rpx;
  342. width: 690rpx;
  343. min-height: 560rpx;
  344. margin: -60rpx 30rpx 30rpx 30rpx;
  345. padding: 30rpx;
  346. position: relative;
  347. z-index: 3;
  348. box-sizing: border-box;
  349. .card-title {
  350. font-size: 30rpx;
  351. font-weight: 500;
  352. margin-bottom: 30rpx;
  353. }
  354. .bank-box {
  355. .name {
  356. font-size: 28rpx;
  357. font-weight: 500;
  358. }
  359. .bank-list {
  360. .empty-text {
  361. font-size: 28rpx;
  362. font-weight: 400;
  363. color: $dark-9;
  364. }
  365. .cicon-forward {
  366. color: $dark-9;
  367. }
  368. }
  369. .input-box {
  370. width: 624rpx;
  371. height: 100rpx;
  372. margin-bottom: 40rpx;
  373. .unit {
  374. font-size: 48rpx;
  375. color: #333;
  376. font-weight: 500;
  377. }
  378. .uni-easyinput__placeholder-class {
  379. font-size: 30rpx;
  380. height: 36rpx;
  381. }
  382. :deep(.uni-easyinput__content-input) {
  383. font-size: 48rpx;
  384. }
  385. }
  386. .save-btn {
  387. width: 616rpx;
  388. height: 86rpx;
  389. line-height: 86rpx;
  390. border-radius: 40rpx;
  391. margin-top: 80rpx;
  392. }
  393. }
  394. .bind-box {
  395. .placeholder-text {
  396. font-size: 26rpx;
  397. color: $dark-9;
  398. }
  399. .add-btn {
  400. width: 100rpx;
  401. height: 50rpx;
  402. border-radius: 25rpx;
  403. line-height: 50rpx;
  404. font-size: 22rpx;
  405. color: var(--ui-BG-Main);
  406. background-color: var(--ui-BG-Main-light);
  407. }
  408. }
  409. .input-box {
  410. width: 624rpx;
  411. height: 100rpx;
  412. margin-bottom: 40rpx;
  413. .unit {
  414. font-size: 48rpx;
  415. color: #333;
  416. font-weight: 500;
  417. }
  418. .uni-easyinput__placeholder-class {
  419. font-size: 30rpx;
  420. }
  421. :deep(.uni-easyinput__content-input) {
  422. font-size: 48rpx;
  423. }
  424. }
  425. .save-btn {
  426. width: 616rpx;
  427. height: 86rpx;
  428. line-height: 86rpx;
  429. border-radius: 40rpx;
  430. margin-top: 80rpx;
  431. }
  432. }
  433. // 提现说明
  434. .draw-notice {
  435. width: 684rpx;
  436. background: #ffffff;
  437. border: 2rpx solid #fffaee;
  438. border-radius: 20rpx;
  439. margin: 20rpx 32rpx 0 32rpx;
  440. padding: 30rpx;
  441. box-sizing: border-box;
  442. .title {
  443. font-weight: 500;
  444. color: #333333;
  445. font-size: 30rpx;
  446. }
  447. .draw-list {
  448. font-size: 24rpx;
  449. color: #999999;
  450. line-height: 46rpx;
  451. }
  452. }
  453. </style>