catalogEdit.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div id="catalogEdit" v-loading="isLoging">
  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" :rules="rules" :model="form" label-width="140px" >
  15. <!-- <el-form-item >-->
  16. <!-- 建议的类型:-->
  17. <!-- <br/>-->
  18. <!-- &emsp;&emsp;行政区划(可选2位/4位/6位/8位/10位数字,例如:130432,表示河北省邯郸市广平县)-->
  19. <!-- <br/>-->
  20. <!-- &emsp;&emsp;业务分组(第11、12、13位215,例如:34020000002150000001)-->
  21. <!-- <br/>-->
  22. <!-- &emsp;&emsp;虚拟组织(第11、12、13位216,例如:34020000002160000001)-->
  23. <!-- </el-form-item>-->
  24. <el-form-item label="节点编号" prop="id" >
  25. <el-input v-model="form.id" :disabled="isEdit" clearable></el-input>
  26. </el-form-item>
  27. <el-form-item label="节点名称" prop="name">
  28. <el-input v-model="form.name" clearable></el-input>
  29. </el-form-item>
  30. <el-form-item>
  31. <div style="float: right;">
  32. <el-button type="primary" @click="onSubmit" >确认</el-button>
  33. <el-button @click="close">取消</el-button>
  34. </div>
  35. </el-form-item>
  36. </el-form>
  37. </div>
  38. </el-dialog>
  39. </div>
  40. </template>
  41. <script>
  42. export default {
  43. name: "catalogEdit",
  44. computed: {},
  45. props: ['platformId', 'platformDeviceId'],
  46. created() {},
  47. data() {
  48. let checkId = (rule, value, callback) => {
  49. console.log("checkId")
  50. console.log(rule)
  51. console.log(value)
  52. console.log(value.length)
  53. console.log(this.level)
  54. if (!value) {
  55. return callback(new Error('编号不能为空'));
  56. }
  57. if (value.trim().length <= 8) {
  58. if (value.trim().length%2 !== 0) {
  59. return callback(new Error('行政区划编号必须为2/4/6/8位'));
  60. }
  61. if (this.form.parentId !== this.platformDeviceId && this.form.parentId.length >= value.trim().length) {
  62. return callback(new Error('行政区划编号长度应该每次两位递增'));
  63. }
  64. }else {
  65. if (value.trim().length !== 20) {
  66. return callback(new Error('编号必须为2/4/6/8位的行政区划或20位的虚拟组织/业务分组'));
  67. }
  68. let catalogType = value.substring(10, 13);
  69. console.log(catalogType)
  70. if (catalogType !== "215" && catalogType !== "216") {
  71. return callback(new Error('编号错误,业务分组11-13位为215,虚拟组织11-13位为216'));
  72. }
  73. if (catalogType === "216") {
  74. if (this.form.parentId !== this.platformDeviceId){
  75. if (this.form.parentId.length <= 8) {
  76. return callback(new Error('编号错误,建立虚拟组织前必须先建立业务分组(11-13位为215)'));
  77. }
  78. }
  79. }
  80. if (catalogType === "215") {
  81. if (this.form.parentId.length === "215") {
  82. return callback(new Error('编号错误,业务分组下只能建立虚拟组织(11-13位为216)'));
  83. }
  84. }
  85. }
  86. callback();
  87. }
  88. return {
  89. submitCallback: null,
  90. showDialog: false,
  91. isLoging: false,
  92. isEdit: false,
  93. level: 0,
  94. form: {
  95. id: null,
  96. name: null,
  97. platformId: null,
  98. parentId: null,
  99. },
  100. rules: {
  101. name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  102. id: [{ required: true, trigger: "blur",validator: checkId }]
  103. },
  104. };
  105. },
  106. methods: {
  107. openDialog: function (isEdit, id, name, parentId, level, callback) {
  108. console.log("parentId: " + parentId)
  109. console.log(this.form)
  110. this.isEdit = isEdit;
  111. this.form.id = id;
  112. this.form.name = name;
  113. this.form.platformId = this.platformId;
  114. this.form.parentId = parentId;
  115. this.showDialog = true;
  116. this.submitCallback = callback;
  117. this.level = level;
  118. },
  119. onSubmit: function () {
  120. console.log("onSubmit");
  121. console.log(this.form);
  122. this.$axios({
  123. method:"post",
  124. url:`/api/platform/catalog/${!this.isEdit? "add":"edit"}`,
  125. data: this.form
  126. }).then((res)=> {
  127. if (res.data.code === 0) {
  128. if (this.submitCallback)this.submitCallback(this.form)
  129. }else {
  130. this.$message({
  131. showClose: true,
  132. message: res.data.msg,
  133. type: "error",
  134. });
  135. }
  136. this.close();
  137. })
  138. .catch((error)=> {
  139. console.log(error);
  140. });
  141. },
  142. close: function () {
  143. this.isEdit = false;
  144. this.form.id = null;
  145. this.form.name = null;
  146. this.form.platformId = null;
  147. this.form.parentId = null;
  148. this.callback = null;
  149. this.showDialog = false;
  150. console.log(this.form)
  151. },
  152. },
  153. };
  154. </script>