index.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. const Parse = getApp().Parse
  2. // const company = getApp().globalData.company
  3. const dateF = require('../../../utils/date')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. consume: 0,
  10. activeColor: "",
  11. titleColor: "",
  12. currentDate: new Date().getTime(),
  13. minDate: (new Date().getTime() - 70 * 12 * 30 * 24 * 60 * 60 * 1000),
  14. account: null,
  15. mobile: null,
  16. nickname: null,
  17. actions: [{
  18. name: '男',
  19. },
  20. {
  21. name: '女',
  22. },
  23. ],
  24. images: []
  25. },
  26. onSelect(event) {
  27. console.log(event.detail);
  28. let {
  29. name
  30. } = event.detail
  31. let {
  32. user
  33. } = this.data
  34. user.sex = name
  35. this.setData({
  36. user,
  37. show2: false
  38. })
  39. },
  40. async getUser() {
  41. let id = Parse.User.current() ? Parse.User.current().id : ""
  42. if (!id) {
  43. wx.showToast({
  44. title: '您还未登录请先登录',
  45. icon: 'error'
  46. })
  47. setTimeout(() => {
  48. wx.navigateBack({
  49. delta: 1
  50. });
  51. }, 1000)
  52. return
  53. }
  54. let new_user = new Parse.Query('_User')
  55. new_user.include('invite')
  56. new_user.include('agentLevel')
  57. new_user.select('objectId', 'avatar', 'authentication', 'nickname', 'mobile', 'invite.nickname',
  58. 'agentLevel.name')
  59. let res = await new_user.get(id)
  60. let user = res.toJSON()
  61. user.joinTime = dateF.formatTime("YYYY-mm-dd", user.createdAt)
  62. if (user.authentication && user.authentication != {}) {
  63. user.auth = { isAuth: true, label: "已认证" }
  64. } else {
  65. user.auth = { isAuth: false, label: "未认证" }
  66. }
  67. console.log(user.avatar)
  68. this.setData({
  69. user: user,
  70. images: [user.avatar]
  71. })
  72. },
  73. // 会员头像,会员昵称,手机号,会员性别,实名认证,会员等级,会员ID, 邀请人,
  74. async getAccount() {
  75. let Account = new Parse.Query('Account')
  76. Account.equalTo('user', Parse.User.current().id)
  77. Account.select('bank', 'wechat')
  78. let account = await Account.first()
  79. let a = account.toJSON()
  80. if (a.bank && a.bank.length > 0) {
  81. a.isBank = { isBank: true, label: "已绑定" }
  82. } else {
  83. a.isBank = { isBank: false, label: "未绑定" }
  84. }
  85. if (a.wechat) {
  86. a.isWechat = { isWechat: true, label: "已绑定" }
  87. } else {
  88. a.isWechat = { isWechat: false, label: "未绑定" }
  89. }
  90. if (account && account.id) {
  91. this.setData({
  92. account: a
  93. })
  94. }
  95. },
  96. editMobile(e) {
  97. let mobile = e.detail.value
  98. let a = /^1[3456789]\d{9}$/;
  99. if (!mobile.match(a)) {
  100. wx.showToast({
  101. icon: "none",
  102. title: "请填写正确的手机记号格式",
  103. });
  104. return;
  105. } else {
  106. this.setData({
  107. mobile: mobile
  108. })
  109. }
  110. },
  111. changeImage(e) {
  112. if (e.detail && e.detail.length > 0) {
  113. this.setData({
  114. image: [e.detail[0].url]
  115. })
  116. } else {
  117. this.setData({
  118. image: []
  119. })
  120. }
  121. },
  122. editNickname(e) {
  123. let nickname = e.detail
  124. this.setData({
  125. nickname: nickname
  126. })
  127. },
  128. onInput(event) {
  129. this.setData({
  130. currentDate: event.detail,
  131. });
  132. },
  133. showPicker() {
  134. this.setData({
  135. show: true
  136. })
  137. },
  138. //取消日期选择
  139. onClose() {
  140. this.setData({
  141. show: false,
  142. show2: false
  143. })
  144. },
  145. showSelect() {
  146. this.setData({
  147. show2: true
  148. })
  149. },
  150. async submit() {
  151. let {
  152. sex
  153. } = this.data.user
  154. console.log(this.data.user)
  155. let id = Parse.User.current().id
  156. let new_user = new Parse.Query('_User')
  157. let res = await new_user.get(id)
  158. if (sex) {
  159. res.set("sex", sex)
  160. }
  161. if (this.data.mobile) {
  162. res.set("mobile", this.data.mobile)
  163. }
  164. if (this.data.nickname) {
  165. res.set("nickname", this.data.nickname)
  166. }
  167. let updateuser = await res.save()
  168. if (updateuser) {
  169. console.log(updateuser)
  170. wx.showToast({
  171. title: '修改成功',
  172. icon: 'success',
  173. image: '',
  174. duration: 1000,
  175. mask: false,
  176. success: (result) => {
  177. setTimeout(() => {
  178. wx.navigateBack({
  179. delta: 1
  180. });
  181. }, 1000);
  182. },
  183. fail: () => {},
  184. complete: () => {}
  185. });
  186. }
  187. },
  188. toAuth() {
  189. wx.navigateTo({
  190. url: '/common-page/pages/info/cauth/cauth'
  191. })
  192. },
  193. bindWechat(e) {
  194. wx.navigateTo({
  195. url: `/common-page/pages/info/bindWechat/index?way='wechat'`,
  196. })
  197. },
  198. bindBank() {
  199. wx.navigateTo({
  200. url: `/common-page/pages/info/bindBank/index`,
  201. })
  202. },
  203. /**
  204. * 生命周期函数--监听页面加载
  205. */
  206. onLoad: function(options) {
  207. this.getUser()
  208. this.getAccount()
  209. console.log(getApp().globalData.activeColor, 'getApp().globalData.activeColor')
  210. this.setData({
  211. activeColor: getApp().globalData.activeColor,
  212. titleColor: getApp().globalData.titleColor
  213. })
  214. console.log(this.data.activeColor);
  215. },
  216. /**
  217. * 生命周期函数--监听页面初次渲染完成
  218. */
  219. onReady: function() {
  220. },
  221. /**
  222. * 生命周期函数--监听页面显示
  223. */
  224. onShow: function() {
  225. this.getUser()
  226. this.getAccount()
  227. },
  228. /**
  229. * 生命周期函数--监听页面隐藏
  230. */
  231. onHide: function() {
  232. },
  233. /**
  234. * 生命周期函数--监听页面卸载
  235. */
  236. onUnload: function() {
  237. },
  238. /**
  239. * 页面相关事件处理函数--监听用户下拉动作
  240. */
  241. onPullDownRefresh: function() {
  242. },
  243. /**
  244. * 页面上拉触底事件的处理函数
  245. */
  246. onReachBottom: function() {
  247. },
  248. /**
  249. * 用户点击右上角分享
  250. */
  251. onShareAppMessage: function() {
  252. }
  253. })