openDoor.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <!-- 远程开门 -->
  3. <div class="page flex-col">
  4. <s-header :name="$t('device.remoteDoorOpening')" :noback="false"></s-header>
  5. <div class="box1">
  6. <div class="block2 flex-row justify-between">
  7. <div class="block3 flex-col"></div>
  8. <span class="info2">{{ $t('device.equipmentName') }}:{{ deviceDetal ? deviceDetal.name : '' }}</span>
  9. </div>
  10. <van-field
  11. colon
  12. readonly
  13. :label="`${$t('device.outDoor')}`"
  14. label-width="40px"
  15. >
  16. <template #input>
  17. <div class="l-flex-RC">
  18. <van-switch
  19. :model-value="deviceDetal.outDoor"
  20. @update:model-value="outDoorChg"
  21. size="22"
  22. active-value="1"
  23. inactive-value="0"
  24. />
  25. </div>
  26. <span class="info3 o-pl-50">{{$t("device.status")}}: </span>
  27. <span class="info3 o-pl-10">{{ deviceDetal.outDoor != 1 ? $t("device.close") : $t("device.open") }}</span>
  28. </template>
  29. </van-field>
  30. <van-field
  31. colon
  32. readonly
  33. :label="`${$t('device.inDoor')}`"
  34. label-width="40px"
  35. >
  36. <template #input>
  37. <div class="l-flex-RC">
  38. <van-switch
  39. :model-value="deviceDetal.inDoor"
  40. @update:model-value="inDoorChg"
  41. size="22"
  42. active-value="1"
  43. inactive-value="0"
  44. />
  45. </div>
  46. <span class="info3 o-pl-50">{{$t("device.status")}}: </span>
  47. <span class="info3 o-pl-10">{{ deviceDetal.inDoor != 1 ? $t("device.close") : $t("device.open") }}</span>
  48. </template>
  49. </van-field>
  50. </div>
  51. </div>
  52. </template>
  53. <script>
  54. import { onMounted, ref } from 'vue';
  55. import sHeader from "@/components/SimpleHeader";
  56. import { useRoute } from 'vue-router';
  57. import { getDeviceDetal, Api_openDoor } from '@/service/device'
  58. import { Toast, Dialog } from 'vant';
  59. import { useI18n } from "vue-i18n";
  60. import { styleUrl } from "../../common/js/utils";
  61. export default {
  62. setup() {
  63. const route = useRoute();
  64. const deviceId = route.query.deviceId;
  65. const deviceDetal = ref({});
  66. const { t } = useI18n();
  67. // 初始化页面获取列表
  68. onMounted(async () => {
  69. // 加载样式
  70. styleUrl('deviceOper');
  71. getDeviceDetalFun();
  72. console.log(deviceDetal.value)
  73. });
  74. // 获取设备列表数据
  75. const getDeviceDetalFun = async () => {
  76. const {
  77. data
  78. } = await getDeviceDetal({
  79. id: deviceId
  80. });
  81. if (data.code === '00000') {
  82. // outDoor如果是null,默认是关闭
  83. if (data.data.outDoor == null) {
  84. data.data.outDoor = "0";
  85. }
  86. // inDoor如果是null,默认是关闭
  87. if (data.data.inDoor == null) {
  88. data.data.inDoor = "0";
  89. }
  90. deviceDetal.value = data.data;
  91. } else {
  92. Toast.fail(data.message);
  93. }
  94. }
  95. // 点击外门开关
  96. const outDoorChg = (outDoor) => {
  97. Dialog.confirm({
  98. title: t('device.openRemind'),
  99. message: t('device.openRemindOut'),
  100. }).then(() => {
  101. Api_openDoor({
  102. equipmentId: deviceDetal.value.id,
  103. type: 0,
  104. status: outDoor,
  105. }).then((res) => {
  106. Toast(res.data.message);
  107. setTimeout(() => {
  108. getDeviceDetalFun();
  109. }, 1000);
  110. });
  111. });
  112. };
  113. // 点击内门开关
  114. const inDoorChg = (inDoor) => {
  115. Dialog.confirm({
  116. title: t('device.openRemind'),
  117. message: t('device.openRemindIn'),
  118. }).then(() => {
  119. Api_openDoor({
  120. equipmentId: deviceDetal.value.id,
  121. type: 1,
  122. status: inDoor,
  123. }).then((res) => {
  124. Toast(res.data.message);
  125. setTimeout(() => {
  126. getDeviceDetalFun();
  127. }, 1000);
  128. });
  129. });
  130. };
  131. return {
  132. deviceDetal,
  133. outDoorChg,
  134. inDoorChg
  135. };
  136. },
  137. components: {
  138. sHeader
  139. },
  140. }
  141. </script>
  142. <style lang="less" scoped>
  143. @import "../../common/style/common";
  144. </style>