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

204 行
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. showPage:false
  22. },
  23. /**
  24. * 获得生日
  25. */
  26. bindDateChange: function (e) {
  27. this.setData({
  28. date: e.detail.value,
  29. flag: 2
  30. })
  31. },
  32. /**
  33. * 职业
  34. */
  35. bindPickerChange: function (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. 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. if (username == null || address == null || sex == 0 || birthdate == null) {
  98. wx.showToast({
  99. title: '请输入完整的用户信息',
  100. icon:"none"
  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.showToast({
  114. title: "修改成功",
  115. icon: 'none',
  116. duration: 2000,
  117. mask: false
  118. })
  119. })
  120. .catch(err => {
  121. wx.showToast({
  122. title: err.message,
  123. icon: 'none',
  124. duration: 2000,
  125. mask: false
  126. })
  127. })
  128. }
  129. },
  130. radioChange: function (e) {
  131. this.setData({
  132. sex: e.detail.value,
  133. flagsex: 1
  134. })
  135. },
  136. /**
  137. * 生命周期函数--监听页面加载
  138. */
  139. onLoad: function (options) {
  140. let that = this;
  141. Http.get({
  142. url: config.api.getScore,
  143. data: {}
  144. })
  145. .then(res => {
  146. console.log(res);
  147. if(res.code == 200){
  148. that.setData({
  149. showPage:true
  150. })
  151. }
  152. var reg = RegExp(/address/);
  153. if (res&&res.data&&res.data.address&&res.data.address.match(reg)) {
  154. that.setData({
  155. address: JSON.parse(res.data.address).address + JSON.parse(res.data.address).name,
  156. addressStr: JSON.parse(res.data.address).address + JSON.parse(res.data.address).name
  157. })
  158. }else{
  159. that.setData({
  160. address: res.data.address,
  161. addressStr: res.data.address
  162. })
  163. }
  164. if (res.data.name) {
  165. that.setData({
  166. username: res.data.name
  167. })
  168. }
  169. if (res.data.sex) {
  170. if (res.data.sex == 1) {
  171. var checked = 'items[' + 0 + '].checked'
  172. that.setData({
  173. [checked]: true,
  174. flagsex: 1
  175. })
  176. } else if (res.data.sex == 2) {
  177. var checked = 'items[' + 1 + '].checked'
  178. that.setData({
  179. [checked]: true,
  180. flagsex: 1
  181. })
  182. }
  183. that.setData({
  184. sex: res.data.sex
  185. })
  186. }
  187. if (res.data.birthdate) {
  188. that.setData({
  189. date: util.fmtDate(parseInt(res.data.birthdate)),
  190. flag: 2
  191. })
  192. }
  193. })
  194. .catch(error=>{
  195. wx.showToast({
  196. title: error.errMsg,
  197. icon: 'none',
  198. duration: 2000,
  199. mask: false
  200. });
  201. })
  202. }
  203. })