alarm.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="container">
  3. <u--form labelPosition="left">
  4. <u-form-item
  5. label="查询日期"
  6. labelWidth="80"
  7. borderBottom
  8. @click="
  9. showCalendar = true;
  10. hideKeyboard();
  11. "
  12. >
  13. <u--input v-model="alarmDate" disabled disabledColor="#ffffff" placeholder="请选择查询日期" border="none"></u--input>
  14. <u-icon slot="right" name="arrow-right"></u-icon>
  15. </u-form-item>
  16. <u-form-item
  17. label="告警类型"
  18. borderBottom
  19. labelWidth="80"
  20. @click="
  21. showAlarmType = true;
  22. hideKeyboard();
  23. "
  24. >
  25. <u--input v-model="alarmTypeName" disabled disabledColor="#ffffff" placeholder="请选择告警类型" border="none"></u--input>
  26. <u-icon slot="right" name="arrow-right"></u-icon>
  27. </u-form-item>
  28. <u-calendar :show="showCalendar" :defaultDate="alarmDateArr" :minDate="calendarMinDate" :allowSameDay="true" :closeOnClickOverlay="true" :maxDate="calendarMaxDate" mode="range" @confirm="calendarConfirm" @close="calendarClose" startText="开始时间" endText="结束时间" confirmDisabledText="请选择查询日期范围"></u-calendar>
  29. <u-action-sheet :show="showAlarmType" :actions="alarmTypeActions" title="请选择告警类型" @close="showAlarmType = false" @select="alarmTypeSelect"></u-action-sheet>
  30. </u--form>
  31. <qiun-title-bar :title="`报警信息概览 (${alarmTotal})`" />
  32. <scroll-view :scroll-y="alarmTotal > 0" @scroll="scroll" :scroll-top="scrollTop" style="height: 620px;">
  33. <view class="alarm-list_none" v-if="alarmTotal == 0">
  34. <text>没有报警信息</text>
  35. <image src="/static/image/no-data.png"></image>
  36. </view>
  37. <view class="alarm-list" v-if="alarmTotal > 0">
  38. <view class="alarm-list_item" v-for="(item, index) in alarmList" :key="index">
  39. <view class="left">
  40. <text class="name">{{ item.device_name }}</text>
  41. <text class="address">{{ item.warn_type_name }}</text>
  42. </view>
  43. <view class="right">
  44. <text v-if="item.warn_value">
  45. 超标值:
  46. <text class="num">{{ item.warn_value }}</text>
  47. </text>
  48. <text class="">{{ item.abnormal_state_name }}</text>
  49. </view>
  50. </view>
  51. </view>
  52. </scroll-view>
  53. </view>
  54. </template>
  55. <script>
  56. import moment from "moment";
  57. import api from "@/common/api.js";
  58. import { log } from "@/utils/base.js";
  59. export default {
  60. data() {
  61. return {
  62. showCalendar: false,
  63. showAlarmType: false,
  64. alarmTypeActions: [],
  65. alarmDateArr: [moment().add(-1, "d"), moment()],
  66. alarmList: [],
  67. alarmTotal: 0,
  68. needQuery: true,
  69. isQuerying: false,
  70. scrollTop: 0,
  71. oldScrollTop: 0,
  72. calendarMinDate: moment()
  73. .add(-10, "d")
  74. .format("YYYY-MM-DD"),
  75. calendarMaxDate: moment()
  76. .add(1, "d")
  77. .format("YYYY-MM-DD"),
  78. search: {
  79. pageIndex: 1,
  80. pageSize: 10,
  81. params: {
  82. id: "",
  83. begin: "",
  84. end: "",
  85. warn_type: "",
  86. },
  87. },
  88. };
  89. },
  90. computed: {
  91. alarmDate: {
  92. get() {
  93. return `${this.alarmDateArr[0].format("YYYY-MM-DD")}/${this.alarmDateArr[1].format("YYYY-MM-DD")}`;
  94. },
  95. set() {},
  96. },
  97. alarmTypeName: {
  98. get() {
  99. if (this.alarmTypeActions && this.alarmTypeActions.length) {
  100. var active = this.alarmTypeActions.find(v => v.code == this.search.params.warn_type);
  101. if (active) {
  102. return active.name;
  103. }
  104. }
  105. return "";
  106. },
  107. set() {},
  108. },
  109. },
  110. props: {
  111. companyId: {
  112. type: String,
  113. required: true,
  114. },
  115. },
  116. onLoad() {},
  117. mounted() {
  118. this.getAlarmTypes();
  119. this.query();
  120. },
  121. methods: {
  122. hideKeyboard() {
  123. uni.hideKeyboard();
  124. },
  125. calendarConfirm(e) {
  126. this.showCalendar = false;
  127. this.alarmDateArr = [moment(e[0]), moment(e[e.length - 1])];
  128. this.search.pageIndex = 1;
  129. this.query();
  130. },
  131. calendarClose() {
  132. this.showCalendar = false;
  133. },
  134. getAlarmTypes() {
  135. api.getWarnTypetList().then(({ data }) => {
  136. this.alarmTypeActions = data.list;
  137. });
  138. },
  139. alarmTypeSelect(e) {
  140. this.showAlarmType = false;
  141. this.search.params.warn_type = e.code;
  142. this.search.pageIndex = 1;
  143. this.query();
  144. },
  145. query(nextPage) {
  146. if (this.needQuery || !nextPage) {
  147. if (!nextPage) {
  148. this.alarmList = [];
  149. this.goTop();
  150. }
  151. this.search.params.id = `10_${this.companyId}`;
  152. this.search.params.begin = this.alarmDateArr[0].format("YYYYMMDD");
  153. this.search.params.end = this.alarmDateArr[1].format("YYYYMMDD");
  154. var search = JSON.parse(JSON.stringify(this.search));
  155. if (!search.params.warn_type) {
  156. delete search.params.warn_type;
  157. }
  158. api.getWarnTable(search).then(({ rows, total }) => {
  159. this.alarmTotal = total;
  160. if ((this.search.pageIndex - 1) * this.search.pageSize < total) {
  161. this.alarmList.push(...rows);
  162. this.isQuerying = false;
  163. } else {
  164. this.needQuery = false;
  165. }
  166. });
  167. }
  168. },
  169. scroll(e) {
  170. this.oldScrollTop = e.detail.scrollTop;
  171. console.log(e.detail.scrollHeight - e.detail.scrollTop, e.detail.scrollHeight, e.detail.scrollTop);
  172. if (e.detail.scrollHeight - e.detail.scrollTop <= 900 && !this.isQuerying) {
  173. log("到达底部");
  174. this.isQuerying = true;
  175. this.search.pageIndex++;
  176. this.query(true);
  177. }
  178. },
  179. goTop() {
  180. this.scrollTop = this.oldScrollTop;
  181. this.$nextTick(() => {
  182. this.scrollTop = 0;
  183. });
  184. },
  185. },
  186. };
  187. </script>
  188. <style lang="scss">
  189. .container {
  190. padding: 0 10px;
  191. font-size: 14px;
  192. line-height: 24px;
  193. }
  194. .alarm-list {
  195. border: 1px solid $uni-color-error;
  196. border-radius: 5px;
  197. margin: 5px 10px;
  198. &_none {
  199. margin-top: 10%;
  200. display: flex;
  201. flex-direction: column;
  202. justify-content: center;
  203. align-items: center;
  204. font-size: 20px;
  205. color: $uni-color-error;
  206. }
  207. &_item {
  208. &:not(:last-child) {
  209. border-bottom: 1px dashed $uni-color-error;
  210. }
  211. display: flex;
  212. padding: 10px 15px;
  213. justify-content: space-between;
  214. align-items: center;
  215. color: lighten($uni-color-error, 15%);
  216. .left {
  217. display: flex;
  218. flex-direction: column;
  219. .name {
  220. font-weight: 600;
  221. }
  222. }
  223. .right {
  224. display: flex;
  225. flex-direction: column;
  226. text-align: right;
  227. .num {
  228. font-weight: 600;
  229. margin-left: 10px;
  230. }
  231. }
  232. }
  233. }
  234. </style>