devices.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <view class="box">
  3. <view class="search-box">
  4. <view class="dropdown-wrapper">
  5. <picker
  6. @change="bindPickerChange"
  7. :value="selectValue"
  8. :range="option"
  9. >
  10. <view class="picker-content">
  11. <text>{{ option[selectValue] }}</text>
  12. </view>
  13. </picker>
  14. </view>
  15. <view class="search-input">
  16. <input
  17. type="text"
  18. placeholder="输入设备全称或简称"
  19. v-model="keyWord"
  20. placeholder-class="placeholder-style"
  21. />
  22. </view>
  23. <view class="search-btn" @click="queryList"> 搜索 </view>
  24. </view>
  25. <view class="cardList">
  26. <view class="card" v-for="item in devs" :key="item.clientId">
  27. <view class="deviceName" @click="gotoPath(item)">
  28. <text>{{ formatDevName(item.devName) }}</text>
  29. <image src="../../static/arrTwo.png" mode="" />
  30. </view>
  31. <view v-if="item.online == 1">
  32. <view class="online" v-if="item.judge">
  33. <view class="cardInfo">当前有人</view>
  34. <view class="wcTimes" v-if="item.wcTimes"
  35. >今日卫生间使用频率{{ item.wcTimes }}次</view
  36. >
  37. </view>
  38. <view class="cardTwo" v-else>
  39. <view class="cardError" v-if="item.lastTargetTime"
  40. >当前无人</view
  41. >
  42. <view class="endTime" v-if="item.lastTargetTime"
  43. >离开时间
  44. {{ forMateTime(item.lastTargetTime) }}</view
  45. >
  46. <view class="cardError" v-else>当前无人</view>
  47. </view>
  48. </view>
  49. <view v-else style="margin-top: 18rpx">
  50. <text style="color: #8b939f; font-size: 24rpx"
  51. >设备离线</text
  52. >
  53. </view>
  54. <view class="cardImage" v-if="item.online == 0">
  55. <image src="../../static/offline_small.png" mode="" />
  56. </view>
  57. <view class="cardImage" v-else>
  58. <image src="../../static/ln_small.png" mode="" />
  59. </view>
  60. </view>
  61. </view>
  62. <alarModel v-if="isInitAlarm" />
  63. </view>
  64. </template>
  65. <script>
  66. export default {
  67. data() {
  68. return {
  69. keyWord: "",
  70. option: ["全部", "离线", "在线", "报警"],
  71. selectValue: 0,
  72. devs: [],
  73. isInitAlarm: false,
  74. };
  75. },
  76. methods: {
  77. onClickLeft() {
  78. uni.navigateBack({
  79. delta: 0,
  80. });
  81. },
  82. bindPickerChange(e) {
  83. this.selectValue = e.detail.value;
  84. this.queryList();
  85. },
  86. gotoPath(item) {
  87. uni.setStorageSync("devIdDetail", item.devId);
  88. uni.setStorageSync("clientIDetail", item.clientId);
  89. uni.navigateTo({
  90. url:
  91. "/pagesA/deviceDetail/deviceDetail?devItem=" +
  92. JSON.stringify(item),
  93. });
  94. },
  95. forMateTime(inputTime) {
  96. if (!inputTime) return "";
  97. const [datePart, timePart] = inputTime.split(" ");
  98. const [year, month, day] = datePart.split("-");
  99. const [hours, minutes] = timePart.split(":");
  100. return `${parseInt(month)}月${parseInt(day)}日${hours}:${minutes}`;
  101. },
  102. queryList() {
  103. uni.showLoading({
  104. title: "查询中...",
  105. });
  106. let now = new Date();
  107. let status = "";
  108. if (this.selectValue == 0) {
  109. status = null;
  110. } else if (this.selectValue == 1) {
  111. status = "0";
  112. } else if (this.selectValue == 2) {
  113. status = "1";
  114. } else if (this.selectValue == 3) {
  115. status = "2";
  116. }
  117. this.$http
  118. .post("wap/device/deviceList", {
  119. userId: uni.getStorageSync("userId"),
  120. keyWord: this.keyWord,
  121. status: status,
  122. })
  123. .then((res) => {
  124. uni.hideLoading();
  125. if (res.data.code == 200) {
  126. let devs = res.data.data;
  127. for (let i = 0; i < devs.length; i++) {
  128. if (
  129. devs[i].installPosition == "Toilet" &&
  130. devs[i].stayTimes?.length > 0
  131. ) {
  132. devs[i].wcTimes = devs[i].stayTimes.length;
  133. } else {
  134. devs[i].wcTimes = 0;
  135. }
  136. if (devs[i].lastTargetTime) {
  137. const signalTimeStr = devs[
  138. i
  139. ].lastTargetTime.replace(/-/g, "/");
  140. const signalTime = new Date(
  141. signalTimeStr
  142. ).getTime();
  143. if (isNaN(signalTime)) {
  144. devs[i].judge = false;
  145. } else {
  146. const currentTime = Date.now();
  147. const diff = Math.abs(
  148. currentTime - signalTime
  149. );
  150. devs[i].judge = diff <= 5000; // 10秒内为 true
  151. }
  152. }
  153. }
  154. this.devs = devs;
  155. }
  156. uni.hideLoading();
  157. });
  158. },
  159. formatDevName(name) {
  160. return typeof name === "string" && name.length > 6
  161. ? name.slice(0, 6) + "..."
  162. : name;
  163. },
  164. onPullDownRefresh() {
  165. uni.showLoading({
  166. title: "加载中...",
  167. icon: "none",
  168. duration: 1500,
  169. });
  170. this.queryList();
  171. setTimeout(() => {
  172. uni.hideLoading();
  173. uni.stopPullDownRefresh();
  174. }, 2000);
  175. },
  176. },
  177. onLoad() {},
  178. onShow() {
  179. this.isInitAlarm = true;
  180. this.queryList();
  181. },
  182. onHide() {
  183. this.isInitAlarm = false;
  184. },
  185. onUnload() {
  186. this.isInitAlarm = false;
  187. },
  188. onPullDownRefresh() {
  189. uni.showNavigationBarLoading();
  190. this.queryList();
  191. setTimeout(() => {
  192. uni.hideLoading();
  193. uni.hideNavigationBarLoading();
  194. uni.stopPullDownRefresh();
  195. }, 2000);
  196. },
  197. };
  198. </script>
  199. <style lang="less" scoped>
  200. .box {
  201. padding: 10rpx 18rpx;
  202. overflow: scroll;
  203. width: 100vw;
  204. height: 100vh;
  205. background: linear-gradient(180deg, #faede2 0%, #f4f4f4 100%);
  206. box-sizing: border-box;
  207. .search-box {
  208. display: flex;
  209. align-items: center;
  210. width: 100%;
  211. height: 80rpx;
  212. background: #fff;
  213. border-radius: 40rpx;
  214. padding: 0 20rpx;
  215. box-sizing: border-box;
  216. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  217. .dropdown-wrapper {
  218. padding: 0 10rpx;
  219. width: 160rpx;
  220. height: 100%;
  221. display: flex;
  222. align-items: center;
  223. .picker-content {
  224. display: flex;
  225. align-items: center;
  226. font-size: 28rpx;
  227. color: #333;
  228. }
  229. }
  230. .search-input {
  231. flex: 1;
  232. height: 100%;
  233. padding: 0 20rpx;
  234. input {
  235. width: 100%;
  236. height: 100%;
  237. font-size: 28rpx;
  238. }
  239. .placeholder-style {
  240. color: #999;
  241. font-size: 28rpx;
  242. }
  243. }
  244. .search-btn {
  245. width: 120rpx;
  246. height: 60rpx;
  247. background: chocolate;
  248. color: white;
  249. border-radius: 30rpx;
  250. display: flex;
  251. align-items: center;
  252. justify-content: center;
  253. font-size: 28rpx;
  254. margin-left: 10rpx;
  255. }
  256. }
  257. .list-box {
  258. margin-top: 30rpx;
  259. }
  260. .cardList {
  261. display: flex;
  262. flex-wrap: wrap;
  263. align-items: center;
  264. justify-content: space-between;
  265. .card {
  266. position: relative;
  267. width: 350rpx;
  268. height: 305rpx;
  269. margin-top: 18rpx;
  270. background: #ffffff;
  271. border: 2.5rpx solid;
  272. border-color: #ffffff;
  273. border-radius: 37rpx;
  274. padding: 37rpx 25rpx;
  275. box-shadow: 0rpx 2.34rpx 14.06rpx rgba(12, 26, 52, 0.03);
  276. box-sizing: border-box;
  277. .deviceName {
  278. width: 300rpx;
  279. display: flex;
  280. align-items: center;
  281. overflow: hidden;
  282. text {
  283. width: 300rpx;
  284. color: #111111;
  285. font-size: 32rpx;
  286. overflow: hidden;
  287. white-space: nowrap;
  288. text-overflow: ellipsis;
  289. }
  290. image {
  291. width: 10rpx;
  292. height: 20rpx;
  293. margin-left: 15rpx;
  294. }
  295. }
  296. .cardInfo {
  297. margin-top: 18rpx;
  298. color: #0db886;
  299. font-size: 24rpx;
  300. }
  301. .wcTimes {
  302. margin-top: 18rpx;
  303. color: chocolate;
  304. font-size: 24rpx;
  305. }
  306. .cardTwo {
  307. margin-top: 18rpx;
  308. .cardError {
  309. color: #8b939f;
  310. font-size: 24rpx;
  311. }
  312. .endTime {
  313. margin-top: 18rpx;
  314. color: chocolate;
  315. font-size: 24rpx;
  316. }
  317. }
  318. .cardTime {
  319. margin-top: 18rpx;
  320. color: #999999;
  321. font-size: 24rpx;
  322. }
  323. .cardImage {
  324. position: absolute;
  325. bottom: 10rpx;
  326. left: 20rpx;
  327. image {
  328. width: 86rpx;
  329. height: 88rpx;
  330. }
  331. }
  332. }
  333. }
  334. }
  335. </style>