C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

209 rindas
4.6 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.showModal({
  99. title: '提示',
  100. content: '请输入完整的用户信息',
  101. showCancel: false
  102. })
  103. } else {
  104. Http.post({
  105. url: config.api.updateInfo,
  106. data: {
  107. sex: sex,
  108. address: address,
  109. name: username,
  110. birthdate: birthdate,
  111. }
  112. })
  113. .then(res => {
  114. wx.showModal({
  115. title: '提示',
  116. content: '修改成功',
  117. showCancel: false,
  118. success: function (res) {
  119. wx.switchTab({
  120. url: '/pages/user/index',
  121. })
  122. }
  123. })
  124. })
  125. .catch(err => {
  126. wx.showToast({
  127. title: err.message,
  128. icon: 'none',
  129. duration: 2000,
  130. mask: false
  131. });
  132. })
  133. }
  134. },
  135. radioChange: function (e) {
  136. this.setData({
  137. sex: e.detail.value,
  138. flagsex: 1
  139. })
  140. },
  141. /**
  142. * 生命周期函数--监听页面加载
  143. */
  144. onLoad: function (options) {
  145. let that = this;
  146. Http.get({
  147. url: config.api.getScore,
  148. data: {}
  149. })
  150. .then(res => {
  151. console.log(res);
  152. if(res.code == 200){
  153. that.setData({
  154. showPage:true
  155. })
  156. }
  157. var reg = RegExp(/address/);
  158. if (res.data.address.match(reg)) {
  159. that.setData({
  160. address: JSON.parse(res.data.address).address + JSON.parse(res.data.address).name,
  161. addressStr: JSON.parse(res.data.address).address + JSON.parse(res.data.address).name
  162. })
  163. }else{
  164. that.setData({
  165. address: res.data.address,
  166. addressStr: res.data.address
  167. })
  168. }
  169. if (res.data.name) {
  170. that.setData({
  171. username: res.data.name
  172. })
  173. }
  174. if (res.data.sex) {
  175. if (res.data.sex == 1) {
  176. var checked = 'items[' + 0 + '].checked'
  177. that.setData({
  178. [checked]: true,
  179. flagsex: 1
  180. })
  181. } else if (res.data.sex == 2) {
  182. var checked = 'items[' + 1 + '].checked'
  183. that.setData({
  184. [checked]: true,
  185. flagsex: 1
  186. })
  187. }
  188. that.setData({
  189. sex: res.data.sex
  190. })
  191. }
  192. if (res.data.birthdate) {
  193. that.setData({
  194. date: util.fmtDate(parseInt(res.data.birthdate)),
  195. flag: 2
  196. })
  197. }
  198. })
  199. .catch(error=>{
  200. console.log(error)
  201. wx.showModal({
  202. title: '提示',
  203. content: error.errMsg,
  204. showCancel:false
  205. })
  206. })
  207. }
  208. })