res.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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: 'sell_bach', title: '销售批次号', operate: 'LIKE'},
  33. {field: 'bach', title: __('Bach'), operate: 'LIKE'},
  34. {field: 'dis', title: __('Dis'),operate: false},
  35. {field: 'dis_impurity', title: __('Dis_impurity'),operate: false},
  36. {field: 'ben_total', title: __('Ben_total'),operate: false},
  37. {field: 'ben', title: __('Ben'),operate: false},
  38. {field: 'unit', title: __('Unit'),operate: false},
  39. {field: 'judge', title: __('Judge'), operate: 'LIKE',custom: {0 :'red', 1:'green'},searchList: {"0":'不合格',"1":'合格'}, formatter: Table.api.formatter.status, function (value,row,index) {
  40. if (value == 1){
  41. value = '合格';
  42. return '<span style="color: #18bc9c">' +value+ '</span>';
  43. }else{
  44. value = '不合格';
  45. return '<span style="color: #f75444">' +value+ '</span>';
  46. }
  47. }},
  48. {field: 'sample_info', title: '样品信息',operate: false},
  49. {field: 'send_sample', title: '送样人',operate:false},
  50. {field: 'machine', title: __('Machine'), operate: ''},
  51. {field: 'sample_no', title: __('Sample_no'), operate: 'LIKE'},
  52. // {field: 'standard_id', title: __('Standard_id')},
  53. {field: 'standard_name', title: __('Standard_name'), operate: 'LIKE',searchList: $.getJSON("res/companyselect")},
  54. {field: 'create', title: __('Create'),operate: 'RANGE_DATE', addclass: 'datetimerange', formatter: Table.api.formatter.date,datetimeFormat:'YYYY-MM-DD'},
  55. {field: 'maker', title: __('Maker'),operate: false},
  56. {field: 'remark', title: __('Remark'),operate: false},
  57. {field: 'params', title: __('Params'),operate: false},
  58. // {field: 'userid', title: __('Userid')},
  59. {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
  60. // {field: 'delete_time', title: __('Delete_time'), operate: 'LIKE'},
  61. // {field: 'work_name',title: '所属公司',operate: 'IN',addclass: 'selectpage',data:'data-multiple="true"'+'data-source=[{"id":"浙江美浓","name":"浙江美浓"},{"id":"涂料","name":"涂料"},{"id":"亚欣","name":"亚欣"}]'},
  62. {field: 'work_name',title: '所属公司',operate: 'IN',addclass: 'selectpage',data:'data-multiple="true"'+'data-source="res/company"'},
  63. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  64. buttons: [
  65. {
  66. name: 'data',
  67. text: __('检测数据'),
  68. title: __('检测数据'),
  69. classname: 'btn btn-xs btn-primary btn-dialog',
  70. icon: 'fa fa-list',
  71. extend:'data-area=["100%","100%"]',
  72. url: 'res/data/id/{ids}',
  73. callback: function (data) {
  74. },
  75. visible: function (row) {
  76. //返回true时按钮显示,返回false隐藏
  77. return true;
  78. }
  79. },
  80. {
  81. name: 'data',
  82. text: __('导出数据报告'),
  83. title: __('导出数据报告'),
  84. classname: 'btn btn-xs btn-primary',
  85. // classname: 'btn btn-xs btn-primary btn-dialog',
  86. icon: 'fa fa-list',
  87. extend:'data-area=["100%","100%"]',
  88. url: 'res/report/id/{ids}',
  89. callback: function (data) {
  90. },
  91. visible: function (row) {
  92. //返回true时按钮显示,返回false隐藏
  93. return true;
  94. }
  95. },
  96. ],
  97. formatter: Table.api.formatter.operate},
  98. {
  99. field: '下载',
  100. title: __('下载'),
  101. align: 'left',
  102. formatter: Controller.api.formatter.download
  103. },
  104. ]
  105. ]
  106. });
  107. $(".btn-edit").data("area", ["100%","100%"]);
  108. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  109. $(".btn-editone").data("area", ["100%", "100%"]);
  110. });
  111. // 为表格绑定事件
  112. Table.api.bindevent(table);
  113. },
  114. add: function () {
  115. Controller.api.bindevent();
  116. },
  117. data: function () {
  118. $(".print-link").on('click', function() {
  119. var printHTML = document.querySelector('#print').innerHTML;
  120. // 将打印的区域赋值,进行打印
  121. window.document.body.innerHTML = printHTML;
  122. window.print();
  123. window.location.reload(); // 打印完成后重新加载页面
  124. Fast.api.close();
  125. });
  126. Controller.api.bindevent();
  127. },
  128. couse: function (){
  129. $('input[name="row[status]"][value="2"]').change(function () {
  130. $('#c-couse').attr('type','text');
  131. });
  132. Controller.api.bindevent();
  133. $('#submit').click(function () {
  134. console.log(1111);
  135. var id = $('#id').val();
  136. if (id == 0 || id == ''){
  137. layer.confirm('未获取到参数!');
  138. return false;
  139. }
  140. var status = $('input:radio:checked').val();
  141. if (status == 0 || status == ''){
  142. layer.confirm('未获取到参数!');
  143. return false;
  144. }
  145. var couse = $('#c-couse').val();
  146. Fast.api.ajax({
  147. url:'res/couses',
  148. data:{id:id,status:status,couse:couse}
  149. },function (data,ret) {
  150. //成功回调
  151. parent.Toastr.success("确认成功");
  152. Fast.api.close();
  153. parent.Fast.api.refreshmenu();
  154. return false;
  155. },function (data,ret) {
  156. parent.Toastr.error("确认失败");
  157. Fast.api.close();
  158. return false;
  159. });
  160. return false;
  161. });
  162. },
  163. edit: function () {
  164. $('input[name="row[status]"][value="2"]').change(function () {
  165. $('#c-couse').attr('type','text');
  166. });
  167. Controller.api.bindevent();
  168. },
  169. api: {
  170. bindevent: function () {
  171. Form.api.bindevent($("form[role=form]"));
  172. },
  173. formatter:{
  174. download: function (value, row, index) {
  175. console.log(row['bach'])
  176. if(row['bach']!=null && row['bach'] !=undefined && row['bach']!=""){
  177. var link;
  178. link="\<a class=\"btn btn-primary btn-edit\" href=\"javascript:POBrowser.openWindowModeless('./index.php/api/word/preview?bach="+row['bach']+"' , 'width=1200px;height=800px;');\">编辑文档</a>";
  179. link+='<a class="btn btn-primary btn-warning" href="./index.php/api/word/download?bach='+row['bach']+'">下载</a>';
  180. return link;
  181. }
  182. return "";
  183. },
  184. }
  185. }
  186. };
  187. return Controller;
  188. });