qcode_product.js 9.1 KB

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