qcode_product.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. sortOrder: 'asc',
  73. pageSize: 8,
  74. pageList: [8, 20, 50, 'All'],
  75. search: false,
  76. singleSelect: true,
  77. searchFormVisible: true,
  78. searchFormTemplate: 'customformtpl',
  79. columns: [
  80. [
  81. {checkbox: true},
  82. {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
  83. {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
  84. {field: 'temple', title: __('Temple')},
  85. {field: 'main_unit', title: __('Main_unit')},
  86. {field: 'sec_unit', title: __('Sec_unit')},
  87. {field: 'proportion', title: __('Proportion')},
  88. {field: 'code', title: __('存货分类编码'), visible:false},
  89. // {field: 'notes', title: __('Notes')},
  90. // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  91. ]
  92. ]
  93. });
  94. // 为表格1绑定事件
  95. Table.api.bindevent(table1);
  96. },
  97. second: function () {
  98. // 表格2
  99. var table2 = $("#table2");
  100. table2.bootstrapTable({
  101. url: 'qcode_product/table2',
  102. extend: {
  103. index_url: '',
  104. add_url: '',
  105. edit_url: '',
  106. del_url: '',
  107. multi_url: '',
  108. table: '',
  109. },
  110. toolbar: '#toolbar2',
  111. pk: 'id',
  112. sortName: 'id',
  113. sortOrder: 'asc',
  114. pageSize: 8,
  115. pageList: [8, 20, 50, 'All'],
  116. search: false,
  117. singleSelect: true,
  118. columns: [
  119. [
  120. {checkbox: true},
  121. {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
  122. {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
  123. {field: 'temple', title: __('Temple'), operate: false},
  124. {field: 'main_unit', title: __('Main_unit'), operate: false},
  125. {field: 'sec_unit', title: __('Sec_unit'), operate: false},
  126. {field: 'proportion', title: __('Proportion'), operate: false},
  127. // {field: 'notes', title: __('Notes')},
  128. // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  129. ]
  130. ]
  131. });
  132. // 为表格2绑定事件
  133. Table.api.bindevent(table2);
  134. }
  135. },
  136. /*recyclebin: function () {
  137. // 初始化表格参数配置
  138. Table.api.init({
  139. extend: {
  140. 'dragsort_url': ''
  141. }
  142. });
  143. var table = $("#table");
  144. // 初始化表格
  145. table.bootstrapTable({
  146. url: 'qcode_product/recyclebin' + location.search,
  147. pk: 'id',
  148. sortName: 'id',
  149. columns: [
  150. [
  151. {checkbox: true},
  152. {field: 'id', title: __('Id')},
  153. {field: 'name', title: __('Name'), align: 'left'},
  154. {
  155. field: 'deletetime',
  156. title: __('Deletetime'),
  157. operate: 'RANGE',
  158. addclass: 'datetimerange',
  159. formatter: Table.api.formatter.datetime
  160. },
  161. {
  162. field: 'operate',
  163. width: '140px',
  164. title: __('Operate'),
  165. table: table,
  166. events: Table.api.events.operate,
  167. buttons: [
  168. {
  169. name: 'Restore',
  170. text: __('Restore'),
  171. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  172. icon: 'fa fa-rotate-left',
  173. url: 'qcode_product/restore',
  174. refresh: true
  175. },
  176. {
  177. name: 'Destroy',
  178. text: __('Destroy'),
  179. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  180. icon: 'fa fa-times',
  181. url: 'qcode_product/destroy',
  182. refresh: true
  183. }
  184. ],
  185. formatter: Table.api.formatter.operate
  186. }
  187. ]
  188. ]
  189. });
  190. // 为表格绑定事件
  191. Table.api.bindevent(table);
  192. },*/
  193. add: function () {
  194. Controller.api.bindevent();
  195. },
  196. edit: function () {
  197. Controller.api.bindevent();
  198. },
  199. api: {
  200. bindevent: function () {
  201. Form.api.bindevent($("form[role=form]"));
  202. }
  203. }
  204. };
  205. return Controller;
  206. });