res.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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: 'res/index' + location.search,
  8. add_url: 'res/add',
  9. edit_url: 'res/edit',
  10. // del_url: 'res/del',
  11. multi_url: 'res/multi',
  12. import_url: 'res/import',
  13. reports_url:'res/report',
  14. couse_url:'res/couse',
  15. table: 'res',
  16. }
  17. });
  18. var table = $("#table");
  19. // 初始化表格
  20. table.bootstrapTable({
  21. url: $.fn.bootstrapTable.defaults.extend.index_url,
  22. pk: 'id',
  23. sortName: 'id',
  24. fixedColumns: true,
  25. fixedRightNumber: 1,
  26. columns: [
  27. [
  28. {checkbox: true},
  29. {field: 'id', title: __('Id'),operate: false},
  30. {field: 'entrust_no', title: __('Entrust_no'), operate: false},
  31. {field: 'name', title: __('Name'), operate: 'LIKE'},
  32. {field: 'bach', title: __('Bach'), operate: 'LIKE'},
  33. {field: 'dis', title: __('Dis'),operate: false},
  34. {field: 'dis_impurity', title: __('Dis_impurity'),operate: false},
  35. {field: 'ben_total', title: __('Ben_total'),operate: false},
  36. {field: 'ben', title: __('Ben'),operate: false},
  37. {field: 'unit', title: __('Unit'),operate: false},
  38. {field: 'judge', title: __('Judge'), operate: 'LIKE',searchList: {"0":'不合格',"1":'合格'}, formatter: Table.api.formatter.status,function (value,row,index) {
  39. if (value == 1){
  40. value = '合格';
  41. return '<span style="color: #18bc9c">' +value+ '</span>';
  42. }else{
  43. value = '不合格';
  44. return '<span style="color: #f75444">' +value+ '</span>';
  45. }
  46. }},
  47. // {field: 'entrust_id', title: __('Entrust_id') },
  48. {field: 'machine', title: __('Machine'), operate: ''},
  49. {field: 'sample_no', title: __('Sample_no'), operate: 'LIKE'},
  50. // {field: 'standard_id', title: __('Standard_id')},
  51. {field: 'standard_name', title: __('Standard_name'), operate: 'LIKE',searchList: $.getJSON("res/companyselect")},
  52. {field: 'create', title: __('Create'),operate: 'RANGE_DATE', addclass: 'datetimerange', formatter: Table.api.formatter.date,datetimeFormat:'YYYY-MM-DD'},
  53. {field: 'maker', title: __('Maker'),operate: false},
  54. {field: 'remark', title: __('Remark'),operate: false},
  55. {field: 'params', title: __('Params'),operate: false},
  56. // {field: 'userid', title: __('Userid')},
  57. {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
  58. // {field: 'delete_time', title: __('Delete_time'), operate: 'LIKE'},
  59. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  60. buttons: [
  61. {
  62. name: 'data',
  63. text: __('检测数据'),
  64. title: __('检测数据'),
  65. classname: 'btn btn-xs btn-primary btn-dialog',
  66. icon: 'fa fa-list',
  67. extend:'data-area=["100%","100%"]',
  68. url: 'res/data/id/{ids}',
  69. callback: function (data) {
  70. },
  71. visible: function (row) {
  72. //返回true时按钮显示,返回false隐藏
  73. return true;
  74. }
  75. },
  76. {
  77. name: 'data',
  78. text: __('导出数据报告'),
  79. title: __('导出数据报告'),
  80. classname: 'btn btn-xs btn-primary',
  81. // classname: 'btn btn-xs btn-primary btn-dialog',
  82. icon: 'fa fa-list',
  83. extend:'data-area=["100%","100%"]',
  84. url: 'res/report/id/{ids}',
  85. callback: function (data) {
  86. },
  87. visible: function (row) {
  88. //返回true时按钮显示,返回false隐藏
  89. return true;
  90. }
  91. }
  92. ],
  93. formatter: Table.api.formatter.operate}
  94. ]
  95. ]
  96. });
  97. $(".btn-edit").data("area", ["100%","100%"]);
  98. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  99. $(".btn-editone").data("area", ["100%", "100%"]);
  100. });
  101. // 为表格绑定事件
  102. Table.api.bindevent(table);
  103. },
  104. add: function () {
  105. Controller.api.bindevent();
  106. },
  107. couse: function (){
  108. $('input[name="row[status]"][value="2"]').change(function () {
  109. $('#c-couse').attr('type','text');
  110. });
  111. Controller.api.bindevent();
  112. $('#submit').click(function () {
  113. console.log(1111);
  114. var id = $('#id').val();
  115. if (id == 0 || id == ''){
  116. layer.confirm('未获取到参数!');
  117. return false;
  118. }
  119. var status = $('input:radio:checked').val();
  120. if (status == 0 || status == ''){
  121. layer.confirm('未获取到参数!');
  122. return false;
  123. }
  124. var couse = $('#c-couse').val();
  125. Fast.api.ajax({
  126. url:'res/couses',
  127. data:{id:id,status:status,couse:couse}
  128. },function (data,ret) {
  129. //成功回调
  130. parent.Toastr.success("确认成功");
  131. Fast.api.close();
  132. parent.Fast.api.refreshmenu();
  133. return false;
  134. },function (data,ret) {
  135. parent.Toastr.error("确认失败");
  136. Fast.api.close();
  137. return false;
  138. });
  139. return false;
  140. });
  141. },
  142. edit: function () {
  143. $('input[name="row[status]"][value="2"]').change(function () {
  144. $('#c-couse').attr('type','text');
  145. });
  146. Controller.api.bindevent();
  147. },
  148. api: {
  149. bindevent: function () {
  150. Form.api.bindevent($("form[role=form]"));
  151. }
  152. }
  153. };
  154. return Controller;
  155. });