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

279 рядки
5.5 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,
  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 {
  159. Http.post({
  160. url: "/user/updateUserInfo",
  161. data,
  162. }).then(res => {
  163. if (res.code == 200) {
  164. wx.showToast({
  165. title: "信息提交成功",
  166. icon: 'success',
  167. duration: 1500,
  168. })
  169. setTimeout(() => {
  170. wx.navigateBack()
  171. }, 1500)
  172. }
  173. }).catch(err => {
  174. console.log(err);
  175. })
  176. }
  177. },
  178. /**
  179. * 生命周期函数--监听页面加载
  180. */
  181. onLoad(options) {
  182. if (app.globalData.token) {
  183. this.getUserInfo(app.globalData.token)
  184. }
  185. this.getType()
  186. wx.onThemeChange((result) => {
  187. this.setData({
  188. theme: result.theme
  189. })
  190. })
  191. },
  192. /**
  193. * 生命周期函数--监听页面初次渲染完成
  194. */
  195. onReady() {
  196. },
  197. /**
  198. * 生命周期函数--监听页面显示
  199. */
  200. onShow() {
  201. },
  202. /**
  203. * 生命周期函数--监听页面隐藏
  204. */
  205. onHide() {
  206. },
  207. /**
  208. * 生命周期函数--监听页面卸载
  209. */
  210. onUnload() {
  211. },
  212. /**
  213. * 页面相关事件处理函数--监听用户下拉动作
  214. */
  215. onPullDownRefresh() {
  216. },
  217. /**
  218. * 页面上拉触底事件的处理函数
  219. */
  220. onReachBottom() {
  221. },
  222. /**
  223. * 用户点击右上角分享
  224. */
  225. // onShareAppMessage() {
  226. // },
  227. onChooseAvatar(e) {
  228. const that = this
  229. const { avatarUrl } = e.detail
  230. wx.uploadFile({
  231. url: config.url + config.api.fileUpload,
  232. header: {
  233. 'token': app.globalData.token
  234. },
  235. filePath: avatarUrl,
  236. name: 'file',
  237. success: function (res) {
  238. that.setData({
  239. avatarUrl: JSON.parse(res.data).data.url
  240. })
  241. console.log(that.data.avatarUrl);
  242. }
  243. })
  244. },
  245. })