message.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. ;var helpSuggestion = new Vue({
  2. el: "#dashboard",
  3. mixins: [noticeMixin,cmSysVitaMixins],
  4. data: {
  5. btnLoading: false,
  6. isRequset:false,
  7. mssageTabBarIndex:0,
  8. mssageTabBar: [
  9. {messageType: '',text: '全部消息',bages:0},
  10. {messageType: 2,text: '账户通知',bages:0},
  11. {messageType: 3,text: '服务通知',bages:0},
  12. ],
  13. allCount:0,
  14. listQuery: {
  15. source: 1,
  16. commonId: 0,
  17. messageType: '',
  18. pageNum: 1,
  19. pageSize: 10
  20. },
  21. noMore:false,
  22. listRecord: 0,
  23. pageInput: '1',
  24. degree:'',
  25. isCheckedAll:false,
  26. messagesList:[],//新闻动态
  27. check:false,
  28. checklist:[],
  29. msgId:'',
  30. },
  31. filters: {
  32. NumBadge: function (n) {//处理
  33. var num = '';
  34. if (n > 100) {
  35. num = 99
  36. } else {
  37. num = n;
  38. }
  39. return num;
  40. }
  41. },
  42. computed: {
  43. pageTotal: function () {
  44. var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
  45. return total > 0 ? total : 1;
  46. },
  47. showPageBtn: function () {
  48. var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
  49. total = total > 0 ? total : 1;
  50. var index = this.listQuery.pageNum, arr = [];
  51. if (total <= 6) {
  52. for (var i = 1; i <= total; i++) {
  53. arr.push(i);
  54. }
  55. return arr;
  56. }
  57. if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
  58. if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
  59. return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
  60. }
  61. },
  62. methods: {
  63. toPagination: function (pageNum) {//点击切换分页
  64. if (pageNum <= this.pageTotal) {
  65. this.listQuery.pageNum = pageNum;
  66. this. getAuthShopMessageList();
  67. }
  68. },
  69. checkNum: function () {//输入跳转分页
  70. if (this.pageInput > this.pageTotal) {
  71. this.pageInput = this.pageTotal;
  72. } else if (this.pageInput < 1) {
  73. this.pageInput = 1;
  74. }
  75. },
  76. changeTabsFn:function(index,messageType){//点击Tab切换消息通知
  77. this.mssageTabBarIndex = index;
  78. this.listQuery.messageType = messageType;
  79. this.listQuery.pageNum = 1;
  80. this.messagesList =[];
  81. this. getAuthShopMessageList();
  82. },
  83. getAuthShopMessageCount:function(){//查询tabs数量
  84. var _self = this;
  85. SupplierApi.getAuthShopMessageCount({commonId:_self.listQuery.commonId},function (response) {
  86. var data = response.data;
  87. _self.mssageTabBar[0].bages = _self.allCount = data.count;
  88. _self.mssageTabBar[1].bages = data.accountCount;
  89. _self.mssageTabBar[2].bages = data.notificationCount;
  90. })
  91. },
  92. getAuthShopMessageList:function(){
  93. var _self = this;
  94. SupplierApi.getAuthShopMessageList(_self.listQuery,function (response) {
  95. if(response.code == 0){
  96. _self.isRequset = false;
  97. _self.isCheckedAll = false;
  98. var data = response.data;
  99. if (data.list.length>0){
  100. if(isPC){
  101. _self.messagesList = data.list.map(function (el) {
  102. el.check = false
  103. return el;
  104. });
  105. }else{
  106. var list = data.list.map(function (el) {
  107. el.check = false
  108. return el;
  109. });
  110. _self.messagesList = _self.messagesList.concat(list);
  111. }
  112. _self.listRecord = data.total;
  113. _self.requestFlag = true;
  114. }else {
  115. _self.requestFlag = false;
  116. _self.listRecord = data.total;
  117. }
  118. }else{
  119. CAIMEI.Alert(response.msg, '确定', false);
  120. _self.requestFlag = false;
  121. }
  122. })
  123. },
  124. checkedContains(arr, val) {// 校验
  125. return arr.some(item => item === val)
  126. },
  127. checkedItemFn:function(item){ //单选
  128. var _self = this;
  129. if(event.target.checked){
  130. if(!_self.checkedContains(_self.checklist,item.id)){
  131. _self.checklist.push(item.id);
  132. }
  133. }else {
  134. _self.checklist.splice(_self.checklist.indexOf(item.id), 1);
  135. }
  136. _self.msgId = _self.checklist.toString()+','
  137. if(_self.checklist.length==_self.messagesList.length){
  138. _self.isCheckedAll=true;
  139. }else {
  140. _self.isCheckedAll=false;
  141. }
  142. },
  143. checkedAllFn: function () { //全選
  144. var _self = this;
  145. _self.isCheckedAll = !_self.isCheckedAll;
  146. if (_self.isCheckedAll) {
  147. _self.checklist = [];
  148. _self.messagesList.forEach(function (item) {
  149. item.check = true;
  150. _self.checklist.push(item.id);
  151. _self.msgId = _self.checklist.toString()+','
  152. })
  153. }else{
  154. _self.messagesList.forEach(function(item){
  155. item.check = false;
  156. });
  157. _self.checklist = [];
  158. _self.msgId = ''
  159. }
  160. },
  161. deleteMessageFn: function(){//删除消息
  162. var _this =this;
  163. if(this.allCount === 0){
  164. CAIMEI.dialog('暂无消息');
  165. }else if(_this.checklist.length==0){
  166. CAIMEI.dialog('请勾选未读消息');
  167. }else{
  168. SupplierApi.authDeleteMessage({id:_this.msgId},function (res) {
  169. if (res.code==0){
  170. CAIMEI.dialog('刪除成功');
  171. setTimeout(function (){
  172. _this.getAuthShopMessageList();
  173. },500)
  174. }else {
  175. CAIMEI.Alert(res.msg, '确定', false);
  176. }
  177. })
  178. }
  179. },
  180. signMessageFn: function(){//标记为已读
  181. var _this =this;
  182. console.log(_this.checklist);
  183. console.log(_this.msgId);
  184. if(this.allCount === 0){
  185. CAIMEI.dialog('暂无未读消息');
  186. }else if(_this.checklist.length==0){
  187. CAIMEI.dialog('请勾选未读消息');
  188. }else {
  189. SupplierApi.authUpdateRead({userType:2,Id:_this.msgId},function (res) {
  190. if(res.code==0){
  191. CAIMEI.dialog('标记已读成功');
  192. setTimeout(function (){
  193. _this.getAuthShopMessageCount();
  194. _this.getAuthShopMessageList();
  195. },500)
  196. }else {
  197. CAIMEI.Alert(res.msg, '确定', false);
  198. }
  199. })
  200. }
  201. }
  202. },
  203. mounted: function () {
  204. const _self = this;
  205. if(globalUserData){
  206. this.listQuery.commonId = globalUserData.shopId;
  207. this.getAuthShopMessageCount();
  208. this.getAuthShopMessageList();
  209. }
  210. if(!isPC){
  211. $('footer').addClass("noneImportant");
  212. //移动端上垃加载更多
  213. $(window).on('scroll', function(){
  214. var scrollTop = $(this).scrollTop();
  215. var scrollHeight = $(document).height();
  216. var windowHeight = window.innerHeight;
  217. if (scrollTop + windowHeight >= scrollHeight) {
  218. //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
  219. var totalPage = Math.ceil(_self.listRecord / _self.listQuery.pageSize)?Math.ceil(_self.listRecord / _self.listQuery.pageSize):1;
  220. var next = _self.listQuery.pageNum+1;
  221. if(next <= totalPage){
  222. if (_self.requestFlag){
  223. _self.listQuery.pageNum = next;
  224. // 获取列表数据
  225. _self.getAuthShopMessageList();
  226. }
  227. _self.requestFlag = false;
  228. }else{
  229. //到底了
  230. _self.noMore = true;
  231. $('footer').removeClass("noneImportant");
  232. }
  233. }
  234. });
  235. }
  236. }
  237. });