index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // pages/register/index.js
  2. const { gender } = require('../../utils/dict')
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '注册', leftArrow: false, useBar: false },
  10. form: {},
  11. fields: [
  12. { label: '头像', model: 'icon', type: "upload" },
  13. { label: '姓名', model: 'name' },
  14. { label: '身份证号', model: 'card' },
  15. { label: '性别', model: 'gender', type: 'select' },
  16. { label: '手机号', model: 'phone' },
  17. { label: '邮箱', model: 'email' },
  18. ]
  19. },
  20. async toSubmit(e) {
  21. const data = e?.detail;
  22. if (!data) return;
  23. const wxInfo = app.globalData.wxInfo
  24. if (!wxInfo.openid) {
  25. wx.showToast({
  26. title: '缺少微信关联',
  27. icon: 'error'
  28. })
  29. return
  30. }
  31. data.openid = wxInfo.openid;
  32. const res = await app.$post('/newCourt/api/user', data)
  33. if (app.$checkRes(res)) {
  34. wx.showToast({
  35. title: '注册成功',
  36. success: () => {
  37. wx.redirectTo({ url: '/pages/index/index' });
  38. }
  39. })
  40. } else {
  41. const { errmsg = '注册失败' } = res;
  42. wx.showModal({
  43. title: errmsg,
  44. showCancel: false
  45. })
  46. }
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad(options) {
  52. const fields = this.data.fields;
  53. const fg = fields.find(f => f.model === 'gender')
  54. if (fg) fg.list = gender
  55. this.setData({ fields })
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady() { },
  61. /**
  62. * 生命周期函数--监听页面显示
  63. */
  64. onShow() { },
  65. /**
  66. * 生命周期函数--监听页面隐藏
  67. */
  68. onHide() { },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload() { },
  73. /**
  74. * 页面相关事件处理函数--监听用户下拉动作
  75. */
  76. onPullDownRefresh() { },
  77. /**
  78. * 页面上拉触底事件的处理函数
  79. */
  80. onReachBottom() { },
  81. /**
  82. * 用户点击右上角分享
  83. */
  84. onShareAppMessage() { },
  85. });