protector.js 14 KB

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