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.

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