C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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