index.js 3.9 KB

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