areas.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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: 'product/areas/index' + location.search+'?ids='+Config.ids,
  8. add_url: 'product/areas/add'+'?ids='+Config.ids,
  9. del_url: 'product/areas/del',
  10. multi_url: 'product/areas/multi',
  11. import_url: 'product/areas/import',
  12. table: 'product_area',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. fixedColumns: true,
  22. fixedRightNumber: 1,
  23. columns: [
  24. [
  25. {checkbox: true},
  26. {field: 'id', title: __('Id'), operate: false},
  27. {field: 'product_id', title: __('Product_id'), operate: false},
  28. {field: 'province', title: __('Province'), operate: false},
  29. {field: 'city', title: __('City'), operate: false},
  30. {field: 'area', title: __('Area'), operate: false},
  31. {field: 'county', title: __('County'), operate: false},
  32. {field: 'address', title: __('Address'), operate: 'LIKE'},
  33. {field: 'status', title: __('状态'), searchList: { "1": __('正常'), "0": __('已出售')}, formatter: Table.api.formatter.status },
  34. {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  35. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  36. ]
  37. ]
  38. });
  39. // 为表格绑定事件
  40. Table.api.bindevent(table);
  41. $(".btn-add").data("area", ["60%", "50%"]);
  42. $(".btn-importlog").data("area", ["70%", "80%"]);
  43. //导入地区
  44. $(document).on("click",".btn-exports",function(){
  45. Fast.api.open('product/areas/exports?ids='+Config.ids, '导入地区',{
  46. });
  47. })
  48. //导入日志
  49. $(document).on("click",".btn-importlog",function(){
  50. Fast.api.open('ledger/importlog/index?ids='+Config.ids, '导入日志', {
  51. area:["70%", "80%"]
  52. });
  53. })
  54. },
  55. add: function () {
  56. Controller.api.bindevent();
  57. let obj = $('#c-address')
  58. $(document).on('change','.province',function(){
  59. let txt = $(this).find("option:selected").text();
  60. obj.val(txt)
  61. });
  62. //城市
  63. $(document).on('change','.city',function(){
  64. let txt = $(this).find("option:selected").text();
  65. var arr = obj.val().split("-");
  66. arr.splice(1, 1);
  67. if(txt != '请选择') arr[1] = txt
  68. obj.val(arr.join('-'))
  69. });
  70. //地区
  71. $(document).on('change','.area',function(){
  72. let txt = $(this).find("option:selected").text();
  73. var arr = obj.val().split("-");
  74. arr.splice(2, 1);
  75. if(txt != '请选择') arr[2] = txt
  76. obj.val(arr.join('-'))
  77. });
  78. //乡镇
  79. $(document).on('change','.county',function(){
  80. let txt = $(this).find("option:selected").text();
  81. var arr = obj.val().split("-");
  82. arr.splice(3, 1);
  83. if(txt != '请选择') arr[3] = txt
  84. obj.val(arr.join('-'))
  85. });
  86. },
  87. exports: function () {
  88. Controller.api.bindevent();
  89. },
  90. importlog: function () {
  91. Controller.api.bindevent();
  92. },
  93. api: {
  94. bindevent: function () {
  95. Form.api.bindevent($("form[role=form]"));
  96. Form.api.bindevent($("form#cxselectform"));
  97. }
  98. }
  99. };
  100. return Controller;
  101. });