center.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. // pages/ucenter/center/center.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. userInfo: {},
  8. isLogin: false,
  9. isBindPhone:0,
  10. sexType: [
  11. {
  12. value: 0,
  13. text: '保密'
  14. },{
  15. value: 1,
  16. text: '男'
  17. }, {
  18. value: 2,
  19. text: '女'
  20. }],
  21. sexIndex: 0,
  22. carNum: null,
  23. email: null,
  24. checkPass: false,
  25. errorMsg: ''
  26. },
  27. inputSex(e) {
  28. this.setData({
  29. sexIndex: parseInt(e.detail.value)
  30. });
  31. let userdata= {
  32. sexIndex: e.detail.value,
  33. carNum: null,
  34. email: null,
  35. };
  36. this.bindUpdateUser(userdata);
  37. },
  38. inputCarNum(e){
  39. let that = this;
  40. wx.showModal({
  41. title: '修改车牌号',
  42. showCancel:true,
  43. editable: true,
  44. confirmColor:'#00AADD',
  45. success: function (res1) {
  46. if (res1.confirm) {
  47. let carNum = res1.content;
  48. that.confirmCarNum(carNum);
  49. }
  50. }
  51. });
  52. },
  53. confirmCarNum(carNum) {
  54. if (!this.checkCarNum(carNum)) {
  55. wx.showModal({
  56. title: '提示',
  57. showCancel:false,
  58. content: '车牌号输入有误,请重新输入',
  59. confirmColor:'#00AADD',
  60. });
  61. return;
  62. } else {
  63. this.setData({
  64. carNum: carNum,
  65. errorMsg: ''
  66. });
  67. }
  68. let userdata= {
  69. sexIndex: null,
  70. carNum: carNum,
  71. email: null,
  72. };
  73. this.bindUpdateUser(userdata);
  74. },
  75. inputEmail(e) {
  76. let that = this;
  77. wx.showModal({
  78. title: '修改邮箱',
  79. showCancel:true,
  80. editable: true,
  81. confirmColor:'#00AADD',
  82. success: function (res1) {
  83. if (res1.confirm) {
  84. let email = res1.content;
  85. that.confirmEmail(email);
  86. }
  87. }
  88. });
  89. },
  90. confirmEmail(email) {
  91. if (!this.checkMail(email)) {
  92. wx.showModal({
  93. title: '提示',
  94. showCancel:false,
  95. content: '邮箱输入有误,请重新输入',
  96. confirmColor:'#00AADD',
  97. });
  98. return;
  99. } else {
  100. this.setData({
  101. email: email,
  102. errorMsg: ''
  103. });
  104. }
  105. let userdata= {
  106. sexIndex: null,
  107. carNum: null,
  108. email: email
  109. };
  110. this.bindUpdateUser(userdata);
  111. },
  112. checkMail(email) {
  113. if(email){
  114. if (!(/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(email))) {
  115. return false;
  116. }
  117. }
  118. return true;
  119. },
  120. checkCarNum(carNum){
  121. if (carNum){
  122. // if (!(/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/.test(this.data.carNum))) {
  123. if (!/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领].*$/.test(carNum)) {
  124. return false;
  125. }
  126. }
  127. return true;
  128. },
  129. bindUpdateUser(userdata) {
  130. let that = this;
  131. let loginName = this.data.userInfo.loginName;
  132. let {
  133. sexIndex,
  134. carNum: license_number,
  135. email
  136. } = userdata;
  137. var sex = null;
  138. if (sexIndex!=null){
  139. sex = this.data.sexType[sexIndex].value;
  140. }
  141. wx.request({
  142. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/updateUser',
  143. data: {
  144. loginName,
  145. sex: sex,
  146. license_number,
  147. email,
  148. },
  149. method: 'POST',
  150. success(res1) {
  151. if (res1.data.code == 1) {
  152. that.setData({
  153. errorMsg: res1.data.msg
  154. })
  155. }else if (res1.data.code == 2) {
  156. wx.showModal({
  157. title: '提示',
  158. content: '您未绑定手机号,请重新登录后自动刷新绑定信息',
  159. confirmText: '去登录',
  160. showCancel:false,
  161. confirmColor:'#00AADD',
  162. success: function (res1) {
  163. if (res1.confirm) {
  164. wx.removeStorageSync('userInfo');
  165. wx.removeStorageSync('isLogin');
  166. let url = '/pages/login/phone_login/phone_login';
  167. wx.redirectTo({
  168. url
  169. })
  170. }
  171. }
  172. });
  173. } else {
  174. //返回该用户
  175. //跳转到上一页
  176. wx.setStorageSync("userInfo", res1.data);
  177. wx.setStorageSync("isLogin", true);
  178. let userInfo = wx.getStorageSync('userInfo');
  179. console.info("fffffffffffff")
  180. console.info(userInfo)
  181. that.setData({
  182. userInfo: userInfo
  183. });
  184. // wx.navigateBack();
  185. //let url = `/pages/ucenter/index/index`;
  186. //wx.redirectTo({
  187. //url
  188. //});
  189. }
  190. }
  191. });
  192. },
  193. /**
  194. * 生命周期函数--监听页面加载
  195. */
  196. onLoad: function(options) {
  197. },
  198. /**
  199. * 生命周期函数--监听页面初次渲染完成
  200. */
  201. onReady: function() {
  202. },
  203. /**
  204. * 生命周期函数--监听页面显示
  205. */
  206. onShow: function() {
  207. let userInfo = wx.getStorageSync('userInfo');
  208. let isLogin = wx.getStorageSync('isLogin');
  209. // 页面显示
  210. if (userInfo && isLogin) {
  211. //userInfo.flag = true;
  212. console.log(userInfo);
  213. this.setData({
  214. userInfo: userInfo,
  215. isLogin: isLogin,
  216. isBindPhone: userInfo.bindingPhone,
  217. carNum: userInfo.license_number,
  218. email:userInfo.email,
  219. sexIndex:userInfo.sex
  220. });
  221. } else {
  222. //未登录信息
  223. this.setData({
  224. userInfo: {}
  225. });
  226. }
  227. },
  228. /**
  229. * 生命周期函数--监听页面隐藏
  230. */
  231. onHide: function() {
  232. },
  233. /**
  234. * 生命周期函数--监听页面卸载
  235. */
  236. onUnload: function() {
  237. },
  238. /**
  239. * 页面相关事件处理函数--监听用户下拉动作
  240. */
  241. onPullDownRefresh: function() {
  242. },
  243. /**
  244. * 页面上拉触底事件的处理函数
  245. */
  246. onReachBottom: function() {
  247. },
  248. /**
  249. * 用户点击右上角分享
  250. */
  251. onShareAppMessage: function() {
  252. }
  253. })