protector.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'comment', 'selectpage'], function ($, undefined, Backend, Table, Form, Comment, Selectpage) {
  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. del_url: 'protector/del',
  12. multi_url: 'protector/multi',
  13. table: 'protector',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. showToggle: false,
  23. showColumns: false,
  24. // showExport: false,
  25. columns: [
  26. [
  27. {field: 'unit_name', title: __('Unit_name')},
  28. {field: 'contacts', title: __('Contacts')},
  29. {field: 'con_position', title: __('Con_position'),searchable: false},
  30. {field: 'unit_type', title: __('Unit_type'),searchable: false},
  31. {field: 'number', title: __('Number'),searchable: false},
  32. {field: 'depart_id', title: '操作人部门',searchList: $.getJSON('auth/group/departList'),formatter:function (value, row) {
  33. return row.usr_depart;
  34. }},
  35. {field: 'usr_nickname', title: '操作人'},
  36. {field: 'usr_depart', title: '操作人部门'},
  37. {field: 'pro_date', title: __('Pro_date'), operate:'RANGE', addclass:'datetimerange',searchable: false},
  38. {field: 'ex_date', title: __('Ex_date'),searchable: false, operate:'RANGE', addclass:'datetimerange'},
  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. console.log(data);
  61. }
  62. });
  63. Controller.api.bindevent();
  64. },
  65. edit: function () {
  66. Controller.api.bindevent();
  67. },
  68. api: {
  69. bindevent: function () {
  70. Form.api.bindevent($("form[role=form]"));
  71. },
  72. formatter:{
  73. operate: function (value, row, index) {
  74. var table = this.table;
  75. // 操作配置
  76. var options = table ? table.bootstrapTable('getOptions') : {};
  77. // 默认按钮组
  78. var buttons = $.extend([], this.buttons || []);
  79. switch (row.status){
  80. case 0: //保护中
  81. buttons.push({name: 'giveup', text: '放弃', classname: 'btn btn-xs btn-danger btn-giveup'});
  82. buttons.push({name: 'sign', text: '签单', classname: 'btn btn-xs btn-success btn-sign'});
  83. break;
  84. case 1:
  85. buttons.push({name: 'again', text: '再次保护', classname: 'btn btn-xs btn-success btn-again'});
  86. break;
  87. case 4:
  88. buttons.push({name: 'again', text:'再次保护', classname: 'btn btn-xs btn-success btn-again'});
  89. break;
  90. }
  91. buttons.push({name: 'follow', text:'跟进', classname: 'btn btn-xs btn-info btn-follow'});
  92. return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
  93. },
  94. },
  95. events:{
  96. operate: {
  97. // 放弃
  98. 'click .btn-giveup': function(e, value, row) {
  99. Layer.confirm('您确定放弃吗?',function (index) {
  100. var id = row.id;
  101. $.ajax({
  102. url: 'protector/giveup',
  103. type: 'post',
  104. data: { id:id },
  105. dataType: 'json',
  106. success: function success(res) {
  107. Layer.close(index);
  108. if(res.code == 1){
  109. Toastr.success(res.msg);
  110. $('.btn-refresh').click();
  111. } else {
  112. Toastr.error(res.msg);
  113. }
  114. }
  115. });
  116. });
  117. },
  118. // 签单
  119. 'click .btn-sign': function(e, value, row) {
  120. Layer.confirm('您确定签单吗?',function (index) {
  121. var id = row.id;
  122. $.ajax({
  123. url: 'protector/sign',
  124. type: 'post',
  125. data: { id:id },
  126. dataType: 'json',
  127. success: function success(res) {
  128. Layer.close(index);
  129. if(res.code == 1){
  130. Toastr.success(res.msg);
  131. $('.btn-refresh').click();
  132. } else {
  133. Toastr.error(res.msg);
  134. }
  135. }
  136. });
  137. });
  138. },
  139. // 再次保护
  140. 'click .btn-again': function(e, value, row) {
  141. Layer.confirm('您确定再次保护吗?',function (index) {
  142. var id = row.id;
  143. $.ajax({
  144. url: 'protector/again',
  145. type: 'post',
  146. data: { id:id },
  147. dataType: 'json',
  148. success: function success(res) {
  149. Layer.close(index);
  150. if(res.code == 1){
  151. Toastr.success(res.msg);
  152. $('.btn-refresh').click();
  153. } else {
  154. Toastr.error(res.msg);
  155. }
  156. }
  157. });
  158. });
  159. },
  160. // 跟进
  161. 'click .btn-follow': function (e, value, row) {
  162. var id = row.id;
  163. $.ajax({
  164. url: 'protector/showFollow',
  165. type: 'post',
  166. data: { id:id },
  167. dataType: 'json',
  168. success: function success(res) {
  169. Layer.open({
  170. area: ['600px','100%'],
  171. content:res.data,
  172. yes: function(index){
  173. addFollow(row.id,row.unit_name);
  174. layer.close(index); //如果设定了yes回调,需进行手工关闭
  175. }
  176. })
  177. }
  178. });
  179. }
  180. }
  181. }
  182. }
  183. };
  184. var addFollow;
  185. // 添加跟进记录
  186. addFollow = function (id,unit_name) {
  187. var time = $('#follow_time').val();
  188. var main = $('#main_text').val();
  189. $.ajax({
  190. url: 'protector/addFollow',
  191. type: 'post',
  192. data: { follow_time:time, main:main, id:id, unit_name:unit_name },
  193. dataType: 'json',
  194. success: function success(res) {
  195. if(res.code ==1){
  196. Toastr.success(res.msg);
  197. }
  198. }
  199. });
  200. }
  201. return Controller;
  202. });