index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div>
  3. <van-nav-bar title="消息记录" left-text="返回" @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. <ww-open-data type='userName' :openid='item.msg2'></ww-open-data>
  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. back() {
  49. history.back();
  50. },
  51. getmsgtext(text){
  52. return text.split('$')[1].split('=')[1]
  53. },
  54. readMsg(index) {
  55. var item = this.list[index];
  56. if (item.type == 0) {
  57. //日报
  58. var date = item.content;
  59. this.$axios.post("/information/check", {id:item.id
  60. })
  61. .then(res => {
  62. if(res.code == "ok") {
  63. //跳转到对应的日报上进行修改
  64. this.getMessage();
  65. this.$router.push('/edit?date='+date);
  66. }
  67. }).catch(err=> {this.$toast.clear();});
  68. } else {
  69. var date = item.content;
  70. this.$axios.post("/information/check", {id:item.id
  71. })
  72. .then(res => {
  73. if(res.code == "ok") {
  74. this.getMessage()
  75. if (item.type == 1 || (item.msg != null && item.msg.indexOf('任务') > 0)) {
  76. //跳到待办任务上
  77. this.$router.push('/task');
  78. } else if (item.type == 3) {
  79. //跳到费用报销上
  80. this.$router.push('/expense');
  81. }
  82. }
  83. }).catch(err=> {this.$toast.clear();});
  84. }
  85. },
  86. //获取消息
  87. getMessage() {
  88. if (this.refreshing) {
  89. this.list = [];
  90. this.refreshing = false;
  91. }
  92. if(this.total == this.list.length && this.list.length != 0) {
  93. this.loading = false;
  94. this.finished = true;
  95. return false;
  96. }
  97. this.$axios.post("/information/list", {
  98. })
  99. .then(res => {
  100. if(res.code == "ok") {
  101. this.loading = false;
  102. this.finished = true;
  103. this.list = res.data;
  104. for(let i in this.list){
  105. if(this.list[i].msg != null && this.list[i].msg.indexOf('$userName=') != -1){
  106. this.list[i].msg1 = this.list[i].msg.split('$')[0]
  107. this.list[i].msg2 = this.list[i].msg.split('$')[1].split('=')[1]
  108. this.list[i].msg3 = this.list[i].msg.split('$')[2]
  109. }
  110. }
  111. } else {
  112. this.$toast.fail('获取失败');
  113. }
  114. }).catch(err=> {this.$toast.clear();});
  115. },
  116. onRefresh() {
  117. this.finished = false;
  118. this.loading = true;
  119. this.page = 1;
  120. this.getMessage();
  121. },
  122. },
  123. mounted() {
  124. }
  125. };
  126. </script>
  127. <style lang="less" scoped>
  128. .van-cell__title {
  129. min-width: 90%;
  130. }
  131. .login_form {
  132. margin-top: 46px;
  133. }
  134. .one_report {
  135. margin-bottom: 15px;
  136. }
  137. .form_text {
  138. margin: 15px 0 30px;
  139. padding: 0 12px;
  140. }
  141. .form_btn {
  142. text-align: right;
  143. }
  144. .form_btn button {
  145. margin-left: 10px;
  146. }
  147. .one_report_data {
  148. margin-bottom: 20px;
  149. padding: 0 22px;
  150. div {
  151. line-height: 30px;
  152. }
  153. }
  154. .userCheckbox {
  155. padding: 10px;;
  156. }
  157. </style>
  158. <style lang="less">
  159. .van-nav-bar .van-icon , .van-nav-bar__text {
  160. color: #20a0ff;
  161. }
  162. </style>