C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

262 рядки
5.2 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. date: '1988-03-12',
  18. dateEnd: '',
  19. dateFlag: 1,
  20. gender: '',
  21. sexArry: ['男', '女'],
  22. sexFlag: 1,
  23. height: '',
  24. weight: '',
  25. theme: wx.getSystemInfoSync().theme,
  26. typeLsit: {}
  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. let adress = null
  60. if (res.data.address) {
  61. adress = JSON.parse(res.data.address)
  62. }
  63. this.setData({
  64. avatarUrl: res.data.avatarUrl,
  65. nickName: res.data.nickName,
  66. username: res.data.name,
  67. gender: res.data.sex,
  68. sexFlag: 2,
  69. date: util.fmtDate(parseInt(res.data.birthdate)),
  70. dateFlag: res.data.birthdate ? 2 : 1,
  71. height: res.data.height,
  72. weight: res.data.weight,
  73. address: adress ? adress.name + '(' + adress.address + ')' : ''
  74. })
  75. }).catch(err => {
  76. console.log(err, 'err');
  77. })
  78. },
  79. bindDateChange(e) {
  80. this.setData({
  81. date: e.detail.value,
  82. dateFlag: 2
  83. })
  84. },
  85. bindGenderChange(e) {
  86. this.setData({
  87. gender: e.detail.value,
  88. sexFlag: 2
  89. })
  90. },
  91. setAddress() {
  92. let that = this;
  93. wx.chooseLocation({
  94. success: function (res) {
  95. that.setData({
  96. address: res.name + '(' + res.address + ')',
  97. addressStr: JSON.stringify(res)
  98. })
  99. },
  100. fail: function (error) {
  101. console.log(error)
  102. },
  103. complete: function (data) {
  104. }
  105. })
  106. },
  107. goSetChildren() {
  108. wx.navigateTo({
  109. url: '/pages/edit/edit?type=1',
  110. })
  111. },
  112. goSetAdress() {
  113. wx.navigateTo({
  114. url: '/pages/siteUser/siteUser',
  115. })
  116. },
  117. formSubmit(e) {
  118. const that = this
  119. let birthdate = null
  120. if (that.data.dateFlag == 2 && that.data.date) {
  121. birthdate = new Date(that.data.date).getTime();
  122. }
  123. const data = {
  124. avatarUrl: that.data.avatarUrl,
  125. nickName: e.detail.value.nickname,
  126. name: e.detail.value.username,
  127. sex: that.data.gender,
  128. birthdate: birthdate,
  129. height: e.detail.value.height ? e.detail.value.height : that.data.height,
  130. weight: e.detail.value.weight ? e.detail.value.weight : that.data.weight,
  131. address: that.data.addressStr || null,
  132. }
  133. console.log(data, 'data');
  134. if (!data.nickName) {
  135. wx.showToast({
  136. title: '请输入昵称',
  137. icon: 'error',
  138. duration: 2000
  139. })
  140. } else if (!data.name) {
  141. wx.showToast({
  142. title: '请输入真实姓名',
  143. icon: 'error',
  144. duration: 2000
  145. })
  146. } else {
  147. Http.post({
  148. url: "/user/updateUserInfo",
  149. data,
  150. }).then(res => {
  151. if (res.code == 200) {
  152. wx.showToast({
  153. title: "信息提交成功,将在3分钟内生效",
  154. icon: 'none',
  155. duration: 2000,
  156. mask: false
  157. })
  158. setTimeout(() => {
  159. wx.navigateBack()
  160. }, 2000)
  161. }
  162. }).catch(err => {
  163. console.log(err);
  164. })
  165. }
  166. },
  167. /**
  168. * 生命周期函数--监听页面加载
  169. */
  170. onLoad(options) {
  171. if (app.globalData.token) {
  172. this.getUserInfo(app.globalData.token)
  173. }
  174. this.getType()
  175. wx.onThemeChange((result) => {
  176. this.setData({
  177. theme: result.theme
  178. })
  179. })
  180. },
  181. /**
  182. * 生命周期函数--监听页面初次渲染完成
  183. */
  184. onReady() {
  185. },
  186. /**
  187. * 生命周期函数--监听页面显示
  188. */
  189. onShow() {
  190. },
  191. /**
  192. * 生命周期函数--监听页面隐藏
  193. */
  194. onHide() {
  195. },
  196. /**
  197. * 生命周期函数--监听页面卸载
  198. */
  199. onUnload() {
  200. },
  201. /**
  202. * 页面相关事件处理函数--监听用户下拉动作
  203. */
  204. onPullDownRefresh() {
  205. },
  206. /**
  207. * 页面上拉触底事件的处理函数
  208. */
  209. onReachBottom() {
  210. },
  211. /**
  212. * 用户点击右上角分享
  213. */
  214. onShareAppMessage() {
  215. },
  216. onChooseAvatar(e) {
  217. const that = this
  218. const { avatarUrl } = e.detail
  219. wx.uploadFile({
  220. url: config.url + config.api.fileUpload,
  221. header: {
  222. 'token': app.globalData.token
  223. },
  224. filePath: avatarUrl,
  225. name: 'file',
  226. success: function (res) {
  227. that.setData({
  228. avatarUrl: JSON.parse(res.data).data.url
  229. })
  230. }
  231. })
  232. },
  233. })