wangzhibo
2026-10-08 220e4fab27b7f419b3e89e2f2d28ae789aac09d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<template>
  <el-dialog :title="title" :visible="dialogVisible" width="600px" class="address-book-dialog" @close="handleClose">
    <el-form ref="addressBookForm" :model="form" :rules="rules" label-width="100px" size="medium">
      <el-form-item :label="$t('addressBookDialog.name')" prop="name">
        <el-input v-model="form.name" :placeholder="$t('addressBookDialog.namePlaceholder')" clearable></el-input>
      </el-form-item>
      <el-form-item :label="$t('addressBookDialog.description')" prop="description">
        <el-input v-model="form.description" :placeholder="$t('addressBookDialog.descriptionPlaceholder')"
          type="textarea" :rows="4" maxlength="300" show-word-limit></el-input>
      </el-form-item>
      <el-form-item :label="$t('addressBookDialog.status')" prop="status">
        <el-switch
          v-model="form.status"
          :active-value="1"
          :inactive-value="0"
          active-color="#13ce66"
          inactive-color="#909399"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleClose">{{ $t('addressBookDialog.cancel') }}</el-button>
      <el-button type="primary" @click="handleSubmit">{{ $t('addressBookDialog.confirm') }}</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
export default {
  name: "AddressBookDialog",
  props: {
    title: {
      type: String,
      default: ""
    },
    visible: {
      type: Boolean,
      default: false
    },
    form: {
      type: Object,
      default: () => ({
        id: null,
        name: "",
        description: "",
        status: 1
      })
    }
  },
  data() {
    return {
      dialogVisible: this.visible,
      rules: {
        name: [
          {
            required: true,
            message: this.$t("addressBookDialog.nameRequired"),
            trigger: "blur"
          },
          {
            min: 1,
            max: 50,
            message: this.$t("addressBookDialog.nameLength"),
            trigger: "blur"
          },
          {
            pattern: /^[一-龥a-zA-Z0-9\s-_]+$/,
            message: this.$t("addressBookDialog.namePattern"),
            trigger: "blur"
          }
        ],
        description: [
          {
            required: true,
            message: this.$t("addressBookDialog.descriptionRequired"),
            trigger: "blur"
          },
          {
            max: 300,
            message: this.$t("addressBookDialog.descriptionLength"),
            trigger: "blur"
          }
        ]
      }
    };
  },
  watch: {
    visible(val) {
      this.dialogVisible = val;
      if (val) {
        if (this.$refs.addressBookForm) {
          this.$refs.addressBookForm.clearValidate();
        }
      }
    }
  },
  methods: {
    handleClose() {
      if (this.$refs.addressBookForm) {
        this.$refs.addressBookForm.clearValidate();
      }
      this.dialogVisible = false;
      this.$emit("update:visible", false);
    },
    handleSubmit() {
      this.$refs.addressBookForm.validate(valid => {
        if (valid) {
          this.$emit("submit", {
            ...this.form
          });
        }
      });
    }
  }
};
</script>
 
<style lang="scss" scoped>
.address-book-dialog {
  ::v-deep .el-dialog {
    border-radius: 20px;
    overflow: hidden;
  }
 
  ::v-deep .el-dialog__body {
    padding: 20px 30px;
  }
 
  ::v-deep .el-form-item {
    margin-bottom: 20px;
  }
 
  ::v-deep .el-form-item__label {
    font-weight: 500;
    color: #34495e;
    font-size: 14px;
  }
 
  ::v-deep .el-input {
    .el-input__inner {
      height: 36px;
      font-size: 14px;
      border-radius: 4px;
      border: 1px solid #ddd;
      transition: all 0.3s ease;
 
      &:focus {
        border-color: #5f70f3;
        box-shadow: 0 0 0 2px rgba(95, 112, 243, 0.2);
      }
    }
  }
 
  ::v-deep .el-textarea {
    .el-textarea__inner {
      font-size: 14px;
      border-radius: 4px;
      border: 1px solid #ddd;
      transition: all 0.3s ease;
 
      &:focus {
        border-color: #5f70f3;
        box-shadow: 0 0 0 2px rgba(95, 112, 243, 0.2);
      }
    }
  }
 
  .dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }
}
</style>