mountForm.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div>
  3. <el-form :model="mountform" :ref="_ref" :rules="mountRules" label-width="120px">
  4. <el-form-item label="挂载区域:">
  5. <el-cascader
  6. :options="areaTree"
  7. :props="{ checkStrictly: true, children: 'childs', label: 'nodeName' ,value:'id'}"
  8. @change="change"
  9. clearable
  10. placeholder="请选择挂载区域"
  11. >
  12. <template slot-scope="{ node, data }">
  13. <span>{{ data.nodeName }}</span>
  14. </template>
  15. </el-cascader>
  16. </el-form-item>
  17. <el-form-item label="配置信息:" prop="meta">
  18. <el-input
  19. v-model="mountform.meta"
  20. placeholder="请输入JSON格式的配置信息"
  21. type="textarea"
  22. :rows="3"
  23. :autosize="{ minRows: 4 }"
  24. ></el-input>
  25. </el-form-item>
  26. </el-form>
  27. <div slot="footer">
  28. <el-button @click="cancel">取 消</el-button>
  29. <el-button type="primary" @click="confirm(_ref)">确认挂载</el-button>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. /* 用在的地方 分别是 设备信息 摄像头管理*/
  35. import { mapActions } from "vuex";
  36. // 区域树 code
  37. const arearCode = "area-info";
  38. // 挂载设备 表单验证规则
  39. const mountRules = {
  40. moumtArea: [
  41. {
  42. type: "array",
  43. required: true,
  44. message: "请选择挂载区域",
  45. trigger: "change"
  46. }
  47. ],
  48. meta: [{ required: true, message: "请输入配置信息", trigger: "blur" }]
  49. };
  50. export default {
  51. data() {
  52. return {
  53. id: "",
  54. mountform: {
  55. areaId: null,
  56. areaName: null,
  57. meta: null
  58. },
  59. areaTree: [],
  60. mountRules
  61. };
  62. },
  63. props: {
  64. rowData: {},
  65. _ref: String
  66. },
  67. created() {
  68. this.getTreeByCode(arearCode);
  69. },
  70. methods: {
  71. ...mapActions(["fetch"]),
  72. // 通过code获取树
  73. getTreeByCode(code) {
  74. this.fetch({
  75. api: "/publics/treenode/getTreeByCode",
  76. method: "POST",
  77. data: { code }, //目前只有一个组织,其他参数调整钟
  78. success: res => {
  79. this.id = res.id;
  80. this.getAreaTree(res.id);
  81. },
  82. fail: err => {
  83. console.log(err);
  84. if (err.errCode == "request_not_authorize") {
  85. this.$message({
  86. message: "请重新登录",
  87. type: "warning"
  88. });
  89. }
  90. }
  91. });
  92. },
  93. // 请求 区域树
  94. getAreaTree(parentId) {
  95. this.fetch({
  96. api: "/publics/treenode/listNodeByParent",
  97. method: "POST",
  98. data: {
  99. parentId,
  100. hasSub: true
  101. },
  102. success: res => {
  103. this.areaTree = res;
  104. },
  105. fail: err => {
  106. if (err.errMsg) this.$message.error(err.errMsg);
  107. else this.$message.error("服务器发生异常");
  108. }
  109. });
  110. },
  111. // 选择器改变
  112. change(value) {
  113. // this.$emit('change')
  114. console.log(value);
  115. let areaId = value[value.length - 1];
  116. this.mountform.areaId = areaId
  117. let areaTree = this.areaTree;
  118. this.mountform.areaName = findName(areaId);
  119. function findName(id) {
  120. let nodeName = undefined;
  121. loopFind(areaTree);
  122. function loopFind(tree) {
  123. tree.forEach(item => {
  124. if (item.id == id) {
  125. nodeName = item.nodeName;
  126. } else if (item.childs) {
  127. loopFind(item.childs);
  128. } else {
  129. return;
  130. }
  131. });
  132. }
  133. return nodeName;
  134. }
  135. },
  136. //确认
  137. confirm(formName) {
  138. // this.$emit('submitMountForm', formName)
  139. if (this.mountform.areaId) this.mountRules.moumtArea = null;
  140. this.$refs[formName].validate(valid => {
  141. if (valid) {
  142. // 请求 挂载设备
  143. this.getMountDevice(this.mountform);
  144. } else {
  145. return false;
  146. }
  147. });
  148. },
  149. // 取消
  150. cancel() {
  151. this.$emit("cancel");
  152. },
  153. // 请求 挂载设备
  154. getMountDevice(data) {
  155. data.id = this.rowData.id
  156. data.categoryId = this.rowData.categoryId
  157. this.fetch({
  158. api: "/device/device/mount",
  159. method: "POST",
  160. data,
  161. success: res => {
  162. this.$message.success("挂载设备成功!");
  163. // this.isShowDialogMount = false;
  164. // this.$parent.$props.visible = false
  165. this.$emit('cancel')
  166. },
  167. fail: err => {
  168. if (err.errMsg) this.$message.error(err.errMsg);
  169. else this.$message.error("服务器发生异常");
  170. }
  171. });
  172. }
  173. }
  174. };
  175. </script>