catalogEdit.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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'],
  46. created() {},
  47. data() {
  48. let checkId = (rule, value, callback) => {
  49. console.log("checkId")
  50. console.log(this.treeType)
  51. console.log(rule)
  52. console.log(value)
  53. console.log(value.length)
  54. console.log(this.level)
  55. if (!value) {
  56. return callback(new Error('编号不能为空'));
  57. }
  58. if (this.treeType === "BusinessGroup" && value.length !== 20) {
  59. return callback(new Error('编号必须由20位数字组成'));
  60. }
  61. if (this.treeType === "CivilCode" && value.length <= 8 && value.length%2 !== 0) {
  62. return callback(new Error('行政区划必须是八位以下的偶数个数字组成'));
  63. }
  64. if (this.treeType === "BusinessGroup") {
  65. let catalogType = value.substring(10, 13);
  66. console.log(catalogType)
  67. // 216 为虚拟组织 215 为业务分组;目录第一级必须为业务分组, 业务分组下为虚拟组织,虚拟组织下可以有其他虚拟组织
  68. if (this.level === 1 && catalogType !== "215") {
  69. return callback(new Error('业务分组模式下第一层目录的编号11到13位必须为215'));
  70. }
  71. if (this.level > 1 && catalogType !== "216") {
  72. return callback(new Error('业务分组模式下第一层以下目录的编号11到13位必须为216'));
  73. }
  74. }
  75. callback();
  76. }
  77. return {
  78. submitCallback: null,
  79. showDialog: false,
  80. isLoging: false,
  81. isEdit: false,
  82. treeType: null,
  83. level: 0,
  84. form: {
  85. id: null,
  86. name: null,
  87. platformId: null,
  88. parentId: null,
  89. },
  90. rules: {
  91. name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  92. id: [{ required: true, trigger: "blur",validator: checkId }]
  93. },
  94. };
  95. },
  96. methods: {
  97. openDialog: function (isEdit, id, name, parentId, treeType, level, callback) {
  98. console.log("parentId: " + parentId)
  99. console.log(this.form)
  100. this.isEdit = isEdit;
  101. this.form.id = id;
  102. this.form.name = name;
  103. this.form.platformId = this.platformId;
  104. this.form.parentId = parentId;
  105. this.showDialog = true;
  106. this.submitCallback = callback;
  107. this.treeType = treeType;
  108. this.level = level;
  109. },
  110. onSubmit: function () {
  111. console.log("onSubmit");
  112. console.log(this.form);
  113. this.$axios({
  114. method:"post",
  115. url:`./api/platform/catalog/${!this.isEdit? "add":"edit"}`,
  116. data: this.form
  117. }).then((res)=> {
  118. if (res.data.code === 0) {
  119. if (this.submitCallback)this.submitCallback(this.form)
  120. }else {
  121. this.$message({
  122. showClose: true,
  123. message: res.data.msg,
  124. type: "error",
  125. });
  126. }
  127. this.close();
  128. })
  129. .catch((error)=> {
  130. console.log(error);
  131. });
  132. },
  133. close: function () {
  134. this.isEdit = false;
  135. this.form.id = null;
  136. this.form.name = null;
  137. this.form.platformId = null;
  138. this.form.parentId = null;
  139. this.callback = null;
  140. this.showDialog = false;
  141. console.log(this.form)
  142. },
  143. },
  144. };
  145. </script>