C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
4.4 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. console.log(res)
  52. that.setData({
  53. address: res.name + '(' + res.address + ')',
  54. addressStr: JSON.stringify(res)
  55. })
  56. },
  57. fail: function (error) {
  58. console.log(error)
  59. },
  60. complete: function (data) {
  61. }
  62. })
  63. },
  64. formSubmit: function (e) {
  65. let that = this;
  66. /**
  67. * sex
  68. * 0 保密
  69. * 1 男
  70. * 2 女
  71. */
  72. if (that.data.flagsex == 0) {
  73. var sex = 0;
  74. } else {
  75. var sex = that.data.sex;
  76. }
  77. if (that.data.addressStr) {
  78. var address = that.data.addressStr;
  79. }
  80. else {
  81. var address = null;
  82. }
  83. if (e.detail.value.username) {
  84. var username = e.detail.value.username;
  85. }
  86. else if (that.data.username) {
  87. var username = that.data.username;
  88. }
  89. else {
  90. var username = null;
  91. }
  92. if (that.data.flag == 2 && that.data.date) {
  93. var birthdate = new Date(that.data.date).getTime();
  94. } else {
  95. var birthdate = null;
  96. }
  97. console.log(username)
  98. console.log(address)
  99. console.log(sex)
  100. console.log(birthdate)
  101. if (username == null || address == null || sex == 0 || birthdate == null) {
  102. wx.showModal({
  103. title: '提示',
  104. content: '请输入完整的用户信息',
  105. showCancel: false
  106. })
  107. } else {
  108. Http.post({
  109. url: config.api.updateInfo,
  110. data: {
  111. sex: sex,
  112. address: address,
  113. name: username,
  114. birthdate: birthdate,
  115. }
  116. })
  117. .then(res => {
  118. wx.showModal({
  119. title: '提示',
  120. content: '修改成功',
  121. showCancel: false,
  122. success: function (res) {
  123. wx.switchTab({
  124. url: '/pages/user/index',
  125. })
  126. }
  127. })
  128. })
  129. .catch(err => {
  130. wx.showToast({
  131. title: err.message,
  132. icon: 'none',
  133. duration: 2000,
  134. mask: false
  135. });
  136. })
  137. }
  138. },
  139. radioChange: function (e) {
  140. this.setData({
  141. sex: e.detail.value,
  142. flagsex: 1
  143. })
  144. },
  145. /**
  146. * 生命周期函数--监听页面加载
  147. */
  148. onLoad: function (options) {
  149. let that = this;
  150. Http.get({
  151. url: config.api.getScore,
  152. data: {}
  153. }).then(res => {
  154. console.log(res.data.address);
  155. var reg = RegExp(/address/);
  156. if (res.data.address.match(reg)) {
  157. that.setData({
  158. address: JSON.parse(res.data.address).address + JSON.parse(res.data.address).name,
  159. addressStr: JSON.parse(res.data.address).address + JSON.parse(res.data.address).name
  160. })
  161. }else{
  162. that.setData({
  163. address: res.data.address,
  164. addressStr: res.data.address
  165. })
  166. }
  167. if (res.data.name) {
  168. that.setData({
  169. username: res.data.name
  170. })
  171. }
  172. if (res.data.sex) {
  173. if (res.data.sex == 1) {
  174. var checked = 'items[' + 0 + '].checked'
  175. that.setData({
  176. [checked]: true,
  177. flagsex: 1
  178. })
  179. } else if (res.data.sex == 2) {
  180. var checked = 'items[' + 1 + '].checked'
  181. that.setData({
  182. [checked]: true,
  183. flagsex: 1
  184. })
  185. }
  186. that.setData({
  187. sex: res.data.sex
  188. })
  189. }
  190. if (res.data.birthdate) {
  191. that.setData({
  192. date: util.fmtDate(parseInt(res.data.birthdate)),
  193. flag: 2
  194. })
  195. }
  196. })
  197. }
  198. })