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.

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