index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div>
  3. <el-popover
  4. trigger="manual"
  5. v-model="isPopoverShow"
  6. placement="bottom-end"
  7. @show="fetchNotice(activeName)"
  8. >
  9. <el-badge
  10. :is-dot="isHadNotice"
  11. slot="reference"
  12. class="header-notice"
  13. @click.native="onPopoverShow"
  14. >
  15. <i class="el-icon-bell" />
  16. </el-badge>
  17. <el-tabs v-model="activeName" @tab-click="fetchNotice(activeName)" v-loading="isShowLoading">
  18. <el-tab-pane label="提示信息" name="alarm" class="el-tab-pane">
  19. <el-container v-if="tabListData.length > 0" direction="vertical">
  20. <el-main>
  21. <el-row
  22. v-for="(item, index) in tabListData"
  23. :key="index"
  24. class="list-row"
  25. @click.native="viewAlarmDetail(item)"
  26. >
  27. <el-col :span="4">
  28. <el-avatar :size="avatarSize" :src="item.avatarUrl" style="background: #fff;"></el-avatar>
  29. </el-col>
  30. <el-col :span="16" style="line-height:22px;font-size: 12px;padding: 0;margin: 0;">
  31. <el-row style="margin-bottom: 8px;">
  32. <el-col>
  33. <!-- <h4 style="margin: 0;">{{item.realname}}</h4> -->
  34. <h4 style="margin: 0;">测试液压泵1</h4>
  35. </el-col>
  36. </el-row>
  37. <el-row style="color:rgba(0,0,0,.45);line-height:1.5">
  38. <!-- <el-col>设备{{item.device_number}}发生了{{item.alarm_type_name}}</el-col> -->
  39. <el-col>设备1001校准有效期临近</el-col>
  40. <el-col style="margin-top: 4px;margin-bottom: 4px;">{{item.createTimeAgo}}</el-col>
  41. </el-row>
  42. </el-col>
  43. <el-col :span="4">
  44. <!-- <i class="el-icon-close" @click="del(index)"></i> -->
  45. </el-col>
  46. </el-row>
  47. </el-main>
  48. </el-container>
  49. <div v-else class="empty-notice">
  50. <el-image style="width: 100px; height: 100px" :src="deviceEmptyUrl" fit="fill"></el-image>
  51. <p>无告警信息</p>
  52. </div>
  53. </el-tab-pane>
  54. </el-tabs>
  55. <div
  56. v-if="tabListData.length > 0"
  57. style="text-align:center;line-height: 46px;height: 46px;width:100%"
  58. >
  59. <router-link :to="viewMore">
  60. <el-button type="text" @click="hideAlalrmDialog()">前往处理</el-button>
  61. </router-link>
  62. </div>
  63. </el-popover>
  64. <view-alarm-dialog
  65. :detailVisible="dialogFormVisible"
  66. @sendVal="closeDialog"
  67. :alarmInfo="alarmInfo"
  68. />
  69. </div>
  70. </template>>
  71. <script>
  72. import viewAlarmDialog from "@/views/alarm/component/viewAlarmDialog"
  73. import { formatTime } from "@/utils/index"
  74. export default {
  75. name: "HeaderNotice",
  76. components: {
  77. viewAlarmDialog,
  78. },
  79. data() {
  80. return {
  81. activeName: "alarm",
  82. avatarSize: "medium",
  83. isShowLoading: false,
  84. isPopoverShow: false,
  85. isHadNotice: true,
  86. alarmInfo:[],
  87. deviceEmptyUrl:
  88. "https://gw.alipayobjects.com/zos/rmsportal/sAuJeJzSKbUmHfBQRzmZ.svg",
  89. alarmMessgeWaitReadImg:require('@/assets/alarm/noread_message.png'),
  90. alarmMessgeHadReadedImg:require('@/assets/alarm/read_message.png'),
  91. tabListData: [],
  92. viewMore: "",
  93. dialogFormVisible: false,
  94. form: {
  95. name: "",
  96. region: "",
  97. date1: "",
  98. date2: "",
  99. delivery: false,
  100. type: [],
  101. resource: "",
  102. desc: ""
  103. },
  104. formLabelWidth: "120px"
  105. };
  106. },
  107. created: function() {
  108. // this.fetchNotice();
  109. },
  110. methods: {
  111. fetchNotice(activeName) {
  112. this.tabListData = [];
  113. this.isShowLoading = true;
  114. const params = {
  115. limit:5,
  116. is_read: 0,
  117. };
  118. this.$http.get("AlarmReport", { params: params }).then(response => {
  119. this.tabListData = response.data.map((item, index, arr) => {
  120. // console.log(item, index, arr);
  121. item.avatarUrl = this.alarmMessgeWaitReadImg;
  122. let rendor_item = item;
  123. //计算据当前时间的分钟数
  124. rendor_item.createTimeAgo = formatTime(rendor_item.alarm_time_str)
  125. return rendor_item;
  126. });
  127. if (this.tabListData.length > 0) {
  128. this.isHadNotice = true
  129. if (activeName == "alarm") {
  130. this.viewMore = {
  131. path: "/alarm/alarmDevice",
  132. params: { type: activeName }
  133. };
  134. }
  135. }
  136. //this.tabListData = response.data;
  137. setTimeout(() => {
  138. this.isShowLoading = false;
  139. }, 1000);
  140. });
  141. },
  142. viewAlarmDetail(item) {
  143. this.dialogFormVisible = true;
  144. this.alarmInfo = item
  145. item.avatarUrl = this.alarmMessgeHadReadedImg;
  146. console.log(item)
  147. //修改为已读
  148. this.$http.put("AlarmReport/"+item.id,{is_read:1}).then(response => {
  149. });
  150. },
  151. onPopoverShow() {
  152. this.isPopoverShow = !this.isPopoverShow;
  153. },
  154. closeDialog(){
  155. this.dialogFormVisible = false
  156. },
  157. hideAlalrmDialog(){
  158. this.isPopoverShow=false
  159. }
  160. }
  161. };
  162. </script>
  163. <style scoped>
  164. .header-notice {
  165. display: inline-block;
  166. transition: all 0.3s;
  167. line-height: 25px;
  168. margin-top: -5px;
  169. }
  170. .empty-notice {
  171. text-align: center;
  172. padding: 73px 0 88px;
  173. }
  174. .el-tab-pane {
  175. width: 336px;
  176. min-height: 326px;
  177. max-height: 400px;
  178. overflow: auto;
  179. }
  180. /*#FBFBFB #B9E1DC #F38181 #756C83 */
  181. .el-main {
  182. padding: 0px;
  183. }
  184. .list-row {
  185. border-bottom: 1px solid #e8e8e8;
  186. line-height: 88px;
  187. cursor: pointer;
  188. padding-top: 12px;
  189. padding-bottom: 12px;
  190. }
  191. .list-row:hover {
  192. background: #ecf6fd;
  193. }
  194. .el-icon-close {
  195. cursor: pointer;
  196. }
  197. .el-icon-close:hover {
  198. color: #ef5f65;
  199. }
  200. </style>