index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // pages/bind/index.js
  2. import util from '../../utils/util'
  3. import http from '../../utils/http'
  4. import api from '../../utils/api'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. projects: [],
  11. projectIndex: -1,
  12. roles: [],
  13. roleIndex: -1,
  14. name: '',
  15. remark: ''
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. },
  22. onInputChange: function(e) {
  23. var name = e.currentTarget.dataset.name
  24. var val = e.detail.value
  25. this.setData({
  26. [name]: val
  27. })
  28. },
  29. updatePhoneNumber(e) {
  30. if(e.detail.errMsg == 'errMsg') {
  31. http({
  32. url: 'auth/parsePhone',
  33. data: e.detail,
  34. success: function(res) {
  35. util.success('手机号获取成功')
  36. }
  37. })
  38. }
  39. },
  40. getUserInfo: function(e) {
  41. var that = this;
  42. util.wechatLogin(e, false, function(res) {
  43. that.submit()
  44. }, true)
  45. },
  46. submit: function() {
  47. if(!this.data.name) {
  48. util.error('真实姓名必填')
  49. return false;
  50. }
  51. if(!this.data.projectIndex < 0) {
  52. util.error('所属项目必填')
  53. return false;
  54. }
  55. if(!this.data.roleIndex < 0) {
  56. util.error('申请角色不能为空')
  57. return false;
  58. }
  59. if(this.data.remark.length < 10) {
  60. util.error('备注需10个字以上')
  61. return false;
  62. }
  63. var project = this.data.projects[this.data.projectIndex]
  64. var role = this.data.roles[this.data.roleIndex]
  65. http({
  66. url: 'user-auth/create',
  67. data: {
  68. name: this.data.name,
  69. project_id: project ? project.id : '',
  70. project_role_id: role ? role.id : '',
  71. remark: this.data.remark
  72. },
  73. success: function(res) {
  74. util.success('操作成功')
  75. }
  76. })
  77. },
  78. bindPickerChange: function(e) {
  79. var name = e.currentTarget.dataset.name
  80. this.setData({
  81. [name]: e.detail.value
  82. })
  83. },
  84. /**
  85. * 生命周期函数--监听页面初次渲染完成
  86. */
  87. onReady: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面显示
  91. */
  92. onShow: function () {
  93. api.getByName(this, 'projects/getAll', 'projects')
  94. api.getByName(this, 'project-roles/getAll', 'roles', {'limit': true})
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. }
  121. })