index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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({ title: '缺少微信关联', icon: 'error' })
  26. return
  27. }
  28. data.openid = wxInfo.openid;
  29. const res = await app.$post('/newCourt/api/user', data)
  30. if (app.$checkRes(res)) {
  31. wx.showToast({
  32. title: '注册成功',
  33. success: () => {
  34. wx.redirectTo({ url: '/pages/index/index' });
  35. }
  36. })
  37. } else {
  38. const { errmsg = '注册失败' } = res;
  39. wx.showModal({ title: errmsg, showCancel: false })
  40. }
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad(options) {
  46. const fields = this.data.fields;
  47. const fg = fields.find(f => f.model === 'gender')
  48. if (fg) fg.list = gender
  49. this.setData({ fields })
  50. },
  51. /**
  52. * 生命周期函数--监听页面初次渲染完成
  53. */
  54. onReady() { },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow() { },
  59. /**
  60. * 生命周期函数--监听页面隐藏
  61. */
  62. onHide() { },
  63. /**
  64. * 生命周期函数--监听页面卸载
  65. */
  66. onUnload() { },
  67. /**
  68. * 页面相关事件处理函数--监听用户下拉动作
  69. */
  70. onPullDownRefresh() { },
  71. /**
  72. * 页面上拉触底事件的处理函数
  73. */
  74. onReachBottom() { },
  75. /**
  76. * 用户点击右上角分享
  77. */
  78. onShareAppMessage() { },
  79. });