| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 | 
							- // pages/create-project-role/index.js
 
- import http from '../../utils/http'
 
- import util from '../../utils/util'
 
- Page({
 
-   /**
 
-    * 页面的初始数据
 
-    */
 
-   data: {
 
-     keyword: '',
 
-     projects: [],
 
-     projectIndex: -1,
 
-     users: [],
 
-     userIndex: -1,
 
-     roleIndex: -1,
 
-     id: -1,
 
-     // create/edit
 
-     type: 'create',
 
-     project_user: null,
 
-     roles: []
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面加载
 
-    */
 
-   onLoad: function (options) {
 
-     this.getProjects()
 
-     if(options.id) {
 
-       this.setData({
 
-         id: options.id,
 
-         type: 'edit'
 
-       })
 
-       this.getProjectUser()
 
-       wx.setNavigationBarTitle({
 
-         title: '修改权限'
 
-       })
 
-     }
 
-     this.getRoles()
 
-   },
 
-   updateIndex: function() {
 
-     var project_user = this.data.project_user
 
-     if(!project_user) return false;
 
-     var projects = this.data.projects
 
-     if(projects.length > 0) {
 
-       for(var i = 0; i < projects.length; ++i) {
 
-         if(projects[i].id == project_user.project_id) {
 
-           this.setData({
 
-             projectIndex: i
 
-           })
 
-           break;
 
-         }
 
-       }
 
-     }
 
-     var roles = this.data.roles
 
-     if(roles.length > 0) {
 
-       for(var i = 0; i < roles.length; ++i) {
 
-         if(roles[i].id == project_user.project_role_id) {
 
-           this.setData({
 
-             roleIndex: i
 
-           })
 
-           break;
 
-         }
 
-       }
 
-     }
 
-   },
 
-   getProjectUser() {
 
-     var that = this
 
-     http({
 
-       url: 'project-users/detail',
 
-       data: {
 
-         id: this.data.id
 
-       },
 
-       success: function(res) {
 
-         if(res.code == 0) {
 
-           that.setData({
 
-             project_user: res.data
 
-           })
 
-           that.updateIndex()
 
-           that.search()
 
-         }
 
-       }
 
-     })
 
-   },
 
-   submit() {
 
-     if(this.data.users.length <= 0) {
 
-       util.error('请选择成员')
 
-       return false
 
-     }
 
-     if(this.data.projectIndex < 0) {
 
-       util.error('请选择项目')
 
-       return false
 
-     }
 
-     if(this.data.roleIndex < 0) {
 
-       util.error('请选择角色')
 
-       return false
 
-     }
 
-     var user_id = this.data.users[0].id;
 
-     var project_id = this.data.projects[this.data.projectIndex].id;
 
-     var role_id = this.data.roles[this.data.roleIndex].id;
 
-     var url = this.data.type == 'create' ? 'projects/addUser' : 'projects/updateUser'
 
-     var data = {
 
-       user_id: user_id,
 
-       project_id: project_id,
 
-       project_role_id: role_id
 
-     }
 
-     if(this.data.type == 'edit') {
 
-       data.id = this.data.project_user.id
 
-     }
 
-     http({
 
-       url: url,
 
-       data: data,
 
-       success: function(res) {
 
-         if(res.code == 0) {
 
-           util.success('操作成功')
 
-         }
 
-       }
 
-     })
 
-   },
 
-   clear: function() {
 
-     this.setData({
 
-       keyword: ''
 
-     })
 
-   },
 
-   blur: function() {
 
-     var that = this
 
-     setTimeout(function() {
 
-       that.search()
 
-     }, 300)
 
-   },
 
-   search: function() {
 
-     var that = this
 
-     if(!this.data.keyword && this.data.type == 'create') return false;
 
-     var data = {
 
-       keyword: this.data.keyword
 
-     }
 
-     if(this.type == 'edit') {
 
-       data = {
 
-         keyword: this.data.keyword,
 
-         id: this.data.project_user.user_id
 
-       }
 
-     }
 
-     http({
 
-       url: 'users/search',
 
-       data: data,
 
-       success: function(res) {
 
-         if(res.code == 0) {
 
-           if(res.data.length <= 0) {
 
-             util.error('未找到相应用户')
 
-           }
 
-           that.setData({
 
-             users: res.data
 
-           })
 
-           that.getProjects()
 
-         }
 
-       }
 
-     })
 
-   },
 
-   bindPickerChange: function(e) {
 
-     var name = e.currentTarget.dataset.name
 
-     this.setData({
 
-       [name]: e.detail.value
 
-     })
 
-   },
 
-   getRoles: function() {
 
-     var that = this
 
-     http({
 
-       url: 'project-roles/getByExclude',
 
-       data: {
 
-         id: this.data.id
 
-       },
 
-       success: function(res) {
 
-         if(res.code == 0) {
 
-           that.setData({
 
-             roles: res.data
 
-           })
 
-           if(that.data.type == 'edit') that.updateIndex()
 
-         }
 
-       }
 
-     })
 
-   },
 
-   getProjects: function() {
 
-     var that = this
 
-     var users = this.data.users
 
-     var user_id = ''
 
-     if(users.length > 0) {
 
-       user_id = users[0].id
 
-     }
 
-     http({
 
-       url: 'projects/getAll',
 
-       data: {
 
-         user_id: user_id,
 
-         self: true
 
-       },
 
-       success: function(res) {
 
-         if(res.code == 0) {
 
-           that.setData({
 
-             projects: res.data,
 
-             projectIndex: -1
 
-           })
 
-           if(that.data.type == 'edit') that.updateIndex()
 
-         }
 
-       }
 
-     })
 
-   },
 
-   updateInput: function(e) {
 
-     var name = e.currentTarget.dataset.name
 
-     this.setData({
 
-       [name]: e.detail.value
 
-     })
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面初次渲染完成
 
-    */
 
-   onReady: function () {
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面显示
 
-    */
 
-   onShow: function () {
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面隐藏
 
-    */
 
-   onHide: function () {
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面卸载
 
-    */
 
-   onUnload: function () {
 
-   },
 
-   /**
 
-    * 页面相关事件处理函数--监听用户下拉动作
 
-    */
 
-   onPullDownRefresh: function () {
 
-   },
 
-   /**
 
-    * 页面上拉触底事件的处理函数
 
-    */
 
-   onReachBottom: function () {
 
-   },
 
-   /**
 
-    * 用户点击右上角分享
 
-    */
 
-   onShareAppMessage: function () {
 
-   }
 
- })
 
 
  |