index.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'supplier/index/index' + location.search,
  8. add_url: 'supplier/index/add',
  9. edit_url: 'supplier/index/edit',
  10. del_url: 'supplier/index/del',
  11. multi_url: 'supplier/index/multi',
  12. import_url: 'supplier/index/import',
  13. table: 'shop_goods_supplier',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'weigh',
  22. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'name', title: __('Name'), operate: 'LIKE'},
  29. // {field: 'code', title: __('Code'), operate: 'LIKE'},
  30. {field: 'category.name', title: __('Supplier_category_id')},
  31. {field: 'contact', title: __('Contact'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  32. {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
  33. {field: 'landline', title: __('Landline'), operate: 'LIKE'},
  34. // {field: 'email', title: __('Email'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  35. // {field: 'province_id', title: __('Province_id')},
  36. // {field: 'city_id', title: __('City_id')},
  37. // {field: 'district_id', title: __('District_id')},
  38. // {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  39. // {field: 'bank_account', title: __('Bank_account'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  40. // {field: 'bank', title: __('Bank'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  41. // {field: 'cardholder_name', title: __('Cardholder_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  42. // {field: 'tax_id', title: __('Tax_id'), operate: 'LIKE'},
  43. {field: 'weigh', title: __('Weigh'), operate: false},
  44. {field: 'status', title: __('Status'), searchList: Controller.api.parseConfigJson('statusList'), formatter: Table.api.formatter.status},
  45. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  46. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  47. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  48. ]
  49. ]
  50. });
  51. // 为表格绑定事件
  52. Table.api.bindevent(table);
  53. },
  54. recyclebin: function () {
  55. // 初始化表格参数配置
  56. Table.api.init({
  57. extend: {
  58. 'dragsort_url': ''
  59. }
  60. });
  61. var table = $("#table");
  62. // 初始化表格
  63. table.bootstrapTable({
  64. url: 'supplier/index/recyclebin' + location.search,
  65. pk: 'id',
  66. sortName: 'id',
  67. columns: [
  68. [
  69. {checkbox: true},
  70. {field: 'id', title: __('Id')},
  71. {field: 'name', title: __('Name'), align: 'left'},
  72. {
  73. field: 'deletetime',
  74. title: __('Deletetime'),
  75. operate: 'RANGE',
  76. addclass: 'datetimerange',
  77. formatter: Table.api.formatter.datetime
  78. },
  79. {
  80. field: 'operate',
  81. width: '140px',
  82. title: __('Operate'),
  83. table: table,
  84. events: Table.api.events.operate,
  85. buttons: [
  86. {
  87. name: 'Restore',
  88. text: __('Restore'),
  89. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  90. icon: 'fa fa-rotate-left',
  91. url: 'supplier/index/restore',
  92. refresh: true
  93. },
  94. {
  95. name: 'Destroy',
  96. text: __('Destroy'),
  97. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  98. icon: 'fa fa-times',
  99. url: 'supplier/index/destroy',
  100. refresh: true
  101. }
  102. ],
  103. formatter: Table.api.formatter.operate
  104. }
  105. ]
  106. ]
  107. });
  108. // 为表格绑定事件
  109. Table.api.bindevent(table);
  110. },
  111. add: function () {
  112. Controller.api.bindevent();
  113. },
  114. edit: function () {
  115. Controller.api.bindevent();
  116. },
  117. api: {
  118. // 解析Config中的JSON字符串的辅助函数
  119. parseConfigJson: function(configKey, defaultValue) {
  120. var configValue = Config[configKey] || defaultValue || {};
  121. // 如果是字符串,尝试解析JSON
  122. if (typeof configValue === 'string') {
  123. try {
  124. return JSON.parse(configValue);
  125. } catch (e) {
  126. return defaultValue || {};
  127. }
  128. }
  129. return configValue;
  130. },
  131. bindevent: function () {
  132. // 省市区联动同步
  133. $(document).on('change', 'select[name="province"]', function() {
  134. $('#province_id_hidden').val($(this).val());
  135. });
  136. $(document).on('change', 'select[name="city"]', function() {
  137. $('#city_id_hidden').val($(this).val());
  138. });
  139. $(document).on('change', 'select[name="area"]', function() {
  140. $('#district_id_hidden').val($(this).val());
  141. });
  142. // 编辑页面初始化省市区选中状态
  143. // if ($('#province_id_hidden').length > 0) {
  144. // var provinceId = $('#province_id_hidden').val();
  145. // var cityId = $('#city_id_hidden').val();
  146. // var districtId = $('#district_id_hidden').val();
  147. // if (provinceId) {
  148. // // 设置省份选中状态
  149. // setTimeout(function() {
  150. // $('select[name="province"]').val(provinceId).trigger('change');
  151. // // 如果有城市ID,等待省份联动完成后设置城市
  152. // if (cityId) {
  153. // setTimeout(function() {
  154. // $('select[name="city"]').val(cityId).trigger('change');
  155. // // 如果有区县ID,等待城市联动完成后设置区县
  156. // if (districtId) {
  157. // setTimeout(function() {
  158. // $('select[name="area"]').val(districtId);
  159. // }, 500);
  160. // }
  161. // }, 500);
  162. // }
  163. // }, 500);
  164. // }
  165. // }
  166. Form.api.bindevent($("form[role=form]"));
  167. }
  168. }
  169. };
  170. return Controller;
  171. });