protector.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'comment'], function ($, undefined, Backend, Table, Form, Comment) {
  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')},
  30. {field: 'unit_type', title: __('Unit_type')},
  31. {field: 'number', title: __('Number')},
  32. {field: 'price', title: '单价', formatter:function (value) {
  33. return '¥' + value;
  34. }},
  35. {field: 'usr_nickname', title: '操作人'},
  36. {field: 'usr_depart', title: '操作人部门'},
  37. {field: 'pro_date', title: __('Pro_date'), operate:'RANGE', addclass:'datetimerange'},
  38. {field: 'ex_date', title: __('Ex_date'), operate:'RANGE', addclass:'datetimerange'},
  39. {field: 'operate', title: __('Operate'),
  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. Controller.api.bindevent();
  52. },
  53. edit: function () {
  54. Controller.api.bindevent();
  55. },
  56. api: {
  57. bindevent: function () {
  58. Form.api.bindevent($("form[role=form]"));
  59. },
  60. formatter:{
  61. operate: function (value, row, index) {
  62. var table = this.table;
  63. // 操作配置
  64. var options = table ? table.bootstrapTable('getOptions') : {};
  65. // 默认按钮组
  66. var buttons = $.extend([], this.buttons || []);
  67. switch (row.status){
  68. case 0: //保护中
  69. buttons.push({name: 'giveup', text: '放弃', classname: 'btn btn-xs btn-danger btn-giveup'});
  70. buttons.push({name: 'sign', text: '转为已签单', classname: 'btn btn-xs btn-success btn-sign'});
  71. break;
  72. case 1:
  73. buttons.push({name: 'again', text: '转为保护客户', classname: 'btn btn-xs btn-success btn-again'});
  74. break;
  75. case 4:
  76. buttons.push({name: 'again', text:'转为保护客户', classname: 'btn btn-xs btn-success btn-again'});
  77. break;
  78. }
  79. buttons.push({name: 'follow', text:'跟进', classname: 'btn btn-xs btn-info btn-follow'});
  80. return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
  81. },
  82. },
  83. events:{
  84. operate: {
  85. // 放弃
  86. 'click .btn-giveup': function(e, value, row) {
  87. Layer.confirm('您确定放弃吗?',function (index) {
  88. var id = row.id;
  89. $.ajax({
  90. url: 'protector/giveup',
  91. type: 'post',
  92. data: { id:id },
  93. dataType: 'json',
  94. success: function success(res) {
  95. Layer.close(index);
  96. if(res.code == 1){
  97. Toastr.success(res.msg);
  98. $('.btn-refresh').click();
  99. } else {
  100. Toastr.error(res.msg);
  101. }
  102. }
  103. });
  104. });
  105. },
  106. // 签单
  107. 'click .btn-sign': function(e, value, row) {
  108. Layer.confirm('您确定签单吗?',function (index) {
  109. var id = row.id;
  110. $.ajax({
  111. url: 'protector/sign',
  112. type: 'post',
  113. data: { id:id },
  114. dataType: 'json',
  115. success: function success(res) {
  116. Layer.close(index);
  117. if(res.code == 1){
  118. Toastr.success(res.msg);
  119. $('.btn-refresh').click();
  120. } else {
  121. Toastr.error(res.msg);
  122. }
  123. }
  124. });
  125. });
  126. },
  127. // 再次保护
  128. 'click .btn-again': function(e, value, row) {
  129. Layer.confirm('您确定再次保护吗?',function (index) {
  130. var id = row.id;
  131. $.ajax({
  132. url: 'protector/again',
  133. type: 'post',
  134. data: { id:id },
  135. dataType: 'json',
  136. success: function success(res) {
  137. Layer.close(index);
  138. if(res.code == 1){
  139. Toastr.success(res.msg);
  140. $('.btn-refresh').click();
  141. } else {
  142. Toastr.error(res.msg);
  143. }
  144. }
  145. });
  146. });
  147. },
  148. // 跟进
  149. 'click .btn-follow': function (e, value, row) {
  150. var id = row.id;
  151. $.ajax({
  152. url: 'protector/showFollow',
  153. type: 'post',
  154. data: { id:id },
  155. dataType: 'json',
  156. success: function success(res) {
  157. Layer.open({
  158. area: ['600px','100%'],
  159. content:res.data,
  160. yes: function(index){
  161. addFollow(row.id,row.unit_name);
  162. layer.close(index); //如果设定了yes回调,需进行手工关闭
  163. }
  164. })
  165. }
  166. });
  167. }
  168. }
  169. }
  170. }
  171. };
  172. var addFollow;
  173. // 添加跟进记录
  174. addFollow = function (id,unit_name) {
  175. var time = $('#follow_time').val();
  176. var main = $('#main_text').val();
  177. $.ajax({
  178. url: 'protector/addFollow',
  179. type: 'post',
  180. data: { follow_time:time, main:main, id:id, unit_name:unit_name },
  181. dataType: 'json',
  182. success: function success(res) {
  183. if(res.code ==1){
  184. Toastr.success(res.msg);
  185. }
  186. }
  187. });
  188. }
  189. // c-total
  190. $("#c-price").change(function(){
  191. var price = $("#c-price").val()
  192. var number = $("#c-price").val()
  193. changeTotal(price,number)
  194. });
  195. $("#c-number").change(function(){
  196. var price = $("#c-price").val()
  197. var number = $("#c-price").val()
  198. changeTotal(price,number)
  199. });
  200. function changeTotal(price,number) {
  201. if(price && number) {
  202. $("#c-price").val(price * number)
  203. }
  204. }
  205. return Controller;
  206. });