leads.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index : function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. });
  7. //绑定事件
  8. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  9. var panel = $($(this).attr("href"));
  10. if (panel.length > 0) {
  11. Controller.table[panel.attr("id")].call(this);
  12. $(this).on('click', function (e) {
  13. $($(this).attr("href")).find(".btn-refresh").trigger("click");
  14. });
  15. }
  16. //移除绑定的事件
  17. $(this).unbind('shown.bs.tab');
  18. });
  19. //必须默认触发shown.bs.tab事件
  20. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  21. $(document).on('click', '.show-detail', function (data) {
  22. var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
  23. var options = {
  24. shadeClose : false,
  25. shade : [0.3, '#393D49'],
  26. area : area,
  27. callback : function (value) {
  28. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  29. console.log(value);
  30. }
  31. };
  32. Fast.api.open($.fn.bootstrapTable.defaults.extend.detail_url + "?ids=" + $(this).data('id'), '线索详情', options);
  33. });
  34. //导入
  35. $(document).on('click','.btn-imports',function () {
  36. Fast.api.open("qingdong/customer/leads/import", "线索导入",{
  37. shadeClose: false,
  38. shade: false,
  39. maxmin: false,
  40. moveOut: false,
  41. scrollbars:false,
  42. 'area':[
  43. $(window).width() > 800 ? '600px' : '400px',
  44. $(window).height() > 600 ? '500px' : '400px'
  45. ],
  46. callback:function(value){
  47. Form.events.plupload("#plupload-local");
  48. // 在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
  49. },
  50. });
  51. });
  52. //导出
  53. $(document).on("click", ".btn-export", function () {
  54. var tab_id=$('.active.in').attr('id');
  55. var table;
  56. switch (tab_id){
  57. case 'first'://全部
  58. table=$('#table');
  59. break;
  60. case 'second'://我负责的
  61. table=$('#table1');
  62. break;
  63. case 'third'://下属负责的
  64. table=$('#table2');
  65. break;
  66. case 'four'://今日待跟进
  67. table=$('#table3');
  68. break;
  69. case 'five'://今日已跟进
  70. table=$('#table4');
  71. break;
  72. case 'six'://从未跟进的
  73. table=$('#table5');
  74. break;
  75. }
  76. var ids = Table.api.selectedids(table);
  77. var page = table.bootstrapTable('getData');
  78. var options = table.bootstrapTable('getOptions');
  79. var all = options.totalRows;
  80. var params=options.queryParams({});
  81. var sort = options.sortName+' '+options.sortOrder;
  82. var filter = params.filter;
  83. var op = params.op;
  84. Layer.confirm("请选择导出的选项", {
  85. title : '导出数据',
  86. btn : ["选中项(" + ids.length + "条)", "本页(" + page.length + "条)", "全部(" + all + "条)"],
  87. success : function (layero, index) {
  88. $(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
  89. }, yes : function (index, layero) {
  90. if (ids.length == 0) {
  91. Layer.alert('数据为空');
  92. return true;
  93. }
  94. $.post('qingdong/customer/leads/export', {sort:sort,ids : ids.join(","), isall : 1}, function (res) {
  95. Layer.alert(res.msg);
  96. window.location.href = res.data.filePath;
  97. Layer.close(index);
  98. table.bootstrapTable('refresh');
  99. }, 'json');
  100. return false;
  101. },
  102. btn2 : function (index, layero) {
  103. if (page.length == 0) {
  104. Layer.alert('数据为空');
  105. return true;
  106. }
  107. var ids = [];
  108. $.each(page, function (i, j) {
  109. ids.push(j.id);
  110. });
  111. $.post('qingdong/customer/leads/export', {sort:sort,ids : ids.join(","), isall : 2}, function (res) {
  112. Layer.alert(res.msg);
  113. window.location.href = res.data.filePath;
  114. Layer.close(index);
  115. table.bootstrapTable('refresh');
  116. }, 'json');
  117. return false;
  118. },
  119. btn3 : function (index, layero) {
  120. if (page.length == 0) {
  121. Layer.alert('数据为空');
  122. return true;
  123. }
  124. $.post('qingdong/customer/leads/export?filter='+filter+'&op='+op, {sort:sort,ids : ids.join(","), isall : 3}, function (res) {
  125. Layer.alert(res.msg);
  126. window.location.href = res.data.filePath;
  127. Layer.close(index);
  128. table.bootstrapTable('refresh');
  129. }, 'json');
  130. return false;
  131. }
  132. })
  133. });
  134. },
  135. tableinfo:{
  136. toolbar: '#toolbar',
  137. pk: 'id',
  138. sortName: 'id',
  139. fixedColumns: true,
  140. fixedNumber: 2,
  141. fixedRightNumber: 1,
  142. search: false,
  143. searchFormVisible: true,
  144. columns: [
  145. [
  146. {checkbox: true},
  147. {
  148. field: 'name',
  149. title: '线索名称',
  150. fixedColumns: true,
  151. formatter: function (value, row, index) {
  152. if (value == '') {
  153. value = '无';
  154. }
  155. return "<a href='javascript:void(0);' data-id='" + row.id + "' class='show-detail'>" + value + "</a>";
  156. }, operate: "like"
  157. },
  158. {
  159. field: 'source', title: '线索来源', fixedColumns: true, operate: "like"
  160. },
  161. {field: 'owner_staff.name', title: '负责人', operate: false},
  162. {field: 'telephone', title: '电话', operate: "like"},
  163. {field: 'mobile', title: '手机', operate: "like"},
  164. {field: 'industry', title: '客户行业'},
  165. {field: 'level', title: '客户星级', operate: false},
  166. {field: 'address_detail', title: '地址', operate: false},
  167. {field: 'next_time', title: '下次联系时间', operate: 'RANGE',addclass: 'datetimerange',autocomplete:false,
  168. formatter: Table.api.formatter.datetime},
  169. {field: 'remarks', title: '备注信息', operate: false},
  170. {
  171. field: 'createtime',
  172. title: __('Createtime'),
  173. operate: 'RANGE',
  174. addclass: 'datetimerange',autocomplete:false,
  175. formatter: Table.api.formatter.datetime
  176. },
  177. {field: 'updatetime', title: '更新时间', operate: false},
  178. {
  179. field: 'operate2', title: __('Operate'),operate: false, events: {
  180. 'click .btn-chooseone': function (e, value, row, index) {
  181. Fast.api.close({id: row.id, name: row.name});
  182. },
  183. }, formatter: function () {
  184. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  185. }},
  186. {
  187. field: 'operate',
  188. title: __('Operate'),
  189. events: Table.api.events.operate,
  190. formatter: Table.api.formatter.buttons,
  191. buttons: [
  192. {
  193. name: 'edit',
  194. text: __('编辑'),
  195. title: __('编辑'),
  196. extend: 'data-area=["80%","80%"]',
  197. classname: 'records btn-dialog',
  198. url: 'qingdong/customer/leads/edit',
  199. visible: function (row) {
  200. //返回true时按钮显示,返回false隐藏
  201. return true;
  202. }
  203. },
  204. {
  205. name: 'detail',
  206. text: __('跟进'),
  207. title: __('跟进'),
  208. extend: 'data-area=["80%","80%"]',
  209. classname: 'records btn-dialog',
  210. url: 'qingdong/leads/record/add',
  211. visible: function (row) {
  212. //返回true时按钮显示,返回false隐藏
  213. return true;
  214. }
  215. }
  216. ]
  217. }
  218. ]
  219. ],
  220. onLoadSuccess: function () {
  221. // 这里就是数据渲染结束后的回调函数
  222. $(".btn-add").data("area", ["80%", "80%"]);
  223. $(".btn-edit").data("area", ["80%", "80%"]);
  224. }
  225. },
  226. table: {
  227. first : function() {
  228. // 初始化表格参数配置
  229. Table.api.init({
  230. extend : {
  231. add_url : 'qingdong/customer/leads/add',
  232. detail_url : 'qingdong/customer/leads/detail',
  233. table : 'lead',
  234. }
  235. });
  236. if(Config.fields !='[]'){
  237. if (Config.fields && Object.keys(Config.fields).length > 0) {
  238. var fields = JSON.parse(Config.fields);
  239. var start = Controller.tableinfo.columns[0].length-2;
  240. for (var i = 0; i < fields.length; i++) {
  241. if (fields[i].hasOwnProperty('formatter'))
  242. fields[i].formatter = eval(fields[i].formatter);
  243. if (fields[i].hasOwnProperty('events'))
  244. fields[i].events = eval(fields[i].events);
  245. if (fields[i].hasOwnProperty('searchList'))
  246. fields[i].searchList = JSON.parse(fields[i].searchList);
  247. Controller.tableinfo.columns[0].splice(start + i, 0, fields[i]);
  248. }
  249. }
  250. }
  251. const q = {};
  252. location.search.replace(/([^?&=]+)=([^&]+)/g,function(_,k,v){q[k]=v});
  253. var table = $("#table");
  254. Controller.tableinfo.url=location.href+'&type=0';
  255. Controller.tableinfo.toolbar='#toolbar';
  256. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  257. if (q.isselect == 1) {
  258. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length - 1].visible = false;
  259. } else {
  260. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length - 2].visible = false;
  261. }
  262. // 初始化表格
  263. table.bootstrapTable(Controller.tableinfo);
  264. // 为表格绑定事件
  265. Table.api.bindevent(table);
  266. },
  267. second : function () {
  268. var table = $("#table1");
  269. Controller.tableinfo.url=location.href+'&type=1';
  270. Controller.tableinfo.toolbar='#toolbar1';
  271. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  272. // 初始化表格
  273. table.bootstrapTable(Controller.tableinfo);
  274. // 为表格绑定事件
  275. Table.api.bindevent(table);
  276. },
  277. third : function () {
  278. var table = $("#table2");
  279. Controller.tableinfo.url=location.href+'&type=2';
  280. Controller.tableinfo.toolbar='#toolbar2';
  281. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  282. // 初始化表格
  283. table.bootstrapTable(Controller.tableinfo);
  284. // 为表格绑定事件
  285. Table.api.bindevent(table);
  286. },
  287. four : function () {
  288. var table = $("#table3");
  289. Controller.tableinfo.url=location.href+'&type=3';
  290. Controller.tableinfo.toolbar='#toolbar3';
  291. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  292. // 初始化表格
  293. table.bootstrapTable(Controller.tableinfo);
  294. // 为表格绑定事件
  295. Table.api.bindevent(table);
  296. },
  297. five : function () {
  298. var table = $("#table4");
  299. Controller.tableinfo.url=location.href+'&type=4';
  300. Controller.tableinfo.toolbar='#toolbar4';
  301. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  302. // 初始化表格
  303. table.bootstrapTable(Controller.tableinfo);
  304. // 为表格绑定事件
  305. Table.api.bindevent(table);
  306. },
  307. six : function () {
  308. var table = $("#table5");
  309. Controller.tableinfo.url=location.href+'&type=5';
  310. Controller.tableinfo.toolbar='#toolbar5';
  311. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  312. // 初始化表格
  313. table.bootstrapTable(Controller.tableinfo);
  314. // 为表格绑定事件
  315. Table.api.bindevent(table);
  316. },
  317. },
  318. add : function () {
  319. Controller.api.bindevent();
  320. },
  321. edit : function () {
  322. Controller.api.bindevent();
  323. },
  324. detail : function () {
  325. // 初始化表格参数配置
  326. Table.api.init({});
  327. //跟进记录
  328. var table1 = $("#records");
  329. // 初始化表格
  330. table1.bootstrapTable({
  331. url : 'qingdong/customer/record/index?leads_id='+Config.idinfo.id,
  332. pk : 'id',
  333. sortName : 'id',
  334. operate : false,
  335. commonSearch : false,
  336. search : false,
  337. visible : false,
  338. showColumns : false,
  339. showExport : false,
  340. showToggle : false,
  341. columns : [
  342. [
  343. {field: 'follow_type', title: __('跟进类型')},
  344. {field: 'follow_time', title: __('跟进时间')},
  345. {field: 'follow', title: __('跟进状态')},
  346. {field: 'content', title: __('跟进内容'),cellStyle:function (value,row,index,field) {
  347. return {
  348. css: {
  349. "min-width": "150px",
  350. "white-space": "nowrap",
  351. "text-overflow": "ellipsis",
  352. "overflow": "hidden",
  353. "max-width":"300px",
  354. 'cursor':"pointer"
  355. }
  356. };
  357. },formatter:function (value,row,index,field) {
  358. var span=document.createElement('span');
  359. span.setAttribute('title',value);
  360. span.innerHTML = value;
  361. return span.outerHTML;
  362. }
  363. },
  364. {field: 'next_time', title: __('下次跟进时间')},
  365. {
  366. field : 'operate',
  367. title : __('Operate'),
  368. table : table1,
  369. events : Table.api.events.operate,
  370. formatter : Table.api.formatter.operate,
  371. buttons : [
  372. {
  373. name : '详情',
  374. text : __('详情'),
  375. classname : 'records btn-dialog',
  376. url : 'qingdong/customer/record/detail',
  377. callback: function (data) {
  378. $('.btn-success').trigger('click');
  379. },
  380. }
  381. ]
  382. }
  383. ]
  384. ]
  385. });
  386. //操作日志
  387. var table2 = $("#operation_log");
  388. // 初始化表格
  389. table2.bootstrapTable({
  390. url : 'qingdong/customer/log/index?leads_id='+Config.idinfo.id,
  391. pk : 'id',
  392. sortName : 'id',
  393. operate : false,
  394. commonSearch : false,
  395. search : false,
  396. visible : false,
  397. showColumns : false,
  398. showExport : false,
  399. showToggle : false,
  400. columns : [
  401. [
  402. {field: 'staff.name', title: __('员工')},
  403. {field: 'content', title: __('内容'),cellStyle:function (value,row,index,field) {
  404. return {
  405. css: {
  406. "min-width": "150px",
  407. "white-space": "nowrap",
  408. "text-overflow": "ellipsis",
  409. "overflow": "hidden",
  410. "max-width":"300px",
  411. 'cursor':"pointer"
  412. }
  413. };
  414. },formatter:function (value,row,index,field) {
  415. var span=document.createElement('span');
  416. span.setAttribute('title',value);
  417. span.innerHTML = value;
  418. return span.outerHTML;
  419. }
  420. },
  421. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  422. ]
  423. ]
  424. });
  425. //附件
  426. $('#files').bootstrapTable({
  427. url : 'qingdong/customer/leads/get_file' + location.search,
  428. pk : 'id',
  429. sortName : 'id',
  430. operate : false,
  431. commonSearch : false,
  432. search : false,
  433. visible : false,
  434. showColumns : false,
  435. showExport : false,
  436. showToggle : false,
  437. columns : [
  438. [
  439. {field : 'name', title : '附件名称'},
  440. {field : 'size', title : '附件大小'},
  441. {field : 'staff.name', title : '上传人'},
  442. {
  443. field : 'file_path', title : '文件预览', events : Table.api.events.image, formatter : Table.api.formatter.image, operate : false
  444. },
  445. ]
  446. ]
  447. });
  448. //编辑
  449. $(document).on('click','.btn-edit',function () {
  450. var id=$('#ids').val();
  451. Fast.api.open("qingdong/customer/leads/edit?ids="+id, "线索编辑",{
  452. shadeClose: false,
  453. shade: false,
  454. maxmin: false,
  455. moveOut: false,
  456. scrollbars:false,
  457. callback:function () {
  458. location.reload()
  459. }
  460. });
  461. }).on('click',".btn-del",function(){//删除
  462. var id=$('#ids').val();
  463. Layer.confirm('确定删除当前线索吗?', {
  464. btn: ['确定','取消'],
  465. title: '提示',
  466. },function(index, layero){
  467. Fast.api.ajax("qingdong/customer/leads/del?ids="+id,function(data,ret){
  468. if(ret.code == 1){
  469. Layer.close(index);
  470. parent.location.reload();
  471. }
  472. },function(data,ret){
  473. });
  474. });
  475. }).on('click',".btn-convert-customer",function(){//转为客户
  476. var id=$('#ids').val();
  477. Layer.confirm('确认要将当前线索转为客户?', {
  478. btn: ['确定','取消'],
  479. title: '提示',
  480. },function(index, layero){
  481. Fast.api.ajax("qingdong/customer/leads/convert_customer?ids="+id,function(data,ret){
  482. if(ret.code == 1){
  483. Layer.close(index);
  484. parent.location.reload();
  485. }
  486. },function(data,ret){
  487. });
  488. });
  489. }).on('click',".btn-convert-leadpool",function(){//放入线索池
  490. var id=$('#ids').val();
  491. Layer.confirm('确认要将当前线索放入线索池?', {
  492. btn: ['确定','取消'],
  493. title: '提示',
  494. },function(index, layero){
  495. Fast.api.ajax("qingdong/customer/leads/movepool?ids="+id,function(data,ret){
  496. if(ret.code == 1){
  497. Layer.close(index);
  498. parent.location.reload();
  499. }
  500. },function(data,ret){
  501. });
  502. });
  503. });
  504. Controller.api.bindevent();
  505. },
  506. import : function () {
  507. Controller.api.bindevent();
  508. },
  509. transfer : function () {
  510. Controller.api.bindevent();
  511. },
  512. api : {
  513. bindevent : function () {
  514. Form.api.bindevent($("form[role=form]"), function(data, ret){
  515. //这里是表单提交处理成功后的回调函数,接收来自php的返回数据
  516. Fast.api.close(data);//这里是重点
  517. });
  518. }
  519. }
  520. };
  521. return Controller;
  522. });