groupEdit.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div id="groupEdit" v-loading="loading">
  3. <el-dialog
  4. title="分组编辑"
  5. width="40%"
  6. top="2rem"
  7. :append-to-body="true"
  8. :close-on-click-modal="false"
  9. :visible.sync="showDialog"
  10. :destroy-on-close="true"
  11. @close="close()"
  12. >
  13. <div id="shared" style="margin-top: 1rem;margin-right: 100px;">
  14. <el-form ref="form" :model="group" label-width="140px" >
  15. <el-form-item label="节点编号" prop="id" >
  16. <el-input v-model="group.deviceId" placeholder="请输入编码">
  17. <el-button slot="append" @click="buildDeviceIdCode(group.deviceId)">生成</el-button>
  18. </el-input>
  19. </el-form-item>
  20. <el-form-item label="节点名称" prop="name">
  21. <el-input v-model="group.name" clearable></el-input>
  22. </el-form-item>
  23. <el-form-item>
  24. <div style="float: right;">
  25. <el-button type="primary" @click="onSubmit" >确认</el-button>
  26. <el-button @click="close">取消</el-button>
  27. </div>
  28. </el-form-item>
  29. </el-form>
  30. </div>
  31. </el-dialog>
  32. <channelCode ref="channelCode"></channelCode>
  33. </div>
  34. </template>
  35. <script>
  36. import channelCode from "./channelCode.vue";
  37. export default {
  38. name: "groupEdit",
  39. components: {channelCode},
  40. computed: {},
  41. props: [],
  42. created() {},
  43. data() {
  44. return {
  45. submitCallback: null,
  46. showDialog: false,
  47. loading: false,
  48. level: 0,
  49. group: {
  50. id: 0,
  51. deviceId: "",
  52. name: "",
  53. parentDeviceId: "",
  54. businessGroup: "",
  55. platformId: "",
  56. },
  57. };
  58. },
  59. methods: {
  60. openDialog: function (group, callback) {
  61. console.log(group)
  62. if (group) {
  63. this.group = group;
  64. }
  65. this.showDialog = true;
  66. this.submitCallback = callback;
  67. },
  68. onSubmit: function () {
  69. this.$axios({
  70. method:"post",
  71. url: this.group.id ? '/api/group/update':'/api/group/add',
  72. data: this.group
  73. }).then((res)=> {
  74. if (res.data.code === 0) {
  75. this.$message.success("保存成功")
  76. if (this.submitCallback)this.submitCallback(this.group)
  77. }else {
  78. this.$message({
  79. showClose: true,
  80. message: res.data.msg,
  81. type: "error",
  82. });
  83. }
  84. this.close();
  85. })
  86. .catch((error)=> {
  87. this.$message({
  88. showClose: true,
  89. message: error,
  90. type: "error",
  91. });
  92. });
  93. },
  94. buildDeviceIdCode: function (deviceId){
  95. console.log(this.group)
  96. let lockContent = this.group.businessGroup ? "216":"215"
  97. this.$refs.channelCode.openDialog(code=>{
  98. this.group.deviceId = code;
  99. }, deviceId, 5 , lockContent);
  100. },
  101. close: function () {
  102. this.showDialog = false;
  103. console.log(this.group)
  104. },
  105. },
  106. };
  107. </script>