devices.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. <alarModel v-if="isInitAlarm" />
  62. </view>
  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. console.log("设备列表", res);
  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. });
  168. this.queryList();
  169. setTimeout(() => {
  170. uni.hideLoading();
  171. uni.stopPullDownRefresh();
  172. }, 2000);
  173. },
  174. },
  175. onLoad() {},
  176. onShow() {
  177. this.isInitAlarm = true;
  178. this.queryList();
  179. },
  180. onHide() {
  181. this.isInitAlarm = false;
  182. },
  183. onUnload() {
  184. // this.isInitAlarm = false;
  185. },
  186. onPullDownRefresh() {
  187. uni.showNavigationBarLoading();
  188. this.queryList();
  189. setTimeout(() => {
  190. uni.hideLoading();
  191. uni.hideNavigationBarLoading();
  192. uni.stopPullDownRefresh();
  193. }, 2000);
  194. },
  195. };
  196. </script>
  197. <style lang="less" scoped>
  198. .box {
  199. padding: 10rpx 18rpx;
  200. overflow: scroll;
  201. width: 100vw;
  202. height: 100vh;
  203. background: linear-gradient(180deg, #faede2 0%, #f4f4f4 100%);
  204. box-sizing: border-box;
  205. .search-box {
  206. display: flex;
  207. align-items: center;
  208. width: 100%;
  209. height: 80rpx;
  210. background: #fff;
  211. border-radius: 40rpx;
  212. padding: 0 20rpx;
  213. box-sizing: border-box;
  214. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  215. .dropdown-wrapper {
  216. padding: 0 10rpx;
  217. width: 160rpx;
  218. height: 100%;
  219. display: flex;
  220. align-items: center;
  221. .picker-content {
  222. display: flex;
  223. align-items: center;
  224. font-size: 28rpx;
  225. color: #333;
  226. }
  227. }
  228. .search-input {
  229. flex: 1;
  230. height: 100%;
  231. padding: 0 20rpx;
  232. input {
  233. width: 100%;
  234. height: 100%;
  235. font-size: 28rpx;
  236. }
  237. .placeholder-style {
  238. color: #999;
  239. font-size: 28rpx;
  240. }
  241. }
  242. .search-btn {
  243. width: 120rpx;
  244. height: 60rpx;
  245. background: chocolate;
  246. color: white;
  247. border-radius: 30rpx;
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. font-size: 28rpx;
  252. margin-left: 10rpx;
  253. }
  254. }
  255. .list-box {
  256. margin-top: 30rpx;
  257. }
  258. .cardList {
  259. display: flex;
  260. flex-wrap: wrap;
  261. align-items: center;
  262. justify-content: space-between;
  263. .card {
  264. position: relative;
  265. width: 350rpx;
  266. height: 305rpx;
  267. margin-top: 18rpx;
  268. background: #ffffff;
  269. border: 2.5rpx solid;
  270. border-color: #ffffff;
  271. border-radius: 37rpx;
  272. padding: 37rpx 25rpx;
  273. box-shadow: 0rpx 2.34rpx 14.06rpx rgba(12, 26, 52, 0.03);
  274. box-sizing: border-box;
  275. .deviceName {
  276. width: 300rpx;
  277. display: flex;
  278. align-items: center;
  279. overflow: hidden;
  280. text {
  281. width: 300rpx;
  282. color: #111111;
  283. font-size: 32rpx;
  284. overflow: hidden;
  285. white-space: nowrap;
  286. text-overflow: ellipsis;
  287. }
  288. image {
  289. width: 10rpx;
  290. height: 20rpx;
  291. margin-left: 15rpx;
  292. }
  293. }
  294. .cardInfo {
  295. margin-top: 18rpx;
  296. color: #0db886;
  297. font-size: 24rpx;
  298. }
  299. .wcTimes {
  300. margin-top: 18rpx;
  301. color: chocolate;
  302. font-size: 24rpx;
  303. }
  304. .cardTwo {
  305. margin-top: 18rpx;
  306. .cardError {
  307. color: #8b939f;
  308. font-size: 24rpx;
  309. }
  310. .endTime {
  311. margin-top: 18rpx;
  312. color: chocolate;
  313. font-size: 24rpx;
  314. }
  315. }
  316. .cardTime {
  317. margin-top: 18rpx;
  318. color: #999999;
  319. font-size: 24rpx;
  320. }
  321. .cardImage {
  322. position: absolute;
  323. bottom: 10rpx;
  324. left: 20rpx;
  325. image {
  326. width: 86rpx;
  327. height: 88rpx;
  328. }
  329. }
  330. }
  331. }
  332. }
  333. </style>