123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- // 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
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.getProjects()
- this.getRoles()
- },
- 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;
- http({
- url: 'projects/addUser',
- data: {
- user_id: user_id,
- project_id: project_id,
- project_role_id: role_id
- },
- 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) return false;
- http({
- url: 'users/search',
- data: {
- keyword: this.data.keyword
- },
- success: function(res) {
- if(res.code == 0) {
- if(res.data.length <= 0) {
- util.error('未找到相应用户')
- }
- that.setData({
- users: res.data
- })
- }
- }
- })
- },
- bindPickerChange: function(e) {
- var name = e.currentTarget.dataset.name
- this.setData({
- [name]: e.detail.value
- })
- },
- getRoles: function() {
- var that = this
- http({
- url: 'project-roles/getAll',
- data: {},
- success: function(res) {
- if(res.code == 0) {
- that.setData({
- roles: res.data
- })
- }
- }
- })
- },
- getProjects: function() {
- var that = this
- http({
- url: 'projects/getAll',
- data: {},
- success: function(res) {
- if(res.code == 0) {
- that.setData({
- projects: res.data
- })
- }
- }
- })
- },
- 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 () {
- }
- })
|