environmentRangePlus.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div class="maintenanceCycle">
  3. <el-row>
  4. <el-col>
  5. <el-form-item label="温度范围限值">
  6. <el-input-number v-model="environmentInfo.temperatureMin" :min="environmentInfo.minTemperature"
  7. :max="environmentInfo.temperatureMax" controls-position="right" :precision="0"
  8. :step="1"></el-input-number>
  9. <span> 至 </span>
  10. <el-input-number v-model="environmentInfo.temperatureMax" :min="environmentInfo.temperatureMin"
  11. :max="environmentInfo.maxTemperature" controls-position="right" :precision="0"
  12. :step="1"></el-input-number>
  13. <span> (℃)</span>
  14. </el-form-item>
  15. </el-col>
  16. <el-col>
  17. <el-form-item label="湿度范围限值">
  18. <el-input-number v-model="environmentInfo.humidityMin" :min="environmentInfo.minHumidity"
  19. :max="environmentInfo.humidityMax" controls-position="right" :precision="0"
  20. :step="1"></el-input-number>
  21. <span> 至 </span>
  22. <el-input-number v-model="environmentInfo.humidityMax" :min="environmentInfo.humidityMin"
  23. :max="environmentInfo.maxHumidity" controls-position="right" :precision="0"
  24. :step="1"></el-input-number>
  25. <span> (%)</span>
  26. </el-form-item></el-col>
  27. </el-row>
  28. </div>
  29. </template>
  30. <script>
  31. export default {
  32. props: {
  33. visible: {
  34. type: Boolean,
  35. default: false,
  36. },
  37. title: {
  38. type: String,
  39. },
  40. customClass: {
  41. type: String,
  42. },
  43. width: {
  44. type: String,
  45. default: "80%",
  46. },
  47. top: {
  48. type: String,
  49. default: "10%",
  50. },
  51. editFromType: {
  52. type: String,
  53. default: "add",
  54. },
  55. dynamicParams: {
  56. type: Object,
  57. },
  58. templateKey: {
  59. type: String,
  60. default: "",
  61. },
  62. // 所有字段数据,(包含主主子表)
  63. formData: [Object, Array],
  64. field: {
  65. type: Object,
  66. required: true
  67. },
  68. // 子表行数
  69. // row: [String, Number],
  70. params: {
  71. type: Object,
  72. },
  73. },
  74. data() {
  75. return {
  76. environmentInfo: {
  77. // 温度默认大小值
  78. temperatureMin: 0,
  79. temperatureMax: 0,
  80. // 温度范围大小值
  81. minTemperature: -100,
  82. maxTemperature: 100,
  83. // 湿度默认大小值
  84. humidityMin: 0,
  85. humidityMax: 0,
  86. // 湿度范围大小值
  87. minHumidity: 0,
  88. maxHumidity: 100,
  89. },
  90. dialogVisible: true, //this.visible,
  91. // qmonthDateOptions: monthLunarGeneration(4), // 貌似是监听函数变化
  92. toolbars: [{ key: "confirm", label: "确定" }, { key: "cancel" }],
  93. toolbarsConsult: [{ key: "cancel" }],
  94. };
  95. },
  96. watch: {
  97. visible: {
  98. handler: function (val, oldVal) {
  99. this.dialogVisible = this.visible;
  100. },
  101. immediate: true,
  102. },
  103. environmentInfo: {
  104. deep: true,
  105. handler() {
  106. this.process();
  107. },
  108. }
  109. },
  110. created() {
  111. this.loadFormData();
  112. },
  113. methods: {
  114. clickBtn() {
  115. this.dialogVisible = true;
  116. },
  117. process() {
  118. const result = this.packageObj();
  119. this.$emit("change-data", "defaultEnvironmen", result);
  120. },
  121. handleActionEvent({ key }) {
  122. switch (key) {
  123. case "confirm":
  124. this.handleConfirm();
  125. break;
  126. case "cancel":
  127. this.closeDialog();
  128. break;
  129. default:
  130. break;
  131. }
  132. },
  133. packageObj() {
  134. const obj = {
  135. temperature: {
  136. min: this.environmentInfo.temperatureMin, // || this.environmentInfo.minTemperature,
  137. max: this.environmentInfo.temperatureMax // || this.environmentInfo.maxTemperature,
  138. },
  139. humidity: {
  140. min: this.environmentInfo.humidityMin, // || this.environmentInfo.minHumidity,
  141. max: this.environmentInfo.humidityMax // || this.environmentInfo.maxHumidity,
  142. },
  143. };
  144. return JSON.stringify(obj);
  145. },
  146. resolveObj(jsonString = "") {
  147. const data = jsonString.trim() !== "" && JSON.parse(jsonString);
  148. this.environmentInfo.temperatureMin = data?.temperature?.min // || this.environmentInfo.temperatureMin;
  149. this.environmentInfo.temperatureMax = data?.temperature?.max // || this.environmentInfo.temperatureMax;
  150. this.environmentInfo.humidityMin = data?.humidity?.min // || this.environmentInfo.humidityMin;
  151. this.environmentInfo.humidityMax = data?.humidity?.max // || this.environmentInfo.humidityMax;
  152. console.log(data,this.environmentInfo)
  153. },
  154. // 关闭当前窗口
  155. closeDialog() {
  156. this.$emit("close", false);
  157. },
  158. loadFormData() {
  159. setTimeout(() => {
  160. const environmentRange = this.formData.defaultEnvironmen
  161. this.resolveObj(environmentRange)
  162. }, 500);
  163. },
  164. },
  165. };
  166. </script>
  167. <style lang="scss" scoped>
  168. .maintenanceCycle {
  169. display: flex;
  170. align-items: center;
  171. margin-left: -120px;
  172. }
  173. </style>