contract.js 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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: 'detail',
  317. text: __('跟进'),
  318. title: __('跟进'),
  319. extend:'data-area=["80%","80%"]',
  320. classname: 'records btn-dialog',
  321. url: 'qingdong/contract/record/add',
  322. visible: function (row) {
  323. //返回true时按钮显示,返回false隐藏
  324. return true;
  325. }
  326. },
  327. {
  328. name: 'detail',
  329. text: __('回款'),
  330. title: __('回款'),
  331. extend:'data-area=["80%","80%"]',
  332. classname: 'records btn-dialog',
  333. url: 'qingdong/customer/receivables/add/customer_id/{customer_id}',
  334. visible: function (row) {
  335. //返回true时按钮显示,返回false隐藏
  336. return true;
  337. }
  338. }
  339. ]
  340. }
  341. ]
  342. ],
  343. pagination : true,
  344. search : false,
  345. commonSearch : true,
  346. searchFormVisible : true,
  347. //显示导出按钮
  348. showExport: false,
  349. onLoadSuccess:function(row){
  350. $('.contract_money').show()
  351. $('.allmoney').html(row.allmoney);
  352. $('.repayment_money').html(row.repayment_money);
  353. $('.no_money').html(row.no_money);
  354. // 这里就是数据渲染结束后的回调函数
  355. $(".btn-add").data("area",["80%","80%"]);
  356. $(".btn-edit").data("area",["80%","80%"]);
  357. }
  358. },
  359. table: {
  360. first: function () {
  361. // 初始化表格参数配置
  362. Table.api.init({
  363. extend : {
  364. add_url : 'qingdong/customer/contract/add',
  365. detail_url : 'qingdong/customer/contract/detail',
  366. table : 'contract',
  367. }
  368. });
  369. if(Config.fields !='[]'){
  370. if (Config.fields && Object.keys(Config.fields).length > 0) {
  371. var fields = JSON.parse(Config.fields);
  372. var start = Controller.tableinfo.columns[0].length-2;
  373. for (var i = 0; i < fields.length; i++) {
  374. if (fields[i].hasOwnProperty('formatter'))
  375. fields[i].formatter = eval(fields[i].formatter);
  376. if (fields[i].hasOwnProperty('events'))
  377. fields[i].events = eval(fields[i].events);
  378. if (fields[i].hasOwnProperty('searchList'))
  379. fields[i].searchList = JSON.parse(fields[i].searchList);
  380. Controller.tableinfo.columns[0].splice(start + i, 0, fields[i]);
  381. }
  382. }
  383. }
  384. const q = {};
  385. location.search.replace(/([^?&=]+)=([^&]+)/g,function(_,k,v){q[k]=v});
  386. var table = $("#table");
  387. Controller.tableinfo.url=location.href+'&type=0';
  388. Controller.tableinfo.toolbar='#toolbar';
  389. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  390. if (q.isselect == 1) {
  391. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length - 1].visible = false;
  392. } else {
  393. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length - 2].visible = false;
  394. }
  395. // 初始化表格
  396. table.bootstrapTable(Controller.tableinfo);
  397. // 为表格绑定事件
  398. Table.api.bindevent(table);
  399. },
  400. second: function () {
  401. // 初始化表格参数配置
  402. Table.api.init({
  403. extend : {
  404. add_url : 'qingdong/customer/contract/add',
  405. detail_url : 'qingdong/customer/contract/detail',
  406. table : 'contract',
  407. }
  408. });
  409. var table = $("#table1");
  410. Controller.tableinfo.url=location.href+'&type=1';
  411. Controller.tableinfo.toolbar='#toolbar1';
  412. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  413. // 初始化表格
  414. table.bootstrapTable(Controller.tableinfo);
  415. // 为表格绑定事件
  416. Table.api.bindevent(table);
  417. },
  418. third: function () {
  419. // 初始化表格参数配置
  420. Table.api.init({
  421. extend : {
  422. add_url : 'qingdong/customer/contract/add',
  423. detail_url : 'qingdong/customer/contract/detail',
  424. table : 'contract',
  425. }
  426. });
  427. var table = $("#table2");
  428. Controller.tableinfo.url=location.href+'&type=2';
  429. Controller.tableinfo.toolbar='#toolbar2';
  430. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  431. // 初始化表格
  432. table.bootstrapTable(Controller.tableinfo);
  433. // 为表格绑定事件
  434. Table.api.bindevent(table);
  435. },
  436. four: function () {
  437. // 初始化表格参数配置
  438. Table.api.init({
  439. extend : {
  440. add_url : 'qingdong/customer/contract/add',
  441. detail_url : 'qingdong/customer/contract/detail',
  442. table : 'contract',
  443. }
  444. });
  445. var table = $("#table3");
  446. Controller.tableinfo.url=location.href+'&type=3';
  447. Controller.tableinfo.toolbar='#toolbar3';
  448. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  449. // 初始化表格
  450. table.bootstrapTable(Controller.tableinfo);
  451. // 为表格绑定事件
  452. Table.api.bindevent(table);
  453. },
  454. five: function () {
  455. // 初始化表格参数配置
  456. Table.api.init({
  457. extend : {
  458. add_url : 'qingdong/customer/contract/add',
  459. detail_url : 'qingdong/customer/contract/detail',
  460. table : 'contract',
  461. }
  462. });
  463. var table = $("#table4");
  464. Controller.tableinfo.url=location.href+'&type=4';
  465. Controller.tableinfo.toolbar='#toolbar4';
  466. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  467. // 初始化表格
  468. table.bootstrapTable(Controller.tableinfo);
  469. // 为表格绑定事件
  470. Table.api.bindevent(table);
  471. },
  472. six: function () {
  473. // 初始化表格参数配置
  474. Table.api.init({
  475. extend : {
  476. add_url : 'qingdong/customer/contract/add',
  477. detail_url : 'qingdong/customer/contract/detail',
  478. table : 'contract',
  479. }
  480. });
  481. var table = $("#table5");
  482. Controller.tableinfo.url=location.href+'&type=5';
  483. Controller.tableinfo.toolbar='#toolbar5';
  484. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  485. // 初始化表格
  486. table.bootstrapTable(Controller.tableinfo);
  487. // 为表格绑定事件
  488. Table.api.bindevent(table);
  489. },
  490. },
  491. add : function () {
  492. Controller.api.bindevent();
  493. },
  494. edit : function () {
  495. Controller.api.bindevent();
  496. },
  497. import : function () {
  498. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  499. //这里是表单提交处理成功后的回调函数,接收来自php的返回数据
  500. Fast.api.close(data);//这里是重点
  501. }, function (data, ret) {
  502. Toastr.error(ret.msg);
  503. return false;
  504. });
  505. },
  506. import_product : function () {
  507. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  508. //这里是表单提交处理成功后的回调函数,接收来自php的返回数据
  509. Fast.api.close(data);//这里是重点
  510. }, function (data, ret) {
  511. Toastr.error(ret.msg);
  512. return false;
  513. });
  514. },
  515. words : function () {
  516. $('.copy').on('click',function (){
  517. var copyhtml=$(this).prev().html();
  518. let copyInput = document.createElement('input');//创建input元素
  519. document.body.appendChild(copyInput);//向页面底部追加输入框
  520. copyInput.setAttribute('value', copyhtml);//添加属性,将url赋值给input元素的value属性
  521. copyInput.select();//选择input元素
  522. document.execCommand("Copy");//执行复制命令
  523. Layer.msg('复制成功!');
  524. copyInput.remove();//删除动态创建的节点
  525. })
  526. $("[name='is_template']").on('click',function (){
  527. var ischecked=$(this).is(':checked');
  528. if(ischecked == true){
  529. $('#template_name').show();
  530. }else{
  531. $('#template_name').hide();
  532. }
  533. })
  534. $("[name='template_id']").on('change',function (){
  535. var url=$(this).find(':selected').data('url');
  536. $('#file').val(url)
  537. })
  538. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  539. Fast.api.close(data);//这里是重点
  540. }, function (data, ret) {
  541. Toastr.error(ret.msg);
  542. return false;
  543. });
  544. },
  545. tabledetail : {
  546. record: function () {
  547. //跟进记录
  548. var table1 = $("#records");
  549. // 初始化表格
  550. table1.bootstrapTable({
  551. url : 'qingdong/customer/record/index?contract_id='+Config.idinfo.id,
  552. pk : 'id',
  553. sortName : 'id',
  554. toolbar: "#toolbar_records",
  555. operate : false,
  556. commonSearch : false,
  557. search : false,
  558. visible : false,
  559. showColumns : false,
  560. showExport : false,
  561. showToggle : false,
  562. columns : [
  563. [
  564. {field: 'follow_type', title: __('跟进类型')},
  565. {field: 'follow_time', title: __('跟进时间')},
  566. {field: 'follow', title: __('跟进状态')},
  567. {field: 'content', title: __('跟进内容'),cellStyle:function (value,row,index,field) {
  568. return {
  569. css: {
  570. "min-width": "150px",
  571. "white-space": "nowrap",
  572. "text-overflow": "ellipsis",
  573. "overflow": "hidden",
  574. "max-width":"300px",
  575. 'cursor':"pointer"
  576. }
  577. };
  578. },formatter:function (value,row,index,field) {
  579. var span=document.createElement('span');
  580. span.setAttribute('title',value);
  581. span.innerHTML = value;
  582. return span.outerHTML;
  583. }
  584. },
  585. {field: 'next_time', title: __('下次跟进时间')},
  586. {
  587. field : 'operate',
  588. title : __('Operate'),
  589. table : table1,
  590. events : Table.api.events.operate,
  591. formatter : Table.api.formatter.operate,
  592. buttons : [
  593. {
  594. name : '详情',
  595. text : __('详情'),
  596. classname : 'records btn-dialog',
  597. url : 'qingdong/customer/record/detail',
  598. callback: function (data) {
  599. $('.btn-success').trigger('click');
  600. },
  601. },
  602. {
  603. name : '评论',
  604. text : __('评论'),
  605. classname : 'records btn-dialog',
  606. url : 'qingdong/customer/comment/add',
  607. callback: function (data) {
  608. $('.btn-success').trigger('click');
  609. },
  610. }
  611. ]
  612. }
  613. ]
  614. ]
  615. });
  616. Table.api.bindevent(table1);
  617. },
  618. settings2: function () {
  619. //回款计划
  620. var table_plan=$('#plan');
  621. table_plan.bootstrapTable({
  622. url : 'qingdong/customer/contract/get_receivables_plan?ids='+Config.idinfo.id,
  623. pk : 'id',
  624. sortName : 'id',
  625. toolbar: "#toolbar_receivablesplan",
  626. operate : false,
  627. commonSearch : false,
  628. search : false,
  629. visible : false,
  630. showColumns : false,
  631. showExport : false,
  632. showToggle : false,
  633. columns : [
  634. [
  635. {field : 'num', title : '期数'},
  636. {field : 'money', title : '计划回款金额'},
  637. {field : 'return_date', title : '计划回款日期'},
  638. {field : 'return_type', title : '计划回款方式'},
  639. {field : 'remind', title : '提前几日提醒'},
  640. {field : 'remarks', title : '备注'},
  641. ]
  642. ]
  643. });
  644. Table.api.bindevent(table_plan);
  645. //回款记录
  646. var table_receivables=$('#receivables');
  647. table_receivables.bootstrapTable({
  648. url : 'qingdong/customer/contract/get_receivables?ids='+Config.idinfo.id,
  649. pk : 'id',
  650. sortName : 'id',
  651. toolbar: "#toolbar_receivables",
  652. operate : false,
  653. commonSearch : false,
  654. search : false,
  655. visible : false,
  656. showColumns : false,
  657. showExport : false,
  658. showToggle : false,
  659. columns : [
  660. [
  661. {field : 'number', title : '回款编号'},
  662. {field : 'money', title : '回款金额'},
  663. {field : 'plan.num', title : '期数'},
  664. {field : 'owner_staff.name', title : '负责人'},
  665. {
  666. field : 'check_status', title : '状态', formatter : Table.api.formatter.status,
  667. searchList : {0 : '待审核', 1 : '审核中', 2 : '审核通过', 3 : '审核未通过', 4 : '撤销', 5 : '草稿(未提交)'},
  668. custom: {0: 'gray', 1: 'gray',2: 'success', 3: 'danger', 4: 'danger', 5: 'danger'}
  669. },
  670. {field : 'return_time', title : '回款日期'},
  671. ]
  672. ]
  673. });
  674. Table.api.bindevent(table_receivables);
  675. },
  676. settings4: function () {
  677. //操作日志
  678. var table2 = $("#operation_log");
  679. // 初始化表格
  680. table2.bootstrapTable({
  681. url : 'qingdong/customer/log/index?contract_id='+Config.idinfo.id,
  682. pk : 'id',
  683. sortName : 'id',
  684. toolbar: "#toolbar_log",
  685. operate : false,
  686. commonSearch : false,
  687. search : false,
  688. visible : false,
  689. showColumns : false,
  690. showExport : false,
  691. showToggle : false,
  692. columns : [
  693. [
  694. {field: 'staff.name', title: __('员工')},
  695. {field: 'content', title: __('内容'),cellStyle:function (value,row,index,field) {
  696. return {
  697. css: {
  698. "min-width": "150px",
  699. "white-space": "nowrap",
  700. "text-overflow": "ellipsis",
  701. "overflow": "hidden",
  702. "max-width":"300px",
  703. 'cursor':"pointer"
  704. }
  705. };
  706. },formatter:function (value,row,index,field) {
  707. var span=document.createElement('span');
  708. span.setAttribute('title',value);
  709. span.innerHTML = value;
  710. return span.outerHTML;
  711. }
  712. },
  713. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  714. ]
  715. ]
  716. });
  717. Table.api.bindevent(table2);
  718. },
  719. basic:function (){
  720. },
  721. product: function () {
  722. //操作日志
  723. var table2 = $("#operation_product");
  724. // 初始化表格
  725. table2.bootstrapTable({
  726. url : 'qingdong/customer/contract/get_contract_product?contract_id='+Config.idinfo.id,
  727. pk : 'id',
  728. sortName : 'id',
  729. toolbar: "#toolbar_product",
  730. operate : false,
  731. commonSearch : false,
  732. search : false,
  733. visible : false,
  734. showColumns : false,
  735. showExport : false,
  736. showToggle : false,
  737. columns : [
  738. [
  739. {field: 'productinfo.name', title: __('产品名称')},
  740. {field: 'productinfo.type', title: __('规格')},
  741. {field: 'productinfo.unit', title: __('单位')},
  742. {field: 'number', title: __('数量')},
  743. {field: 'price', title: __('销售单价')},
  744. {field: 'wholesale', title: __('批发价')},
  745. {field: 'total_price', title: __('销售价格小计(元)'), formatter : function (value, row, index) {
  746. return row.price * row.number;
  747. }},
  748. // {field: 'ship_status', title: __('发货状态'),formatter:Table.api.formatter.status, searchList: {0:'待发货', 1: '已发货',2:'已收货'}},
  749. ]
  750. ]
  751. });
  752. Table.api.bindevent(table2);
  753. },
  754. },
  755. detail : function () {
  756. // 初始化表格参数配置
  757. Table.api.init({});
  758. $('.stafflist').popover({
  759. placement : 'bottom',
  760. trigger : 'hover'
  761. });
  762. //绑定事件
  763. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  764. var panel = $($(this).attr("href"));
  765. if (panel.length > 0) {
  766. Controller.tabledetail[panel.attr("id")].call(this);
  767. $(this).on('click', function (e) {
  768. $($(this).attr("href")).find(".btn-refresh").trigger("click");
  769. });
  770. }
  771. //移除绑定的事件
  772. $(this).unbind('shown.bs.tab');
  773. });
  774. //必须默认触发shown.bs.tab事件
  775. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  776. //附件
  777. var table_files=$('#files');
  778. table_files.bootstrapTable({
  779. url : 'qingdong/customer/contract/get_file'+ location.search,
  780. pk : 'id',
  781. sortName : 'id',
  782. toolbar: "#toolbar_files",
  783. operate : false,
  784. commonSearch : false,
  785. search : false,
  786. visible : false,
  787. showColumns : false,
  788. showExport : false,
  789. showToggle : false,
  790. columns : [
  791. [
  792. {field : 'name', title : '附件名称'},
  793. {field : 'size', title : '附件大小'},
  794. {
  795. field : 'file_path', title : '文件预览', events : Table.api.events.image, formatter : Table.api.formatter.image, operate : false
  796. },
  797. ]
  798. ]
  799. });
  800. Table.api.bindevent(table_files);
  801. //编辑
  802. $(document).on('click','#edits',function () {
  803. var id=$('#contractId').val();
  804. Fast.api.open("qingdong/customer/contract/edit?ids="+id, "合同编辑",{
  805. shadeClose: false,
  806. shade: false,
  807. maxmin: false,
  808. moveOut: false,
  809. scrollbars:false,
  810. callback:function(value){
  811. location.reload();
  812. },
  813. });
  814. }).on('click', '.btn-word', function (data) {
  815. //导出word
  816. var area = [$(window).width() > 1200 ? '1200px' : '70%', $(window).height() > 800 ? '800px' : '80%'];
  817. var options = {
  818. shadeClose : false,
  819. shade : [0.3, '#393D49'],
  820. area : area,
  821. callback : function (value) {
  822. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  823. window.location.href = value.file;
  824. }
  825. };
  826. Fast.api.open("qingdong/customer/contract/words?ids=" + $(this).data('id'), '导出word', options);
  827. });
  828. //删除
  829. $("#dels").on('click',function(){
  830. var id=$('#contractId').val();
  831. Layer.confirm('确定删除合同吗?', {
  832. btn: ['确定','取消']
  833. },function(index, layero){
  834. Fast.api.ajax("qingdong/customer/contract/del?ids="+id,function(data,ret){
  835. if(ret.code == 1){
  836. Layer.close(index);
  837. parent.location.reload();
  838. }
  839. },function(data,ret){
  840. });
  841. });
  842. });
  843. Controller.api.bindevent();
  844. },
  845. api : {
  846. bindevent : function () {
  847. $(document).on("fa.event.appendfieldlist", '.fieldlist', function(){
  848. //通用的表单组件事件绑定和组件渲染
  849. Form.events.selectpage($("form"));
  850. Form.events.datetimepicker($("form"));
  851. });
  852. $(".selectpage").data("params", function (obj) {
  853. var customer_id=$('#customer').val()
  854. //obj为SelectPage对象
  855. return {ids: customer_id};
  856. });
  857. function set_money(){
  858. var $price = $('.price');
  859. var $number = $('.number');
  860. var price=0;
  861. $.each($price, function (index, item) {
  862. var p = $(item).val(), n = $number.eq(index).val();
  863. p = parseFloat(p);
  864. n = parseInt(n);
  865. price += p * n;
  866. });
  867. $('#c-money').val(price);
  868. }
  869. $(document).on("change", ".product", function(){
  870. var $this=$(this);
  871. var id=$this.next('input').val();
  872. Fast.api.ajax("qingdong/customer/contract/get_product_price?id="+id,function(data,ret){
  873. $this.parent().parent().next('span').find('input').val(data.price);
  874. set_money();
  875. $(".fieldlist input:eq(2)").trigger("change");
  876. return false;
  877. });
  878. }).on("change", ".price", function(){
  879. set_money();
  880. }).on("change", ".number", function(){
  881. set_money();
  882. }).on("change", "#ratio_id", function(){
  883. var ratio=$('#ratio_id').find('option:selected').data('ratio');
  884. if(!ratio){
  885. $('.table_ratio').hide();
  886. return false;
  887. }
  888. var html="";
  889. $.each(ratio,function (index,item){
  890. html+="<tr>" +
  891. "<td>"+item.ratio+"%<input type='hidden' name='row[ratios]["+index+"][ratio]' value='"+item.ratio+"'></td>" +
  892. "<td><input data-source=\"qingdong/customer/customer/getteam\"" +
  893. "class=\"form-control selectpage\" name=\"row[ratios]["+index+"][staff_id]\" placeholder=\"请选择团队成员\" type=\"text\" value=\"\"></td>" +
  894. "</tr>";
  895. });
  896. $('.table_ratio').find('tbody').html(html);
  897. $('.table_ratio').show();
  898. Form.events.selectpage($("form"));
  899. $(".selectpage").data("params", function (obj) {
  900. var customer_id=$('[name="row[customer_id]"]').val()
  901. if(!customer_id){
  902. layer.msg('请先选择客户');
  903. return false;
  904. }
  905. //obj为SelectPage对象
  906. return {ids: customer_id};
  907. });
  908. }).on("click", ".select-customer", function(){
  909. var $this=$(this);
  910. top.Fast.api.open($(this).data("url") , __('Select'), {callback: function (data) {
  911. $this.html(data.name);
  912. $('[name="'+$this.data('name')+'"]').val(data.id);
  913. },area:["100%", "100%"]});
  914. }).on("click", ".select-contacts", function(){
  915. var $this=$(this),customer_id=$('[name="row[customer_id]"]').val();
  916. if(!customer_id){
  917. Layer.msg('请先选择客户');
  918. return false;
  919. }
  920. top.Fast.api.open($(this).data("url")+"&customer_id="+customer_id , __('Select'), {callback: function (data) {
  921. $this.html(data.name);
  922. $('[name="'+$this.data('name')+'"]').val(data.id);
  923. },area:["100%", "100%"]});
  924. }).on("click", ".select-business", function(){
  925. var $this=$(this),customer_id=$('[name="row[customer_id]"]').val();
  926. if(!customer_id){
  927. Layer.msg('请先选择客户');
  928. return false;
  929. }
  930. top.Fast.api.open($(this).data("url")+"&customer_id="+customer_id , __('Select'), {callback: function (data) {
  931. $this.html(data.name);
  932. $('[name="'+$this.data('name')+'"]').val(data.id);
  933. $.post('qingdong/customer/contract/get_business_product',{business_id:data.id},function (data){
  934. if(data.code == 1){
  935. var result=[];
  936. $.each(data.data,function (index,params){
  937. var r={};
  938. if(params.productinfo){
  939. r.product_name=params.productinfo.name;
  940. r.type=params.productinfo.type;
  941. r.cost_price=params.productinfo.cost_price;
  942. if(params.productinfo.goods){
  943. r.goods_name=params.productinfo.goods.name;
  944. }
  945. }
  946. r.product_id=params.product_id;
  947. r.price=params.price;
  948. r.number=params.number;
  949. result.push(r);
  950. });
  951. var res=JSON.stringify(result);
  952. $('textarea[name="row[product]"]').val(res);
  953. $('.fieldlist').trigger("fa.event.refreshfieldlist");
  954. set_money();
  955. }
  956. },'json');
  957. },area:["100%", "100%"]});
  958. }).on("click", ".select-product", function(){
  959. var $this=$(this);
  960. top.Fast.api.open($(this).data("url"), __('Select'), {callback: function (data) {
  961. $this.html(data.name);
  962. $('[name="'+$this.data('name')+'"]').val(data.id);
  963. $this.parent().parent().next('td').find('input').val(data.price);
  964. $this.parent().parent().parent().find('.price2').val(data.wholesale);
  965. if(data.goods){
  966. $this.parent().parent().parent().find('.goods').html(data.goods.name);
  967. }
  968. $this.parent().parent().parent().find('.type').html(data.type);
  969. set_money();
  970. $(".fieldlist input:eq(2)").trigger("change");
  971. },area:["100%", "100%"]});
  972. });
  973. Form.api.bindevent($("form[role=form]"), function(data, ret){
  974. //这里是表单提交处理成功后的回调函数,接收来自php的返回数据
  975. Fast.api.close(data);//这里是重点
  976. });
  977. }
  978. }
  979. };
  980. return Controller;
  981. });