query.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div class="ioc-query-form">
  3. <a-form layout="inline" :form="formData">
  4. <a-form-item label="单位名称:" class="formItem" v-if="visible.company">
  5. <a-select default-value="0" style="width: 200px" v-model="formData.company">
  6. <a-select-option value="0"> 全部 </a-select-option>
  7. <a-select-option v-for="item in companyData" :key="item.value" :value="item.value"> {{ item.label }} </a-select-option>
  8. </a-select>
  9. </a-form-item>
  10. <a-form-item label="部门名称:" class="formItem" v-if="visible.dept">
  11. <a-select default-value="0" style="width: 200px" v-model="formData.dept">
  12. <a-select-option value="0"> 全部 </a-select-option>
  13. <a-select-option v-for="item in deptData" :key="item.value" :value="item.value"> {{ item.label }} </a-select-option>
  14. </a-select>
  15. </a-form-item>
  16. <a-form-item label="楼层:" class="formItem" v-if="visible.floor">
  17. <a-select default-value="0" style="width: 120px" v-model="formData.floor">
  18. <a-select-option value="0"> 全部 </a-select-option>
  19. <a-select-option v-for="item in floorData" :key="item.value" :value="item.value"> {{ item.label }} </a-select-option>
  20. </a-select>
  21. </a-form-item>
  22. <a-form-item label="能源类型:" class="formItem" v-if="visible.energy">
  23. <a-select default-value="0" style="width: 200px" v-model="formData.energy">
  24. <a-select-option value="0"> 全部 </a-select-option>
  25. <a-select-option v-for="item in energyData" :key="item.value" :value="item.value"> {{ item.label }} </a-select-option>
  26. </a-select>
  27. </a-form-item>
  28. <a-form-item label="时间范围:" class="formItem" v-if="visible.time">
  29. <timeRange :time-range.sync="formData.timeRange" ref="timeRange" style="width: 250px"></timeRange>
  30. </a-form-item>
  31. <slot name="extraItem"></slot>
  32. <a-form-item class="formItem" style="float: right;margin-right: 3%">
  33. <a-space size="middle">
  34. <a-button type="primary" size="small" style="width: 70px;background-color: #B3B3B3;border: none;" @click="formReset">重置</a-button>
  35. <a-button type="primary" size="small" style="width: 70px;" @click="search(formData)">查询</a-button>
  36. </a-space>
  37. </a-form-item>
  38. </a-form>
  39. </div>
  40. </template>
  41. <script>
  42. import timeRange from "@/components/common/timeRange.vue";
  43. export default {
  44. components: {
  45. timeRange,
  46. },
  47. props: {
  48. queryData: Object,
  49. show: Array,
  50. reset: Function,
  51. search: Function,
  52. },
  53. emits: ['update:queryData'],
  54. setup(props, context) {
  55. const methods = {
  56. updateFormData(obj) {
  57. context.emit('update:queryData', obj)
  58. }
  59. }
  60. return methods
  61. },
  62. watch: {
  63. formData: {
  64. handler: function (val) {
  65. this.updateFormData(val)
  66. },
  67. deep: true,
  68. }
  69. },
  70. data() {
  71. return {
  72. oriQueryData: {},
  73. visible: {
  74. company: false,
  75. floor: false,
  76. dept: false,
  77. energy: false,
  78. time: false
  79. },
  80. formData: {},
  81. // 单位数据
  82. companyData: [
  83. {
  84. label: '中讯邮电咨询设计院',
  85. value: '1'
  86. },
  87. {
  88. label: '北京电信规划院',
  89. value: '2'
  90. },
  91. {
  92. label: '上分',
  93. value: '3'
  94. }
  95. ],
  96. // 楼层数据
  97. floorData: [
  98. {
  99. label: '1F',
  100. value: '1'
  101. },{
  102. label: '2F',
  103. value: '2'
  104. },{
  105. label: '3F',
  106. value: '3'
  107. },{
  108. label: '4F',
  109. value: '4'
  110. },{
  111. label: '5F',
  112. value: '5'
  113. }
  114. ],
  115. // 部门数据
  116. deptData: [
  117. {
  118. label: '市场部',
  119. value: '1'
  120. },
  121. {
  122. label: '研发部',
  123. value: '2'
  124. }
  125. ],
  126. // 能源类型
  127. energyData: [
  128. {
  129. label: '用电',
  130. value: 'electric'
  131. },
  132. {
  133. label: '用水',
  134. value: 'water'
  135. },
  136. {
  137. label: '用热',
  138. value: 'hot'
  139. },
  140. {
  141. label: '用冷',
  142. value: 'cold'
  143. },
  144. {
  145. label: '光伏',
  146. value: 'pv'
  147. }
  148. ]
  149. };
  150. },
  151. created() {
  152. if (this.show) {
  153. for (let i = 0; i < this.show.length; i++) {
  154. this.visible[this.show[i]] = true
  155. }
  156. }
  157. },
  158. mounted() {
  159. if (this.queryData) {
  160. this.formData = JSON.parse(JSON.stringify(this.queryData))
  161. this.oriQueryData = JSON.parse(JSON.stringify(this.queryData));
  162. }
  163. },
  164. methods: {
  165. formReset() {
  166. this.formData = JSON.parse(JSON.stringify(this.oriQueryData));
  167. this.search();
  168. }
  169. }
  170. };
  171. </script>
  172. <style lang="less" scoped>
  173. .formItem {
  174. margin: 0px 15px;
  175. }
  176. </style>