addSiteCom.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <transition name="dialog-fade">
  3. <el-dialog
  4. v-if="showDialog"
  5. :title="dialogTitle"
  6. class="add-group-com"
  7. :visible.sync="showDialog"
  8. width="400px"
  9. @close="closeDialog(0)"
  10. >
  11. <el-form
  12. ref="formInfo"
  13. :model="formInfo"
  14. class="demo-form-inline"
  15. label-width="100px"
  16. :rules="rules"
  17. >
  18. <el-form-item label="站点名称:" prop="watchName">
  19. <el-input v-model="formInfo.watchName"></el-input>
  20. </el-form-item>
  21. <el-form-item label="站点编号:" prop="watchName">
  22. <el-input v-model="formInfo.watchName"></el-input>
  23. </el-form-item>
  24. <el-form-item label="选择模板:" prop="region">
  25. <el-select v-model="formInfo.region" placeholder="请选择">
  26. <el-option label="选择模板1" value="1"></el-option>
  27. <el-option label="选择模板2" value="2"></el-option>
  28. </el-select>
  29. </el-form-item>
  30. <div style="text-align: right">
  31. <el-button type="primary" @click="submitForm('formInfo')"
  32. >保存</el-button
  33. >
  34. </div>
  35. </el-form>
  36. </el-dialog>
  37. </transition>
  38. </template>
  39. <script>
  40. export default {
  41. name: "AddSiteCom",
  42. props: {
  43. dialogTitle: {
  44. type: String,
  45. default: "新建站点",
  46. },
  47. itemInfo: {
  48. type: Object,
  49. default: function () {
  50. return {};
  51. },
  52. },
  53. },
  54. data() {
  55. return {
  56. checked: true,
  57. showDialog: false,
  58. formInfo: JSON.parse(JSON.stringify(this.itemInfo)),
  59. rules: {
  60. watchName: [
  61. // required 是否为必填项, trigger:表单验证的触发时机,失去焦点进行验证
  62. { required: true, message: "请输入站点名称", trigger: "blur" },
  63. {
  64. min: 3,
  65. max: 6,
  66. message: "用户名长度在 3 到 6 个字符",
  67. trigger: "blur",
  68. },
  69. ],
  70. },
  71. };
  72. },
  73. methods: {
  74. roleValid(rule, value, callback) {
  75. if (value.length === 0) {
  76. callback(new Error("不能为空"));
  77. } else {
  78. callback();
  79. }
  80. },
  81. // 保存操作
  82. submitForm(formName) {
  83. const that = this;
  84. const params = Object.assign(that.formInfo, {});
  85. that.$refs[formName].validate((valid) => {
  86. if (valid) {
  87. // 走保存请求
  88. that.$message({
  89. message: "操作成功!",
  90. type: "success",
  91. });
  92. that.closeDialog(1);
  93. } else {
  94. return false;
  95. }
  96. });
  97. },
  98. // 关闭弹框
  99. closeDialog(flag) {
  100. this.$refs["formInfo"].resetFields();
  101. this.showDialog = false;
  102. this.$emit("closeDialog", flag);
  103. },
  104. },
  105. };
  106. </script>
  107. <style scoped lang="scss">
  108. </style>