123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- // pages/project-user/index.js
- import http from '../../utils/http'
- import util from '../../utils/util'
- import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- id: -1,
- list: [],
- keyword: '',
- project: null,
- showAction: false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var id = options.id ? options.id : 1
- this.setData({
- id: id
- })
- },
- change: function() {
- var user = this.getUser()
- var id = user.id ? user.id : -1
- wx.navigateTo({
- url: '/pages/create-project-role/index?id=' + user.id,
- })
- },
- getUser() {
- var list = this.data.list
- for(var i = 0; i < list.length; ++i) {
- if(list[i].selected) {
- return list[i]
- }
- }
- return null
- },
- deleteUser: function() {
- var user = this.getUser()
- var id = user ? user.id : -1
- var that = this
- http({
- url: 'projects/deleteUser',
- data: {
- id: id
- },
- success: function (res) {
- if (res.code == 0) {
- util.success('操作成功')
- setTimeout(function() {
- that.getList()
- }, 300)
- } else {
- util.error('操作失败')
- }
- }
- })
- },
- delete: function () {
- var that = this
- Dialog.confirm({
- title: '确认删除该成员吗',
- message: '删除该成员后,该成员将不再显示在该项目中,请再次确定是否需要删除该成员',
- })
- .then(() => {
- that.deleteUser()
- })
- .catch(() => {
- // on cancel
- });
- },
- selectUser: function (e) {
- var index = e.currentTarget.dataset.index
- var list = this.data.list
- for (var i = 0; i < list.length; ++i) {
- if (i != index) list[i].selected = false
- }
- list[index].selected = !list[index].selected
- this.setData({
- list,
- showAction: list[index].selected
- })
- // this.updateShowAction()
- },
- updateShowAction: function () {
- var list = this.data.list
- for (var i = 0; i < list.length; ++i) {
- if (list[i].selected) {
- this.setData({
- showAction: true
- })
- return false;
- }
- }
- this.setData({
- showAction: false
- })
- },
- getList: function () {
- var that = this
- http({
- url: 'projects/getUsers',
- data: {
- id: this.data.id,
- keyword: this.data.keyword
- },
- success: function (res) {
- if (res.code == 0) {
- that.setData({
- list: res.data
- })
- that.updateShowAction()
- }
- }
- })
- },
- getProject() {
- var that = this
- http({
- url: 'projects/detail',
- data: {
- id: this.data.id
- },
- success: function (res) {
- if (res.code == 0) {
- that.setData({
- project: res.data
- })
- }
- }
- })
- },
- clear: function () {
- this.setData({
- keyword: ''
- })
- },
- blur: function () {
- var that = this
- setTimeout(function () {
- that.getList()
- }, 300)
- },
- updateInput: function (e) {
- var name = e.currentTarget.dataset.name
- this.setData({
- [name]: e.detail.value
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getProject()
- this.getList();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|