user.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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: 'groupid_text', title: __('Groupid'), operate:false,events: Controller.api.events.groupid, formatter: Controller.api.formatter.groupid},
  25. {field: 'tagid_list_text', title: __('Tagid_list'), operate:false,events: Controller.api.events.tagid_list, formatter: Controller.api.formatter.tagid_list},
  26. {field: 'subscribe', title: __('Subscribe'), searchList: {"0":__('否'),"1":__('是')}, formatter: Controller.api.subscribe},
  27. {field: 'subscribe_time', title: __('Subscribe_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  28. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  29. {
  30. field: 'operate',
  31. title: __('Operate'),
  32. table: table,
  33. events: Table.api.events.operate,
  34. formatter: Table.api.formatter.operate,
  35. buttons: [
  36. {
  37. name: 'detail',
  38. title: __('修改标签'),
  39. classname: 'btn btn-xs btn-success btn-dialog',
  40. icon: 'fa fa-tag',
  41. //extend: 'data-area=\'["700px", "500px"]\'',
  42. url: 'weixin/user/edit_user_tag',
  43. callback: function (data) {
  44. Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  45. }
  46. },{
  47. name: 'detail',
  48. title: __('修改分组'),
  49. classname: 'btn btn-xs btn-info btn-dialog',
  50. icon: 'fa fa-group',
  51. //extend: 'data-area=\'["700px", "500px"]\'',
  52. url: 'weixin/user/edit_user_group',
  53. callback: function (data) {
  54. Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  55. }
  56. }
  57. ]
  58. }
  59. ]
  60. ]
  61. });
  62. // 获取选中项
  63. $(document).on("click", ".btn-selected", function () {
  64. var ids = '';
  65. $.each(table.bootstrapTable('getSelections'), function (index, row) {
  66. ids += row.uid + ',';
  67. });
  68. var that = this;
  69. var options = $.extend({}, $(that).data() || {});
  70. var url = Backend.api.replaceids(that, $(that).data("url") || $(that).attr('href'));
  71. var title = $(that).attr("title") || $(that).data("title") || $(that).data('original-title');
  72. var button = Backend.api.gettablecolumnbutton(options);
  73. if (button && typeof button.callback === 'function') {
  74. options.callback = button.callback;
  75. }
  76. url += '/ids/' + ids;
  77. if (typeof options.confirm !== 'undefined') {
  78. Layer.confirm(options.confirm, function (index) {
  79. Backend.api.open(url, title, options);
  80. Layer.close(index);
  81. });
  82. } else {
  83. window[$(that).data("window") || 'self'].Backend.api.open(url, title, options);
  84. }
  85. return false;
  86. });
  87. // 为表格绑定事件
  88. Table.api.bindevent(table);
  89. },
  90. edit: function () {
  91. Controller.api.bindevent();
  92. },
  93. edit_user_tag: function () {
  94. Controller.api.bindevent();
  95. },
  96. edit_user_group: function () {
  97. Controller.api.bindevent();
  98. },
  99. tag: function () {
  100. // 初始化表格参数配置
  101. Table.api.init({
  102. extend: {
  103. index_url: 'weixin/user/tag' + location.search,
  104. add_url: 'weixin/user/tagadd',
  105. edit_url: 'weixin/user/tagedit',
  106. del_url: 'weixin/user/tagdel',
  107. table: 'weixin_user',
  108. }
  109. });
  110. var table = $("#table");
  111. // 初始化表格
  112. table.bootstrapTable({
  113. url: $.fn.bootstrapTable.defaults.extend.index_url,
  114. search:false,
  115. commonSearch:false,
  116. columns: [
  117. [
  118. {checkbox: true},
  119. {field: 'id', title: __('编号')},
  120. {field: 'name', title: __('标签名')},
  121. {field: 'count', title: __('人数')},
  122. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  123. ]
  124. ]
  125. });
  126. // 为表格绑定事件
  127. Table.api.bindevent(table);
  128. },
  129. tagadd: function () {
  130. Controller.api.bindevent();
  131. },
  132. tagedit: function () {
  133. Controller.api.bindevent();
  134. },
  135. group: function () {
  136. // 初始化表格参数配置
  137. Table.api.init({
  138. extend: {
  139. index_url: 'weixin/user/group' + location.search,
  140. add_url: 'weixin/user/groupadd',
  141. edit_url: 'weixin/user/groupedit',
  142. del_url: 'weixin/user/groupdel',
  143. table: 'weixin_user',
  144. }
  145. });
  146. var table = $("#table");
  147. // 初始化表格
  148. table.bootstrapTable({
  149. url: $.fn.bootstrapTable.defaults.extend.index_url,
  150. search:false,
  151. commonSearch:false,
  152. columns: [
  153. [
  154. {checkbox: true},
  155. {field: 'id', title: __('编号')},
  156. {field: 'name', title: __('分组名')},
  157. {field: 'count', title: __('人数')},
  158. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  159. ]
  160. ]
  161. });
  162. // 为表格绑定事件
  163. Table.api.bindevent(table);
  164. },
  165. groupadd: function () {
  166. Controller.api.bindevent();
  167. },
  168. groupedit: function () {
  169. Controller.api.bindevent();
  170. },
  171. sendmsg: function (){
  172. //不可见的元素不验证
  173. $("form[role=form]").data("validator-options", {ignore: ':hidden'});
  174. Form.api.bindevent($("form[role=form]"));
  175. //显示和隐藏
  176. $(document).on("click", "input[name='row[type]']", function () {
  177. var type = $("input[name='row[type]']:checked").val();
  178. $('.isshow').hide();
  179. $('.' + type).show();
  180. });
  181. Controller.api.bindevent();
  182. $("input[name='row[type]']:checked").trigger("click");
  183. },
  184. api: {
  185. bindevent: function () {
  186. Form.api.bindevent($("form[role=form]"));
  187. },
  188. sex: function (value, row, index) {
  189. if(row.sex == "1") {
  190. return '男';
  191. } else if (row.sex == "2"){
  192. return '女';
  193. }else{
  194. return '未知';
  195. }
  196. }
  197. ,
  198. subscribe: function (value, row, index) {
  199. if(row.subscribe == "1") {
  200. return '是';
  201. }else{
  202. return '否';
  203. }
  204. },
  205. formatter: {//渲染的方法
  206. groupid: function (value, row, index) {
  207. return '<a class="btn btn-xs btn-groupid bg-info">' + value + '</a>';
  208. },
  209. tagid_list: function (value, row, index) {
  210. var str = '';
  211. var arr = new Array();
  212. arr = value;
  213. for(var i=0;i<arr.length;i++)
  214. {
  215. str += '<a class="btn btn-xs btn-tagid_list bg-success">' + arr[i] + '</a>';
  216. }
  217. return str;
  218. }
  219. },
  220. events: {//绑定事件的方法
  221. groupid: {
  222. //格式为:方法名+空格+DOM元素
  223. 'click .btn-groupid': function (e, value, row, index) {
  224. e.stopPropagation();
  225. var container = $("#table").data("bootstrap.table").$container;
  226. var options = $("#table").bootstrapTable('getOptions');
  227. //这里我们手动将数据填充到表单然后提交
  228. $("form.form-commonsearch [name='groupid']", container).val(value);
  229. $("form.form-commonsearch", container).trigger('submit');
  230. }
  231. },
  232. tagid_list: {
  233. //格式为:方法名+空格+DOM元素
  234. 'click .btn-tagid_list': function (e, value, row, index) {
  235. e.stopPropagation();
  236. var container = $("#table").data("bootstrap.table").$container;
  237. var options = $("#table").bootstrapTable('getOptions');
  238. //这里我们手动将数据填充到表单然后提交
  239. $("form.form-commonsearch [name='tagid_list']", container).val(value);
  240. $("form.form-commonsearch", container).trigger('submit');
  241. }
  242. }
  243. }
  244. }
  245. };
  246. return Controller;
  247. });