oaComment.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. mbui.define(['tool','layer','userPicker','loadData'], function (exports) {
  2. const layer = mbui.layer, tool = mbui.tool,userPicker = mbui.userPicker,loadData = mbui.loadData;
  3. const obj = {
  4. comment_box:'comment_box',
  5. module:'module',
  6. topic_id:'topic_id',
  7. load: function (comment_box,module,topic_id) {
  8. let that = this;
  9. that.comment_box=comment_box;
  10. that.module=module;
  11. that.topic_id=topic_id;
  12. loadData({
  13. url:'/api/comment/datalist',
  14. elem:'#'+comment_box,
  15. where: {topic_id: topic_id, module: module},
  16. limit:100,
  17. template:function(data){
  18. let to_names = '', ops = '' ,ptext='';
  19. if (data.to_names !='') {
  20. to_names = `<span class="text-blue">@${data.to_names}</span>`;
  21. }
  22. if (data.admin_id == login_admin) {
  23. ops = `<span class="mbui-btn mbui-btn-primary xs" data-event="edit" data-id="${data.id}">编辑</span><span class="mbui-btn mbui-btn-primary xs" data-event="del" data-id="${data.id}">删除</span>`;
  24. }
  25. else{
  26. ops = `<span class="mbui-btn mbui-btn-primary xs" data-event="replay" data-id="${data.id}" data-uid="${data.admin_id}" data-unames="${data.name}">回复</span>`;
  27. }
  28. if(data.pid>0){
  29. ptext=`<div style="padding-bottom:8px;"><fieldset><legend>回复『${data.padmin}』${data.ptimes}的评论</legend>${data.pcontent}</fieldset></div>`;
  30. }
  31. let listItem = `
  32. <div id="comment_${data.id}" class="mbui-comment-box border-bottom" data-content="${data.content}">
  33. <div class="comment-avatar" title="${data.name}">
  34. <img class="comment-image" src="${data.thumb}">
  35. </div>
  36. <div class="comment-body">
  37. <div class="comment-meta">
  38. <span class="comment-name">${data.name}</span><span title="${data.create_time}">${data.create_times}${data.update_times}</span>
  39. </div>
  40. <div class="comment-content">${to_names} ${data.content}</div>
  41. ${ptext}
  42. <div class="comment-btn mbui-btn-group">${ops}</div>
  43. </div>
  44. </div>
  45. `;
  46. return listItem;
  47. }
  48. });
  49. },
  50. add: function (topic_id, module,content,to_uids,pid) {
  51. let that = this;
  52. let callback = function (res) {
  53. layer.closeAll();
  54. that.load(that.comment_box,that.module,that.topic_id);
  55. }
  56. if (content == '') {
  57. layer.msg('请完善评论内容');
  58. return false;
  59. }
  60. let postData = { module: module,topic_id: topic_id, content: content, to_uids: to_uids, pid: pid};
  61. tool.post("/api/comment/add", postData, callback);
  62. },
  63. edit: function (id,content) {
  64. let that = this;
  65. let callback = function (res) {
  66. layer.closeAll();
  67. that.load(that.comment_box,that.module,that.topic_id);
  68. }
  69. if (content == '') {
  70. layer.msg('请完善评论内容');
  71. return false;
  72. }
  73. let postData = {id: id, content: content};
  74. tool.post("/api/comment/add", postData, callback);
  75. },
  76. del: function (id) {
  77. let that = this;
  78. layer.confirm('确定删除该评论吗?', function (index) {
  79. let callback = function (e) {
  80. layer.msg(e.msg);
  81. if (e.code == 0) {
  82. that.load(that.comment_box,that.module,that.topic_id);
  83. }
  84. }
  85. tool.delete("/api/comment/del", { id: id }, callback);
  86. layer.close(index);
  87. });
  88. },
  89. //文本
  90. textarea: function (id, topic_id, module, content, to_uids, to_unames, pid) {
  91. let that = this;
  92. let usersInput='';
  93. if(id==0){
  94. usersInput='<div class="mbui-input-wrap" style="margin-bottom:5px;"><div class="mbui-input-prefix"><i class="mbui-icon mbui-icon-at"></i></div><input type="text" placeholder="@ 要提醒的员工" value="'+to_unames+'" readonly class="mbui-input picker-admin" data-type="2" /><input type="hidden" id="to_uids" value="'+to_uids+'" /></div>';
  95. }
  96. layer.open({
  97. type:5,
  98. title: '请输入评论内容',
  99. content: '<div style="padding:0 6px 6px;">'+usersInput+'<textarea class="mbui-textarea" id="editTextarea" style="width: 100%; height: 100px;">'+content+'</textarea></div>',
  100. btn:['确定','取消'],
  101. yes:function(index){
  102. let content = $("#editTextarea").val();
  103. if (content != '') {
  104. if(id>0){
  105. that.edit(id, content);
  106. }
  107. else{
  108. let to_uids = $("#to_uids").val();
  109. that.add(topic_id, module, content, to_uids, pid);
  110. }
  111. } else {
  112. layer.msg('请输入评论内容');
  113. }
  114. }
  115. });
  116. }
  117. };
  118. exports('oaComment', obj);
  119. });