闫增涛
2025-04-14 4a0006c0b8df5befabf7403c0702f4429cf244e3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<div class="bg-white">
    <table class="layui-hide" id="user" lay-filter="user"></table>
</div>
<script type="text/html" id="toolbaruser">
  <div class="layui-btn-container">
      <button class="layui-btn layui-btn-sm" lay-event="add">+ 新增项目成员</button>
  </div>
</script>
<script>
function project_user(){
    if($('#projectTab').find('li').eq(4).data('load') =='true'){
        return false;
    }
    $('#projectTab').find('li').eq(4).data('load','true');
    let tool = layui.tool, table = layui.tablePlus,oaPicker = layui.oaPicker;
    //项目成员
    layui.userTable = table.render({
        elem: '#user',
        title: '项目成员列表',
        cellMinWidth: 60,
        toolbar: '#toolbaruser',
        url: "/project/api/project_user", //数据接口
        where: { 'tid': project_id },
        page: false, //开启分页
        limit: 20,
        cols: [[ //表头
            { field: 'name', fixed: 'left', title: '成员姓名', width: 90, align: 'center', rowspan: 2 }
            , { field: 'create_time', title: '进入项目日期', width: 110, align: 'center', rowspan: 2 }
            , { field: 'role', title: '角色', align: 'center', width: 90, rowspan: 2, templet: function (d) {
                var html='<span style="color: #4285F4;">普通成员</span>';
                if(d.role==1){
                    html='<span style="color: #EE6666;">项目创建人</span>';
                }
                if(d.role==2){
                    html='<span style="color: #91CC75;">项目负责人</span>';
                }
                return html;
            }}
            , { field: 'position', title: '职位', align: 'center', width: 100, rowspan: 2 }
            , { field: 'department', title: '所在部门', align: 'center', width: 120, rowspan: 2 }
            , { field: 'mobile', title: '手机号码', align: 'center', width: 110, rowspan: 2 }
            , { align: 'center', title: '工作记录', colspan: 2 }
            , { align: 'center', title: '项目任务', colspan: 3 }
            , { field: 'delete_time', title: '移除日期', align: 'center', minWidth: 120, rowspan: 2 }
            , { field: 'status',fixed: 'right', title: '状态', align: 'center', width: 60, rowspan: 2, templet: function (d) {
                    var html = '<span style="color:#EE6666">✘</span>';
                    if(d.delete_time == '-')
                        html = '<span style="color:#91CC75">✔</span>';
                    return html;
                }}                
            , {title: '操作',fixed: 'right', align: 'center', width: 60, rowspan: 2, templet: function (d) {
                    var html = '<span class="layui-btn layui-btn-xs" lay-event="recover">恢复</span>';
                    if(d.delete_time == '-')
                        html = '<span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="remove">移除</span>';
                    return html;
                }
            }
        ], [
            { field: 'schedules', align: 'center', style: 'color: #91CC75;', width: 72, 'title': '记录' }
            , { field: 'labor_times', align: 'center', style: 'color: #4285F4;', width: 70, 'title': '工时' }
            , { field: 'tasks_unfinish', align: 'center', style: 'color: #91CC75;', width: 72, 'title': '进行中' }
            , { field: 'tasks_finish', align: 'center', style: 'color: #FAC858;', width: 70, 'title': '已完成' }
            , { field: 'tasks_pensent', align: 'center', style: 'color: #EE6666;', width: 72, 'title': '完成率' }
        ]]
    });
    
    //触发事件
    table.on('toolbar(user)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event){
            case 'add':
              oaPicker.employeeInit({
                type: 1,
                callback: function (data) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if(e.code == 0){
                            layui.userTable.reload();
                        }                        
                    }
                    let select_id=[];
                    for(var a=0; a<data.length;a++){
                        select_id.push(data[a].id);
                    }
                    let ids = select_id.join(',');
                    tool.post("/project/api/add_user", {uid: ids,project_id: project_id}, callback);
                }
            })            
            break;
        };
    });
 
    //监听行工具事件
    table.on('tool(user)', function (obj) {
        let postData = { "id": obj.data.id };
        let callback = function (e) {
                layer.closeAll();
                layer.msg(e.msg);
                if(e.code == 0){
                    layui.userTable.reload();
                }
            }
        if (obj.event === 'remove') {
            layer.confirm('确定要移除该项目成员吗?', { icon: 3, title: '提示' }, function (index) {
                tool.delete("/project/api/remove_user", postData, callback);
            });
        }
        if (obj.event === 'recover') {
            layer.confirm('确定要恢复该项目成员吗?', { icon: 3, title: '提示' }, function (index) {
                tool.post("/project/api/recover_user", postData, callback);
            });
        }
        return;
    });
}
</script>