sample_apply.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'books/sample_apply/index' + location.search,
  8. add_url: 'books/sample_apply/add',
  9. edit_url: 'books/sample_apply/edit',
  10. del_url: 'books/sample_apply/del',
  11. multi_url: 'books/sample_apply/multi',
  12. import_url: 'books/sample_apply/import',
  13. table: 'sample_apply',
  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. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'user.nickname', title: __('申请用户')},
  29. {field: 'book.title', title: __('申请书籍')},
  30. {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  31. {field: 'phone', title: __('Phone'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  32. {field: 'email', title: __('Email'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  33. {field: 'school', title: __('School'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  34. {field: 'use_to', title: __('用途'), searchList: {"0":__('教材用书'),"1":__('学习参考'),"2":__('其他')}, formatter: Table.api.formatter.normal},
  35. {field: 'mailing_name', title: __('Mailing_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  36. {field: 'mailing_area', title: __('Mailing_area'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  37. {field: 'mailing_address', title: __('Mailing_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  38. {field: 'mailing_phone', title: __('Mailing_phone'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  39. {field: 'status', title: __('状态'), searchList: {"0":__('未审核'),"1":__('已寄出'),"2":__('已拒绝')}, formatter: Table.api.formatter.status},
  40. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  41. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  42. {
  43. field: 'operate',
  44. title: __('Operate'),
  45. table: table,
  46. events: Table.api.events.operate,
  47. buttons: [{
  48. name: 'click',
  49. text:'已寄出',
  50. title: __('已寄出'),
  51. classname: 'btn btn-xs btn-info btn-click',
  52. url: 'books.books_level/edit?ids/{id}',
  53. data: {status:0},
  54. // icon: 'fa fa-leaf',
  55. click: function (data,row) {
  56. var temp=table.bootstrapTable('getSelections');
  57. var id = row.id;
  58. console.log(row);
  59. return $.ajax({
  60. // url:'http://up.kuman.cn/settle/cancel',
  61. url:'books.sample_apply/update_status?ids='+id,
  62. type:'post',
  63. // dataType:'json',
  64. data:{status:1},
  65. success:function(data){
  66. if(data.code === 1){
  67. layer.msg('操作成功');
  68. window.location.reload();
  69. }else{
  70. layer.msg(data.msg);
  71. }
  72. }
  73. });
  74. // Layer.alert("点击按钮执行的事件");
  75. },
  76. visible: function (row) {
  77. console.log(row)
  78. if (row.status === "0"){
  79. return true;
  80. }
  81. return false;
  82. },
  83. refresh:true,
  84. },
  85. {
  86. name: 'click',
  87. text:'拒绝',
  88. title: __('拒绝'),
  89. classname: 'btn btn-xs btn-danger btn-click',
  90. url: 'books.sample_apply/edit?ids/{id}',
  91. data: {status:1},
  92. // icon: 'fa fa-leaf',
  93. click: function (data,row) {
  94. var temp=table.bootstrapTable('getSelections');
  95. var id = row.id;
  96. console.log(row);
  97. return $.ajax({
  98. // url:'http://up.kuman.cn/settle/cancel',
  99. url:'books.sample_apply/update_status?ids='+id,
  100. type:'post',
  101. // dataType:'json',
  102. data:{status:2},
  103. success:function(data){
  104. if(data.code === 1){
  105. layer.msg('操作成功');
  106. window.location.reload();
  107. }else{
  108. layer.alert(data.msg);
  109. }
  110. }
  111. });
  112. // Layer.alert("点击按钮执行的事件");
  113. },
  114. visible: function (row) {
  115. // console.log(row)
  116. if (row.status === "0"){
  117. return true;
  118. }
  119. return false;
  120. },
  121. refresh:true,
  122. },
  123. ],
  124. formatter: function (value, row, index) {
  125. var that = $.extend({}, this);
  126. $(table).data("operate-del", null); // 列表页面隐藏 .编辑operate-edit - 删除按钮operate-del
  127. $(table).data("operate-edit", null); // 列表页面隐藏 .编辑operate-edit - 删除按钮operate-del
  128. that.table = table;
  129. return Table.api.formatter.operate.call(that, value, row, index);
  130. },
  131. }
  132. ]
  133. ]
  134. });
  135. // 为表格绑定事件
  136. Table.api.bindevent(table);
  137. },
  138. add: function () {
  139. Controller.api.bindevent();
  140. },
  141. edit: function () {
  142. Controller.api.bindevent();
  143. },
  144. api: {
  145. bindevent: function () {
  146. Form.api.bindevent($("form[role=form]"));
  147. }
  148. }
  149. };
  150. return Controller;
  151. });