Remotecontrol.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <template>
  2. <view>
  3. <view class="header"></view>
  4. <view class="position">
  5. <picker mode="multiSelector" @columnchange="bindMultiPickerColumnChange"
  6. @change="(val)=>confirmHandle(val,'position')" :range="positionList" style="width:100%;height: 100%;"
  7. range-key="orgName">
  8. <u-icon name="map-fill" color="#fff" class="inline"></u-icon>
  9. <view class="uni-input inline positionName">{{name}}</view>
  10. <u-icon name="arrow-rightward" class="inline" color="#fff"></u-icon>
  11. </picker>
  12. </view>
  13. <view class="form">
  14. <view class="drawdownMenu">
  15. <picker @change="(val)=>confirmHandle(val,'deviceType')" :value="deviceTypeIndex"
  16. :range="deviceTypeList" style="width:100%;height: 100%;" range-key="dictLabel">
  17. <view class="uni-input">{{deviceTypeList[deviceTypeIndex].dictLabel}}</view>
  18. <u-icon name="arrow-down-fill" color="#666" size="16" class="inline"></u-icon>
  19. </picker>
  20. </view>
  21. <view class="drawdownMenu">
  22. <picker @change="(val)=>confirmHandle(val,'deviceStatus')" :value="deviceStatusIndex"
  23. :range="deviceStatusList" style="width:100%;height: 100%;" range-key="text">
  24. <view class="uni-input">{{deviceStatusList[deviceStatusIndex].text}}</view>
  25. <u-icon name="arrow-down-fill" color="#666" size="16" class="inline"></u-icon>
  26. </picker>
  27. </view>
  28. </view>
  29. <view class="total">
  30. 共有<text style="color: #f44;">{{total}}</text>条记录
  31. </view>
  32. <!-- 列表 -->
  33. <view class="list">
  34. <view class="each" v-for="(item,index) in dataList">
  35. <template v-if="deviceType == 'AirConditioner'">
  36. <view class="l1">{{item.airConditionerName}}</view>
  37. <view class="l2">空间信息:{{ item.installSite }}{{ item.roomNumbers }}</view>
  38. <view class="l2" v-if="item.attributeList">室温:{{ item.attributeList[4].value }}℃</view>
  39. <view class="operation" v-if="item.attributeList">
  40. <picker @change="(val)=>confirmHandle(val,'modeType',item.deviceId)"
  41. :value="item.attributeList[2].value|findInd(modeTypeList)" :range="modeTypeList"
  42. style="width:100%;height: 100%;" range-key="dictLabel">
  43. <view class="uni-input">{{findInd2(item.attributeList[2].value,modeTypeList)}}</view>
  44. <u-icon name="arrow-down" color="#999" size="16" class="inline"></u-icon>
  45. </picker>
  46. <picker @change="(val)=>confirmHandle(val,'temp',item.deviceId)"
  47. :value="item.attributeList[5].value|findInd(temperatureList)" :range="temperatureList"
  48. style="width:100%;height: 100%;">
  49. <view class="uni-input">{{item.attributeList[5].value}}</view>
  50. <u-icon name="arrow-down" color="#999" size="16" class="inline"></u-icon>
  51. </picker>
  52. <picker @change="(val)=>confirmHandle(val,'speedType',item.deviceId)"
  53. :value="item.attributeList[0].value|findInd(speedTypeList)" :range="speedTypeList"
  54. style="width:100%;height: 100%;" range-key="dictLabel">
  55. <view class="uni-input">{{findInd2(item.attributeList[0].value,speedTypeList)}}</view>
  56. <u-icon name="arrow-down" color="#999" size="16" class="inline"></u-icon>
  57. </picker>
  58. </view>
  59. <switch :checked="item.attributeList[3].value==1?true:false"
  60. @change="(val)=>changeSwitch('AirConditioner', val, item.deviceId, index)"
  61. style="transform:scale(0.7)" class="switch" />
  62. </template>
  63. <template v-if="deviceType == 'Relay'">
  64. <view class="l1">{{item.controlName}}</view>
  65. <view class="l2">空间信息:{{ item.installSite }}</view>
  66. <switch :checked="item.status==1?true:false"
  67. @change="(val)=>changeSwitch('Relay', val, item.deviceId, index)" style="transform:scale(0.7)"
  68. class="switch" />
  69. </template>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </template>
  76. <script>
  77. import {
  78. isEmpty,
  79. getDictDataList,
  80. getUrlKey
  81. } from "@/utils/index";
  82. import Api from "./@/http/Api.js";
  83. export default {
  84. data() {
  85. return {
  86. modeTypeList: [],
  87. modeTypeIndex: 0,
  88. temperatureList: [],
  89. tempIndex: 0,
  90. speedTypeList: [],
  91. speedTypeIndex: 0,
  92. dataForm: {
  93. page: 1,
  94. limit: 10,
  95. buildingId: "",
  96. storeyId: "",
  97. status: "",
  98. controlCategory: "CommonLighting",
  99. },
  100. total: 0,
  101. refreshing: false,
  102. finished: false,
  103. deviceTypeIndex: 0,
  104. deviceStatusIndex: 0,
  105. name: '跨境电商',
  106. projectName: '',
  107. p1: 0,
  108. p2: 0,
  109. positionList: [
  110. [],
  111. []
  112. ],
  113. deviceType: "AirConditioner",
  114. deviceStatus: '',
  115. deviceTypeList: [],
  116. dataList: [],
  117. deviceStatusList: [{
  118. text: "全部",
  119. value: ""
  120. },
  121. {
  122. text: "开启",
  123. value: 1
  124. },
  125. {
  126. text: "关闭",
  127. value: 0
  128. },
  129. ],
  130. }
  131. },
  132. onReachBottom() {
  133. if (!this.finished) {
  134. this.dataForm.page++;
  135. this.getDataList();
  136. }
  137. },
  138. onLoad() {
  139. let getDictDataList = uni.getStorageSync('getDictDataList');
  140. for (let i = 0; i < getDictDataList.length; i++) {
  141. if (getDictDataList[i].dictType == 'ModeType') {
  142. this.modeTypeList = getDictDataList[i].dataList
  143. }
  144. if (getDictDataList[i].dictType == 'SpeedType') {
  145. this.speedTypeList = getDictDataList[i].dataList
  146. }
  147. if (getDictDataList[i].dictType == 'DeviceCategory') {
  148. this.deviceTypeList = getDictDataList[i].dataList;
  149. console.log('7777',this.deviceTypeList)
  150. this.deviceTypeList.forEach((item) => {
  151. item.text = item.dictLabel;
  152. item.value = item.dictValue;
  153. });
  154. this.deviceTypeList = this.deviceTypeList.filter(
  155. (item) => item.value != "WaterMeter" && item.value != "Ammeter"
  156. );
  157. }
  158. }
  159. this.getBuildList();
  160. // this.getDeviceTypeList();
  161. this.setTemperatureList();
  162. this.getDataList()
  163. },
  164. watch: {
  165. "dataForm.buildingId"(newval, oldval) {
  166. if (newval != oldval) {
  167. this.onRefresh();
  168. }
  169. },
  170. "dataForm.storeyId"(newval, oldval) {
  171. if (newval != oldval) {
  172. this.onRefresh();
  173. }
  174. },
  175. },
  176. filters: {
  177. findInd(val, list) {
  178. if (isEmpty(val)) {
  179. return 0;
  180. }
  181. if (list.length > 5) {
  182. return list.findIndex((item) => item == val);
  183. } else {
  184. return list.findIndex((item) => parseFloat(item.dictValue) == val);
  185. }
  186. }
  187. },
  188. methods: {
  189. findInd2(val, list) {
  190. if (isEmpty(val)) {
  191. return 0;
  192. }
  193. if (list.find((item) => parseFloat(item.dictValue) == val)) {
  194. return list.find((item) => parseFloat(item.dictValue) == val).dictLabel;
  195. } else {
  196. return list[0].dictLabel
  197. }
  198. },
  199. //获取楼栋
  200. getBuildList() {
  201. Api.getBuildInfo().then((res) => {
  202. if (res.data.code == 0) {
  203. this.name = this.projectName = res.data.data[0].orgName;
  204. this.positionList[0] = [];
  205. let positionList = res.data.data[0].childrenList;
  206. if (positionList) {
  207. let json = {
  208. category: "s",
  209. childrenList: null,
  210. orgId: "",
  211. orgName: "全部",
  212. };
  213. for (let i = 0; i < positionList.length; i++) {
  214. positionList[i].childrenList.unshift(json);
  215. this.positionList[0].push(positionList[i]);
  216. }
  217. this.positionList[0].unshift(json);
  218. this.positionList[1] = this.positionList[0][0].childrenList;
  219. }
  220. }
  221. });
  222. },
  223. bindMultiPickerColumnChange(e) {
  224. this.positionList[1] = this.positionList[1] = this.positionList[0][e.detail.value].childrenList;
  225. },
  226. setTemperatureList() {
  227. this.temperatureList = [];
  228. for (let i = 16; i < 33; i++) {
  229. this.temperatureList.push(i);
  230. }
  231. },
  232. confirmHandle(e, type, deviceId) {
  233. this.dataForm.page = 1;
  234. if (type == 'position') {
  235. this.p1 = e.detail.value[0];
  236. this.p2 = e.detail.value[1];
  237. this.dataForm.buildingId = this.p1 == 0 ? '' : this.positionList[0][this.p1].orgId;
  238. this.dataForm.storeyId = this.p2 == 0 ? "" : this.positionList[1][this.p2].orgId;
  239. let buildName = this.p1 == 0 ? "" : '-' + this.positionList[0][this.p1].orgName;
  240. let storeyName = this.p2 == 0 ? "" : '-' + this.positionList[1][this.p2].orgName;
  241. this.name = this.projectName + buildName + storeyName;
  242. } else {
  243. let index = type + "Index";
  244. this[index] = e.detail.value;
  245. if (type == "deviceType") {
  246. this.deviceType = this.deviceTypeList[e.detail.value].value;
  247. this.onRefresh();
  248. }
  249. if (type == "deviceStatus") {
  250. this.deviceStatus = this.deviceStatusList[e.detail.value].value;
  251. this.dataForm.status = this.deviceStatus;
  252. this.onRefresh();
  253. }
  254. if (type == "modeType") {
  255. let data = this.modeTypeList[e.detail.value].dictValue;
  256. this.onConfirmMode(data, 'modeTypeList', deviceId);
  257. }
  258. if (type == "speedType") {
  259. let data = this.speedTypeList[e.detail.value].dictValue;
  260. this.onConfirmMode(data, 'speedTypeList', deviceId);
  261. }
  262. if (type == "temp") {
  263. let data = this.temperatureList[e.detail.value];
  264. this.onConfirmMode(data, 'temperatureList', deviceId);
  265. }
  266. }
  267. },
  268. //刷新
  269. onRefresh() {
  270. this.finished = false;
  271. // 重新加载数据
  272. this.dataList = [];
  273. // 将 loading 设置为 true,表示处于加载状态
  274. this.total = 0;
  275. this.loading = true;
  276. this.dataForm.page = 1; // 分页数赋值为1
  277. this.loadData();
  278. },
  279. //加载数据
  280. loadData() {
  281. setTimeout(async () => {
  282. if (this.refreshing) {
  283. this.dataList = [];
  284. this.refreshing = false;
  285. }
  286. await this.getDataList();
  287. //this.dataForm.page++; // 分页数加一
  288. }, 100);
  289. },
  290. getDataList() {
  291. if (this.deviceType == "AirConditioner") {
  292. this.getAircond();
  293. }
  294. if (this.deviceType == "Relay") {
  295. this.getElec();
  296. }
  297. },
  298. // getDeviceTypeList() {
  299. // this.deviceTypeList = JSON.parse(
  300. // JSON.stringify(getDictDataList("DeviceCategory"))
  301. // );
  302. // this.deviceTypeList.forEach((item) => {
  303. // item.text = item.dictLabel;
  304. // item.value = item.dictValue;
  305. // });
  306. // this.deviceTypeList = this.deviceTypeList.filter(
  307. // (item) => item.value != "WaterMeter" && item.value != "Ammeter"
  308. // );
  309. // },
  310. getAircond() {
  311. this.dataForm.status = "";
  312. Api.airconditioner(this.dataForm).then((res) => {
  313. if (res.data.code == 0) {
  314. if (res.data.data) {
  315. if (res.data.data.list.length == 0) {
  316. // 判断获取数据条数若等于0
  317. this.dataList = []; // 清空数组
  318. this.finished = true; // 停止加载
  319. }
  320. // 若数据条数不等于0
  321. this.dataList.push(...res.data.data.list); // 将数据放入list中
  322. this.loading = false; // 加载状态结束
  323. this.total = res.data.data.total;
  324. // 如果list长度大于等于总数据条数,数据全部加载完成
  325. if (this.dataList.length >= res.data.data.total) {
  326. this.finished = true; // 结束加载状态
  327. }
  328. } else {
  329. // 判断获取数据条数若等于0
  330. this.dataList = []; // 清空数组
  331. this.finished = true; // 停止加载
  332. }
  333. } else {
  334. this.loading = false; // 加载状态结束
  335. this.finished = true; // 停止加载
  336. }
  337. });
  338. },
  339. getElec() {
  340. Api.getElec(this.dataForm).then((res) => {
  341. if (res.data.code == 0) {
  342. if (res.data.data) {
  343. if (res.data.data.list.length == 0) {
  344. // 判断获取数据条数若等于0
  345. this.dataList = []; // 清空数组
  346. this.finished = true; // 停止加载
  347. }
  348. // 若数据条数不等于0
  349. this.dataList.push(...res.data.data.list); // 将数据放入list中
  350. this.loading = false; // 加载状态结束
  351. this.total = res.data.data.total;
  352. // 如果list长度大于等于总数据条数,数据全部加载完成
  353. if (this.dataList.length >= res.data.data.total) {
  354. this.finished = true; // 结束加载状态
  355. }
  356. } else {
  357. // 判断获取数据条数若等于0
  358. this.dataList = []; // 清空数组
  359. this.finished = true; // 停止加载
  360. }
  361. } else {
  362. this.loading = false; // 加载状态结束
  363. this.finished = true; // 停止加载
  364. }
  365. });
  366. },
  367. //下发指令开关
  368. changeSwitch(type, val, deviceId, index) {
  369. let msg = "";
  370. if (val.detail.value) {
  371. msg = "开启";
  372. } else {
  373. msg = "关闭";
  374. }
  375. uni.showModal({
  376. title: '提示',
  377. content: `请确认是否【${msg}】此设备`,
  378. success: function(res) {
  379. if (res.confirm) {
  380. if (type == "AirConditioner") {
  381. Api.setControl({
  382. keyword: "setPower",
  383. param: val.detail.value ? 1 : 0,
  384. deviceId: deviceId,
  385. }).then((res) => {
  386. if (res.data.code == 0) {
  387. this.dataList[index].attributeList[3].value = val;
  388. uni.showToast({
  389. title: '操作成功',
  390. duration: 2000
  391. });
  392. } else {
  393. uni.showToast({
  394. title: '操作失败',
  395. duration: 2000
  396. });
  397. }
  398. });
  399. }
  400. if (type == "Relay") {
  401. Api.setControlElec({
  402. keyword: "setRelay",
  403. param: val.detail.value ? 1 : 0,
  404. deviceId: deviceId,
  405. }).then((res) => {
  406. if (res.data.code == 0) {
  407. this.dataList[index].status = val;
  408. uni.showToast({
  409. title: '操作成功',
  410. duration: 2000
  411. });
  412. } else {
  413. uni.showToast({
  414. title: '操作失败',
  415. duration: 2000
  416. });
  417. }
  418. });
  419. }
  420. } else if (res.cancel) {
  421. console.log('用户点击取消');
  422. }
  423. }
  424. });
  425. },
  426. onConfirmMode(data, module, deviceId) {
  427. let deviceCommandDTO = {};
  428. switch (module) {
  429. case "modeTypeList":
  430. deviceCommandDTO = {
  431. keyword: "setMode",
  432. param: data,
  433. deviceId: deviceId,
  434. };
  435. break;
  436. case "temperatureList":
  437. deviceCommandDTO = {
  438. keyword: "setTemp",
  439. param: data,
  440. deviceId: deviceId,
  441. };
  442. break;
  443. case "speedTypeList":
  444. deviceCommandDTO = {
  445. keyword: "setFan",
  446. param: data,
  447. deviceId: deviceId,
  448. };
  449. break;
  450. }
  451. Api.setControl(deviceCommandDTO).then((res) => {
  452. this.$toast.clear();
  453. if (res.data.code == 0) {
  454. uni.showToast({
  455. title: '操作成功',
  456. duration: 2000
  457. });
  458. }
  459. });
  460. },
  461. }
  462. }
  463. </script>
  464. <style lang="scss" scoped>
  465. .uni-input {
  466. margin-right: 4px;
  467. }
  468. .uni-input,
  469. .inline {
  470. display: inline-block;
  471. }
  472. .form {
  473. display: flex;
  474. height: 48px;
  475. align-items: center;
  476. background-color: #fff;
  477. .drawdownMenu {
  478. display: flex;
  479. text-align: center;
  480. width: 50%;
  481. }
  482. }
  483. .header {
  484. background-color: #5c8fff;
  485. height: 25px;
  486. }
  487. .position {
  488. font-size: 16px;
  489. color: #fff;
  490. padding: 10px 16px;
  491. background: #5c8fff;
  492. .positionName {
  493. margin: 0 5px;
  494. }
  495. }
  496. .total {
  497. padding: 0 16px;
  498. margin: 8px 0;
  499. line-height: 15px;
  500. display: flex;
  501. text-align: left;
  502. text {
  503. font-size: 15px;
  504. vertical-align: middle;
  505. }
  506. }
  507. .list {
  508. padding: 0 16px;
  509. .each {
  510. background: #ffffff;
  511. box-shadow: 0px 0px 10px 0px rgba(153, 153, 153, 0.15);
  512. border-radius: 4px;
  513. margin-bottom: 12px;
  514. padding: 12px 16px;
  515. display: flex;
  516. flex-direction: column;
  517. align-items: flex-start;
  518. position: relative;
  519. .l1 {
  520. height: 22px;
  521. font-size: 16px;
  522. color: #0c1935;
  523. line-height: 22px;
  524. margin-bottom: 8px;
  525. }
  526. .l2,
  527. .operation {
  528. height: 18px;
  529. font-size: 14px;
  530. color: #999999;
  531. line-height: 18px;
  532. margin-bottom: 4px;
  533. }
  534. .operation {
  535. display: flex;
  536. width: 100%;
  537. position: relative;
  538. font-size: 13px;
  539. margin-top: 10px;
  540. text-align: center;
  541. }
  542. .switch {
  543. position: absolute;
  544. right: 10px;
  545. font-size: 18px;
  546. top: auto;
  547. z-index: 1;
  548. }
  549. }
  550. }
  551. </style>