contacts.js 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/weixin/contacts/index',
  8. del_url : 'qingdongams/weixin/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 : 'mobile', title : __('手机号')},
  23. {field : 'remarks', title : __('备注'),operate:false},
  24. {field : 'ownerstaff.name', title : __('负责人'),operate:false},
  25. {field: 'status', title: __('状态'), formatter: Table.api.formatter.status, searchList: {0: __('未同步'), 1: __('已同步')}, operate: false},
  26. {field: 'createtime', title: __('创建时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  27. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  28. ]
  29. ],
  30. search:false,
  31. //启用普通表单搜索
  32. commonSearch : true,
  33. searchFormVisible : false,
  34. onLoadSuccess:function(){
  35. // 这里就是数据渲染结束后的回调函数
  36. $('.btn-editone').html('编辑');
  37. $('.fa-pencil').remove();
  38. $('.btn-delone').html('删除');
  39. $('.fa-trash').remove();
  40. $('.btn-editone').removeClass('btn-success')
  41. $('.btn-editone').removeClass('btn')
  42. $('.btn-delone').removeClass('btn')
  43. $('.btn-delone').removeClass('btn-danger')
  44. }
  45. });
  46. //同步到CRM中
  47. $(document).on("click", ".batchall", function () {
  48. Layer.confirm("请确认是否同步", {
  49. title : '批量同步',
  50. btn : [ "是","否"],
  51. success : function (layero, index) {
  52. $(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
  53. }
  54. , yes : function (index, layero) {
  55. var windex = layer.load();
  56. $.post('qingdongams/weixin/contacts/batch', {}, function (res) {
  57. Layer.alert(res.msg);
  58. Layer.close(index);
  59. Layer.close(windex);
  60. table.bootstrapTable('refresh');
  61. }, 'json');
  62. }
  63. ,
  64. btn2 : function (index, layero) {
  65. Layer.close(index);
  66. }
  67. })
  68. });
  69. // 为表格绑定事件
  70. Table.api.bindevent(table);
  71. },
  72. edit: function () {
  73. Controller.api.bindevent();
  74. },
  75. api: {
  76. bindevent: function () {
  77. Form.api.bindevent($("form[role=form]"));
  78. },
  79. formatter: {
  80. title: function (value, row, index) {
  81. value = value.toString().replace(/(&|&)nbsp;/g, ' ');
  82. return value;
  83. },
  84. },
  85. }
  86. };
  87. return Controller;
  88. });