contacts.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'qingdongams/dingding/contacts/index',
  8. del_url : 'qingdongams/dingding/contacts/del',
  9. table: 'contacts',
  10. }
  11. });
  12. var table = $("#table");
  13. // 初始化表格
  14. table.bootstrapTable({
  15. url : $.fn.bootstrapTable.defaults.extend.index_url,
  16. sortName : 'id',
  17. columns : [
  18. [
  19. {checkbox: true},
  20. {field : 'customer.name', title : __('客户名称'),operate:false},
  21. {field : 'name', title : __('姓名')},
  22. {field : 'post', title : __('职务')},
  23. {field : 'email', title : __('邮箱')},
  24. {field : 'mobile', title : __('手机号')},
  25. {field : 'remarks', title : __('备注'),operate:false},
  26. {field : 'ownerstaff.name', title : __('负责人'),operate:false},
  27. {field: 'status', title: __('状态'), formatter: Table.api.formatter.status, searchList: {0: __('未同步'), 1: __('已同步')}, operate: false},
  28. {field: 'createtime', title: __('创建时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  29. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  30. ]
  31. ],
  32. search:false,
  33. //启用普通表单搜索
  34. commonSearch : true,
  35. searchFormVisible : false,
  36. onLoadSuccess:function(){
  37. // 这里就是数据渲染结束后的回调函数
  38. $('.btn-editone').html('编辑');
  39. $('.fa-pencil').remove();
  40. $('.btn-delone').html('删除');
  41. $('.fa-trash').remove();
  42. $('.btn-editone').removeClass('btn-success')
  43. $('.btn-editone').removeClass('btn')
  44. $('.btn-delone').removeClass('btn')
  45. $('.btn-delone').removeClass('btn-danger')
  46. }
  47. });
  48. //获取钉钉数据
  49. $(document).on("click", ".batch", function () {
  50. Layer.confirm("请确认是否同步", {
  51. title : '批量同步',
  52. btn : ["是","否"],
  53. success : function (layero, index) {
  54. $(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
  55. }
  56. , yes : function (index, layero) {
  57. var dindex = layer.load();
  58. $.post('qingdongams/dingding/dingding/contacts', {}, function (res) {
  59. Layer.alert(res.msg);
  60. Layer.close(index);
  61. Layer.close(dindex);
  62. table.bootstrapTable('refresh');
  63. }, 'json');
  64. }
  65. ,
  66. btn2 : function (index, layero) {
  67. Layer.close(index);
  68. }
  69. })
  70. });
  71. //同步到CRM中
  72. $(document).on("click", ".batchall", function () {
  73. Layer.confirm("请确认是否同步", {
  74. title : '批量同步',
  75. btn : [ "是","否"],
  76. success : function (layero, index) {
  77. $(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
  78. }
  79. , yes : function (index, layero) {
  80. var dindex = layer.load();
  81. $.post('qingdongams/dingding/contacts/batch', {}, function (res) {
  82. Layer.alert(res.msg);
  83. Layer.close(index);
  84. Layer.close(dindex);
  85. table.bootstrapTable('refresh');
  86. }, 'json');
  87. }
  88. ,
  89. btn2 : function (index, layero) {
  90. Layer.close(index);
  91. }
  92. })
  93. });
  94. // 为表格绑定事件
  95. Table.api.bindevent(table);
  96. },
  97. edit: function () {
  98. Controller.api.bindevent();
  99. },
  100. api: {
  101. bindevent: function () {
  102. Form.api.bindevent($("form[role=form]"));
  103. },
  104. formatter: {
  105. title: function (value, row, index) {
  106. value = value.toString().replace(/(&|&)nbsp;/g, ' ');
  107. return value;
  108. },
  109. },
  110. }
  111. };
  112. return Controller;
  113. });