C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
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. array: ['上班族', '学生', '企业高管', '个体户', '自由职业', '其他'],
  18. array1: ['附近住户', '距离2km', '距离3km', '更远'],
  19. index: 0,
  20. index1: 0,
  21. },
  22. /**
  23. * 获得生日
  24. */
  25. bindDateChange: function (e) {
  26. this.setData({
  27. date: e.detail.value,
  28. flag: 2
  29. })
  30. },
  31. /**
  32. * 职业
  33. */
  34. bindPickerChange: function (e) {
  35. this.setData({
  36. index: e.detail.value
  37. })
  38. },
  39. /**
  40. * 生活半径
  41. */
  42. bindPickerChange1: function (e) {
  43. this.setData({
  44. index1: e.detail.value
  45. })
  46. },
  47. address: function () {
  48. let that = this;
  49. wx.chooseLocation({
  50. success: function (res) {
  51. that.setData({
  52. address: res.name + '(' + res.address + ')',
  53. })
  54. },
  55. fail: function (error) {
  56. console.log(error)
  57. },
  58. complete: function (data) {
  59. }
  60. })
  61. },
  62. formSubmit: function (e) {
  63. let that = this;
  64. /**
  65. * sex
  66. * 0 保密
  67. * 1 男
  68. * 2 女
  69. */
  70. if (that.data.flagsex == 0) {
  71. var sex = 0;
  72. } else {
  73. var sex = that.data.sex;
  74. }
  75. if (that.data.address) {
  76. var address = that.data.address;
  77. }
  78. else {
  79. var address = null;
  80. }
  81. if (e.detail.value.username) {
  82. var username = e.detail.value.username;
  83. }
  84. else if (that.data.username) {
  85. var username = that.data.username;
  86. }
  87. else {
  88. var username = null;
  89. }
  90. if (that.data.flag == 2 && that.data.date) {
  91. var birthdate = new Date(that.data.date).getTime();
  92. } else {
  93. var birthdate = null;
  94. }
  95. if (username == null || address == null || sex == 0 || birthdate == null) {
  96. wx.showModal({
  97. title: '提示',
  98. content: '请输入完整的用户信息',
  99. showCancel: false
  100. })
  101. } else {
  102. Http.post({
  103. url: config.api.updateInfo,
  104. data: {
  105. sex: sex,
  106. address: address,
  107. name: username,
  108. birthdate: birthdate,
  109. }
  110. })
  111. .then(res => {
  112. wx.showModal({
  113. title: '提示',
  114. content: '修改成功',
  115. showCancel: false,
  116. success: function (res) {
  117. wx.switchTab({
  118. url: '/pages/user/index',
  119. })
  120. }
  121. })
  122. })
  123. .catch(err => {
  124. wx.showToast({
  125. title: err.message,
  126. icon: 'none',
  127. duration: 2000,
  128. mask: false
  129. });
  130. })
  131. }
  132. },
  133. radioChange: function (e) {
  134. this.setData({
  135. sex: e.detail.value,
  136. flagsex: 1
  137. })
  138. },
  139. /**
  140. * 生命周期函数--监听页面加载
  141. */
  142. onLoad: function (options) {
  143. let that = this;
  144. Http.get({
  145. url: config.api.getScore,
  146. data: {}
  147. }).then(res => {
  148. console.log(res);
  149. if (res.data.address) {
  150. that.setData({
  151. address: res.data.address,
  152. })
  153. }
  154. if (res.data.name) {
  155. that.setData({
  156. username: res.data.name
  157. })
  158. }
  159. if (res.data.sex) {
  160. if (res.data.sex == 1) {
  161. var checked = 'items[' + 0 + '].checked'
  162. that.setData({
  163. [checked]: true,
  164. flagsex: 1
  165. })
  166. } else if (res.data.sex == 2) {
  167. var checked = 'items[' + 1 + '].checked'
  168. that.setData({
  169. [checked]: true,
  170. flagsex: 1
  171. })
  172. }
  173. that.setData({
  174. sex: res.data.sex
  175. })
  176. }
  177. if (res.data.birthdate) {
  178. that.setData({
  179. date: util.fmtDate(parseInt(res.data.birthdate)),
  180. flag: 2
  181. })
  182. }
  183. })
  184. }
  185. })