qcode_bach.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. // layer.confirm('确定提交选中的 1 项?!', {
  20. // btn: ['确定', '取消'],
  21. // cancel: function(index, layero) {
  22. // }
  23. // },function (index) {
  24. // $.get('qcode_product/bind',{'ids':ids},function (data) {
  25. // if(data.code==1){
  26. // Toastr.success(data.msg)
  27. // table2.bootstrapTable('refresh');
  28. // }else{
  29. // Toastr.error(data.msg)
  30. // }
  31. // },'json');
  32. // Layer.close(index);
  33. //
  34. // },function (){})
  35. })
  36. //绑定
  37. $('#unbind').click(function (e) {
  38. layer.confirm('确定提交选中的 1 项?!', {
  39. btn: ['确定', '取消'],
  40. cancel: function(index, layero) {
  41. }
  42. },function (index) {
  43. var ids = $('#table2').bootstrapTable('getSelections')[0]['id'];
  44. $.get('qcode_product/unbind',{'ids':ids},function (data) {
  45. if(data.code==1){
  46. Toastr.success(data.msg)
  47. $('#table2').bootstrapTable('refresh');
  48. }else{
  49. Toastr.error(data.msg)
  50. }
  51. },'json');
  52. Layer.close(index);
  53. },function (){})
  54. })
  55. },
  56. table: {
  57. first: function () {
  58. // 表格1
  59. var table1 = $("#table1");
  60. table1.bootstrapTable({
  61. url: 'qcode_product/table1',
  62. extend: {
  63. index_url: 'qcode_product/table1' + location.search,
  64. add_url: 'qcode_product/add',
  65. edit_url: 'qcode_product/edit',
  66. del_url: 'qcode_product/del',
  67. table: 'qcode_product',
  68. },
  69. toolbar: '#toolbar1',
  70. pk: 'id',
  71. sortName: 'id',
  72. pageSize: 8,
  73. pageList: [8, 20, 50, 'All'],
  74. search: false,
  75. singleSelect: true,
  76. columns: [
  77. [
  78. {checkbox: true},
  79. {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
  80. {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
  81. {field: 'temple', title: __('Temple'), operate: 'LIKE'},
  82. {field: 'main_unit', title: __('Main_unit'), operate: 'LIKE'},
  83. {field: 'sec_unit', title: __('Sec_unit'), operate: 'LIKE'},
  84. {field: 'proportion', title: __('Proportion'), operate: 'LIKE'},
  85. // {field: 'notes', title: __('Notes')},
  86. // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  87. ]
  88. ]
  89. });
  90. // 为表格1绑定事件
  91. Table.api.bindevent(table1);
  92. },
  93. second: function () {
  94. // 表格2
  95. var table2 = $("#table2");
  96. table2.bootstrapTable({
  97. url: 'qcode_product/table2',
  98. extend: {
  99. index_url: '',
  100. add_url: '',
  101. edit_url: '',
  102. del_url: '',
  103. multi_url: '',
  104. table: '',
  105. },
  106. toolbar: '#toolbar2',
  107. pk: 'id',
  108. sortName: 'id',
  109. pageSize: 8,
  110. pageList: [8, 20, 50, 'All'],
  111. search: false,
  112. singleSelect: true,
  113. columns: [
  114. [
  115. {checkbox: true},
  116. {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
  117. {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
  118. {field: 'temple', title: __('Temple'), operate: 'LIKE'},
  119. {field: 'main_unit', title: __('Main_unit'), operate: 'LIKE'},
  120. {field: 'sec_unit', title: __('Sec_unit'), operate: 'LIKE'},
  121. {field: 'proportion', title: __('Proportion'), operate: 'LIKE'},
  122. // {field: 'notes', title: __('Notes')},
  123. // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  124. ]
  125. ]
  126. });
  127. // 为表格2绑定事件
  128. Table.api.bindevent(table2);
  129. }
  130. },
  131. /*recyclebin: function () {
  132. // 初始化表格参数配置
  133. Table.api.init({
  134. extend: {
  135. 'dragsort_url': ''
  136. }
  137. });
  138. var table = $("#table");
  139. // 初始化表格
  140. table.bootstrapTable({
  141. url: 'qcode_product/recyclebin' + location.search,
  142. pk: 'id',
  143. sortName: 'id',
  144. columns: [
  145. [
  146. {checkbox: true},
  147. {field: 'id', title: __('Id')},
  148. {field: 'name', title: __('Name'), align: 'left'},
  149. {
  150. field: 'deletetime',
  151. title: __('Deletetime'),
  152. operate: 'RANGE',
  153. addclass: 'datetimerange',
  154. formatter: Table.api.formatter.datetime
  155. },
  156. {
  157. field: 'operate',
  158. width: '140px',
  159. title: __('Operate'),
  160. table: table,
  161. events: Table.api.events.operate,
  162. buttons: [
  163. {
  164. name: 'Restore',
  165. text: __('Restore'),
  166. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  167. icon: 'fa fa-rotate-left',
  168. url: 'qcode_product/restore',
  169. refresh: true
  170. },
  171. {
  172. name: 'Destroy',
  173. text: __('Destroy'),
  174. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  175. icon: 'fa fa-times',
  176. url: 'qcode_product/destroy',
  177. refresh: true
  178. }
  179. ],
  180. formatter: Table.api.formatter.operate
  181. }
  182. ]
  183. ]
  184. });
  185. // 为表格绑定事件
  186. Table.api.bindevent(table);
  187. },*/
  188. add: function () {
  189. Controller.api.bindevent();
  190. },
  191. edit: function () {
  192. Controller.api.bindevent();
  193. },
  194. api: {
  195. bindevent: function () {
  196. Form.api.bindevent($("form[role=form]"));
  197. }
  198. }
  199. };
  200. return Controller;
  201. });