area.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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: 'shop/area/index' + location.search,
  8. add_url: 'shop/area/add',
  9. edit_url: 'shop/area/edit',
  10. del_url: 'shop/area/del',
  11. multi_url: 'shop/area/multi',
  12. import_url: 'shop/area/import',
  13. table: 'shop_area',
  14. }
  15. });
  16. $(document).on("click", ".btn-refresh-area", function () {
  17. Layer.confirm("更新地区数据将导致现有的地区数据表重置,请谨慎操作<br>数据源采用高德地图行政区划数据,请在配置管理中配置高德地图Web服务API密钥", {icon: 0}, function (index, layero) {
  18. Fast.api.ajax({
  19. url: 'shop/area/refresh'
  20. }, function (data, ret) {
  21. Layer.close(index);
  22. $(".btn-refresh").trigger("click");
  23. });
  24. });
  25. return false;
  26. });
  27. var table = $("#table");
  28. table.on('load-success.bs.table', function (e, data) {
  29. if (!data.initialized) {
  30. Layer.confirm("当前地区数据未导入,请点击确定导入地区数据", {}, function (index, layero) {
  31. Fast.api.ajax({
  32. url: 'shop/area/import'
  33. }, function(){
  34. Layer.close(index);
  35. $(".btn-refresh").trigger("click");
  36. });
  37. });
  38. }
  39. });
  40. // 初始化表格
  41. table.bootstrapTable({
  42. url: $.fn.bootstrapTable.defaults.extend.index_url,
  43. pk: 'id',
  44. sortName: 'id',
  45. sortOrder: 'asc',
  46. columns: [
  47. [
  48. {checkbox: true},
  49. {field: 'id', title: __('Id')},
  50. {field: 'pid', title: __('Pid'), formatter: Table.api.formatter.search},
  51. {field: 'level', title: __('Level'), formatter: Table.api.formatter.search},
  52. {field: 'name', title: __('Name'), operate: 'LIKE'},
  53. {field: 'pinyin', title: __('Pinyin'), operate: 'LIKE'},
  54. {field: 'py', title: __('Py'), operate: 'LIKE'},
  55. {field: 'adcode', title: __('Adcode'), operate: 'LIKE'},
  56. {field: 'lng', title: __('Lng'), operate: 'LIKE'},
  57. {field: 'lat', title: __('Lat'), operate: 'LIKE'},
  58. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  59. ]
  60. ]
  61. });
  62. // 为表格绑定事件
  63. Table.api.bindevent(table);
  64. },
  65. add: function () {
  66. Controller.api.bindevent();
  67. },
  68. edit: function () {
  69. Controller.api.bindevent();
  70. },
  71. api: {
  72. bindevent: function () {
  73. Form.api.bindevent($("form[role=form]"));
  74. }
  75. }
  76. };
  77. return Controller;
  78. });