protector.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], function ($, undefined, Backend, Table, Form, 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: 'price', title: '单价',searchable: false},
  33. {field: 'total', title: '总价',searchable: false},
  34. {field: 'depart_id', title: '操作人部门',searchable: false,searchList: $.getJSON('auth/group/departList'),formatter:function (value, row) {
  35. return row.usr_depart;
  36. }},
  37. {field: 'usr_nickname', title: '操作人'},
  38. {field: 'pro_date', title: __('Pro_date'), operate:'RANGE', addclass:'datetimerange'},
  39. {field: 'ex_date', title: __('Ex_date'),searchable: false, operate:'RANGE', addclass:'datetimerange'},
  40. {field: 'operate', title: __('Operate'),searchable: false,visible: status!='contract' ? true : false,
  41. table: table,
  42. events: Controller.api.events.operate,
  43. formatter: Controller.api.formatter.operate
  44. }
  45. ]
  46. ]
  47. });
  48. // 为表格绑定事件
  49. Table.api.bindevent(table);
  50. },
  51. add: function () {
  52. $.ajax({
  53. url: 'intention/unitTypeList',
  54. type: 'post',
  55. dataType: 'json',
  56. success: function success(res) {
  57. var data = res.rows;
  58. $('#c-unit_type').selectPage({
  59. data : data,
  60. });
  61. console.log(data);
  62. }
  63. });
  64. Controller.api.bindevent();
  65. },
  66. edit: function () {
  67. $.ajax({
  68. url: 'intention/unitTypeList',
  69. type: 'post',
  70. dataType: 'json',
  71. success: function success(res) {
  72. var data = res.rows;
  73. $('#c-unit_type').selectPage({
  74. data : data,
  75. });
  76. console.log(data);
  77. }
  78. });
  79. Controller.api.bindevent();
  80. },
  81. api: {
  82. bindevent: function () {
  83. Form.api.bindevent($("form[role=form]"));
  84. },
  85. formatter:{
  86. operate: function (value, row, index) {
  87. var table = this.table;
  88. // 操作配置
  89. var options = table ? table.bootstrapTable('getOptions') : {};
  90. // 默认按钮组
  91. var buttons = $.extend([], this.buttons || []);
  92. switch (row.status){
  93. case 0: //保护中
  94. buttons.push({name: 'giveup', text: '放弃', classname: 'btn btn-xs btn-danger btn-giveup'});
  95. buttons.push({name: 'sign', text: '签单', classname: 'btn btn-xs btn-success btn-sign'});
  96. buttons.push({name: 'follow', text:'跟进', classname: 'btn btn-xs btn-info btn-follow'});
  97. buttons.push({name: 'edit', text:'修改', classname: 'btn btn-xs btn-warning btn-editone'});
  98. break;
  99. case 1:
  100. buttons.push({name: 'again', text: '再次保护', classname: 'btn btn-xs btn-success btn-again'});
  101. break;
  102. case 4:
  103. buttons.push({name: 'again', text:'再次保护', classname: 'btn btn-xs btn-success btn-again'});
  104. break;
  105. }
  106. return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
  107. },
  108. },
  109. events:{
  110. operate: {
  111. // 放弃
  112. 'click .btn-giveup': function(e, value, row) {
  113. Layer.confirm('您确定放弃吗?',function (index) {
  114. var id = row.id;
  115. $.ajax({
  116. url: 'protector/giveup',
  117. type: 'post',
  118. data: { id:id },
  119. dataType: 'json',
  120. success: function success(res) {
  121. Layer.close(index);
  122. if(res.code == 1){
  123. Toastr.success(res.msg);
  124. $('.btn-refresh').click();
  125. } else {
  126. Toastr.error(res.msg);
  127. }
  128. }
  129. });
  130. });
  131. },
  132. // 签单
  133. 'click .btn-sign': function(e, value, row) {
  134. Layer.confirm('您确定签单吗?',function (index) {
  135. var id = row.id;
  136. $.ajax({
  137. url: 'protector/sign',
  138. type: 'post',
  139. data: { id:id },
  140. dataType: 'json',
  141. success: function success(res) {
  142. Layer.close(index);
  143. if(res.code == 1){
  144. Toastr.success(res.msg);
  145. $('.btn-refresh').click();
  146. } else {
  147. Toastr.error(res.msg);
  148. }
  149. }
  150. });
  151. });
  152. },
  153. // 再次保护
  154. 'click .btn-again': function(e, value, row) {
  155. Layer.confirm('您确定再次保护吗?',function (index) {
  156. var id = row.id;
  157. $.ajax({
  158. url: 'protector/again',
  159. type: 'post',
  160. data: { id:id },
  161. dataType: 'json',
  162. success: function success(res) {
  163. Layer.close(index);
  164. if(res.code == 1){
  165. Toastr.success(res.msg);
  166. $('.btn-refresh').click();
  167. } else {
  168. Toastr.error(res.msg);
  169. }
  170. }
  171. });
  172. });
  173. },
  174. // 跟进
  175. 'click .btn-follow': function (e, value, row) {
  176. var id = row.id;
  177. $.ajax({
  178. url: 'protector/showFollow',
  179. type: 'post',
  180. data: { id:id },
  181. dataType: 'json',
  182. success: function success(res) {
  183. Layer.open({
  184. area: ['600px','100%'],
  185. content:res.data,
  186. yes: function(index){
  187. addFollow(row.id,row.unit_name);
  188. layer.close(index); //如果设定了yes回调,需进行手工关闭
  189. }
  190. })
  191. }
  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. }
  205. }
  206. }
  207. };
  208. var addFollow;
  209. // 添加跟进记录
  210. addFollow = function (id,unit_name) {
  211. var time = $('#follow_time').val();
  212. var main = $('#main_text').val();
  213. $.ajax({
  214. url: 'protector/addFollow',
  215. type: 'post',
  216. data: { follow_time:time, main:main, id:id, unit_name:unit_name },
  217. dataType: 'json',
  218. success: function success(res) {
  219. if(res.code ==1){
  220. Toastr.success(res.msg);
  221. }
  222. }
  223. });
  224. };
  225. return Controller;
  226. });