view_user.html 4.2 KB

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