environmentRange.vue 5.0 KB

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