environmentRange.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. judgeShow: 0,
  95. };
  96. },
  97. watch: {
  98. visible: {
  99. handler: function (val, oldVal) {
  100. this.dialogVisible = this.visible;
  101. },
  102. immediate: true,
  103. },
  104. environmentInfo: {
  105. deep: true,
  106. handler() {
  107. this.process();
  108. },
  109. }
  110. },
  111. created() {
  112. this.loadFormData();
  113. },
  114. methods: {
  115. clickBtn() {
  116. this.dialogVisible = true;
  117. },
  118. process() {
  119. const result = this.packageObj();
  120. this.$emit("change-data", "environmentRange", result);
  121. },
  122. handleActionEvent({ key }) {
  123. switch (key) {
  124. case "confirm":
  125. this.handleConfirm();
  126. break;
  127. case "cancel":
  128. this.closeDialog();
  129. break;
  130. default:
  131. break;
  132. }
  133. },
  134. packageObj() {
  135. const obj = {
  136. temperature: {
  137. min: this.environmentInfo.temperatureMin, // || this.environmentInfo.minTemperature,
  138. max: this.environmentInfo.temperatureMax // || this.environmentInfo.maxTemperature,
  139. },
  140. humidity: {
  141. min: this.environmentInfo.humidityMin, // || this.environmentInfo.minHumidity,
  142. max: this.environmentInfo.humidityMax // || this.environmentInfo.maxHumidity,
  143. },
  144. };
  145. return JSON.stringify(obj);
  146. },
  147. resolveObj(jsonString = "") {
  148. const data = jsonString.trim() !== "" && JSON.parse(jsonString);
  149. this.environmentInfo.temperatureMin = data?.temperature?.min // || this.environmentInfo.temperatureMin;
  150. this.environmentInfo.temperatureMax = data?.temperature?.max // || this.environmentInfo.temperatureMax;
  151. this.environmentInfo.humidityMin = data?.humidity?.min // || this.environmentInfo.humidityMin;
  152. this.environmentInfo.humidityMax = data?.humidity?.max // || this.environmentInfo.humidityMax;
  153. },
  154. // 关闭当前窗口
  155. closeDialog() {
  156. this.$emit("close", false);
  157. },
  158. loadFormData() {
  159. setTimeout(() => {
  160. const environmentRange = this.formData.environmentRange
  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: 2%;
  172. margin-left: -120px;
  173. }
  174. </style>