index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. getUserInfo: function(e) {
  30. var that = this;
  31. util.wechatLogin(e, false, function(res) {
  32. that.submit()
  33. }, true)
  34. },
  35. submit: function() {
  36. if(!this.data.name) {
  37. util.error('真实姓名必填')
  38. return false;
  39. }
  40. if(!this.data.projectIndex < 0) {
  41. util.error('所属项目必填')
  42. return false;
  43. }
  44. if(!this.data.roleIndex < 0) {
  45. util.error('申请角色不能为空')
  46. return false;
  47. }
  48. if(this.data.remark.length < 10) {
  49. util.error('备注需10个字以上')
  50. return false;
  51. }
  52. var project = this.data.projects[this.data.projectIndex]
  53. var role = this.data.roles[this.data.roleIndex]
  54. http({
  55. url: 'user-auth/create',
  56. data: {
  57. name: this.data.name,
  58. project_id: project ? project.id : '',
  59. project_role_id: role ? role.id : '',
  60. remark: this.data.remark
  61. },
  62. success: function(res) {
  63. util.success('操作成功')
  64. }
  65. })
  66. },
  67. bindPickerChange: function(e) {
  68. var name = e.currentTarget.dataset.name
  69. this.setData({
  70. [name]: e.detail.value
  71. })
  72. },
  73. /**
  74. * 生命周期函数--监听页面初次渲染完成
  75. */
  76. onReady: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面显示
  80. */
  81. onShow: function () {
  82. api.getByName(this, 'projects/getAll', 'projects')
  83. api.getByName(this, 'project-roles/getAll', 'roles', {'limit': true})
  84. },
  85. /**
  86. * 生命周期函数--监听页面隐藏
  87. */
  88. onHide: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面卸载
  92. */
  93. onUnload: function () {
  94. },
  95. /**
  96. * 页面相关事件处理函数--监听用户下拉动作
  97. */
  98. onPullDownRefresh: function () {
  99. },
  100. /**
  101. * 页面上拉触底事件的处理函数
  102. */
  103. onReachBottom: function () {
  104. },
  105. /**
  106. * 用户点击右上角分享
  107. */
  108. onShareAppMessage: function () {
  109. }
  110. })