index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // pages/bdAccount/bdAccount.js
  2. const util = require('../../utils/util.js');
  3. const app = getApp();
  4. Page({
  5. data: {
  6. wxbd:"未绑定",
  7. bankbd:"未绑定",
  8. wxName:"",
  9. wxHeadImg:"",
  10. cardHolder:"",
  11. bankAccount:"",
  12. bankName:"",
  13. storeTel:"",
  14. storeCard:"",
  15. agentTel:"",
  16. agentCard:"",
  17. agentQualifications:"",
  18. userInfo:{
  19. cardName: '',
  20. bankCard: '',
  21. bankName: '',
  22. nickName:null,
  23. realname:null,
  24. avatarUrl:null,
  25. bankCode:null,
  26. },
  27. wechatVo:{
  28. },
  29. },
  30. setVal:function(e){
  31. this.setData({
  32. [e.target.dataset.key] : e.detail.value
  33. })
  34. },
  35. binding:function(e){
  36. util.request(util.api.updateBankInfo, this.data.userInfo, "POST", true, true,app.globalData.token).then((res)=>{
  37. if (res.code == 200) {
  38. this.setData({
  39. userInfo: res.result,
  40. })
  41. app.globalData.userInfo = res.result
  42. //存入缓存
  43. wx.setStorage({
  44. data: res.result,
  45. key: 'birthdayUserInfo',
  46. })
  47. util.toast('保存成功')
  48. }
  49. });
  50. },
  51. submit:function(){
  52. util.request(util.api.updateInfo, this.data.userInfo, "POST", true, true,app.globalData.token).then((res)=>{
  53. if (res.code == 200) {
  54. this.setData({
  55. userInfo: res.result,
  56. })
  57. app.globalData.userInfo = res.result
  58. //存入缓存
  59. wx.setStorage({
  60. data: res.result,
  61. key: 'birthdayUserInfo',
  62. })
  63. util.toast('保存成功')
  64. }
  65. });
  66. },
  67. getUserProfile: function (e) {
  68. var that = this
  69. if(util.isNullOrEmpty(that.data.userInfo.realname)) {
  70. util.toast('请输入真实姓名');
  71. return;
  72. }
  73. wx.getUserProfile({
  74. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  75. success :(res) => { //有箭头函数可以直接用this 没有要 let that = this
  76. // 存储本地信息
  77. console.log(res.userInfo)
  78. console.log(1111111111)
  79. this.data.wechatVo.realName = that.data.userInfo.realname
  80. this.data.wechatVo.avatarUrl = res.userInfo.avatarUrl
  81. this.data.wechatVo.nickName = res.userInfo.nickName
  82. // this.data
  83. wx.login({
  84. success: res => {
  85. var code = res.code
  86. this.data.wechatVo.code = code
  87. // util.request(util.api.addRole, that.data.userInfo, "POST", false, true,app.globalData.token).then((res)=>{
  88. util.request(util.api.miniAppLogin, this.data.wechatVo, "POST", false, true,app.globalData.token).then((res)=>{
  89. if (res.code == 200) {
  90. // app.globalData.openId = res.result.userInfo.openId
  91. util.toast('绑定成功')
  92. this.setData({
  93. userInfo: res.result,
  94. isLogin: 1,
  95. })
  96. app.globalData.userInfo = res.result
  97. //存入缓存
  98. wx.setStorage({
  99. data: res.result,
  100. key: 'birthdayUserInfo',
  101. })
  102. this.onLoad();
  103. }else{
  104. util.toast('绑定失败,请联系管理员')
  105. }
  106. })
  107. }
  108. })
  109. },
  110. fail(res){
  111. console.log(res)
  112. }
  113. })
  114. // if (e.detail.userInfo) {
  115. // //用户按了允许授权按钮
  116. // //插入登录的用户的相关信息到数据库
  117. // wx.login({
  118. // success: res => {
  119. // var code = res.code
  120. // util.request(util.api.miniAppLogin, {rawData: that.data.bindInfo,realName:that.data.userInfo.realname,
  121. // code: code,}, "POST", true, true,app.globalData.token).then((res)=>{
  122. // if (res.code == 200) {
  123. // // app.globalData.openId = res.result.userInfo.openId
  124. // console.log(res)
  125. // this.setData({
  126. // userInfo: res.result,
  127. // isLogin: 1,
  128. // })
  129. // app.globalData.userInfo = res.result
  130. // //存入缓存
  131. // wx.setStorage({
  132. // data: res.result,
  133. // key: 'birthdayUserInfo',
  134. // })
  135. // this.onLoad();
  136. // }
  137. // })
  138. // }
  139. // })
  140. // } else {
  141. // //用户按了拒绝按钮
  142. // wx.showModal({
  143. // title: '警告',
  144. // content: '您点击了拒绝授权,将无法进入小程序,请授权之后再进入!!!',
  145. // showCancel: false,
  146. // confirmText: '返回授权',
  147. // success: function (res) {
  148. // if (res.confirm) {
  149. // console.log('用户点击了“返回授权”')
  150. // }
  151. // }
  152. // })
  153. // }
  154. },
  155. /**
  156. * 生命周期函数--监听页面加载
  157. */
  158. onLoad: function (options) {
  159. if(app.globalData.userInfo && app.globalData.userInfo.bankCard!=null){
  160. this.data.bankbd="已绑定"
  161. }
  162. this.setData({
  163. userInfo: app.globalData.userInfo,
  164. bankbd:this.data.bankbd
  165. })
  166. },
  167. inputedit: function (e) {
  168. let _this = this;
  169. let dataset = e.currentTarget.dataset;
  170. let value = e.detail.value;
  171. let name = dataset.name;
  172. _this.data[name] = value;
  173. _this.setData({
  174. [name]: _this.data[name]
  175. });
  176. },
  177. })