user.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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: 'weixin/user/index' + location.search,
  8. table: 'weixin_user',
  9. }
  10. });
  11. var table = $("#table");
  12. // 初始化表格
  13. table.bootstrapTable({
  14. url: $.fn.bootstrapTable.defaults.extend.index_url,
  15. pk: 'uid',
  16. sortName: 'uid',
  17. columns: [
  18. [
  19. {checkbox: true},
  20. {field: 'uid', title: __('Uid')},
  21. {field: 'nickname', title: __('Nickname')},
  22. {field: 'headimgurl', title: __('Headimgurl'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
  23. {field: 'sex', title: __('Sex'), searchList: {"1":__('男'),"2":__('女')}, formatter: Controller.api.sex},
  24. {field: 'tagid_list_text', title: __('Tagid_list'), operate:false,events: Controller.api.events.tagid_list, formatter: Controller.api.formatter.tagid_list},
  25. {field: 'subscribe', title: __('Subscribe'), searchList: {"0":__('否'),"1":__('是')}, formatter: Controller.api.subscribe},
  26. {field: 'subscribe_time', title: __('Subscribe_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  27. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  28. {
  29. field: 'operate',
  30. title: __('Operate'),
  31. table: table,
  32. events: Table.api.events.operate,
  33. formatter: Table.api.formatter.operate,
  34. buttons: [
  35. {
  36. name: 'detail',
  37. title: __('修改标签'),
  38. classname: 'btn btn-xs btn-success btn-dialog',
  39. icon: 'fa fa-tag',
  40. //extend: 'data-area=\'["700px", "500px"]\'',
  41. url: 'weixin/user/edit_user_tag',
  42. callback: function (data) {
  43. Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  44. }
  45. }
  46. ]
  47. }
  48. ]
  49. ]
  50. });
  51. // 获取选中项
  52. $(document).on("click", ".btn-selected", function () {
  53. var ids = '';
  54. $.each(table.bootstrapTable('getSelections'), function (index, row) {
  55. ids += row.uid + ',';
  56. });
  57. var that = this;
  58. var options = $.extend({}, $(that).data() || {});
  59. var url = Backend.api.replaceids(that, $(that).data("url") || $(that).attr('href'));
  60. var title = $(that).attr("title") || $(that).data("title") || $(that).data('original-title');
  61. var button = Backend.api.gettablecolumnbutton(options);
  62. if (button && typeof button.callback === 'function') {
  63. options.callback = button.callback;
  64. }
  65. url += '/ids/' + ids;
  66. if (typeof options.confirm !== 'undefined') {
  67. Layer.confirm(options.confirm, function (index) {
  68. Backend.api.open(url, title, options);
  69. Layer.close(index);
  70. });
  71. } else {
  72. window[$(that).data("window") || 'self'].Backend.api.open(url, title, options);
  73. }
  74. return false;
  75. });
  76. // 为表格绑定事件
  77. Table.api.bindevent(table);
  78. },
  79. edit: function () {
  80. Controller.api.bindevent();
  81. },
  82. edit_user_tag: function () {
  83. Controller.api.bindevent();
  84. },
  85. tag: function () {
  86. // 初始化表格参数配置
  87. Table.api.init({
  88. extend: {
  89. index_url: 'weixin/user/tag' + location.search,
  90. add_url: 'weixin/user/tagadd',
  91. edit_url: 'weixin/user/tagedit',
  92. del_url: 'weixin/user/tagdel',
  93. table: 'weixin_user',
  94. }
  95. });
  96. var table = $("#table");
  97. // 初始化表格
  98. table.bootstrapTable({
  99. url: $.fn.bootstrapTable.defaults.extend.index_url,
  100. search:false,
  101. commonSearch:false,
  102. columns: [
  103. [
  104. {checkbox: true},
  105. {field: 'id', title: __('编号')},
  106. {field: 'name', title: __('标签名')},
  107. {field: 'count', title: __('人数')},
  108. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  109. ]
  110. ]
  111. });
  112. // 为表格绑定事件
  113. Table.api.bindevent(table);
  114. },
  115. tagadd: function () {
  116. Controller.api.bindevent();
  117. },
  118. tagedit: function () {
  119. Controller.api.bindevent();
  120. },
  121. sendmsg: function (){
  122. //不可见的元素不验证
  123. $("form[role=form]").data("validator-options", {ignore: ':hidden'});
  124. Form.api.bindevent($("form[role=form]"));
  125. //显示和隐藏
  126. $(document).on("click", "input[name='row[type]']", function () {
  127. var type = $("input[name='row[type]']:checked").val();
  128. $('.isshow').hide();
  129. $('.' + type).show();
  130. });
  131. Controller.api.bindevent();
  132. $("input[name='row[type]']:checked").trigger("click");
  133. },
  134. api: {
  135. bindevent: function () {
  136. Form.api.bindevent($("form[role=form]"));
  137. },
  138. sex: function (value, row, index) {
  139. if(row.sex == "1") {
  140. return '男';
  141. } else if (row.sex == "2"){
  142. return '女';
  143. }else{
  144. return '未知';
  145. }
  146. }
  147. ,
  148. subscribe: function (value, row, index) {
  149. if(row.subscribe == "1") {
  150. return '是';
  151. }else{
  152. return '否';
  153. }
  154. },
  155. formatter: {//渲染的方法
  156. tagid_list: function (value, row, index) {
  157. var str = '';
  158. var arr = new Array();
  159. arr = value;
  160. for(var i=0;i<arr.length;i++)
  161. {
  162. str += '<a class="btn btn-xs btn-tagid_list bg-success">' + arr[i] + '</a>';
  163. }
  164. return str;
  165. }
  166. },
  167. events: {//绑定事件的方法
  168. tagid_list: {
  169. //格式为:方法名+空格+DOM元素
  170. 'click .btn-tagid_list': function (e, value, row, index) {
  171. e.stopPropagation();
  172. var container = $("#table").data("bootstrap.table").$container;
  173. var options = $("#table").bootstrapTable('getOptions');
  174. //这里我们手动将数据填充到表单然后提交
  175. $("form.form-commonsearch [name='tagid_list']", container).val(value);
  176. $("form.form-commonsearch", container).trigger('submit');
  177. }
  178. }
  179. }
  180. }
  181. };
  182. return Controller;
  183. });