index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div>
  3. <van-nav-bar title="消息记录" left-text="返回" right-text="全部已读" @click-right="allRead()" @click-left="back" fixed left-arrow/>
  4. <div class="login_form">
  5. <van-list v-model="loading" :finished="finished" finished-text="没有更多了" :error.sync="error" error-text="请求失败,点击重新加载" @load="getMessage">
  6. <van-cell @click="readMsg(index)" v-for="(item,index) in list" :key="index"
  7. :label="item.time.replace('T', ' ')" >
  8. <template #title>
  9. <span v-if="user.userNameNeedTranslate == 1 && item.msg != null && item.msg.indexOf('$userName=') != -1">
  10. <span>{{item.msg1}}</span>
  11. <TranslationOpenDataText type='userName' :openid='item.msg2'></TranslationOpenDataText>
  12. <span>{{item.msg3}}</span>
  13. </span>
  14. <span v-else-if="item.msg != null">{{item.msg}}</span>
  15. <span v-else>{{msgType[item.type]}}</span>
  16. </template>
  17. <div >
  18. <span v-if="item.checked == 1" style="color:green">已读</span>
  19. <span v-if="item.checked == 0" style="color:red">未读</span>
  20. </div>
  21. </van-cell>
  22. </van-list>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. msgType:["日报审核未通过","有新任务"],
  31. user: JSON.parse(localStorage.userInfo),
  32. total: 0,
  33. page: 1,
  34. size: 20,
  35. list: [],
  36. loading: false,
  37. finished: false,
  38. error: false,
  39. refreshing: false,
  40. show: false,
  41. title: "标题",
  42. };
  43. },
  44. created() {
  45. },
  46. methods: {
  47. // 全部已读
  48. allRead() {
  49. this.$axios.post("/information/checkAll", {})
  50. .then(res => {
  51. if(res.code == "ok") {
  52. // 重新获取消息
  53. this.getMessage();
  54. }
  55. }).catch(err=> {this.$toast.clear();});
  56. },
  57. // 返回
  58. back() {
  59. history.back();
  60. },
  61. getmsgtext(text){
  62. return text.split('$')[1].split('=')[1]
  63. },
  64. readMsg(index) {
  65. var item = this.list[index];
  66. if (item.type == 0) {
  67. //日报
  68. var date = item.content;
  69. this.$axios.post("/information/check", {id:item.id
  70. })
  71. .then(res => {
  72. if(res.code == "ok") {
  73. //跳转到对应的日报上进行修改
  74. this.getMessage();
  75. this.$router.push('/edit?date='+date);
  76. }
  77. }).catch(err=> {this.$toast.clear();});
  78. } else {
  79. var date = item.content;
  80. this.$axios.post("/information/check", {id:item.id
  81. })
  82. .then(res => {
  83. if(res.code == "ok") {
  84. this.getMessage()
  85. if (item.type == 1 || (item.msg != null && item.msg.indexOf('任务') > 0)) {
  86. //跳到待办任务上
  87. this.$router.push('/task');
  88. } else if (item.type == 3) {
  89. //跳到费用报销上
  90. this.$router.push('/expense');
  91. }
  92. }
  93. }).catch(err=> {this.$toast.clear();});
  94. }
  95. },
  96. //获取消息
  97. getMessage() {
  98. if (this.refreshing) {
  99. this.list = [];
  100. this.refreshing = false;
  101. }
  102. if(this.total == this.list.length && this.list.length != 0) {
  103. this.loading = false;
  104. this.finished = true;
  105. return false;
  106. }
  107. this.$axios.post("/information/list", {
  108. })
  109. .then(res => {
  110. if(res.code == "ok") {
  111. this.loading = false;
  112. this.finished = true;
  113. this.list = res.data;
  114. for(let i in this.list){
  115. if(this.list[i].msg != null && this.list[i].msg.indexOf('$userName=') != -1){
  116. this.list[i].msg1 = this.list[i].msg.split('$')[0]
  117. this.list[i].msg2 = this.list[i].msg.split('$')[1].split('=')[1]
  118. this.list[i].msg3 = this.list[i].msg.split('$')[2]
  119. }
  120. }
  121. } else {
  122. this.$toast.fail('获取失败');
  123. }
  124. }).catch(err=> {this.$toast.clear();});
  125. },
  126. onRefresh() {
  127. this.finished = false;
  128. this.loading = true;
  129. this.page = 1;
  130. this.getMessage();
  131. },
  132. },
  133. mounted() {
  134. }
  135. };
  136. </script>
  137. <style lang="less" scoped>
  138. .van-cell__title {
  139. min-width: 90%;
  140. }
  141. .login_form {
  142. margin-top: 46px;
  143. }
  144. .one_report {
  145. margin-bottom: 15px;
  146. }
  147. .form_text {
  148. margin: 15px 0 30px;
  149. padding: 0 12px;
  150. }
  151. .form_btn {
  152. text-align: right;
  153. }
  154. .form_btn button {
  155. margin-left: 10px;
  156. }
  157. .one_report_data {
  158. margin-bottom: 20px;
  159. padding: 0 22px;
  160. div {
  161. line-height: 30px;
  162. }
  163. }
  164. .userCheckbox {
  165. padding: 10px;;
  166. }
  167. </style>
  168. <style lang="less">
  169. .van-nav-bar .van-icon , .van-nav-bar__text {
  170. color: #20a0ff;
  171. }
  172. </style>