shelf.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //$('body').on('click','.my-shelf-right', function(){
  2. $('.my-shelf-right').click(function () {
  3. $('.my-shelf-right').hide()
  4. if($(this).hasClass('my-shelf-setting')){
  5. $('.my-shelf-cancle').show()
  6. $('.book-item:not(.book-item-more)').addClass('book-item-unselected')
  7. }else if($(this).hasClass('my-shelf-cancle')){
  8. $('.my-shelf-setting').show()
  9. $('.my-shelf-left strong').show();
  10. $('.my-shelf-left em').hide()
  11. $('.book-item').removeClass('book-item-unselected book-item-selected')
  12. }else if($(this).hasClass('my-shelf-delete')){
  13. $('.my-shelf-setting').show();
  14. var books_arr = [];
  15. $(".book-item-selected").each(function () {
  16. books_arr.push($(this).data('book_id'));
  17. });
  18. bookids_str = JSON.stringify(books_arr);
  19. $.ajax({
  20. type: 'post',
  21. url: '/api/bookshelf/delbooks',
  22. timeout: 10000,
  23. cache: false,
  24. data: {
  25. bookIds:bookids_str
  26. },
  27. success: function (data) {
  28. if(data.err==0){
  29. //consoleMain('删除成功');
  30. window.location.reload();
  31. }
  32. },
  33. error: function (XMLHttpRequest, textStatus, errorThrown) {
  34. consoleMain('删除失败,请稍后重试');
  35. }
  36. });
  37. // 删除选中的书籍
  38. $('.book-item-selected').remove()
  39. $('.book-item').removeClass('book-item-unselected')
  40. }
  41. })
  42. $('body').on('click','.book-item', function(e){
  43. if($(this).hasClass('book-item-unselected')){
  44. $(this).removeClass('book-item-unselected').addClass('book-item-selected')
  45. }else if($(this).hasClass('book-item-selected')){
  46. $(this).removeClass('book-item-selected').addClass('book-item-unselected')
  47. }else{
  48. return
  49. }
  50. $('.my-shelf-left strong').hide();
  51. $('.my-shelf-left em').html('已选择'+$('.book-item-selected').length+'本书').css('display', 'inline-block');
  52. if ($('.book-item-selected').length > 0) {
  53. $('.my-shelf-right').hide()
  54. $('.my-shelf-delete').show()
  55. } else {
  56. $('.my-shelf-right').hide()
  57. $('.my-shelf-cancle').show()
  58. }
  59. //不要删 阻止点击a标签跳转
  60. e.stopPropagation();
  61. return false;
  62. })
  63. //编辑最近阅读
  64. $('.r_bookshelf_edit_open').click(function(){
  65. $('.r_my_bookshelf_box').addClass('r_bookshelf_list_edit');
  66. });
  67. //取消编辑最近阅读
  68. $('.r_bookshelf_edit_close').click(function(){
  69. $('.r_my_bookshelf_box').removeClass('r_bookshelf_list_edit');
  70. });
  71. //选中要删除的book
  72. $('.r_my_bookshelf_box').on('click','.r_bookshelf_list_edit .r_my_bookshelf a',function(e){
  73. var $this=$(this),booknum=0;
  74. $this.toggleClass('r_bookshelf_remove_select');
  75. booknum=$('.r_bookshelf_remove_select').length;
  76. $('.r_bookshelf_num em span').text(booknum);
  77. if(booknum<=0){
  78. $('.r_my_bookshelf_box').removeClass('r_bookshelf_list_edit_remove');
  79. }else{
  80. $('.r_my_bookshelf_box').addClass('r_bookshelf_list_edit_remove');
  81. }
  82. //不要删 阻止点击a标签跳转
  83. e.stopPropagation();
  84. return false;
  85. });
  86. //删除操作
  87. $('.r_bookshelf_edit_remove').on('click',function(){
  88. $('.r_my_bookshelf_box').removeClass('r_bookshelf_list_edit_remove');
  89. $('.r_my_bookshelf_box').removeClass('r_bookshelf_list_edit');
  90. var books_arr = [];
  91. $(".r_bookshelf_remove_select").each(function () {
  92. books_arr.push($(this).attr('book_id'));
  93. });
  94. bookids_str = JSON.stringify(books_arr);
  95. console.log(bookids_str);
  96. $.ajax({
  97. type: 'post',
  98. url: '/api/bookshelf/delbooks',
  99. timeout: 10000,
  100. cache: false,
  101. data: {
  102. bookIds:bookids_str
  103. },
  104. success: function (data) {
  105. if(data.err==0){
  106. consoleMain('删除成功');
  107. window.location.reload();
  108. }
  109. },
  110. error: function (XMLHttpRequest, textStatus, errorThrown) {
  111. consoleMain('删除失败,请稍后重试');
  112. }
  113. });
  114. })