contract.js 51 KB

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