index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // pages/create-project-role/index.js
  2. import http from '../../utils/http'
  3. import util from '../../utils/util'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. keyword: '',
  10. projects: [],
  11. projectIndex: -1,
  12. users: [],
  13. userIndex: -1,
  14. roleIndex: -1
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. this.getProjects()
  21. this.getRoles()
  22. },
  23. submit() {
  24. if(this.data.users.length <= 0) {
  25. util.error('请选择成员')
  26. return false
  27. }
  28. if(this.data.projectIndex < 0) {
  29. util.error('请选择项目')
  30. return false
  31. }
  32. if(this.data.roleIndex < 0) {
  33. util.error('请选择角色')
  34. return false
  35. }
  36. var user_id = this.data.users[0].id;
  37. var project_id = this.data.projects[this.data.projectIndex].id;
  38. var role_id = this.data.roles[this.data.roleIndex].id;
  39. http({
  40. url: 'projects/addUser',
  41. data: {
  42. user_id: user_id,
  43. project_id: project_id,
  44. project_role_id: role_id
  45. },
  46. success: function(res) {
  47. if(res.code == 0) {
  48. util.success('操作成功')
  49. }
  50. }
  51. })
  52. },
  53. clear: function() {
  54. this.setData({
  55. keyword: ''
  56. })
  57. },
  58. blur: function() {
  59. var that = this
  60. setTimeout(function() {
  61. that.search()
  62. }, 300)
  63. },
  64. search: function() {
  65. var that = this
  66. if(!this.data.keyword) return false;
  67. http({
  68. url: 'users/search',
  69. data: {
  70. keyword: this.data.keyword
  71. },
  72. success: function(res) {
  73. if(res.code == 0) {
  74. if(res.data.length <= 0) {
  75. util.error('未找到相应用户')
  76. }
  77. that.setData({
  78. users: res.data
  79. })
  80. }
  81. }
  82. })
  83. },
  84. bindPickerChange: function(e) {
  85. var name = e.currentTarget.dataset.name
  86. this.setData({
  87. [name]: e.detail.value
  88. })
  89. },
  90. getRoles: function() {
  91. var that = this
  92. http({
  93. url: 'project-roles/getAll',
  94. data: {},
  95. success: function(res) {
  96. if(res.code == 0) {
  97. that.setData({
  98. roles: res.data
  99. })
  100. }
  101. }
  102. })
  103. },
  104. getProjects: function() {
  105. var that = this
  106. http({
  107. url: 'projects/getAll',
  108. data: {},
  109. success: function(res) {
  110. if(res.code == 0) {
  111. that.setData({
  112. projects: res.data
  113. })
  114. }
  115. }
  116. })
  117. },
  118. updateInput: function(e) {
  119. var name = e.currentTarget.dataset.name
  120. this.setData({
  121. [name]: e.detail.value
  122. })
  123. },
  124. /**
  125. * 生命周期函数--监听页面初次渲染完成
  126. */
  127. onReady: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面显示
  131. */
  132. onShow: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面隐藏
  136. */
  137. onHide: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面卸载
  141. */
  142. onUnload: function () {
  143. },
  144. /**
  145. * 页面相关事件处理函数--监听用户下拉动作
  146. */
  147. onPullDownRefresh: function () {
  148. },
  149. /**
  150. * 页面上拉触底事件的处理函数
  151. */
  152. onReachBottom: function () {
  153. },
  154. /**
  155. * 用户点击右上角分享
  156. */
  157. onShareAppMessage: function () {
  158. }
  159. })