config.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'upload'], function ($, undefined, Backend, Table, Form, Upload) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. search: true,
  7. advancedSearch: true,
  8. pagination: true,
  9. extend: {
  10. "index_url": "kefu/config/index",
  11. "add_url": "",
  12. "edit_url": "",
  13. "del_url": "",
  14. "multi_url": "",
  15. }
  16. });
  17. Form.api.bindevent($("form[role=form]"));
  18. $('input[name="row[csr_admin]"]').data("eSelect", function () {
  19. Controller.api.build_csr_config()
  20. });
  21. $('input[name="row[csr_admin]"]').data("eTagRemove", function (data) {
  22. if (!Controller.selectPageReady) {
  23. Controller.selectPageReady = true;
  24. } else {
  25. Controller.api.build_csr_config()
  26. }
  27. });
  28. $(document).on('click', '.run_config', function () {
  29. Fast.api.open("addon/config?name=kefu", __('Setting'));
  30. });
  31. $('input[name="row[csr_distribution]"]').on('change', function (that) {
  32. var csr_distribution = $(that.target).val();
  33. var tis = '';
  34. if (csr_distribution == 0) {
  35. tis = '按工作强度:优先分配给当前接待量最少的客服,若有多个客服接待量相同,则分配给其中最久未进行接待的客服';
  36. } else if (csr_distribution == 1) {
  37. tis = '智能分配:根据接待上限和当前接待量,分配给最能接待的客服';
  38. } else if (csr_distribution == 2) {
  39. tis = '轮流分配:每次都分配给最久未进行接待的客服';
  40. }
  41. $('#distribution_help').html(tis);
  42. })
  43. },
  44. selectPageReady: false,
  45. api: {
  46. build_csr_config: function () {
  47. var csr = $('input[name="row[csr_admin]"]').selectPageText();
  48. var csrs = csr.split(",");
  49. for (var i = 0; i < csrs.length; i++) {
  50. Controller.api.build_csr_input(csrs[i]);
  51. }
  52. // 删除-获取已构建的配置框
  53. var csr_config_list = $('#csr_config').children("div");
  54. var csr_config_length = $('#csr_config').children("div").length;
  55. if (csrs.length) {
  56. for (var i = 0; i < csr_config_length; i++) {
  57. let csr = $(csr_config_list[i]).data('name').toString();
  58. if (csrs.indexOf(csr) == -1) {
  59. Controller.api.build_csr_input(csr, true);
  60. }
  61. }
  62. } else {
  63. for (let i in csr_config_length) {
  64. let csr = $(csr_config_list[i]).data('name')
  65. Controller.api.build_csr_input(csr, true);
  66. }
  67. }
  68. },
  69. build_csr_input: function (username, is_del = false) {
  70. if (!username) {
  71. return;
  72. }
  73. var csr_item = $('#csr_config').children("[data-name='" + username + "']");
  74. if (is_del && csr_item.length) {
  75. // 删除
  76. csr_item.remove();
  77. return;
  78. } else if (csr_item.length) {
  79. return;
  80. }
  81. var el = $('\
  82. <div data-name="' + username + '">\
  83. <div class="form-group">\
  84. <label class="control-label">' + username + ':</label>\
  85. <div class="input-group">\
  86. <div class="input-group-addon">接待上限</div>\
  87. <input class="form-control" name="row[csr_config][' + username + ']" placeholder="请输入接待上限人数" value="1" />\
  88. <div class="input-group-addon">人</div>\
  89. </div>\
  90. </div>\
  91. </div>\
  92. ');
  93. $('#csr_config').append(el)//插入
  94. }
  95. }
  96. };
  97. return Controller;
  98. })