business.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  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. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  8. var panel = $($(this).attr("href"));
  9. if (panel.length > 0) {
  10. Controller.table[panel.attr("id")].call(this);
  11. $(this).on('click', function (e) {
  12. $($(this).attr("href")).find(".btn-refresh").trigger("click");
  13. });
  14. }
  15. //移除绑定的事件
  16. $(this).unbind('shown.bs.tab');
  17. });
  18. //必须默认触发shown.bs.tab事件
  19. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  20. $(document).on('click', '.show-detail', function (data) {
  21. var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
  22. var options = {
  23. shadeClose : false,
  24. shade : [0.3, '#393D49'],
  25. area : area,
  26. callback : function (value) {
  27. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  28. console.log(value);
  29. }
  30. };
  31. Fast.api.open($.fn.bootstrapTable.defaults.extend.detail_url + "?ids=" + $(this).data('id'), '商机', options);
  32. });
  33. $(document).on('click', '.show-customer', function (data) {
  34. var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
  35. var options = {
  36. shadeClose : false,
  37. shade : [0.3, '#393D49'],
  38. area : area,
  39. callback : function (value) {
  40. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  41. console.log(value);
  42. }
  43. };
  44. Fast.api.open("qingdong/customer/customer/detail?ids=" + $(this).data('id'), '客户详情', options);
  45. });
  46. //商机转移
  47. $(document).on('click','.btn-transfer',function () {
  48. var tab_id=$('.active.in').attr('id');
  49. var table;
  50. switch (tab_id){
  51. case 'first'://全部
  52. table=$('#table');
  53. break;
  54. case 'second'://我负责的
  55. table=$('#table1');
  56. break;
  57. case 'third'://下属负责的
  58. table=$('#table2');
  59. break;
  60. case 'four'://今日待跟进
  61. table=$('#table3');
  62. break;
  63. case 'five'://今日已跟进
  64. table=$('#table4');
  65. break;
  66. case 'six'://从未跟进的
  67. table=$('#table5');
  68. break;
  69. }
  70. //在templateView的模式下不能调用table.bootstrapTable('getSelections')来获取选中的ID,只能通过下面的Table.api.selectedids来获取
  71. if(Table.api.selectedids(table).length == 0){
  72. layer.alert('请选择要筛选的商机!');
  73. return false;
  74. }
  75. var ids=JSON.stringify(Table.api.selectedids(table));
  76. Fast.api.open("qingdong/customer/business/batch_change?ids="+ids, "批量转移商机",{
  77. shadeClose: false,
  78. shade: false,
  79. maxmin: false,
  80. moveOut: false,
  81. scrollbars:false,
  82. 'area':[
  83. $(window).width() > 800 ? '600px' : '400px',
  84. $(window).height() > 600 ? '500px' : '400px'
  85. ],
  86. callback:function(value){
  87. Form.events.plupload("#plupload-local");
  88. // 在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
  89. },
  90. });
  91. }).on("click", ".btn-export", function () {
  92. var tab_id=$('.active.in').attr('id');
  93. var table,type;
  94. switch (tab_id){
  95. case 'first'://全部
  96. table=$('#table');
  97. type=0;
  98. break;
  99. case 'second'://我负责的
  100. table=$('#table1');
  101. type=1;
  102. break;
  103. case 'third'://下属负责的
  104. table=$('#table2');
  105. type=2;
  106. break;
  107. case 'four'://今日待跟进
  108. table=$('#table3');
  109. type=3;
  110. break;
  111. case 'five'://今日已跟进
  112. table=$('#table4');
  113. type=4;
  114. break;
  115. case 'six'://从未跟进的
  116. table=$('#table5');
  117. type=5;
  118. break;
  119. }
  120. var ids = Table.api.selectedids(table);
  121. var page = table.bootstrapTable('getData');
  122. var all = table.bootstrapTable('getOptions').totalRows;
  123. var search = $("form.form-commonsearch").serialize();
  124. var sort = table.bootstrapTable('getOptions').sortName+' '+table.bootstrapTable('getOptions').sortOrder;
  125. var filter = search.filter;
  126. var op = search.op;
  127. Layer.confirm("请选择导出的选项", {
  128. title : '导出数据',
  129. btn : ["选中项(" + ids.length + "条)", "本页(" + page.length + "条)", "全部(" + all + "条)"],
  130. success : function (layero, index) {
  131. $(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
  132. }, yes : function (index, layero) {
  133. if (ids.length == 0) {
  134. Layer.alert('数据为空');
  135. return true;
  136. }
  137. $.post('qingdong/customer/business/export', {sort:sort,ids : ids.join(","), filter:filter,op:op}, function (res) {
  138. Layer.alert(res.msg);
  139. if(res.code ==1){
  140. window.location.href = res.data.filePath;
  141. Layer.close(index);
  142. table.bootstrapTable('refresh');
  143. }
  144. }, 'json');
  145. return false;
  146. },
  147. btn2 : function (index, layero) {
  148. if (page.length == 0) {
  149. Layer.alert('数据为空');
  150. return true;
  151. }
  152. var ids = [];
  153. $.each(page, function (i, j) {
  154. ids.push(j.id);
  155. });
  156. $.post('qingdong/customer/business/export', {sort:sort,ids : ids.join(","), filter:filter,op:op}, function (res) {
  157. Layer.alert(res.msg);
  158. if(res.code ==1){
  159. window.location.href = res.data.filePath;
  160. Layer.close(index);
  161. table.bootstrapTable('refresh');
  162. }
  163. }, 'json');
  164. return false;
  165. },
  166. btn3 : function (index, layero) {
  167. if (page.length == 0) {
  168. Layer.alert('数据为空');
  169. return true;
  170. }
  171. $.post('qingdong/customer/business/export', {sort:sort,ids : ids.join(","), type : type, filter:filter,op:op}, function (res) {
  172. Layer.alert(res.msg);
  173. if(res.code ==1){
  174. window.location.href = res.data.filePath;
  175. Layer.close(index);
  176. table.bootstrapTable('refresh');
  177. }
  178. }, 'json');
  179. return false;
  180. }
  181. })
  182. }).on('click','.btn-imports',function () {
  183. Fast.api.open("qingdong/customer/business/import", "商机导入",{
  184. shadeClose: false,
  185. shade: false,
  186. maxmin: false,
  187. moveOut: false,
  188. scrollbars:false,
  189. 'area':[
  190. $(window).width() > 800 ? '600px' : '400px',
  191. $(window).height() > 600 ? '500px' : '400px'
  192. ],
  193. callback:function(value){
  194. Form.events.plupload("#plupload-local");
  195. // 在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
  196. },
  197. });
  198. }).on("click", ".btn-export-product", function () {
  199. var tab_id=$('.active.in').attr('id');
  200. var table,type;
  201. switch (tab_id){
  202. case 'first'://全部
  203. table=$('#table');
  204. type=0;
  205. break;
  206. case 'second'://我负责的
  207. table=$('#table1');
  208. type=1;
  209. break;
  210. case 'third'://下属负责的
  211. table=$('#table2');
  212. type=2;
  213. break;
  214. case 'four'://今日待跟进
  215. table=$('#table3');
  216. type=3;
  217. break;
  218. case 'five'://今日已跟进
  219. table=$('#table4');
  220. type=4;
  221. break;
  222. case 'six'://从未跟进的
  223. table=$('#table5');
  224. type=5;
  225. break;
  226. }
  227. var ids = Table.api.selectedids(table);
  228. var page = table.bootstrapTable('getData');
  229. var options = table.bootstrapTable('getOptions');
  230. var params=options.queryParams({});
  231. var all = options.totalRows;
  232. var sort = options.sortName+' '+options.sortOrder;
  233. var filter = params.filter;
  234. var op = params.op;
  235. Layer.confirm("请选择导出的选项", {
  236. title : '导出产品明细数据',
  237. btn : ["选中项(" + ids.length + "条)", "本页(" + page.length + "条)", "全部(" + all + "条)"],
  238. success : function (layero, index) {
  239. $(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
  240. }, yes : function (index, layero) {
  241. if (ids.length == 0) {
  242. Layer.alert('数据为空');
  243. return true;
  244. }
  245. $.post('qingdong/customer/business/export_product', {sort:sort,ids : ids.join(","), isall : 1}, function (res) {
  246. Layer.alert(res.msg);
  247. if(res.code == 1){
  248. window.location.href = res.data.filePath;
  249. Layer.close(index);
  250. }
  251. table.bootstrapTable('refresh');
  252. }, 'json');
  253. return false;
  254. },
  255. btn2 : function (index, layero) {
  256. if (page.length == 0) {
  257. Layer.alert('数据为空');
  258. return true;
  259. }
  260. var ids = [];
  261. $.each(page, function (i, j) {
  262. ids.push(j.id);
  263. });
  264. $.post('qingdong/customer/business/export_product', {sort:sort,ids : ids.join(","), isall : 2}, function (res) {
  265. Layer.alert(res.msg);
  266. if(res.code == 1){
  267. window.location.href = res.data.filePath;
  268. Layer.close(index);
  269. }
  270. table.bootstrapTable('refresh');
  271. }, 'json');
  272. return false;
  273. },
  274. btn3 : function (index, layero) {
  275. if (page.length == 0) {
  276. Layer.alert('数据为空');
  277. return true;
  278. }
  279. $.post('qingdong/customer/business/export_product?filter='+filter+'&op='+op, {sort:sort,ids : ids.join(","), isall : 3,type:type}, function (res) {
  280. Layer.alert(res.msg);
  281. if(res.code == 1){
  282. window.location.href = res.data.filePath;
  283. Layer.close(index);
  284. }
  285. table.bootstrapTable('refresh');
  286. }, 'json');
  287. return false;
  288. }
  289. })
  290. }).on('click','.btn-imports-product',function () {
  291. Fast.api.open("qingdong/customer/business/import_product", "商机导入产品明细",{
  292. shadeClose: false,
  293. shade: false,
  294. maxmin: false,
  295. moveOut: false,
  296. scrollbars:false,
  297. 'area':[
  298. $(window).width() > 800 ? '600px' : '400px',
  299. $(window).height() > 600 ? '500px' : '400px'
  300. ],
  301. callback:function(value){
  302. Form.events.plupload("#plupload-local");
  303. // 在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
  304. },
  305. });
  306. });
  307. },
  308. tableinfo:{
  309. url : '',
  310. toolbar: '#toolbar',
  311. pk : 'id',
  312. sortName : 'id',
  313. fixedColumns : true,
  314. fixedNumber : 2,
  315. fixedRightNumber : 1,
  316. columns : [
  317. [
  318. {checkbox : true},
  319. {
  320. field : 'name', title : '商机名称', fixedColumns : true, formatter : function (value, row, index) {
  321. if(value ==''){
  322. value = '无';
  323. }
  324. return "<a href='javascript:void(0);' data-id='" + row.id + "' class='show-detail'>" + value + "</a>";
  325. }
  326. },
  327. {field : 'customer', title : '客户名称', formatter : function (value, row, index) {
  328. if(row.customer){
  329. return "<a href='javascript:void(0);' data-id='" + row.customer_id + "' class='show-customer'>" + row.customer.name + "</a>";
  330. }
  331. return '';
  332. },operate:false},
  333. {field : 'customer_id', title : '客户名称', visible: false, addClass: "selectpage", extend: "data-source='qingdong/customer/customer/index' data-field='name'"},
  334. {field : 'money', title : '商机金额'},
  335. {field : 'expect_time', title : '预计成交时间',operate: 'RANGE',autocomplete:false, addclass: 'datetimerange'},
  336. {field : 'next_time', title : '下次联系时间',operate: 'RANGE',autocomplete:false, addclass: 'datetimerange'},
  337. {field : 'owner_staff.name', title : '负责人',operate:false},
  338. {field : 'owner_staff_id', title : '负责人', visible: false, addClass: "selectpage", extend: "data-source='qingdong/department/staff/index' data-field='name'"},
  339. {field : 'type', title : '商机阶段', formatter : Table.api.formatter.status,operate:false,
  340. searchList : {0 : '初期沟通', 1 : '立项跟踪', 2 : '方案/报价', 3 : '谈判审核', 4 : '赢单', 5 : '输单', 6 : '无效'}},
  341. {field: 'createtime', title: __('Createtime'), operate:'RANGE',autocomplete:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  342. {field : 'updatetime', title : '更新时间',operate:false},
  343. {
  344. field: 'operate2', title: __('Operate'), events: {
  345. 'click .btn-chooseone': function (e, value, row, index) {
  346. Fast.api.close({id: row.id, name: row.name});
  347. },
  348. }, formatter: function () {
  349. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  350. }
  351. },
  352. {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.buttons,
  353. buttons: [
  354. {
  355. name: 'detail',
  356. text: __('推进商机'),
  357. title: __('推进商机'),
  358. extend:'data-area=["80%","80%"]',
  359. classname: 'records btn-dialog',
  360. url: 'qingdong/customer/business/batch_status',
  361. visible: function (row) {
  362. //返回true时按钮显示,返回false隐藏
  363. return true;
  364. }
  365. },
  366. {
  367. name: 'detail',
  368. text: __('跟进'),
  369. title: __('跟进'),
  370. extend:'data-area=["80%","80%"]',
  371. classname: 'records btn-dialog',
  372. url: 'qingdong/customer/business/record',
  373. visible: function (row) {
  374. //返回true时按钮显示,返回false隐藏
  375. return true;
  376. }
  377. },
  378. {
  379. name: 'detail',
  380. text: __('编辑'),
  381. title: __('编辑'),
  382. extend:'data-area=["80%","80%"]',
  383. classname: 'records btn-dialog',
  384. url: 'qingdong/customer/business/edit',
  385. visible: function (row) {
  386. //返回true时按钮显示,返回false隐藏
  387. return true;
  388. }
  389. }
  390. ]
  391. }
  392. ]
  393. ],
  394. pagination : true,
  395. search : false,
  396. commonSearch : true,
  397. searchFormVisible : true,
  398. //显示导出按钮
  399. showExport: false,
  400. onLoadSuccess:function(){
  401. // 这里就是数据渲染结束后的回调函数
  402. $(".btn-add").data("area",["80%","80%"]);
  403. $(".btn-edit").data("area",["80%","80%"]);
  404. }
  405. },
  406. table: {
  407. first: function () {
  408. // 初始化表格参数配置
  409. Table.api.init({
  410. extend : {
  411. add_url : 'qingdong/customer/business/add',
  412. detail_url : 'qingdong/customer/business/detail',
  413. table : 'business',
  414. }
  415. });
  416. if(Config.fields !='[]'){
  417. if (Config.fields && Object.keys(Config.fields).length > 0) {
  418. var fields = JSON.parse(Config.fields);
  419. var start = Controller.tableinfo.columns[0].length-2;
  420. for (var i = 0; i < fields.length; i++) {
  421. if (fields[i].hasOwnProperty('formatter'))
  422. fields[i].formatter = eval(fields[i].formatter);
  423. if (fields[i].hasOwnProperty('events'))
  424. fields[i].events = eval(fields[i].events);
  425. if (fields[i].hasOwnProperty('searchList'))
  426. fields[i].searchList = JSON.parse(fields[i].searchList);
  427. Controller.tableinfo.columns[0].splice(start + i, 0, fields[i]);
  428. }
  429. }
  430. }
  431. const q = {};
  432. location.search.replace(/([^?&=]+)=([^&]+)/g,function(_,k,v){q[k]=v});
  433. var table = $("#table");
  434. Controller.tableinfo.url=location.href+'&type=0';
  435. Controller.tableinfo.toolbar='#toolbar';
  436. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  437. if (q.isselect == 1) {
  438. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length - 1].visible = false;
  439. } else {
  440. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length - 2].visible = false;
  441. }
  442. // 初始化表格
  443. table.bootstrapTable(Controller.tableinfo);
  444. // 为表格绑定事件
  445. Table.api.bindevent(table);
  446. },
  447. second: function () {
  448. // 初始化表格参数配置
  449. Table.api.init({
  450. extend : {
  451. add_url : 'qingdong/customer/business/add',
  452. detail_url : 'qingdong/customer/business/detail',
  453. table : 'business',
  454. }
  455. });
  456. var table = $("#table1");
  457. Controller.tableinfo.url=location.href+'&type=1';
  458. Controller.tableinfo.toolbar='#toolbar1';
  459. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  460. // 初始化表格
  461. table.bootstrapTable(Controller.tableinfo);
  462. // 为表格绑定事件
  463. Table.api.bindevent(table);
  464. },
  465. third: function () {
  466. // 初始化表格参数配置
  467. Table.api.init({
  468. extend : {
  469. add_url : 'qingdong/customer/business/add',
  470. detail_url : 'qingdong/customer/business/detail',
  471. table : 'business',
  472. }
  473. });
  474. var table = $("#table2");
  475. Controller.tableinfo.url=location.href+'&type=2';
  476. Controller.tableinfo.toolbar='#toolbar2';
  477. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  478. table.bootstrapTable(Controller.tableinfo);
  479. // 为表格绑定事件
  480. Table.api.bindevent(table);
  481. },
  482. four: function () {
  483. // 初始化表格参数配置
  484. Table.api.init({
  485. extend : {
  486. add_url : 'qingdong/customer/business/add',
  487. detail_url : 'qingdong/customer/business/detail',
  488. table : 'business',
  489. }
  490. });
  491. var table = $("#table3");
  492. Controller.tableinfo.url=location.href+'&type=3';
  493. Controller.tableinfo.toolbar='#toolbar3';
  494. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  495. table.bootstrapTable(Controller.tableinfo);
  496. // 为表格绑定事件
  497. Table.api.bindevent(table);
  498. },
  499. five: function () {
  500. // 初始化表格参数配置
  501. Table.api.init({
  502. extend : {
  503. add_url : 'qingdong/customer/business/add',
  504. detail_url : 'qingdong/customer/business/detail',
  505. table : 'business',
  506. }
  507. });
  508. var table = $("#table4");
  509. Controller.tableinfo.url=location.href+'&type=4';
  510. Controller.tableinfo.toolbar='#toolbar4';
  511. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  512. // 初始化表格
  513. table.bootstrapTable(Controller.tableinfo);
  514. // 为表格绑定事件
  515. Table.api.bindevent(table);
  516. },
  517. six: function () {
  518. // 初始化表格参数配置
  519. Table.api.init({
  520. extend : {
  521. add_url : 'qingdong/customer/business/add',
  522. detail_url : 'qingdong/customer/business/detail',
  523. table : 'business',
  524. }
  525. });
  526. var table = $("#table5");
  527. Controller.tableinfo.url=location.href+'&type=5';
  528. Controller.tableinfo.toolbar='#toolbar5';
  529. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  530. // 初始化表格
  531. table.bootstrapTable(Controller.tableinfo);
  532. // 为表格绑定事件
  533. Table.api.bindevent(table);
  534. },
  535. },
  536. add : function () {
  537. Controller.api.bindevent();
  538. },
  539. edit : function () {
  540. Controller.api.bindevent();
  541. },
  542. import : function () {
  543. Form.api.bindevent($("form[role=form]"));
  544. },
  545. import_product : function () {
  546. Form.api.bindevent($("form[role=form]"));
  547. },
  548. batch_change : function () {
  549. Controller.api.bindevent();
  550. },
  551. record : function () {
  552. Controller.api.bindevent();
  553. },
  554. batch_status : function () {
  555. Controller.api.bindevent();
  556. },
  557. tabledetail : {
  558. record: function () {
  559. //跟进记录
  560. var table1 = $("#records");
  561. // 初始化表格
  562. table1.bootstrapTable({
  563. url : 'qingdong/customer/record/index?busniess_id='+Config.idinfo.id,
  564. pk : 'id',
  565. sortName : 'id',
  566. toolbar: "#toolbar_records",
  567. operate : false,
  568. commonSearch : false,
  569. search : false,
  570. visible : false,
  571. showColumns : false,
  572. showExport : false,
  573. showToggle : false,
  574. columns : [
  575. [
  576. {field: 'follow_type', title: __('跟进类型')},
  577. {field: 'follow_time', title: __('跟进时间')},
  578. {field: 'follow', title: __('跟进状态')},
  579. {field: 'content', title: __('跟进内容'),cellStyle:function (value,row,index,field) {
  580. return {
  581. css: {
  582. "min-width": "150px",
  583. "white-space": "nowrap",
  584. "text-overflow": "ellipsis",
  585. "overflow": "hidden",
  586. "max-width":"300px",
  587. 'cursor':"pointer"
  588. }
  589. };
  590. },formatter:function (value,row,index,field) {
  591. var span=document.createElement('span');
  592. span.setAttribute('title',value);
  593. span.innerHTML = value;
  594. return span.outerHTML;
  595. }
  596. },
  597. {field: 'next_time', title: __('下次跟进时间')},
  598. {
  599. field : 'operate',
  600. title : __('Operate'),
  601. table : table1,
  602. events : Table.api.events.operate,
  603. formatter : Table.api.formatter.operate,
  604. buttons : [
  605. {
  606. name : '详情',
  607. text : __('详情'),
  608. classname : 'records btn-dialog',
  609. url : 'qingdong/customer/record/detail',
  610. callback: function (data) {
  611. $('.btn-success').trigger('click');
  612. },
  613. },
  614. {
  615. name : '评论',
  616. text : __('评论'),
  617. classname : 'records btn-dialog',
  618. url : 'qingdong/customer/comment/add',
  619. callback: function (data) {
  620. $('.btn-success').trigger('click');
  621. },
  622. }
  623. ]
  624. }
  625. ]
  626. ]
  627. });
  628. Table.api.bindevent(table1);
  629. },
  630. secord: function () {
  631. //商机产品
  632. var table=$('#product');
  633. table.bootstrapTable({
  634. url : 'qingdong/customer/business/product?business_id=' +Config.idinfo.id,
  635. pk : 'business_product.id',
  636. sortName : 'business_product.id',
  637. toolbar: "#toolbar_secord",
  638. operate : false,
  639. commonSearch : false,
  640. search : false,
  641. visible : false,
  642. showColumns : false,
  643. showExport : false,
  644. showToggle : false,
  645. columns : [
  646. [
  647. {
  648. field : 'product.name', title : '产品名称', operate : 'like', fixedColumns : true, formatter : function (value, row, index) {
  649. if(row.product){
  650. return "<a href='javascript:void(0);' data-id='" + row.product.id + "' class='show-detail_product'>" + row.product.name + "</a>";
  651. }
  652. }
  653. },
  654. {field : 'product.num', title : '产品编码', operate : 'like'},
  655. {field: 'product.img', title: '产品图片', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  656. {field : 'product.unit', title : '产品单位', operate : false},
  657. {field : 'price', title : '零售价', operate : false},
  658. {field : 'wholesale', title : '批发价', operate : false},
  659. {field : 'number', title : '数量', operate : false},
  660. ]
  661. ]
  662. });
  663. $(document).on('click', '.show-detail_product', function (data) {
  664. var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
  665. var options = {
  666. shadeClose : false,
  667. shade : [0.3, '#393D49'],
  668. area : area,
  669. callback : function (value) {
  670. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  671. console.log(value);
  672. }
  673. };
  674. Fast.api.open("qingdong/product/product/detail?ids=" + $(this).data('id'), '产品详情', options);
  675. });
  676. Table.api.bindevent(table);
  677. },
  678. //合同
  679. third: function () {
  680. var table1 = $("#contract");
  681. // 初始化表格
  682. table1.bootstrapTable({
  683. url : 'qingdong/customer/business/get_contract?business_id=' +Config.idinfo.id,
  684. pk : 'id',
  685. sortName : 'id',
  686. toolbar:"#toolbar_third",
  687. operate : false,
  688. commonSearch : false,
  689. search : false,
  690. visible : false,
  691. showColumns : false,
  692. showExport : false,
  693. showToggle : false,
  694. columns : [
  695. [
  696. {
  697. field : 'num', title : '合同编号', fixedColumns : true, formatter : function (value, row, index) {
  698. if(value ==''){
  699. value = '无';
  700. }
  701. return "<a href='javascript:void(0);' data-area=[\"90%\",\"90%\"] class='btn-dialog' " +
  702. "data-url='qingdong/customer/contract/detail/ids/"+row.id+"' data-title='合同详情' >" + value + "</a>";
  703. },operate:'like'
  704. },
  705. {field : 'name', title : '合同名称'},
  706. {field : 'customer.name', title : '客户名称'},
  707. {field : 'money', title : '合同金额'},
  708. {field : 'start_time', title : '开始日期'},
  709. {field : 'end_time', title : '结束日期'},
  710. {field : 'check_status', title : '状态', formatter : Table.api.formatter.status,
  711. searchList : {0 : '待审核', 1 : '审核中', 2 : '审核通过', 3 : '审核未通过', 4 : '撤销', 5 : '草稿(未提交)'}},
  712. ]
  713. ]
  714. });
  715. Table.api.bindevent(table1);
  716. },
  717. //推进历史
  718. four: function () {
  719. var table1 = $("#history");
  720. // 初始化表格
  721. table1.bootstrapTable({
  722. url : 'qingdong/customer/business/get_business_status?business_id=' +Config.idinfo.id,
  723. pk : 'id',
  724. sortName : 'id',
  725. toolbar:"#toolbar_four",
  726. operate : false,
  727. commonSearch : false,
  728. search : false,
  729. visible : false,
  730. showColumns : false,
  731. showExport : false,
  732. showToggle : false,
  733. columns : [
  734. [
  735. {field : 'type', title : '商机阶段', formatter : Table.api.formatter.status,
  736. searchList : {0 : '初期沟通', 1 : '立项跟踪', 2 : '方案/报价', 3 : '谈判审核', 4 : '赢单', 5 : '输单', 6 : '无效'}},
  737. {field : 'remark', title : '备注'},
  738. {field : 'money', title : '图片', formatter: Controller.api.formatter.thumb},
  739. {field: 'createtime', title: __('推进时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  740. ]
  741. ]
  742. });
  743. Table.api.bindevent(table1);
  744. },
  745. },
  746. detail : function () {
  747. // 初始化表格参数配置
  748. Table.api.init({});
  749. $('.stafflist').popover({
  750. placement : 'bottom',
  751. trigger : 'hover'
  752. });
  753. //绑定事件
  754. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  755. var panel = $($(this).attr("href"));
  756. if (panel.length > 0) {
  757. Controller.tabledetail[panel.attr("id")].call(this);
  758. $(this).on('click', function (e) {
  759. $($(this).attr("href")).find(".btn-refresh").trigger("click");
  760. });
  761. }
  762. //移除绑定的事件
  763. $(this).unbind('shown.bs.tab');
  764. });
  765. //必须默认触发shown.bs.tab事件
  766. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  767. //编辑
  768. $(document).on('click','.btn-edit',function () {
  769. var id=$('#ids').val();
  770. Fast.api.open("qingdong/customer/business/edit?ids="+id, "商机编辑",{
  771. shadeClose: false,
  772. shade: false,
  773. maxmin: false,
  774. moveOut: false,
  775. scrollbars:false,
  776. callback:function(value){
  777. location.reload();
  778. },
  779. });
  780. });
  781. //推进
  782. $(document).on('click','.btn-status',function () {
  783. var id=$('#ids').val();
  784. Fast.api.open("qingdong/customer/business/batch_status?ids="+id, "推进商机",{
  785. shadeClose: false,
  786. shade: false,
  787. maxmin: false,
  788. moveOut: false,
  789. scrollbars:false,
  790. callback:function(value){
  791. location.reload();
  792. },
  793. });
  794. });
  795. //删除
  796. $("#dels").on('click',function(){
  797. var id=$('#ids').val();
  798. Layer.confirm('确定删除商机吗?', {
  799. btn: ['确定','取消']
  800. },function(index, layero){
  801. Fast.api.ajax("qingdong/customer/business/delete?ids="+id,function(data,ret){
  802. if(ret.code == 1){
  803. Layer.close(index);
  804. parent.location.reload();
  805. }
  806. },function(data,ret){
  807. });
  808. });
  809. });
  810. //商机转移
  811. $(document).on('click','.btn-transfer',function () {
  812. var ids=$(this).data('id');
  813. if(!ids){
  814. layer.alert('商机不存在!');
  815. return false;
  816. }
  817. Fast.api.open("qingdong/customer/business/batch_change?ids="+ids, "转移商机",{
  818. shadeClose: false,
  819. shade: false,
  820. maxmin: false,
  821. moveOut: false,
  822. scrollbars:false,
  823. 'area':[
  824. $(window).width() > 800 ? '600px' : '400px',
  825. $(window).height() > 600 ? '500px' : '400px'
  826. ],
  827. callback:function(value){
  828. Form.events.plupload("#plupload-local");
  829. // 在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
  830. },
  831. });
  832. });
  833. Controller.api.bindevent();
  834. },
  835. api : {
  836. bindevent : function () {
  837. $(document).on("fa.event.appendfieldlist", '.fieldlist', function(){
  838. //通用的表单组件事件绑定和组件渲染
  839. Form.events.selectpage($("form"));
  840. Form.events.datetimepicker($("form"));
  841. });
  842. $(".selectpage").data("params", function (obj) {
  843. var customer_id=$('#customer').val()
  844. //obj为SelectPage对象
  845. return {ids: customer_id};
  846. });
  847. function set_money(){
  848. var $price = $('.price');
  849. var $number = $('.number');
  850. var price=0;
  851. $.each($price, function (index, item) {
  852. var p = $(item).val(), n = $number.eq(index).val();
  853. p = parseFloat(p);
  854. n = parseInt(n);
  855. price += p * n;
  856. });
  857. $('#c-money').val(price);
  858. }
  859. $(document).on("change", ".product", function(){
  860. var $this=$(this);
  861. var id=$this.next('input').val();
  862. Fast.api.ajax("qingdong/customer/contract/get_product_price?id="+id,function(data,ret){
  863. $this.parent().parent().next('span').find('input').val(data.price);
  864. set_money();
  865. $(".fieldlist input:eq(2)").trigger("change");
  866. return false;
  867. });
  868. }).on("change", ".price", function(){
  869. set_money();
  870. }).on("change", ".number", function(){
  871. set_money();
  872. }).on("click", ".select-customer", function(){
  873. var $this=$(this);
  874. top.Fast.api.open($(this).data("url") , __('Select'), {callback: function (data) {
  875. $this.html(data.name);
  876. $('[name="'+$this.data('name')+'"]').val(data.id);
  877. },area:["100%", "100%"]});
  878. }).on("click", ".select-product", function(){
  879. var $this=$(this);
  880. top.Fast.api.open($(this).data("url"), __('Select'), {callback: function (data) {
  881. console.log('sssss');
  882. console.log(data);
  883. $this.html(data.name);
  884. $('[name="'+$this.data('name')+'"]').val(data.id);
  885. $this.parent().parent().next('td').find('input').val(data.price);
  886. $this.parent().parent().parent().find('.price2').val(data.wholesale);
  887. if(data.goods){
  888. $this.parent().parent().parent().find('.goods').html(data.goods.name);
  889. }
  890. $this.parent().parent().parent().find('.type').html(data.type);
  891. set_money();
  892. $(".fieldlist input:eq(2)").trigger("change");
  893. },area:["100%", "100%"]});
  894. });
  895. Form.events.selectpage($("form"));
  896. $(".selectpage").data("params", function (obj) {
  897. var customer_id=$('#customer').val()
  898. if(!customer_id){
  899. layer.msg('请先选择客户');
  900. return false;
  901. }
  902. //obj为SelectPage对象
  903. return {ids: customer_id};
  904. });
  905. Form.api.bindevent($("form[role=form]"), function(data, ret){
  906. //这里是表单提交处理成功后的回调函数,接收来自php的返回数据
  907. Fast.api.close(data);//这里是重点
  908. });
  909. },
  910. formatter : {
  911. thumb : function (value, row, index) {
  912. var length = row.file.length;
  913. var html='';
  914. for(var i=0;i<length;i++){
  915. html += '<a href="' + row.file[i]['file_path'] + '" target="_blank"><img src="' + row.file[i]['file_path'] + '" data-tips-image alt="" title="商机图" style="max-height:90px;max-width:120px;margin-right:10px;"></a>';
  916. }
  917. return html;
  918. },
  919. }
  920. }
  921. };
  922. return Controller;
  923. });