qcode_product.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init();
  6. this.table.first();
  7. this.table.second();
  8. //绑定
  9. $('#bind').click(function (e) {
  10. var ids = $('#table1').bootstrapTable('getSelections')[0]['id'];
  11. $.get('qcode_product/bind',{'ids':ids},function (data) {
  12. if(data.code==1){
  13. Toastr.success(data.msg)
  14. $('#table2').bootstrapTable('refresh');
  15. }else{
  16. Toastr.error(data.msg)
  17. }
  18. },'json');
  19. })
  20. //解绑
  21. $('#unbind').click(function (e) {
  22. layer.confirm('确定提交选中的 1 项?!', {
  23. btn: ['确定', '取消'],
  24. cancel: function(index, layero) {
  25. }
  26. },function (index) {
  27. var ids = $('#table2').bootstrapTable('getSelections')[0]['id'];
  28. $.get('qcode_product/unbind',{'ids':ids},function (data) {
  29. if(data.code==1){
  30. Toastr.success(data.msg)
  31. $('#table2').bootstrapTable('refresh');
  32. }else{
  33. Toastr.error(data.msg)
  34. }
  35. },'json');
  36. Layer.close(index);
  37. },function (){})
  38. })
  39. },
  40. table: {
  41. first: function () {
  42. // 表格1
  43. var table1 = $("#table1");
  44. table1.bootstrapTable({
  45. url: 'qcode_product/products',
  46. extend: {
  47. index_url: 'qcode_product/products' + location.search,
  48. add_url: 'qcode_product/add',
  49. edit_url: 'qcode_product/edit',
  50. del_url: 'qcode_product/del',
  51. table: 'qcode_product',
  52. },
  53. toolbar: '#toolbar1',
  54. pk: 'id',
  55. sortName: 'id',
  56. sortOrder: 'asc',
  57. pageSize: 8,
  58. pageList: [8, 20, 50, 'All'],
  59. search: false,
  60. showToggle: false,
  61. showColumns: false,
  62. showExport: false,
  63. singleSelect: true,
  64. searchFormVisible: true,
  65. searchFormTemplate: 'customformtpl',
  66. columns: [
  67. [
  68. {checkbox: true},
  69. {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
  70. {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
  71. {field: 'temple', title: __('Temple')},
  72. {field: 'main_unit', title: __('Main_unit')},
  73. {field: 'sec_unit', title: __('Sec_unit')},
  74. {field: 'proportion', title: __('Proportion')},
  75. {field: 'code', title: __('存货分类编码'), visible:false},
  76. // {field: 'notes', title: __('Notes')},
  77. // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  78. ]
  79. ]
  80. });
  81. // 为表格1绑定事件
  82. Table.api.bindevent(table1);
  83. },
  84. second: function () {
  85. // 表格2
  86. var table2 = $("#table2");
  87. table2.bootstrapTable({
  88. url: 'qcode_product/product',
  89. extend: {
  90. index_url: '',
  91. add_url: '',
  92. edit_url: '',
  93. del_url: '',
  94. multi_url: '',
  95. table: '',
  96. },
  97. toolbar: '#toolbar2',
  98. pk: 'id',
  99. sortName: 'id',
  100. sortOrder: 'asc',
  101. pageSize: 8,
  102. pageList: [8, 20, 50, 'All'],
  103. search: false,
  104. showToggle: false,
  105. showColumns: false,
  106. showExport: false,
  107. singleSelect: true,
  108. columns: [
  109. [
  110. {checkbox: true},
  111. {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
  112. {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
  113. {field: 'temple', title: __('Temple'), operate: false},
  114. {field: 'main_unit', title: __('Main_unit'), operate: false},
  115. {field: 'sec_unit', title: __('Sec_unit'), operate: false},
  116. {field: 'proportion', title: __('Proportion'), operate: false},
  117. // {field: 'notes', title: __('Notes')},
  118. // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  119. ]
  120. ]
  121. });
  122. // 为表格2绑定事件
  123. Table.api.bindevent(table2);
  124. }
  125. },
  126. add: function () {
  127. Controller.api.bindevent();
  128. },
  129. edit: function () {
  130. Controller.api.bindevent();
  131. },
  132. api: {
  133. bindevent: function () {
  134. Form.api.bindevent($("form[role=form]"));
  135. }
  136. }
  137. };
  138. return Controller;
  139. });