index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. Dialog.close()
  56. setTimeout(function () {
  57. that.getList()
  58. }, 300)
  59. } else {
  60. util.error('操作失败')
  61. }
  62. }
  63. })
  64. },
  65. delete: function () {
  66. var that = this
  67. Dialog.confirm({
  68. title: '确认删除该成员吗',
  69. message: '删除该成员后,该成员将不再显示在该项目中,请再次确定是否需要删除该成员',
  70. })
  71. .then(() => {
  72. that.deleteUser()
  73. })
  74. .catch(() => {
  75. Dialog.close()
  76. })
  77. },
  78. selectUser: function (e) {
  79. var index = e.currentTarget.dataset.index
  80. var list = this.data.list
  81. var item = list[index]
  82. if (item.project_role.level >= this.data.project.role.level) return false
  83. for (var i = 0; i < list.length; ++i) {
  84. if (i != index) list[i].selected = false
  85. }
  86. list[index].selected = !list[index].selected
  87. this.setData({
  88. list,
  89. showAction: list[index].selected
  90. })
  91. // this.updateShowAction()
  92. },
  93. updateShowAction: function () {
  94. var list = this.data.list
  95. for (var i = 0; i < list.length; ++i) {
  96. if (list[i].selected) {
  97. this.setData({
  98. showAction: true
  99. })
  100. return false;
  101. }
  102. }
  103. this.setData({
  104. showAction: false
  105. })
  106. },
  107. getList: function () {
  108. var that = this
  109. http({
  110. url: 'projects/getUsers',
  111. data: {
  112. id: this.data.id,
  113. keyword: this.data.keyword
  114. },
  115. success: function (res) {
  116. if (res.code == 0) {
  117. res.data.reverse()
  118. that.setData({
  119. list: res.data
  120. })
  121. that.updateShowAction()
  122. }
  123. }
  124. })
  125. },
  126. getProject() {
  127. var that = this
  128. http({
  129. url: 'projects/detail',
  130. data: {
  131. id: this.data.id
  132. },
  133. success: function (res) {
  134. if (res.code == 0) {
  135. that.setData({
  136. project: res.data
  137. })
  138. }
  139. }
  140. })
  141. },
  142. clear: function () {
  143. this.setData({
  144. keyword: ''
  145. })
  146. },
  147. blur: function () {
  148. var that = this
  149. setTimeout(function () {
  150. that.getList()
  151. }, 300)
  152. },
  153. updateInput: function (e) {
  154. var name = e.currentTarget.dataset.name
  155. this.setData({
  156. [name]: e.detail.value
  157. })
  158. },
  159. /**
  160. * 生命周期函数--监听页面初次渲染完成
  161. */
  162. onReady: function () {
  163. },
  164. /**
  165. * 生命周期函数--监听页面显示
  166. */
  167. onShow: function () {
  168. this.getProject()
  169. this.getList();
  170. },
  171. /**
  172. * 生命周期函数--监听页面隐藏
  173. */
  174. onHide: function () {
  175. },
  176. /**
  177. * 生命周期函数--监听页面卸载
  178. */
  179. onUnload: function () {
  180. },
  181. /**
  182. * 页面相关事件处理函数--监听用户下拉动作
  183. */
  184. onPullDownRefresh: function () {
  185. },
  186. /**
  187. * 页面上拉触底事件的处理函数
  188. */
  189. onReachBottom: function () {
  190. },
  191. /**
  192. * 用户点击右上角分享
  193. */
  194. onShareAppMessage: function () {
  195. }
  196. })