addWithdrawApply.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // pages/fund/addWithdrawApply.js
  2. import * as API_WithdrawAccount from '../../api/withdrawAccount'
  3. import * as API_RebateShop from '../../api/rebateShop'
  4. import Toast from '../../miniprogram_npm/vant-weapp/toast/toast'
  5. import * as API_Member from '../../api/member'
  6. const app=getApp()
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. accounts:[],
  13. selectedAccount:null,
  14. rebateShop:{},
  15. submitForm:{
  16. apply_money: null,
  17. apply_remark:''
  18. },
  19. member:{}
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. this.getRebateAccounts()
  26. this.getRebateShop()
  27. this.getMemberDetail(app.globalData.authorInfo.uid)
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady: function () {
  33. },
  34. /**
  35. * 生命周期函数--监听页面显示
  36. */
  37. onShow: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面隐藏
  41. */
  42. onHide: function () {
  43. },
  44. /**
  45. * 生命周期函数--监听页面卸载
  46. */
  47. onUnload: function () {
  48. },
  49. /**
  50. * 页面相关事件处理函数--监听用户下拉动作
  51. */
  52. onPullDownRefresh: function () {
  53. },
  54. /**
  55. * 页面上拉触底事件的处理函数
  56. */
  57. onReachBottom: function () {
  58. },
  59. /**
  60. * 用户点击右上角分享
  61. */
  62. onShareAppMessage: function () {
  63. },
  64. getRebateAccounts(){
  65. let that=this
  66. API_WithdrawAccount.getListByShopId(app.globalData.sellerShop.shop_id).then(res=>{
  67. that.setData({
  68. accounts:[...res]
  69. })
  70. })
  71. },
  72. onClick(e){
  73. const { name } = e.currentTarget.dataset;
  74. this.setData({
  75. selectedAccount: name,
  76. })
  77. },
  78. getRebateShop(){
  79. let that=this
  80. API_RebateShop.getRebateShop(app.globalData.sellerShop.shop_id).then(res=>{
  81. that.setData({
  82. rebateShop:{...res}
  83. })
  84. })
  85. },
  86. submit(){
  87. let that=this
  88. if(!that.data.submitForm.apply_money||that.data.submitForm.apply_money===''){
  89. Toast.fail('请输入提现金额')
  90. return false
  91. }
  92. if(that.data.selectedAccount===null){
  93. Toast.fail('请选择提现账户')
  94. return false
  95. }
  96. const account=that.data.accounts.find(p=>p.id===that.data.selectedAccount)
  97. let param = {
  98. ...that.data.submitForm,
  99. ...account,
  100. apply_member_id:account.member_id,
  101. apply_name:that.data.member.nickname,
  102. rebate_account_id:account.id
  103. }
  104. delete param.id
  105. console.log(param)
  106. API_RebateShop.applyWithdraw(param).then(res=>{
  107. Toast.success({
  108. type: 'success',
  109. message: '提交成功',
  110. duration:2000,
  111. onClose: () => {
  112. wx.navigateBack({
  113. delta: 1,
  114. })
  115. },
  116. })
  117. }).catch(err=>{
  118. Toast.fail(err.message)
  119. })
  120. },
  121. onChange(e){
  122. console.log(e.detail)
  123. this.setData({
  124. ['submitForm.apply_money']:Number(e.detail)
  125. })
  126. },
  127. remarkChange(e){
  128. this.setData({
  129. ['submitForm.apply_remark']:e.detail
  130. })
  131. },
  132. /** 获取当前登录用户信息 */
  133. getMemberDetail(id){
  134. let that=this
  135. API_Member.getCareMember(id,{}).then(res=>{
  136. console.log(res)
  137. that.setData({
  138. member:{...res}
  139. })
  140. })
  141. }
  142. })