protector.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage', 'bootstrap-datetimepicker'], function ($, undefined, Backend, Table, Form, Selectpage, Datetimepicker) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. var status = GetQueryString('status');
  6. Table.api.init({
  7. extend: {
  8. index_url: 'protector/index' + '/status/' + status,
  9. add_url: 'protector/add',
  10. edit_url: 'protector/edit',
  11. sign_url: 'protector/sign',
  12. follow_url: 'protector/follow',
  13. del_url: 'protector/del',
  14. sign_url: 'protector/sign',
  15. multi_url: 'protector/multi',
  16. table: 'protector',
  17. }
  18. });
  19. var table = $("#table");
  20. // 初始化表格
  21. table.bootstrapTable({
  22. url: $.fn.bootstrapTable.defaults.extend.index_url,
  23. pk: 'id',
  24. sortName: 'id',
  25. showToggle: false,
  26. showColumns: false,
  27. showExport: false,
  28. columns: [
  29. [
  30. {field: 'unit_name', title: '公司名称'},
  31. {field: 'unit_type', title:'单位性质',searchable: false},
  32. {field: 'usr_nickname', title: '操作人'},
  33. {field: 'depart_id', title: '操作人部门',searchable: false,searchList: $.getJSON('auth/group/departList'),formatter:function (value, row) {
  34. return row.usr_depart;
  35. }},
  36. {field: 'pro_date', title: __('Pro_date'), operate:'RANGE', addclass:'datetimerange'},
  37. {field: 'ex_date', title: __('Ex_date'),searchable: false, visible: status == 'contract' ? false : true, operate:'RANGE', addclass:'datetimerange'},
  38. {field: 'again_date', title: '签单到期时间',searchable: false, visible: status == 'contract' ? true : false},
  39. {field: 'operate', title: __('Operate'),searchable: false,
  40. table: table,
  41. events: Controller.api.events.operate,
  42. formatter: Controller.api.formatter.operate
  43. }
  44. ]
  45. ]
  46. });
  47. // 为表格绑定事件
  48. Table.api.bindevent(table);
  49. },
  50. add: function () {
  51. $.ajax({
  52. url: 'intention/unitTypeList',
  53. type: 'post',
  54. dataType: 'json',
  55. success: function success(res) {
  56. var data = res.rows;
  57. $('#c-unit_type').selectPage({
  58. data : data,
  59. });
  60. }
  61. });
  62. Controller.api.bindevent();
  63. },
  64. edit: function () {
  65. $.ajax({
  66. url: 'intention/unitTypeList',
  67. type: 'post',
  68. dataType: 'json',
  69. success: function success(res) {
  70. var data = res.rows;
  71. $('#c-unit_type').selectPage({
  72. data : data,
  73. });
  74. console.log(data);
  75. }
  76. });
  77. Controller.api.bindevent();
  78. },
  79. follow: function () {
  80. Controller.api.bindevent();
  81. },
  82. sign: function () {
  83. Controller.api.bindevent();
  84. },
  85. api: {
  86. bindevent: function () {
  87. Form.api.bindevent($("form[role=form]"));
  88. },
  89. formatter:{
  90. operate: function (value, row, index) {
  91. var table = this.table;
  92. // 操作配置
  93. var options = table ? table.bootstrapTable('getOptions') : {};
  94. // 默认按钮组
  95. var buttons = $.extend([], this.buttons || []);
  96. switch (row.status){
  97. case 0: //保护中
  98. buttons.push({text: '放弃', classname: 'btn btn-xs btn-danger btn-giveup'});
  99. buttons.push({name:'sign',text: '签单', classname: 'btn btn-xs btn-success btn-sign'});
  100. buttons.push({text:'跟进', classname: 'btn btn-xs btn-info btn-follow'});
  101. buttons.push({text:'修改', classname: 'btn btn-xs btn-primary btn-editone'});
  102. buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'});
  103. buttons.push({
  104. name: 'del',
  105. icon: 'fa fa-trash',
  106. title: __('Del'),
  107. extend: 'data-toggle="tooltip"',
  108. classname: 'btn btn-xs btn-danger btn-delone'
  109. });
  110. break;
  111. case 1:
  112. buttons.push({text: '再次保护', classname: 'btn btn-xs btn-success btn-again'});
  113. break;
  114. case 2:
  115. buttons.push({text:'修改', classname: 'btn btn-xs btn-primary btn-editone'});
  116. buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'});
  117. break;
  118. case 4:
  119. buttons.push({text:'再次保护', classname: 'btn btn-xs btn-success btn-again'});
  120. break;
  121. }
  122. return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
  123. },
  124. },
  125. events:{
  126. operate: {
  127. // 放弃
  128. 'click .btn-giveup': function(e, value, row) {
  129. Layer.confirm('您确定放弃吗?',function (index) {
  130. var id = row.id;
  131. $.ajax({
  132. url: 'protector/giveup',
  133. type: 'post',
  134. data: { id:id },
  135. dataType: 'json',
  136. success: function success(res) {
  137. Layer.close(index);
  138. if(res.code == 1){
  139. Toastr.success(res.msg);
  140. $('.btn-refresh').click();
  141. } else {
  142. Toastr.error(res.msg);
  143. }
  144. }
  145. });
  146. });
  147. },
  148. // 签单
  149. 'click .btn-sign': function(e, value, row) {
  150. e.stopPropagation();
  151. e.preventDefault();
  152. var options = $(this).closest('table').bootstrapTable('getOptions');
  153. var open = Fast.api.open(options.extend.sign_url + (options.extend.sign_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Sign'), {
  154. title: '签单',
  155. maxmin: false
  156. });
  157. },
  158. // 再次保护
  159. 'click .btn-again': function(e, value, row) {
  160. Layer.confirm('您确定再次保护吗?',function (index) {
  161. var id = row.id;
  162. $.ajax({
  163. url: 'protector/again',
  164. type: 'post',
  165. data: { id:id },
  166. dataType: 'json',
  167. success: function success(res) {
  168. Layer.close(index);
  169. if(res.code == 1){
  170. Toastr.success(res.msg);
  171. $('.btn-refresh').click();
  172. } else {
  173. Toastr.error(res.msg);
  174. }
  175. }
  176. });
  177. });
  178. },
  179. // 跟进
  180. 'click .btn-follow': function (e, value, row) {
  181. e.stopPropagation();
  182. e.preventDefault();
  183. var options = $(this).closest('table').bootstrapTable('getOptions');
  184. var open = Fast.api.open(options.extend.follow_url + (options.extend.follow_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Follow'), {
  185. title: '跟进',
  186. maxmin: false
  187. });
  188. },
  189. // 修改
  190. 'click .btn-editone': function clickBtnEditone(e, value, row, index) {
  191. e.stopPropagation();
  192. e.preventDefault();
  193. var options = $(this).closest('table').bootstrapTable('getOptions');
  194. var open = Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Edit'), {
  195. title: '修改',
  196. maxmin: false
  197. });
  198. },
  199. 'click .btn-detail': function clickBtnEditone(e, value, row, index) {
  200. var html = '<table class="table table-striped table-bordered table-hover">';
  201. html += '<tr><td>公司名称</td><td>'+ row.unit_name +'</td></tr>';
  202. html += '<tr><td>联系人</td><td>'+ row.contacts +'</td></tr>';
  203. html += '<tr><td>联系方式</td><td>'+ row.phone +'</td></tr>';
  204. html += '<tr><td>固定电话</td><td>'+ row.fixed_phone +'</td></tr>';
  205. html += '<tr><td>地址</td><td>'+ row.address +'</td></tr>';
  206. html += '<tr><td>联系人职位</td><td>'+ row.con_position +'</td></tr>';
  207. html += '<tr><td>单位性质</td><td>'+ row.unit_type +'</td></tr>';
  208. html += '<tr><td>人数</td><td>'+ row.number +'</td></tr>';
  209. html += '<tr><td>单价</td><td>'+ row.price +'</td></tr>';
  210. html += '<tr><td>备注</td><td>'+ row.remark +'</td></tr>';
  211. html += '<tr><td>总价</td><td>'+ row.total +'</td></tr>';
  212. html += '<tr><td>操作人</td><td>'+ row.usr_nickname +'</td></tr>';
  213. html += '<tr><td>操作人部门</td><td>'+ row.usr_depart +'</td></tr>';
  214. html += '</table>';
  215. Layer.open({
  216. content : html,
  217. area : ['500px'],
  218. })
  219. },
  220. 'click .btn-delone': function (e, value, row, index) {
  221. e.stopPropagation();
  222. e.preventDefault();
  223. var that = this;
  224. var top = $(that).offset().top - $(window).scrollTop();
  225. var left = $(that).offset().left - $(window).scrollLeft() - 260;
  226. if (top + 154 > $(window).height()) {
  227. top = top - 154;
  228. }
  229. if ($(window).width() < 480) {
  230. top = left = undefined;
  231. }
  232. Layer.confirm(
  233. __('Are you sure you want to delete this item?'),
  234. {icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true},
  235. function (index) {
  236. var table = $(that).closest('table');
  237. var options = table.bootstrapTable('getOptions');
  238. Table.api.multi("del", row[options.pk], table, that);
  239. Layer.close(index);
  240. }
  241. );
  242. }
  243. }
  244. }
  245. }
  246. };
  247. // 添加跟进记录
  248. addFollow = function (id,unit_name) {
  249. var time = $('#follow_time').val();
  250. var main = $('#main_text').val();
  251. $.ajax({
  252. url: 'protector/addFollow',
  253. type: 'post',
  254. data: { follow_time:time, main:main, id:id, unit_name:unit_name },
  255. dataType: 'json',
  256. success: function success(res) {
  257. if(res.code ==1){
  258. Toastr.success(res.msg);
  259. }
  260. }
  261. });
  262. };
  263. // 检测保护单位名称
  264. $('.btn-TestingName').click(function () {
  265. var unit_name = $('#c-unit_name').val();
  266. if(unit_name != null){
  267. $.ajax({
  268. url: 'protector/TestingName',
  269. type: 'post',
  270. data: {unit_name:unit_name},
  271. dataType: 'json',
  272. success: function success(res) {
  273. if(res.code == 1){
  274. Toastr.success(res.msg);
  275. } else {
  276. Toastr.error(res.msg);
  277. }
  278. }
  279. });
  280. }
  281. });
  282. // 全系统搜索
  283. $('.btn-all-search').click(function () {
  284. var val = $('.input-all-search').val();
  285. $.ajax({
  286. url: 'protector/allSearch',
  287. type: 'post',
  288. data: { val:val },
  289. dataType: 'json',
  290. success: function success(res) {
  291. Layer.open({
  292. content:res,
  293. area:['800px'],
  294. title:val
  295. })
  296. }
  297. });
  298. });
  299. return Controller;
  300. });
  301. var addFollow;