Remotecontrol.vue 17 KB

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