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.

206 line
4.5 KiB

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