index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // pages/project-user/index.js
  2. import http from '../../utils/http'
  3. import util from '../../utils/util'
  4. import api from '../../utils/api'
  5. import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. id: -1,
  12. list: [],
  13. keyword: '',
  14. project: null,
  15. showAction: false,
  16. role: null
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. var id = options.id ? options.id : 1
  23. this.setData({
  24. id: id
  25. })
  26. },
  27. change: function() {
  28. var user = this.getUser()
  29. var id = user.id ? user.id : -1
  30. wx.navigateTo({
  31. url: '/pages/create-project-role/index?id=' + user.id,
  32. })
  33. },
  34. getUser() {
  35. var list = this.data.list
  36. for(var i = 0; i < list.length; ++i) {
  37. if(list[i].selected) {
  38. return list[i]
  39. }
  40. }
  41. return null
  42. },
  43. deleteUser: function() {
  44. var user = this.getUser()
  45. var id = user ? user.id : -1
  46. var that = this
  47. http({
  48. url: 'projects/deleteUser',
  49. data: {
  50. id: id
  51. },
  52. success: function (res) {
  53. if (res.code == 0) {
  54. util.success('操作成功')
  55. setTimeout(function() {
  56. that.getList()
  57. }, 300)
  58. } else {
  59. util.error('操作失败')
  60. }
  61. }
  62. })
  63. },
  64. delete: function () {
  65. var that = this
  66. Dialog.confirm({
  67. title: '确认删除该成员吗',
  68. message: '删除该成员后,该成员将不再显示在该项目中,请再次确定是否需要删除该成员',
  69. })
  70. .then(() => {
  71. that.deleteUser()
  72. })
  73. .catch(() => {
  74. // on cancel
  75. });
  76. },
  77. selectUser: function (e) {
  78. var index = e.currentTarget.dataset.index
  79. var list = this.data.list
  80. var item = list[index]
  81. if(item.project_role.level >= this.data.project.role.level) return false
  82. for (var i = 0; i < list.length; ++i) {
  83. if (i != index) list[i].selected = false
  84. }
  85. list[index].selected = !list[index].selected
  86. this.setData({
  87. list,
  88. showAction: list[index].selected
  89. })
  90. // this.updateShowAction()
  91. },
  92. updateShowAction: function () {
  93. var list = this.data.list
  94. for (var i = 0; i < list.length; ++i) {
  95. if (list[i].selected) {
  96. this.setData({
  97. showAction: true
  98. })
  99. return false;
  100. }
  101. }
  102. this.setData({
  103. showAction: false
  104. })
  105. },
  106. getList: function () {
  107. var that = this
  108. http({
  109. url: 'projects/getUsers',
  110. data: {
  111. id: this.data.id,
  112. keyword: this.data.keyword
  113. },
  114. success: function (res) {
  115. if (res.code == 0) {
  116. res.data.reverse()
  117. that.setData({
  118. list: res.data
  119. })
  120. that.updateShowAction()
  121. }
  122. }
  123. })
  124. },
  125. getProject() {
  126. var that = this
  127. http({
  128. url: 'projects/detail',
  129. data: {
  130. id: this.data.id
  131. },
  132. success: function (res) {
  133. if (res.code == 0) {
  134. that.setData({
  135. project: res.data
  136. })
  137. }
  138. }
  139. })
  140. },
  141. clear: function () {
  142. this.setData({
  143. keyword: ''
  144. })
  145. },
  146. blur: function () {
  147. var that = this
  148. setTimeout(function () {
  149. that.getList()
  150. }, 300)
  151. },
  152. updateInput: function (e) {
  153. var name = e.currentTarget.dataset.name
  154. this.setData({
  155. [name]: e.detail.value
  156. })
  157. },
  158. /**
  159. * 生命周期函数--监听页面初次渲染完成
  160. */
  161. onReady: function () {
  162. },
  163. /**
  164. * 生命周期函数--监听页面显示
  165. */
  166. onShow: function () {
  167. this.getProject()
  168. this.getList();
  169. },
  170. /**
  171. * 生命周期函数--监听页面隐藏
  172. */
  173. onHide: function () {
  174. },
  175. /**
  176. * 生命周期函数--监听页面卸载
  177. */
  178. onUnload: function () {
  179. },
  180. /**
  181. * 页面相关事件处理函数--监听用户下拉动作
  182. */
  183. onPullDownRefresh: function () {
  184. },
  185. /**
  186. * 页面上拉触底事件的处理函数
  187. */
  188. onReachBottom: function () {
  189. },
  190. /**
  191. * 用户点击右上角分享
  192. */
  193. onShareAppMessage: function () {
  194. }
  195. })