protector.js 14 KB

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