areas.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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'),
  36. buttons:[
  37. {
  38. name:'importlog',//名称开始按钮 classname: 'btn btn-xs btn-primary btn-dialog',
  39. text:'导入日志',//文本
  40. classname:'btn btn-xs btn-info btn-primary btn-dialog',//按钮样式
  41. icon:'fa fa-cog',//图标
  42. url:'ledger/importlog/index',//请求的方法
  43. extend:'data-area=["80%","85%"]',
  44. refresh:true,//一开始界面需要刷新
  45. },
  46. ],
  47. table: table, events: Table.api.events.operate,
  48. formatter: Table.api.formatter.operate
  49. }
  50. ]
  51. ]
  52. });
  53. // 为表格绑定事件
  54. Table.api.bindevent(table);
  55. $(".btn-add").data("area", ["60%", "50%"]);
  56. //导入地区
  57. $(document).on("click",".btn-exports",function(){
  58. Fast.api.open('product/areas/exports?ids='+Config.ids, '导入地区',{
  59. //接收产品弹窗Fast.api.close传过来的参数
  60. callback:function(data){
  61. }
  62. });
  63. })
  64. },
  65. add: function () {
  66. Controller.api.bindevent();
  67. let obj = $('#c-address')
  68. $(document).on('change','.province',function(){
  69. let txt = $(this).find("option:selected").text();
  70. obj.val(txt)
  71. });
  72. //城市
  73. $(document).on('change','.city',function(){
  74. let txt = $(this).find("option:selected").text();
  75. var arr = obj.val().split("-");
  76. arr.splice(1, 1);
  77. if(txt != '请选择') arr[1] = txt
  78. obj.val(arr.join('-'))
  79. });
  80. //地区
  81. $(document).on('change','.area',function(){
  82. let txt = $(this).find("option:selected").text();
  83. var arr = obj.val().split("-");
  84. arr.splice(2, 1);
  85. if(txt != '请选择') arr[2] = txt
  86. obj.val(arr.join('-'))
  87. });
  88. //乡镇
  89. $(document).on('change','.county',function(){
  90. let txt = $(this).find("option:selected").text();
  91. var arr = obj.val().split("-");
  92. arr.splice(3, 1);
  93. if(txt != '请选择') arr[3] = txt
  94. obj.val(arr.join('-'))
  95. });
  96. },
  97. exports: function () {
  98. Controller.api.bindevent();
  99. },
  100. importlog: function () {
  101. Controller.api.bindevent();
  102. },
  103. api: {
  104. bindevent: function () {
  105. Form.api.bindevent($("form[role=form]"));
  106. Form.api.bindevent($("form#cxselectform"));
  107. }
  108. }
  109. };
  110. return Controller;
  111. });