facilityData.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <!--
  2. author:luoaoxuan
  3. subject:设施环境通用组件
  4. -->
  5. <template>
  6. <div class="ficily-data">
  7. <el-row type="flex">
  8. <el-col style="margin:0 0 5px 0">
  9. <div class="button">
  10. <el-button v-if="!isCul" type="danger" size="mini" icon="ibps-icon-close" @click="goRemove">删除</el-button>
  11. <el-button v-if="!isCul" type="success" size="mini" icon="ibps-icon-plus" @click="goAdd">添加</el-button>
  12. </div>
  13. </el-col>
  14. </el-row>
  15. <el-row type="flex">
  16. <el-col>
  17. <el-table :data="forms" border @selection-change="handleSelectionChange">
  18. <el-table-column
  19. width="50"
  20. type="selection"
  21. />
  22. <el-table-column label="参数名称" prop="label">
  23. <template slot-scope="{row}">
  24. <el-input v-if="!readonly && !isCul" v-model="row.label" size="mini" placeholder="请输入" />
  25. <span v-else>{{ row.label|| '/' }}</span>
  26. </template>
  27. </el-table-column>
  28. <el-table-column label="参数单位" prop="unit">
  29. <template slot-scope="{row}">
  30. <el-autocomplete
  31. v-if="!readonly"
  32. v-model="row.unit"
  33. class="inline-input"
  34. :fetch-suggestions="querySearch"
  35. placeholder="请输入内容"
  36. size="mini"
  37. />
  38. <span v-else>{{ row.unit || '/' }}</span>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="参数范围限值" prop="range">
  42. <template slot-scope="{row}">
  43. <NumberRange v-model="row.range" :precision="2" :disabled="readonly || isCul" /></template>
  44. </el-table-column>
  45. <el-table-column label="参数修正值" prop="fixValue">
  46. <template slot-scope="{row}">
  47. <el-input v-if="!readonly && !isCul" v-model="row.fixValue" size="mini" placeholder="请输入" type="number" />
  48. <span v-else>{{ row.fixValue|| '/' }}</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column v-if="isCul" label="参数值" prop="value">
  52. <template slot-scope="{row}">
  53. <el-input v-if="!readonly" v-model="row.value" size="mini" placeholder="请输入" type="number" :readonly="readonly" />
  54. <span v-else>{{ row.value || '/' }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column v-if="isCul" label="最终值" prop="result">
  58. <template slot-scope="{row}">
  59. <span>{{ row.result || '/' }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column v-if="isCul" label="状态" prop="status">
  63. <template slot-scope="{row}">
  64. <span>{{ row.status || '/' }}</span>
  65. </template>
  66. </el-table-column>
  67. </el-table>
  68. </el-col>
  69. </el-row>
  70. </div>
  71. </template>
  72. <script>
  73. import NumberRange from '@/views/component/xcomponent/numberRange.vue'
  74. export default {
  75. components: {
  76. NumberRange
  77. },
  78. props: {
  79. formData: {
  80. type: Object,
  81. default: () => {}
  82. },
  83. readonly: {
  84. type: Boolean,
  85. default: false
  86. },
  87. isCul: {
  88. type: Boolean,
  89. default: true
  90. }
  91. },
  92. data () {
  93. return {
  94. isFirst: true,
  95. forms: [],
  96. multipleSelection: []
  97. }
  98. },
  99. computed: {
  100. },
  101. watch: {
  102. formData: {
  103. handler (val) {
  104. // console.log('formData', val)
  105. if (val.lieBiaoShuJu) {
  106. if (!this.isCul) {
  107. this.forms = JSON.parse(val.lieBiaoShuJu)
  108. } else {
  109. if (this.isFirst) {
  110. this.forms = JSON.parse(val.lieBiaoShuJu)
  111. this.isFirst = false
  112. }
  113. }
  114. }
  115. this.culXiuZheng()
  116. },
  117. deep: true,
  118. immediate: true
  119. },
  120. forms: {
  121. handler (val) {
  122. // console.log('forms', val)
  123. this.culXiuZheng()
  124. this.$emit('change-data', 'lieBiaoShuJu', JSON.stringify(val))
  125. },
  126. deep: true
  127. }
  128. },
  129. mounted () {
  130. // console.log('mounted', this.formData)
  131. },
  132. methods: {
  133. // 默认单位
  134. querySearch (queryString, cb) {
  135. const units = [{ value: '℃' }, { value: '%' }, { value: 'Pa' }]
  136. // 调用 callback 返回建议列表的数据
  137. cb(units)
  138. },
  139. // 计算状态
  140. getStatus (range, result) {
  141. let [min, max] = range
  142. if (min === null || min === '' || typeof min === 'undefined') min = Number.MIN_VALUE
  143. if (max === null || max === '' || typeof max === 'undefined') max = Number.MAX_VALUE
  144. // console.log(min, max, result)
  145. if (+min === 0 && +max === 0) {
  146. return '正常'
  147. }
  148. if (+result <= +max && +result >= +min) {
  149. return '正常'
  150. }
  151. return '失控'
  152. },
  153. // 计算修正值
  154. culXiuZheng () {
  155. if (!this.isCul) return
  156. if (this.readonly) return
  157. this.forms.forEach(item => {
  158. if (item.value) {
  159. if (item.fixValue) {
  160. item.result = (+item.fixValue + +item.value).toFixed(2)
  161. } else {
  162. item.result = (+item.value).toFixed(2)
  163. }
  164. item.status = this.getStatus(item.range, item.result)
  165. } else {
  166. item.result = ''
  167. item.status = ''
  168. }
  169. })
  170. },
  171. formatData (val) {
  172. return JSON.stringify(val)
  173. },
  174. goAdd () {
  175. if (this.forms.length >= 10) {
  176. return this.$message({
  177. message: '超过最大限制!',
  178. type: 'warning'
  179. })
  180. }
  181. this.forms.push({
  182. label: '',
  183. range: [],
  184. fixValue: '',
  185. value: '',
  186. result: '',
  187. status: '',
  188. unit: ''
  189. })
  190. },
  191. goRemove () {
  192. this.forms = this.forms.filter(item => !this.multipleSelection.includes(item))
  193. },
  194. handleSelectionChange (val) {
  195. this.multipleSelection = val
  196. }
  197. }
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. .ficily-data{
  202. margin-bottom: 20px;
  203. .button{
  204. display: flex;
  205. flex-direction: row-reverse;
  206. .el-button{
  207. margin-left: 5px;
  208. }
  209. }
  210. }
  211. </style>