protector.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. sign: function () {
  81. Controller.api.bindevent();
  82. },
  83. api: {
  84. bindevent: function () {
  85. Form.api.bindevent($("form[role=form]"));
  86. },
  87. formatter:{
  88. operate: function (value, row, index) {
  89. var table = this.table;
  90. // 操作配置
  91. var options = table ? table.bootstrapTable('getOptions') : {};
  92. // 默认按钮组
  93. var buttons = $.extend([], this.buttons || []);
  94. switch (row.status){
  95. case 0: //保护中
  96. buttons.push({text: '放弃', classname: 'btn btn-xs btn-danger btn-giveup'});
  97. buttons.push({text: '签单', classname: 'btn btn-xs btn-success btn-sign'});
  98. buttons.push({text:'跟进', classname: 'btn btn-xs btn-info btn-follow'});
  99. buttons.push({text:'修改', classname: 'btn btn-xs btn-primary btn-editone'});
  100. buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'});
  101. buttons.push({
  102. name: 'del',
  103. icon: 'fa fa-trash',
  104. title: __('Del'),
  105. extend: 'data-toggle="tooltip"',
  106. classname: 'btn btn-xs btn-danger btn-delone'
  107. });
  108. break;
  109. case 1:
  110. buttons.push({text: '再次保护', classname: 'btn btn-xs btn-success btn-again'});
  111. break;
  112. case 2:
  113. buttons.push({text:'修改', classname: 'btn btn-xs btn-primary btn-editone'});
  114. buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'});
  115. break;
  116. case 4:
  117. buttons.push({text:'再次保护', classname: 'btn btn-xs btn-success btn-again'});
  118. break;
  119. }
  120. return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
  121. },
  122. },
  123. events:{
  124. operate: {
  125. // 放弃
  126. 'click .btn-giveup': function(e, value, row) {
  127. Layer.confirm('您确定放弃吗?',function (index) {
  128. var id = row.id;
  129. $.ajax({
  130. url: 'protector/giveup',
  131. type: 'post',
  132. data: { id:id },
  133. dataType: 'json',
  134. success: function success(res) {
  135. Layer.close(index);
  136. if(res.code == 1){
  137. Toastr.success(res.msg);
  138. $('.btn-refresh').click();
  139. } else {
  140. Toastr.error(res.msg);
  141. }
  142. }
  143. });
  144. });
  145. },
  146. // 签单
  147. 'click .btn-sign': function(e, value, row) {
  148. e.stopPropagation();
  149. e.preventDefault();
  150. var options = $(this).closest('table').bootstrapTable('getOptions');
  151. var open = Fast.api.open(options.extend.sign_url + (options.extend.sign_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Sign'), {
  152. title: '签单',
  153. maxmin: false
  154. });
  155. },
  156. // 再次保护
  157. 'click .btn-again': function(e, value, row) {
  158. Layer.confirm('您确定再次保护吗?',function (index) {
  159. var id = row.id;
  160. $.ajax({
  161. url: 'protector/again',
  162. type: 'post',
  163. data: { id:id },
  164. dataType: 'json',
  165. success: function success(res) {
  166. Layer.close(index);
  167. if(res.code == 1){
  168. Toastr.success(res.msg);
  169. $('.btn-refresh').click();
  170. } else {
  171. Toastr.error(res.msg);
  172. }
  173. }
  174. });
  175. });
  176. },
  177. // 跟进
  178. 'click .btn-follow': function (e, value, row) {
  179. e.stopPropagation();
  180. e.preventDefault();
  181. var options = $(this).closest('table').bootstrapTable('getOptions');
  182. var open = Fast.api.open(options.extend.follow_url + (options.extend.follow_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Follow'), {
  183. title: '跟进',
  184. maxmin: false
  185. });
  186. },
  187. // 修改
  188. 'click .btn-editone': function clickBtnEditone(e, value, row, index) {
  189. e.stopPropagation();
  190. e.preventDefault();
  191. var options = $(this).closest('table').bootstrapTable('getOptions');
  192. var open = Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Edit'), {
  193. title: '修改',
  194. maxmin: false
  195. });
  196. },
  197. 'click .btn-detail': function clickBtnEditone(e, value, row, index) {
  198. var html = '<table class="table table-striped table-bordered table-hover">';
  199. html += '<tr><td>公司名称</td><td>'+ row.unit_name +'</td></tr>';
  200. html += '<tr><td>联系人</td><td>'+ row.contacts +'</td></tr>';
  201. html += '<tr><td>联系方式</td><td>'+ row.phone +'</td></tr>';
  202. html += '<tr><td>固定电话</td><td>'+ row.fixed_phone +'</td></tr>';
  203. html += '<tr><td>地址</td><td>'+ row.address +'</td></tr>';
  204. html += '<tr><td>联系人职位</td><td>'+ row.con_position +'</td></tr>';
  205. html += '<tr><td>单位性质</td><td>'+ row.unit_type +'</td></tr>';
  206. html += '<tr><td>人数</td><td>'+ row.number +'</td></tr>';
  207. html += '<tr><td>单价</td><td>'+ row.price +'</td></tr>';
  208. html += '<tr><td>备注</td><td>'+ row.remark +'</td></tr>';
  209. html += '<tr><td>总价</td><td>'+ row.total +'</td></tr>';
  210. html += '<tr><td>操作人</td><td>'+ row.usr_nickname +'</td></tr>';
  211. html += '<tr><td>操作人部门</td><td>'+ row.usr_depart +'</td></tr>';
  212. html += '</table>';
  213. Layer.open({
  214. content : html,
  215. area : ['500px'],
  216. })
  217. },
  218. 'click .btn-delone': function (e, value, row, index) {
  219. e.stopPropagation();
  220. e.preventDefault();
  221. var that = this;
  222. var top = $(that).offset().top - $(window).scrollTop();
  223. var left = $(that).offset().left - $(window).scrollLeft() - 260;
  224. if (top + 154 > $(window).height()) {
  225. top = top - 154;
  226. }
  227. if ($(window).width() < 480) {
  228. top = left = undefined;
  229. }
  230. Layer.confirm(
  231. __('Are you sure you want to delete this item?'),
  232. {icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true},
  233. function (index) {
  234. var table = $(that).closest('table');
  235. var options = table.bootstrapTable('getOptions');
  236. Table.api.multi("del", row[options.pk], table, that);
  237. Layer.close(index);
  238. }
  239. );
  240. }
  241. }
  242. }
  243. }
  244. };
  245. // 添加跟进记录
  246. addFollow = function (id,unit_name) {
  247. var time = $('#follow_time').val();
  248. var main = $('#main_text').val();
  249. $.ajax({
  250. url: 'protector/addFollow',
  251. type: 'post',
  252. data: { follow_time:time, main:main, id:id, unit_name:unit_name },
  253. dataType: 'json',
  254. success: function success(res) {
  255. if(res.code ==1){
  256. Toastr.success(res.msg);
  257. }
  258. }
  259. });
  260. };
  261. // 检测保护单位名称
  262. $('.btn-TestingName').click(function () {
  263. var unit_name = $('#c-unit_name').val();
  264. if(unit_name != null){
  265. $.ajax({
  266. url: 'protector/TestingName',
  267. type: 'post',
  268. data: {unit_name:unit_name},
  269. dataType: 'json',
  270. success: function success(res) {
  271. if(res.code == 1){
  272. Toastr.success(res.msg);
  273. } else {
  274. Toastr.error(res.msg);
  275. }
  276. }
  277. });
  278. }
  279. });
  280. return Controller;
  281. });
  282. var addFollow;