C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

177 行
3.9 KiB

  1. const util = require("../../utils/util.js");
  2. const Http = require("../../utils/HttpBasics");
  3. const config = require("../../config/config");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. date: '1988-03-12',
  10. flag: 1,
  11. flagsex: 0,
  12. items: [
  13. { name: 1, value: '男', checked: false },
  14. { name: 2, value: '女', checked: false },
  15. ],
  16. username: ""
  17. },
  18. /**
  19. * 获得生日
  20. */
  21. bindDateChange: function (e) {
  22. console.log('picker发送选择改变,携带值为', e.detail.value);
  23. console.log(typeof (e.detail.value))
  24. this.setData({
  25. date: e.detail.value,
  26. flag: 2
  27. })
  28. },
  29. address: function () {
  30. let that = this;
  31. wx.chooseLocation({
  32. success: function (res) {
  33. console.log(res);
  34. that.setData({
  35. name: res.name,
  36. address: JSON.stringify(res),
  37. })
  38. },
  39. fail: function (error) {
  40. console.log(error)
  41. },
  42. complete: function (data) {
  43. console.log(data);
  44. }
  45. })
  46. },
  47. formSubmit: function (e) {
  48. console.log(e);
  49. let that = this;
  50. /**
  51. * sex
  52. * 0 保密
  53. * 1 男
  54. * 2 女
  55. */
  56. if (that.data.flagsex == 0) {
  57. var sex = 0;
  58. } else {
  59. var sex = that.data.sex;
  60. }
  61. if (that.data.address) {
  62. var address = that.data.address;
  63. }
  64. else {
  65. var address = null;
  66. }
  67. if (e.detail.value.username) {
  68. var username = e.detail.value.username;
  69. }
  70. else if (that.data.username) {
  71. var username = that.data.username;
  72. }
  73. else {
  74. var username = null;
  75. }
  76. if (that.data.flag == 2 && that.data.date) {
  77. var birthdate = new Date(that.data.date).getTime();
  78. } else {
  79. var birthdate = null;
  80. }
  81. if (username == null || address == null || sex == 0 || birthdate == null) {
  82. wx.showModal({
  83. title: '提示',
  84. content: '请输入完整的用户信息',
  85. showCancel: false
  86. })
  87. } else {
  88. console.log(username)
  89. console.log(address)
  90. console.log(sex)
  91. console.log(birthdate)
  92. Http.post({
  93. url: config.api.updateInfo,
  94. data: {
  95. sex: sex,
  96. address: address,
  97. name: username,
  98. birthdate: birthdate,
  99. }
  100. })
  101. .then(res => {
  102. console.log(res);
  103. wx.showModal({
  104. title: '提示',
  105. content: '修改成功',
  106. showCancel: false,
  107. success: function (res) {
  108. wx.switchTab({
  109. url: '/pages/user/index',
  110. })
  111. }
  112. })
  113. })
  114. }
  115. },
  116. radioChange: function (e) {
  117. console.log(e.detail.value)
  118. this.setData({
  119. sex: e.detail.value,
  120. flagsex: 1
  121. })
  122. },
  123. /**
  124. * 生命周期函数--监听页面加载
  125. */
  126. onLoad: function (options) {
  127. let that = this;
  128. Http.get({
  129. url: config.api.getScore,
  130. data: {}
  131. }).then(res => {
  132. console.log(res);
  133. if (res.data.address && JSON.parse(res.data.address).name) {
  134. that.setData({
  135. address: res.data.address,
  136. name: JSON.parse(res.data.address).name,
  137. })
  138. }
  139. if (!JSON.parse(res.data.address).name) {
  140. that.setData({
  141. name: null,
  142. })
  143. }
  144. if (res.data.name) {
  145. that.setData({
  146. username: res.data.name
  147. })
  148. }
  149. if (res.data.sex) {
  150. if (res.data.sex == 1) {
  151. var checked = 'items[' + 0 + '].checked'
  152. that.setData({
  153. [checked]: true,
  154. flagsex: 1
  155. })
  156. } else if (res.data.sex == 2) {
  157. var checked = 'items[' + 1 + '].checked'
  158. that.setData({
  159. [checked]: true,
  160. flagsex: 1
  161. })
  162. }
  163. that.setData({
  164. sex: res.data.sex
  165. })
  166. }
  167. if (res.data.birthdate) {
  168. that.setData({
  169. date: util.fmtDate(parseInt(res.data.birthdate)),
  170. flag: 2
  171. })
  172. }
  173. })
  174. }
  175. })