market.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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: 'wwh/market/index' + location.search,
  8. add_url: 'wwh/market/add',
  9. edit_url: 'wwh/market/edit',
  10. del_url: 'wwh/market/del',
  11. multi_url: 'wwh/market/multi',
  12. import_url: 'wwh/market/import',
  13. table: 'wwh_market',
  14. dragsort_url:'',
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'weigh',
  23. fixedColumns: true,
  24. fixedRightNumber: 1,
  25. columns: [
  26. [
  27. {checkbox: true},
  28. {field: 'id', title: __('Id')},
  29. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  30. {field: 'citylist', title: __('Citylist'), operate: 'LIKE'},
  31. {field: 'address', title: __('Address'), operate: 'LIKE'},
  32. {field: 'sale', title: __('Sale'), operate: 'LIKE'},
  33. {field: 'tech', title: __('Tech'), operate: 'LIKE'},
  34. {field: 'mail', title: __('Mail'), operate: 'LIKE'},
  35. {field: 'fax', title: __('Fax'), operate: 'LIKE'},
  36. {
  37. field: 'weigh',
  38. title: __('Weigh'),
  39. operate: false,
  40. sortable: true,
  41. formatter: function (value, row, index) {
  42. return '<input type="text" class="form-control text-center text-weigh" data-id="' + row.id + '" value="' + value + '" style="width:50px;margin:0 auto;" />';
  43. },
  44. events: {
  45. "dblclick .text-weigh": function (e) {
  46. e.preventDefault();
  47. e.stopPropagation();
  48. return false;
  49. }
  50. }
  51. },
  52. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  53. {field: 'lang', title: __('Lang'), searchList: {"1":__('Lang 1'),"2":__('Lang 2')}, custom: {1: 'success', 2: 'warning'}, formatter: Table.api.formatter.normal},
  54. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  55. ]
  56. ]
  57. });
  58. // 权重修改
  59. $(document).on("change", ".text-weigh", function () {
  60. $(this).data("params", {weigh: $(this).val()});
  61. Table.api.multi('', [$(this).data("id")], table, this);
  62. return false;
  63. });
  64. // 为表格绑定事件
  65. Table.api.bindevent(table);
  66. // 弹窗窗口大小
  67. table.on('post-body.bs.table',function(e, settings, json, xhr){
  68. $(".btn-add").data("area", ['80%','80%']);
  69. $(".btn-editone").data("area", ['80%','80%']);
  70. });
  71. // TAB选项卡默认选中简体中文
  72. $('ul.nav-tabs li a[data-toggle="tab"]').eq(0).trigger("click");
  73. // 获取TAB选项卡值,通过options.extend.add_url传递
  74. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  75. var options = table.bootstrapTable('getOptions');
  76. options.extend.add_url = 'wwh/market/add?lang=' + $(this).data('value');
  77. });
  78. },
  79. add: function () {
  80. // 将TAB选项卡赋值给lang
  81. $('#c-lang option').each(function(){
  82. if($(this).attr('value') == Fast.api.query('lang'))
  83. {
  84. $(this).attr('selected', 'selected');
  85. }
  86. });
  87. Controller.api.bindevent();
  88. },
  89. edit: function () {
  90. Controller.api.bindevent();
  91. },
  92. api: {
  93. bindevent: function () {
  94. Form.api.bindevent($("form[role=form]"));
  95. }
  96. }
  97. };
  98. return Controller;
  99. });