Remotecontrol.vue 17 KB

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