devices.vue 10 KB

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