paramsSetInfo.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <!-- 设备参数调整 -->
  3. <div class="paramsSetPage flex-col">
  4. <s-header :name="paramsTitle" :noback="false"></s-header>
  5. <div class="paramsSetBox mod1 flex-col">
  6. <div class="wrap2 flex-col van-hairline--bottom">
  7. <div class="outer1 flex-row justify-between">
  8. <div class="block1 flex-col"></div>
  9. <span class="txt2">{{ $t('device.equipmentName') }}:{{ deviceDetal ? deviceDetal.name : "" }}</span>
  10. </div>
  11. </div>
  12. <!-- <van-divider :style="{ margin: '5px 16px' }" /> -->
  13. <div class="" v-if="type == '3'">
  14. <van-field :label="$t('device.numberOneTm')" :model-value="(deviceDetal.numberOne == null ? $t('device.noData') : deviceDetal.numberOne + $t('device.degree'))" readonly />
  15. <van-field :label="$t('device.furnaceHeadTemperature')" :model-value="(deviceDetal.furnaceTm == null ? $t('device.noData') : deviceDetal.furnaceTm + $t('device.degree'))" readonly />
  16. <van-field :label="$t('device.candyGeneratorTm')" :model-value="(deviceDetal.candyGeneratorTm == null ? $t('device.noData') : deviceDetal.candyGeneratorTm + $t('device.degree'))" readonly />
  17. <van-field :label="$t('device.temperatureInCabinet')" :model-value="(deviceDetal.cabinetTm == null ? $t('device.noData') : deviceDetal.cabinetTm + $t('device.degree'))" readonly />
  18. <van-field :label="$t('device.humidityInCabinet')" :model-value="(deviceDetal.cabinetHd == null? $t('device.noData') : deviceDetal.cabinetHd + $t('device.humidity'))" readonly />
  19. <van-field :label="$t('device.outsideTm')" :model-value="(deviceDetal.outsideTm == null ? $t('device.noData') : deviceDetal.outsideTm + $t('device.degree'))" readonly />
  20. <van-field :label="$t('device.outsidehd')" :model-value="(deviceDetal.outsideHd == null? $t('device.noData') : deviceDetal.outsideHd + $t('device.humidity'))" readonly />
  21. </div>
  22. <div class="paramsList" v-for="(item, key) in paramsList" :key="key">
  23. <van-field v-model="item.val" v-if="item.name != 'M502' && item.name != 'M506'" name="phone" type="tel"
  24. :label="paramName[key]">
  25. <template #button>
  26. <van-button size="small" type="primary" class="updataButton" @click="updateParams(item)">{{
  27. $t('device.submitUpdates') }}</van-button>
  28. </template>
  29. </van-field>
  30. <div class="flex-row" v-else>
  31. <span class="txt3 o-pl-15 o-mtb-18">{{ paramName[key] }}
  32. </span>
  33. <van-switch class="o-mt-8" :model-value="checked[key]" @update:model-value="onUpdateValue(item, key)">
  34. </van-switch>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. import { onMounted, ref } from "vue";
  42. import sHeader from "@/components/SimpleHeader";
  43. import { useRoute } from "vue-router";
  44. import { getDeviceDetal, getParameters, updateParameters } from "@/service/device";
  45. import { Toast, Dialog } from "vant";
  46. import { useI18n } from 'vue-i18n';
  47. import { styleUrl } from "../../../common/js/utils";
  48. export default {
  49. components: { sHeader },
  50. setup() {
  51. const { t } = useI18n();
  52. const route = useRoute();
  53. const deviceId = route.query.deviceId;
  54. const deviceDetal = ref([]);
  55. const paramsTitle = ref("");
  56. const paramsList = ref([]);
  57. const comParams = ref([]);
  58. const paramName = ref([]);
  59. const checked = ref([]);
  60. const type = ref("");
  61. // 初始化页面获取列表
  62. onMounted(async () => {
  63. // 加载样式
  64. styleUrl('paramsSet');
  65. type.value = route.query.type;
  66. if (route.query.type === "0") {
  67. paramsTitle.value = t('device.generalParameterConfiguration');
  68. }
  69. if (route.query.type === "1") {
  70. paramsTitle.value = t('device.advancedParameterConfiguration');
  71. }
  72. if (route.query.type === "2") {
  73. paramsTitle.value = t('device.debuggingParameterConfiguration');
  74. }
  75. if (route.query.type === "3") {
  76. paramsTitle.value = t('device.humidityParameterConfiguration');
  77. }
  78. getDeviceDetalFun();
  79. });
  80. // 获取设备列表数据
  81. const getDeviceDetalFun = async () => {
  82. const { data } = await getDeviceDetal({ id: deviceId });
  83. if (data.code === "00000") {
  84. deviceDetal.value = data.data;
  85. getParametersFun();
  86. } else {
  87. Toast.fail(data.message);
  88. }
  89. };
  90. // 获取参数列表
  91. const getParametersFun = async () => {
  92. paramsList.value = [];
  93. const params = {
  94. id: deviceId,
  95. status: route.query.type,
  96. clientId: deviceDetal.value.clientId,
  97. };
  98. const { data } = await getParameters(params);
  99. if (data.code) {
  100. paramsList.value = data.data;
  101. paramsList.value.forEach((paramItem) => {
  102. // console.log("paramItem:", paramItem);
  103. comParams.value.push(paramItem.name);
  104. paramName.value.push(t("paramNames." + paramItem.name));
  105. if (paramItem.val === '1') {
  106. checked.value.push(true);
  107. } else {
  108. checked.value.push(false);
  109. }
  110. })
  111. // console.log("checked:", checked.value);
  112. } else {
  113. Toast.fail(data.message);
  114. }
  115. };
  116. // 更新参数值
  117. const updateParams = async (item) => {
  118. const params = {
  119. id: deviceId,
  120. name: item.name,
  121. val: item.val,
  122. };
  123. const { data } = await updateParameters(params);
  124. if (data.code) {
  125. Toast.success(t('device.modificationSucceeded'));
  126. } else {
  127. Toast.fail(data.message);
  128. }
  129. }
  130. const onUpdateValue = async (item, key) => {
  131. console.log(item);
  132. const params = {
  133. id: deviceId,
  134. name: item.name,
  135. val: item.val === '0' ? '1' : '0',
  136. };
  137. Dialog.confirm({
  138. title: '提醒',
  139. message: '是否切换开关?',
  140. }).then(() => {
  141. checked.value[key] = !checked.value[key];
  142. const { data } = updateParameters(params);
  143. if (data.code) {
  144. Toast.success(t('device.modificationSucceeded'));
  145. } else {
  146. Toast.fail(data.message);
  147. }
  148. }).catch(() => {
  149. // on cancel
  150. });
  151. };
  152. return {
  153. deviceDetal,
  154. paramsTitle,
  155. paramsList,
  156. // getParamName,
  157. updateParams,
  158. paramName,
  159. checked,
  160. onUpdateValue,
  161. type,
  162. };
  163. },
  164. };
  165. </script>
  166. <style lang="less" scoped>
  167. @import "../../../common/style/common";
  168. .paramsValue {
  169. margin: 0 40px;
  170. }
  171. </style>