index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. const Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. hasInfo: false,
  9. name: '',
  10. accountId: ''
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. console.log(options)
  17. this.setData({
  18. way: options.way
  19. })
  20. this.getAuthInfo(options.way)
  21. },
  22. bindKeyInput(e) {
  23. this.setData({
  24. [e.currentTarget.dataset.prop]: e.detail.value
  25. })
  26. },
  27. getAuthInfo(type) {
  28. const _this = this
  29. let account = new Parse.Query("Account")
  30. account.equalTo("user", Parse.User.current().id)
  31. account.first().then(res => {
  32. console.log(res)
  33. let info = res.toJSON()
  34. console.log(type, info)
  35. if (type == 'alipay' && info.ali) {
  36. console.log(222)
  37. _this.setData({
  38. name: info.ali.name,
  39. accountId: info.ali.accountId,
  40. hasInfo: true
  41. })
  42. }
  43. if (type == 'wechat' && info.wechat) {
  44. _this.setData({
  45. name: info.wechat.name,
  46. accountId: info.wechat.accountId,
  47. hasInfo: true
  48. })
  49. }
  50. _this.setData({
  51. account: res.id
  52. })
  53. })
  54. },
  55. submit() {
  56. const _this = this
  57. if (!this.data.name || !this.data.accountId) {
  58. wx.showToast({
  59. icon: 'none',
  60. title: '请填写完整信息',
  61. duration: 2000
  62. })
  63. return
  64. }
  65. try {
  66. let Account = Parse.Object.extend("Account")
  67. let account = new Account()
  68. account.id = this.data.account
  69. this.data.way == 'alipay' ? account.set('ali', {
  70. name: _this.data.name,
  71. accountId: _this.data.accountId
  72. }) : account.set('wechat', {
  73. name: _this.data.name,
  74. accountId: _this.data.accountId
  75. })
  76. account.save().then(res => {
  77. wx.showToast({
  78. icon: 'none',
  79. title: '保存成功',
  80. duration: 2000
  81. })
  82. _this.setData({
  83. hasInfo: true
  84. })
  85. })
  86. } catch (error) {
  87. console.log(error)
  88. wx.showToast({
  89. icon: 'none',
  90. title: '保存失败',
  91. duration: 2000
  92. })
  93. }
  94. },
  95. change() {
  96. this.setData({
  97. hasInfo: false
  98. })
  99. },
  100. /**
  101. * 生命周期函数--监听页面初次渲染完成
  102. */
  103. onReady: function () {
  104. },
  105. /**
  106. * 生命周期函数--监听页面显示
  107. */
  108. onShow: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload: function () {
  119. },
  120. /**
  121. * 页面相关事件处理函数--监听用户下拉动作
  122. */
  123. onPullDownRefresh: function () {
  124. },
  125. /**
  126. * 页面上拉触底事件的处理函数
  127. */
  128. onReachBottom: function () {
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage: function () {
  134. }
  135. })