contract.js 50 KB

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