withdrawAccountEdit.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // pages/fund/withdrawAccountEdit.js
  2. import * as API_WithdrawAccount from '../../api/withdrawAccount'
  3. import * as API_Passport from '../../api/passport'
  4. import Toast from '../../miniprogram_npm/vant-weapp/toast/toast';
  5. const app=getApp()
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. bankTypes: [{
  12. name: '支付宝',
  13. value: 'alipayDirectPlugin',
  14. disabled: false
  15. }, {
  16. name: '微信',
  17. value: 'weixinPayPlugin',
  18. disabled: false
  19. }, {
  20. name: '其他',
  21. value: '',
  22. disabled: false
  23. }],
  24. show:false,
  25. bankTypeSelected:{},
  26. editForm:{
  27. id:'',
  28. bank_account: '',
  29. account_name: '',
  30. bank_name:'',
  31. payment_plugin_id:'',
  32. member_id:app.globalData.sellerShop.member_id,
  33. shop_id:app.globalData.sellerShop.shop_id
  34. }
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. const {id}=options
  41. if(id){
  42. this.getAccount(id)
  43. }
  44. },
  45. /**
  46. * 生命周期函数--监听页面初次渲染完成
  47. */
  48. onReady: function () {
  49. },
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面隐藏
  57. */
  58. onHide: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面卸载
  62. */
  63. onUnload: function () {
  64. },
  65. /**
  66. * 页面相关事件处理函数--监听用户下拉动作
  67. */
  68. onPullDownRefresh: function () {
  69. },
  70. /**
  71. * 页面上拉触底事件的处理函数
  72. */
  73. onReachBottom: function () {
  74. },
  75. /**
  76. * 用户点击右上角分享
  77. */
  78. onShareAppMessage: function () {
  79. },
  80. showPopup(){
  81. this.setData({
  82. show:true
  83. })
  84. },
  85. onCancel(){
  86. this.setData({
  87. show:false
  88. })
  89. },
  90. onConfirm(e){
  91. const {value} = e.detail
  92. let bankName=value.value===''?'':value.name
  93. if(value.value!==this.data.bankTypeSelected.value){ //账号类型发生变化,清空账户名和账号
  94. this.setData({
  95. ['editForm.account_name']:'',
  96. ['editForm.bank_account']:''
  97. })
  98. }
  99. this.setData({
  100. bankTypeSelected:value,
  101. show:false,
  102. ['editForm.bank_name']:value.value!==this.data.bankTypeSelected.value?bankName:this.data.editForm.bank_name,
  103. ['editForm.payment_plugin_id']:value.value
  104. })
  105. },
  106. onChange(event) {
  107. const that = this
  108. let dataKey = event.currentTarget.dataset.name
  109. // event.detail 为当前输入的值
  110. this.setData({
  111. [dataKey]: event.detail
  112. })
  113. },
  114. submit(e){
  115. console.log(this.data.editForm)
  116. let that=this
  117. //校验输入项
  118. if(Object.keys(that.data.bankTypeSelected).length===0){
  119. Toast.fail('请选择银行账号类型')
  120. return false
  121. }
  122. if(!that.data.editForm.bank_name||that.data.editForm.bank_name.trim()===''){
  123. Toast.fail('请输入银行名称')
  124. return false
  125. }
  126. if(!that.data.editForm.account_name|| that.data.editForm.account_name.trim()===''){
  127. Toast.fail('请输入账号实名')
  128. return false
  129. }
  130. if(!that.data.editForm.bank_account||that.data.editForm.bank_account.trim()===''){
  131. Toast.fail('请输入账号')
  132. return false
  133. }
  134. if(!that.data.editForm.id){
  135. API_WithdrawAccount.add(that.data.editForm).then(res=>{
  136. that.setData({
  137. editForm:{...res}
  138. })
  139. wx.showToast({
  140. title: '添加成功!',
  141. icon: 'success',
  142. duration: 2000
  143. })
  144. })
  145. }else{
  146. API_WithdrawAccount.update(that.data.editForm.id,that.data.editForm).then(res=>{
  147. that.setData({
  148. editForm:{...res}
  149. })
  150. wx.showToast({
  151. title: '修改成功!',
  152. icon: 'success',
  153. duration: 2000
  154. })
  155. })
  156. }
  157. },
  158. getAccount(id){
  159. let that=this
  160. API_WithdrawAccount.get(id,{}).then(res=>{
  161. let bankt = that.data.bankTypes.find(p=>p.value===res.payment_plugin_id)
  162. console.log(bankt)
  163. that.setData({
  164. editForm:{...res},
  165. bankTypeSelected:bankt
  166. })
  167. })
  168. },
  169. async getOpenId(e){
  170. const uuid =wx.getStorageSync('uuid')
  171. let code=await this.wxlogin()
  172. const mp_type = 'miniprogramo2oseller'
  173. let {
  174. encryptedData,
  175. iv
  176. } = await this.wxgetUserInfo({
  177. withCredentials: true,
  178. lang: 'zh_CN'
  179. })
  180. let final = await API_Passport.decryptWxUser({
  181. code,
  182. uuid,
  183. encrypted_data: encryptedData,
  184. iv,
  185. mini_program_type:mp_type
  186. })
  187. this.setData({
  188. ['editForm.bank_account']:final.openid
  189. })
  190. },
  191. // 同步获取登录code
  192. wxlogin(){
  193. return new Promise((resolve,reject)=>{
  194. wx.login({
  195. complete: (res) => {resolve(res.code)}
  196. })
  197. })
  198. },
  199. // 同步获取用户信息
  200. wxgetUserInfo(option){
  201. return new Promise((resolve,reject)=>{
  202. wx.getUserInfo({
  203. ...option,
  204. complete: (res) => {
  205. console.log(res)
  206. resolve(res)
  207. }
  208. })
  209. })
  210. }
  211. })