C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

238 satır
4.6 KiB

  1. let app = getApp();
  2. const Http = require("../../utils/HttpBasics");
  3. const util = require("../../utils/util.js");
  4. const bgColor = require("../../utils/bgColor.js")
  5. const config = require("../../config/config");
  6. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  7. const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. navigationBarHeight,
  14. avatarUrl: defaultAvatarUrl,
  15. nickName: '',
  16. username: '',
  17. theme: wx.getSystemInfoSync().theme,
  18. typeLsit: {},
  19. date: '1988-03-12',
  20. dateEnd: '',
  21. dateFlag: 1,
  22. gender: '',
  23. sexArry: ['男', '女'],
  24. sexFlag: 1,
  25. height: '',
  26. weight: ''
  27. },
  28. /**
  29. * 获取全局样式
  30. */
  31. getType() {
  32. Http.get({
  33. url: config.api.setType,
  34. data: {
  35. mouldType: app.globalData.mouldType
  36. }
  37. }).then(res => {
  38. const {
  39. code,
  40. data
  41. } = res
  42. if (code == 200) {
  43. app.globalData.typeLsit = data
  44. this.setData({
  45. typeLsit: data,
  46. })
  47. }
  48. })
  49. },
  50. getUserInfo(token) {
  51. let that = this;
  52. Http.get({
  53. url: config.api.getScore,
  54. data: {
  55. token: token
  56. }
  57. }).then(res => {
  58. console.log(res, 'res');
  59. this.setData({
  60. avatarUrl: res.data.avatarUrl,
  61. nickName: res.data.nickName,
  62. username: res.data.name,
  63. gender: res.data.sex,
  64. sexFlag: 2,
  65. date: util.fmtDate(parseInt(res.data.birthdate)),
  66. dateFlag: 2,
  67. height: res.data.height,
  68. weight: res.data.weight,
  69. })
  70. }).catch(err => {
  71. console.log(err, 'err');
  72. })
  73. },
  74. bindDateChange(e) {
  75. this.setData({
  76. date: e.detail.value,
  77. dateFlag: 2
  78. })
  79. },
  80. bindGenderChange(e) {
  81. this.setData({
  82. gender: e.detail.value,
  83. sexFlag: 2
  84. })
  85. },
  86. address() {
  87. let that = this;
  88. wx.chooseLocation({
  89. success: function (res) {
  90. that.setData({
  91. address: res.name + '(' + res.address + ')',
  92. addressStr: JSON.stringify(res)
  93. })
  94. },
  95. fail: function (error) {
  96. console.log(error)
  97. },
  98. complete: function (data) {
  99. }
  100. })
  101. },
  102. goSetChildren() {
  103. wx.navigateTo({
  104. url: '/pages/edit/edit?type=1"',
  105. })
  106. },
  107. goSetAdress() {
  108. wx.navigateTo({
  109. url: '/pages/siteUser/siteUser"',
  110. })
  111. },
  112. formSubmit(e) {
  113. const that = this
  114. let birthdate = null
  115. if (that.data.dateFlag == 2 && that.data.date) {
  116. birthdate = new Date(that.data.date).getTime();
  117. }
  118. const data = {
  119. avatarUrl: that.data.avatarUrl,
  120. nickName: e.detail.value.nickname,
  121. name: e.detail.value.username,
  122. sex: that.data.gender,
  123. birthdate: birthdate,
  124. height: e.detail.value.height ? e.detail.value.height : that.data.height,
  125. weight: e.detail.value.weight ? e.detail.value.weight : that.data.weight,
  126. address: that.data.addressStr || null,
  127. }
  128. console.log(data, 'data');
  129. if (data.nickName) {
  130. Http.post({
  131. url: "/user/updateUserInfo",
  132. data,
  133. }).then(res => {
  134. if (res.code == 200) {
  135. wx.showToast({
  136. title: "信息提交成功,将在3分钟内生效",
  137. icon: 'none',
  138. duration: 2000,
  139. mask: false
  140. })
  141. setTimeout(() => {
  142. wx.navigateBack()
  143. }, 2000)
  144. }
  145. }).catch(err => {
  146. console.log(err);
  147. })
  148. } else {
  149. wx.showToast({
  150. title: '请输入昵称',
  151. icon: 'error',
  152. duration: 2000
  153. })
  154. }
  155. },
  156. /**
  157. * 生命周期函数--监听页面加载
  158. */
  159. onLoad(options) {
  160. if (app.globalData.token) {
  161. this.getUserInfo(app.globalData.token)
  162. }
  163. this.getType()
  164. wx.onThemeChange((result) => {
  165. this.setData({
  166. theme: result.theme
  167. })
  168. })
  169. },
  170. /**
  171. * 生命周期函数--监听页面初次渲染完成
  172. */
  173. onReady() {
  174. },
  175. /**
  176. * 生命周期函数--监听页面显示
  177. */
  178. onShow() {
  179. },
  180. /**
  181. * 生命周期函数--监听页面隐藏
  182. */
  183. onHide() {
  184. },
  185. /**
  186. * 生命周期函数--监听页面卸载
  187. */
  188. onUnload() {
  189. },
  190. /**
  191. * 页面相关事件处理函数--监听用户下拉动作
  192. */
  193. onPullDownRefresh() {
  194. },
  195. /**
  196. * 页面上拉触底事件的处理函数
  197. */
  198. onReachBottom() {
  199. },
  200. /**
  201. * 用户点击右上角分享
  202. */
  203. onShareAppMessage() {
  204. },
  205. onChooseAvatar(e) {
  206. const { avatarUrl } = e.detail
  207. this.setData({
  208. avatarUrl,
  209. })
  210. },
  211. })