dialog.edit.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div class="rule-type">
  3. <DialogCom
  4. :title="id ? '编辑报警控制器' : '新增报警控制器'"
  5. :visible.sync="isShow"
  6. @close="onHide"
  7. width="500px"
  8. >
  9. <div class="page-body">
  10. <el-form
  11. :model="formData"
  12. :rules="formDataRules"
  13. size="small"
  14. ref="form"
  15. label-position="right"
  16. label-width="130px"
  17. label-prefix=":"
  18. >
  19. <el-form-item label="所属机构" prop="orgId">
  20. <orgDropDown
  21. v-model="formData.orgId"
  22. placeholder="选择所属机构"
  23. @select="onOrgSelect"
  24. />
  25. </el-form-item>
  26. <el-form-item label="报警主机" prop="alarmHostId">
  27. <el-select
  28. label="报警主机"
  29. v-model="formData.alarmHostId"
  30. placeholder="请选择报警主机"
  31. clearable
  32. style="width: 330px"
  33. >
  34. <el-option
  35. v-for="host in alarmHostOptions"
  36. :key="host.id"
  37. :label="host.name"
  38. :value="host.id"
  39. />
  40. </el-select>
  41. </el-form-item>
  42. <el-form-item prop="name" label="报警控制器名称:">
  43. <el-input
  44. v-model="formData.name"
  45. :maxlength="50"
  46. name="name"
  47. placeholder="请输入报警控制器名称"
  48. clearable
  49. />
  50. </el-form-item>
  51. <el-form-item prop="type" label="24小时报警控制器:">
  52. <el-switch
  53. v-model="formData.allHour"
  54. :active-value="1"
  55. :inactive-value="0"
  56. >
  57. </el-switch>
  58. </el-form-item>
  59. </el-form>
  60. </div>
  61. <div slot="footer" class="dialog-footer">
  62. <el-button type="primary" @click="onSubmit">确定</el-button>
  63. <el-button @click="isShow = false">取消</el-button>
  64. </div>
  65. </DialogCom>
  66. </div>
  67. </template>
  68. <script>
  69. import { mapState, mapMutations, mapGetters } from "vuex";
  70. import * as api from "@/api/resumption/protection";
  71. import { listIdName } from "@/api/system/device";
  72. import orgDropDown from "../../../components/orgTree/orgDropDown.vue";
  73. export default {
  74. data() {
  75. return {
  76. id: null,
  77. isShow: false,
  78. formData: this.reset(),
  79. alarmHostOptions: [],
  80. // 机构树选项
  81. formDataRules: {
  82. orgId: [{ required: true, message: "请选择所属机构" }],
  83. name: [{ required: true, message: "请输入报警控制器名称" }],
  84. alarmHostId: [{ required: true, message: "请选择报警主机" }],
  85. },
  86. };
  87. },
  88. props: {},
  89. watch: {
  90. // "formData.orgId":{
  91. // handler(v){
  92. // console.info("formData.orgId",v)
  93. // }
  94. // }
  95. },
  96. computed: {
  97. ...mapGetters(["orgId"]),
  98. },
  99. methods: {
  100. ...mapMutations([]),
  101. reset() {
  102. return {
  103. id: null,
  104. orgId: null,
  105. orgPath: null,
  106. orgName: null,
  107. name: null,
  108. allHour: 0,
  109. alarmHostId: null,
  110. };
  111. },
  112. async refresh(id, other) {
  113. this.formData = id ? (await api.get(id)).data : this.reset(other);
  114. },
  115. async show(id, other = {}) {
  116. this.id = id;
  117. await this.refresh(id, other);
  118. this.isShow = true;
  119. },
  120. // 事件
  121. onHide() {
  122. this.$refs.form.resetFields();
  123. this.formData = this.reset();
  124. },
  125. onSubmit() {
  126. this.$refs.form.validate(async (isValidate) => {
  127. if (!isValidate) return;
  128. await api.update(this.formData);
  129. this.$emit("success");
  130. this.isShow = false;
  131. });
  132. },
  133. onOrgSelect(node) {
  134. // console.info(node)
  135. this.formData.orgPath = node.path;
  136. this.formData.orgName = node.shortName;
  137. listIdName({ orgId: node.id, deviceType: 1, assetType: 2 }).then((d) => {
  138. this.alarmHostOptions = d.data;
  139. if (!d.data.find((i) => i.id == this.formData.alarmHostId)) {
  140. this.formData.alarmHostId = null;
  141. }
  142. });
  143. },
  144. },
  145. created() {},
  146. mounted() {},
  147. components: { orgDropDown },
  148. };
  149. </script>
  150. <style lang="scss" scoped>
  151. .brand_info {
  152. .el-form {
  153. width: 600px;
  154. padding-top: 40px;
  155. }
  156. }
  157. </style>