user.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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: 'user/user/index',
  8. add_url: 'user/user/add',
  9. edit_url: 'user/user/edit',
  10. del_url: 'user/user/del',
  11. multi_url: 'user/user/multi',
  12. table: 'user',
  13. }
  14. });
  15. var table = $("#table");
  16. var c_remarks = Config.c_remarks;
  17. var b_remarks = Config.b_remarks;
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'user.id',
  23. fixedColumns: true,
  24. fixedRightNumber: 1,
  25. columns: [
  26. [
  27. {checkbox: true},
  28. {field: 'id', title: __('Id'), sortable: true},
  29. {field: 'username', title: __('Username'), operate: 'LIKE'},
  30. {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
  31. {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
  32. {
  33. field: 'avatar',
  34. title: __('Avatar'),
  35. events: Table.api.events.image,
  36. formatter: Table.api.formatter.image,
  37. operate: false
  38. },
  39. {
  40. field: 'level',
  41. title: __('Level'),
  42. searchList: {"1": __('Level 1'), "2": __('Level 2'), "3": __('Level 3')},
  43. formatter: Table.api.formatter.normal
  44. },
  45. {field: 'joinremarks1.value', title: __('Remarks1'),visible:c_remarks},
  46. {field: 'joinremarks2.value', title: __('Remarks2'),visible:c_remarks},
  47. {field: 'joinremarks3.value', title: __('Remarks3'),visible:c_remarks},
  48. {
  49. field: 'type_remarks',
  50. title: __('TypeRemarks'),
  51. formatter: Table.api.formatter.normal,
  52. searchList: {"1": __('TypeRemarks 1'), "2": __('TypeRemarks 2'), "3": __('TypeRemarks 3')},visible:b_remarks
  53. },
  54. {field: 'bindremarks.value', title: __('BindRemarks'), operate: false,visible:b_remarks},
  55. {field: 'score', title: __('Score'), operate: 'LIKE'},
  56. {
  57. field: 'logintime',
  58. title: __('Logintime'),
  59. formatter: Table.api.formatter.datetime,
  60. operate: 'RANGE',
  61. addclass: 'datetimerange',
  62. sortable: true
  63. },
  64. {
  65. field: 'status',
  66. title: __('Status'),
  67. formatter: Table.api.formatter.status,
  68. searchList: {normal: __('Normal'), hidden: __('Hidden')}
  69. },
  70. {
  71. field: 'cancel_shop',
  72. title: __('Cancelshop'),
  73. formatter: Table.api.formatter.normal,
  74. searchList: {"0": __('Cancelshop 0'), "1": __('Cancelshop 1')}
  75. },
  76. {field: 'loginip', title: __('Loginip'), formatter: Table.api.formatter.search},
  77. {
  78. field: 'jointime',
  79. title: __('Jointime'),
  80. formatter: Table.api.formatter.datetime,
  81. operate: 'RANGE',
  82. addclass: 'datetimerange',
  83. sortable: true
  84. },
  85. {field: 'city', title: __('City'), operate: 'LIKE'},
  86. {field: 'address', title: __('Address'), operate: 'LIKE'},
  87. {field: 'remarks', title: __('Remarks'), operate: 'LIKE'},
  88. {
  89. field: 'operate',
  90. title: __('Operate'),
  91. table: table,
  92. events: Table.api.events.operate,
  93. formatter: Table.api.formatter.operate,
  94. buttons: [{
  95. name: 'ajax',
  96. text: __('Reset Password'),
  97. icon: 'fa fa-wrench',
  98. classname: 'btn btn-xs btn-success btn-magic btn-ajax',
  99. confirm: '确认重置密码?重置后密码:123456',
  100. url: 'user/user/reset_password?ids={id}',
  101. // visible: function (row) {
  102. // if ((row.status == 1) || (row.status == 5)) {
  103. // return true;
  104. // } else {
  105. // return false;
  106. // }
  107. // //返回true时按钮显示,返回false隐藏
  108. // },
  109. success: function (data, ret) {
  110. //Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data));
  111. //如果需要阻止成功提示,则必须使用return false;
  112. Layer.alert(ret.msg);
  113. table.bootstrapTable('refresh', {});
  114. return false;
  115. },
  116. error: function (data, ret) {
  117. console.log(data, ret);
  118. Layer.alert(ret.msg);
  119. table.bootstrapTable('refresh', {});
  120. return false;
  121. }
  122. }],
  123. }
  124. ]
  125. ]
  126. });
  127. // 为表格绑定事件
  128. Table.api.bindevent(table);
  129. },
  130. add: function () {
  131. Controller.api.bindevent();
  132. $(document).on("change", "#c-level", function () {
  133. //变更后的回调事件
  134. let checkValue = $("#c-level").val();
  135. if (checkValue == 1) {
  136. $("#div_c-c_user_id").addClass("hidden");
  137. $("#div_c_remarks").removeClass("hidden");
  138. } else {
  139. $("#div_c-c_user_id").removeClass("hidden");
  140. $("#div_c_remarks").addClass("hidden");
  141. }
  142. });
  143. $(document).on("change", "#c-type_remarks", function () {
  144. //变更后的回调事件
  145. let checkValue = $("#c-type_remarks").val();
  146. Fast.api.ajax({
  147. url: 'user/user_common/remarks_list',
  148. type: 'post',
  149. data: {
  150. type_remarks: checkValue,
  151. }
  152. }, function (data, ret) {
  153. var op = '<option value="">--请选择备注--</option>';
  154. for (var i in data.list) {
  155. op += '<option value="' + data.list[i]['id'] + '">' + data.list[i]['value'] + '</option>'
  156. }
  157. $("#c-bind_remarks").html(op);
  158. $("#c-bind_remarks").selectpicker("refresh");
  159. }, function (data, ret) {
  160. console.log("type_remarks-error")
  161. });
  162. });
  163. },
  164. edit: function () {
  165. Controller.api.bindevent();
  166. $(document).on("change", "#c-type_remarks", function () {
  167. //变更后的回调事件
  168. let checkValue = $("#c-type_remarks").val();
  169. Fast.api.ajax({
  170. url: 'user/user_common/remarks_list',
  171. type: 'post',
  172. data: {
  173. type_remarks: checkValue,
  174. }
  175. }, function (data, ret) {
  176. var op = '<option value="">--请选择备注--</option>';
  177. for (var i in data.list) {
  178. op += '<option value="' + data.list[i]['id'] + '">' + data.list[i]['value'] + '</option>'
  179. }
  180. $("#c-bind_remarks").html(op);
  181. $("#c-bind_remarks").selectpicker("refresh");
  182. }, function (data, ret) {
  183. console.log("type_remarks-error")
  184. });
  185. });
  186. },
  187. api: {
  188. bindevent: function () {
  189. Form.api.bindevent($("form[role=form]"));
  190. }
  191. }
  192. };
  193. return Controller;
  194. });