leadspool.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. add_url : 'qingdong/customer/leadspool/add',
  8. detail_url : 'qingdong/customer/leadspool/detail',
  9. table : 'lead',
  10. }
  11. });
  12. var table = $("#table");
  13. // 初始化表格
  14. table.bootstrapTable({
  15. url: 'qingdong/customer/leadspool/index',
  16. pk: 'id',
  17. sortName: 'id',
  18. fixedColumns: true,
  19. fixedNumber: 2,
  20. fixedRightNumber: 1,
  21. search: false,
  22. searchFormVisible: true,
  23. columns: [
  24. [
  25. {checkbox: true},
  26. {
  27. field: 'name',
  28. title: '线索名称',
  29. fixedColumns: true,
  30. formatter: function (value, row, index) {
  31. if (value == '') {
  32. value = '无';
  33. }
  34. return "<a href='javascript:void(0);' data-id='" + row.id + "' class='show-detail'>" + value + "</a>";
  35. }
  36. },
  37. {
  38. field: 'source', title: '线索来源', fixedColumns: true
  39. },
  40. {field: 'telephone', title: '电话'},
  41. {field: 'mobile', title: '手机'},
  42. {field: 'industry', title: '客户行业'},
  43. {field: 'address_detail', title: '地址', operate: false},
  44. {field: 'remarks', title: '备注信息', operate: false},
  45. {field: 'create_staff.name', title: '创建人', operate: false},
  46. {
  47. field: 'createtime',
  48. title: __('Createtime'),
  49. operate: 'RANGE',
  50. addclass: 'datetimerange',
  51. formatter: Table.api.formatter.datetime
  52. },
  53. {
  54. field: 'operate',
  55. title: __('Operate'),
  56. table: table,
  57. events: Table.api.events.operate,
  58. formatter: Table.api.formatter.buttons,
  59. buttons: [
  60. {
  61. name: 'edit',
  62. text: __('编辑'),
  63. title: __('编辑'),
  64. extend: 'data-area=["80%","80%"]',
  65. classname: 'records btn-dialog',
  66. url: 'qingdong/customer/leads/edit',
  67. visible: function (row) {
  68. //返回true时按钮显示,返回false隐藏
  69. return true;
  70. }
  71. },
  72. {
  73. name: 'detail',
  74. text: __('跟进'),
  75. title: __('跟进'),
  76. extend: 'data-area=["80%","80%"]',
  77. classname: 'records btn-dialog',
  78. url: 'qingdong/leads/record/add',
  79. visible: function (row) {
  80. //返回true时按钮显示,返回false隐藏
  81. return true;
  82. }
  83. }
  84. ]
  85. }
  86. ]
  87. ],
  88. onLoadSuccess: function () {
  89. // 这里就是数据渲染结束后的回调函数
  90. $(".btn-add").data("area", ["80%", "80%"]);
  91. $(".btn-edit").data("area", ["80%", "80%"]);
  92. }
  93. });
  94. $(document).on('click', '.show-detail', function (data) {
  95. var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
  96. var options = {
  97. shadeClose : false,
  98. shade : [0.3, '#393D49'],
  99. area : area,
  100. callback : function (value) {
  101. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  102. console.log(value);
  103. }
  104. };
  105. Fast.api.open($.fn.bootstrapTable.defaults.extend.detail_url + "?ids=" + $(this).data('id'), '线索详情', options);
  106. });
  107. //导入
  108. $(document).on('click','.btn-imports',function () {
  109. Fast.api.open("qingdong/customer/leadspool/import", "线索导入",{
  110. shadeClose: false,
  111. shade: false,
  112. maxmin: false,
  113. moveOut: false,
  114. scrollbars:false,
  115. 'area':[
  116. $(window).width() > 800 ? '600px' : '400px',
  117. $(window).height() > 600 ? '500px' : '400px'
  118. ],
  119. callback:function(value){
  120. Form.events.plupload("#plupload-local");
  121. // 在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
  122. },
  123. });
  124. })
  125. //批量分配
  126. $(document).on('click','.btn-transfer',function () {
  127. //在templateView的模式下不能调用table.bootstrapTable('getSelections')来获取选中的ID,只能通过下面的Table.api.selectedids来获取
  128. if(Table.api.selectedids(table).length == 0){
  129. layer.alert('请选择要线索!');
  130. return false;
  131. }
  132. var ids=JSON.stringify(Table.api.selectedids(table));
  133. Fast.api.open("qingdong/customer/leadspool/transfer?ids="+ids, "批量分配线索",{
  134. shadeClose: false,
  135. shade: false,
  136. maxmin: false,
  137. moveOut: false,
  138. scrollbars:false,
  139. 'area':[
  140. $(window).width() > 800 ? '600px' : '400px',
  141. $(window).height() > 600 ? '500px' : '400px'
  142. ],
  143. callback:function(value){
  144. Form.events.plupload("#plupload-local");
  145. // 在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
  146. },
  147. });
  148. });
  149. // 为表格绑定事件
  150. Table.api.bindevent(table);
  151. },
  152. add : function () {
  153. Controller.api.bindevent();
  154. },
  155. edit : function () {
  156. Controller.api.bindevent();
  157. },
  158. detail : function () {
  159. // 初始化表格参数配置
  160. Table.api.init({});
  161. //跟进记录
  162. var table1 = $("#records");
  163. // 初始化表格
  164. table1.bootstrapTable({
  165. url : 'qingdong/customer/record/index?leads_id='+Config.idinfo.id,
  166. pk : 'id',
  167. sortName : 'id',
  168. operate : false,
  169. commonSearch : false,
  170. search : false,
  171. visible : false,
  172. showColumns : false,
  173. showExport : false,
  174. showToggle : false,
  175. columns : [
  176. [
  177. {field: 'follow_type', title: __('跟进类型')},
  178. {field: 'follow_time', title: __('跟进时间')},
  179. {field: 'follow', title: __('跟进状态')},
  180. {field: 'content', title: __('跟进内容'),cellStyle:function (value,row,index,field) {
  181. return {
  182. css: {
  183. "min-width": "150px",
  184. "white-space": "nowrap",
  185. "text-overflow": "ellipsis",
  186. "overflow": "hidden",
  187. "max-width":"300px",
  188. 'cursor':"pointer"
  189. }
  190. };
  191. },formatter:function (value,row,index,field) {
  192. var span=document.createElement('span');
  193. span.setAttribute('title',value);
  194. span.innerHTML = value;
  195. return span.outerHTML;
  196. }
  197. },
  198. {field: 'next_time', title: __('下次跟进时间')},
  199. {
  200. field : 'operate',
  201. title : __('Operate'),
  202. table : table1,
  203. events : Table.api.events.operate,
  204. formatter : Table.api.formatter.operate,
  205. buttons : [
  206. {
  207. name : '详情',
  208. text : __('详情'),
  209. classname : 'records btn-dialog',
  210. url : 'qingdong/customer/record/detail',
  211. callback: function (data) {
  212. $('.btn-success').trigger('click');
  213. },
  214. }
  215. ]
  216. }
  217. ]
  218. ]
  219. });
  220. //操作日志
  221. var table2 = $("#operation_log");
  222. // 初始化表格
  223. table2.bootstrapTable({
  224. url : 'qingdong/customer/log/index?leads_id='+Config.idinfo.id,
  225. pk : 'id',
  226. sortName : 'id',
  227. operate : false,
  228. commonSearch : false,
  229. search : false,
  230. visible : false,
  231. showColumns : false,
  232. showExport : false,
  233. showToggle : false,
  234. columns : [
  235. [
  236. {field: 'staff.name', title: __('员工')},
  237. {field: 'content', title: __('内容'),cellStyle:function (value,row,index,field) {
  238. return {
  239. css: {
  240. "min-width": "150px",
  241. "white-space": "nowrap",
  242. "text-overflow": "ellipsis",
  243. "overflow": "hidden",
  244. "max-width":"300px",
  245. 'cursor':"pointer"
  246. }
  247. };
  248. },formatter:function (value,row,index,field) {
  249. var span=document.createElement('span');
  250. span.setAttribute('title',value);
  251. span.innerHTML = value;
  252. return span.outerHTML;
  253. }
  254. },
  255. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  256. ]
  257. ]
  258. });
  259. //编辑
  260. $(document).on('click','.btn-edit',function () {
  261. var id=$('#ids').val();
  262. Fast.api.open("qingdong/customer/leads/edit?ids="+id, "线索编辑",{
  263. shadeClose: false,
  264. shade: false,
  265. maxmin: false,
  266. moveOut: false,
  267. scrollbars:false,
  268. callback:function () {
  269. location.reload()
  270. }
  271. });
  272. }).on('click',".btn-del",function(){//删除
  273. var id=$('#ids').val();
  274. Layer.confirm('确定删除当前线索吗?', {
  275. btn: ['确定','取消'],
  276. title: '提示',
  277. },function(index, layero){
  278. Fast.api.ajax("qingdong/customer/leads/del?ids="+id,function(data,ret){
  279. if(ret.code == 1){
  280. Layer.close(index);
  281. parent.location.reload();
  282. }
  283. },function(data,ret){
  284. });
  285. });
  286. }).on('click',".btn-convert-customer",function(){//删除
  287. var id=$('#ids').val();
  288. Layer.confirm('确认要将当前线索转为客户?', {
  289. btn: ['确定','取消'],
  290. title: '提示',
  291. },function(index, layero){
  292. Fast.api.ajax("qingdong/customer/leads/convert_customer?ids="+id,function(data,ret){
  293. if(ret.code == 1){
  294. Layer.close(index);
  295. parent.location.reload();
  296. }
  297. },function(data,ret){
  298. });
  299. });
  300. });
  301. Controller.api.bindevent();
  302. },
  303. import : function () {
  304. Controller.api.bindevent();
  305. },
  306. transfer : function () {
  307. Controller.api.bindevent();
  308. },
  309. api : {
  310. bindevent : function () {
  311. Form.api.bindevent($("form[role=form]"), function(data, ret){
  312. //这里是表单提交处理成功后的回调函数,接收来自php的返回数据
  313. Fast.api.close(data);//这里是重点
  314. });
  315. }
  316. }
  317. };
  318. return Controller;
  319. });