dimension.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], function ($, undefined, Backend, Table, Form, SelectPage) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'manage/dimension/index' + location.search,
  8. add_url: 'manage/dimension/add',
  9. edit_url: 'manage/dimension/edit',
  10. del_url: 'manage/dimension/del',
  11. multi_url: 'manage/dimension/multi',
  12. table: 'qc_dimension',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'weight',
  21. columns: [
  22. [
  23. {field: 'standard_id', title: __('Standard_id'), visible: false},
  24. {field: 'standard_name', title: __('标准名称'), align: 'left', searchable: false},
  25. {field: 'title', title: __('Title'), width: '200', formatter: Table.api.formatter.content},
  26. {field: 'description', title: __('Description'), width: '400', formatter: Table.api.formatter.content},
  27. {field: 'weight', title: __('Weight')},
  28. {field: 'status', title: __('Status'),formatter: function (value){
  29. if(value == 0){return '禁用'}else if(value == 1){return '启用'}else{return ''}
  30. }},
  31. {field: 'createdAt', title: __('Createdat'), operate:'RANGE', addclass:'datetimerange'},
  32. {field: 'updatedAt', title: __('Updatedat'), operate:'RANGE', addclass:'datetimerange'},
  33. {field: 'sort', title: __('Sort')},
  34. {
  35. field: 'operate',
  36. export: false,
  37. title: __('Operate'),
  38. table: table,
  39. buttons: [
  40. {
  41. name : 'btn_topup',
  42. title : __('质控选项'),
  43. text : '质控选项',
  44. extend : 'data-toggle="tooltip"',
  45. classname: 'btn btn-xs btn-warning btn-dialog',
  46. url : function (row){return 'manage/options/index?dimension='+row.id}
  47. }
  48. ],
  49. events: Controller.api.events.operate,
  50. formatter: Table.api.formatter.operate,
  51. }
  52. ]
  53. ]
  54. });
  55. // 为表格绑定事件
  56. Table.api.bindevent(table);
  57. },
  58. add: function () {
  59. standardSearchList();
  60. Controller.api.bindevent();
  61. },
  62. edit: function () {
  63. standardSearchList();
  64. Controller.api.bindevent();
  65. },
  66. api: {
  67. bindevent: function () {
  68. Form.api.bindevent($("form[role=form]"));
  69. },
  70. events:{
  71. operate:{
  72. 'click .btn-editone': function (e, value, row, index) {
  73. e.stopPropagation();
  74. e.preventDefault();
  75. var table = $(this).closest('table');
  76. var options = table.bootstrapTable('getOptions');
  77. var ids = row[options.pk];
  78. row = $.extend({}, row ? row : {}, {ids: ids});
  79. var url = options.extend.edit_url;
  80. Fast.api.open(Table.api.replaceurl(url, row, table), __('Edit'), $(this).data() || {});
  81. },
  82. 'click .btn-delone': function (e, value, row, index) {
  83. e.stopPropagation();
  84. e.preventDefault();
  85. let that = this;
  86. var table = $(this).closest('table');
  87. var options = table.bootstrapTable('getOptions');
  88. $(that).data('url',options.extend.del_url);
  89. let top = $(that).offset().top - $(window).scrollTop();
  90. let left = $(that).offset().left - $(window).scrollLeft() - 260;
  91. if (top + 154 > $(window).height()) {
  92. top = top - 154;
  93. }
  94. if ($(window).width() < 480) {
  95. top = left = undefined;
  96. }
  97. Layer.confirm(
  98. __('Are you sure you want to delete this item?'),
  99. {icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true},
  100. function (index) {
  101. let table = $(that).closest('table');
  102. let options = table.bootstrapTable('getOptions');
  103. Table.api.multi("del", row[options.pk], table, that);
  104. Layer.close(index);
  105. }
  106. );
  107. }
  108. }
  109. }
  110. }
  111. };
  112. let standardSearchList = function () {
  113. $.ajax({
  114. url: 'manage/standards/standardSelectList',
  115. type: 'post',
  116. dataType: 'json',
  117. success: function success(res) {
  118. let data = res.rows;
  119. $('#c-standard_id').selectPage({
  120. data : data,
  121. orderBy: 'id'
  122. });
  123. }
  124. });
  125. };
  126. return Controller;
  127. });