protector.js 9.2 KB

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