qcode_product.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/index',
  46. extend: {
  47. index_url: 'qcode_product/index' + location.search,
  48. table: '工单_基本资料',
  49. add_url: 'qcode_product/add',
  50. },
  51. toolbar: '#toolbar1',
  52. pk: 'Uniqid',
  53. sortName: 'Uniqid',
  54. sortOrder: 'desc',
  55. pageSize: 8,
  56. pageList: [8, 20, 50, 'All'],
  57. search: true,
  58. showToggle: false,
  59. showColumns: false,
  60. showExport: false,
  61. singleSelect: false,
  62. columns: [
  63. [
  64. {checkbox: true},
  65. {field: 'Gd_gdbh', title: '工单编号', operate: 'LIKE'},
  66. {field: 'Gd_cpdh', title: __('产品代号'), operate: 'LIKE'},
  67. {field: 'Gd_cpmc', title: '产品名称', operate: 'LIKE'}
  68. ]
  69. ]
  70. });
  71. // 为表格1绑定事件
  72. Table.api.bindevent(table1);
  73. // 绑定自定义按钮点击事件
  74. $(".btn-operate").click(function() {
  75. var ids = Table.api.selectedids(table1);
  76. if (ids.length == 0) {
  77. Toastr.error("请至少选择一条记录");
  78. return false;
  79. }
  80. console.log(ids);
  81. $.ajax({
  82. url: 'qcode_product/bind',
  83. type: 'GET',
  84. dataType: 'json',
  85. data: {
  86. ids: ids
  87. },
  88. success: function(response) {
  89. },
  90. });
  91. });
  92. },
  93. second: function () {
  94. // 表格2
  95. var table2 = $("#table2");
  96. table2.bootstrapTable({
  97. url: 'qcode_product/product',
  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. sortOrder: 'asc',
  110. pageSize: 8,
  111. pageList: [8, 20, 50, 'All'],
  112. search: false,
  113. showToggle: false,
  114. showColumns: false,
  115. showExport: false,
  116. singleSelect: true,
  117. columns: [
  118. [
  119. {checkbox: true},
  120. {field: 'Gd_gdbh', title: '工单编号', operate: 'LIKE'},
  121. {field: 'Gd_cpdh', title: __('产品代号'), operate: 'LIKE'},
  122. {field: 'Gd_cpmc', title: '产品名称', operate: 'LIKE'}
  123. // {field: 'notes', title: __('Notes')},
  124. // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  125. ]
  126. ]
  127. });
  128. // 为表格2绑定事件
  129. Table.api.bindevent(table2);
  130. }
  131. // first: function () {
  132. // // 表格1
  133. // var table1 = $("#table1");
  134. // table1.bootstrapTable({
  135. // url: 'qcode_product/products',
  136. // extend: {
  137. // index_url: 'qcode_product/products' + location.search,
  138. // add_url: 'qcode_product/add',
  139. // edit_url: 'qcode_product/edit',
  140. // del_url: 'qcode_product/del',
  141. // table: 'qcode_product',
  142. // },
  143. // toolbar: '#toolbar1',
  144. // pk: 'id',
  145. // sortName: 'id',
  146. // sortOrder: 'asc',
  147. // pageSize: 8,
  148. // pageList: [8, 20, 50, 'All'],
  149. // search: false,
  150. // showToggle: false,
  151. // showColumns: false,
  152. // showExport: false,
  153. // singleSelect: true,
  154. // searchFormVisible: true,
  155. // searchFormTemplate: 'customformtpl',
  156. // columns: [
  157. // [
  158. // {checkbox: true},
  159. // {field: 'Gd_gdbh', title: '工单编号', operate: 'LIKE'},
  160. // // {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
  161. // // {field: 'temple', title: __('Temple')},
  162. // // {field: 'main_unit', title: __('Main_unit')},
  163. // // {field: 'sec_unit', title: __('Sec_unit')},
  164. // // {field: 'proportion', title: __('Proportion')},
  165. // // {field: 'code', title: __('存货分类编码'), visible:false},
  166. // // {field: 'notes', title: __('Notes')},
  167. // // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  168. // ]
  169. // ]
  170. // });
  171. //
  172. // // 为表格1绑定事件
  173. // Table.api.bindevent(table1);
  174. // },
  175. // second: function () {
  176. // // 表格2
  177. // var table2 = $("#table2");
  178. // table2.bootstrapTable({
  179. // url: 'qcode_product/product',
  180. // extend: {
  181. // index_url: '',
  182. // add_url: '',
  183. // edit_url: '',
  184. // del_url: '',
  185. // multi_url: '',
  186. // table: '',
  187. // },
  188. // toolbar: '#toolbar2',
  189. // pk: 'id',
  190. // sortName: 'id',
  191. // sortOrder: 'asc',
  192. // pageSize: 8,
  193. // pageList: [8, 20, 50, 'All'],
  194. // search: false,
  195. // showToggle: false,
  196. // showColumns: false,
  197. // showExport: false,
  198. // singleSelect: true,
  199. // columns: [
  200. // [
  201. // {checkbox: true},
  202. // {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
  203. // {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
  204. // {field: 'temple', title: __('Temple'), operate: false},
  205. // {field: 'main_unit', title: __('Main_unit'), operate: false},
  206. // {field: 'sec_unit', title: __('Sec_unit'), operate: false},
  207. // {field: 'proportion', title: __('Proportion'), operate: false},
  208. // // {field: 'notes', title: __('Notes')},
  209. // // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  210. // ]
  211. // ]
  212. // });
  213. //
  214. // // 为表格2绑定事件
  215. // Table.api.bindevent(table2);
  216. // }
  217. },
  218. add: function () {
  219. Controller.api.bindevent();
  220. },
  221. edit: function () {
  222. Controller.api.bindevent();
  223. },
  224. api: {
  225. bindevent: function () {
  226. Form.api.bindevent($("form[role=form]"));
  227. }
  228. }
  229. };
  230. return Controller;
  231. });