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.

208 lines
4.6 KiB

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