人人商城

biz.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. define(['bootstrap'], function($){
  2. var biz = {};
  3. biz.user = {};
  4. /**
  5. * vals array 已经选中的用户编号
  6. * callback function(users) 选择成功后回调
  7. * options object mode 已经选中的用户展示方式, visible 显示出已经选中的用户, 并标记为选中状态(默认值) invisible 隐藏已经选中的用户
  8. */
  9. biz.user.browser = function(vals, callback, options) {
  10. var mode = 'visible';
  11. if(options && options.mode){
  12. mode = options.mode;
  13. }
  14. var uids = '0';
  15. if($.isArray(vals) && vals.length>0){
  16. uids = vals.join();
  17. }
  18. if ($('#user-browser-dialog')[0]) {
  19. $('#user-browser-dialog').remove();
  20. }
  21. var footer =
  22. '<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>' +
  23. '<button type="button" class="btn btn-primary">确认</button>';
  24. var url = './index.php?c=utility&a=user&do=browser&callback=aMember'+'&mode='+mode+'&uids=' + uids;
  25. var dialog = util.dialog('请选择用户', '数据加载中......', footer,{containerName : 'user-browser-dialog'});
  26. dialog.modal('show');
  27. dialog.on('shown.bs.modal', function(){
  28. window.aMember.pIndex = 1;
  29. window.aMember.query();
  30. });
  31. dialog.find('.modal-footer .btn-primary').click(function(){
  32. var users = [];
  33. var chks = $('.user-browser .btn-primary');
  34. if(chks.length>0){
  35. chks.each(function(){
  36. users.push($(this).attr('js-uid'));
  37. });
  38. if($.isFunction(callback)) {
  39. callback(users);
  40. dialog.modal('hide');
  41. }
  42. }
  43. });
  44. window.aMember = {
  45. pIndex : 1,
  46. query : function() {
  47. var data = {
  48. keyword: $('#keyword').val(),
  49. page: aMember.pIndex,
  50. callback:'aMember',
  51. mode: mode,
  52. uids: uids
  53. };
  54. $.post(url, data, function(dat){
  55. dialog.find('.modal-body').html(dat);
  56. if (options.direct) {
  57. dialog.find('.js-btn-select').click(function(){
  58. dialog.find('.modal-footer .btn-primary').trigger('click');
  59. });
  60. }
  61. dialog.find('.pagination a').click(function(){
  62. window.aMember.pIndex = $(this).attr('page');
  63. window.aMember.query();
  64. });
  65. });
  66. }
  67. };
  68. }
  69. return biz;
  70. });