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

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