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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
| "use strict";
|
| var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
| exports.__esModule = true;
| exports.default = void 0;
|
| var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
| var _utils = require("../utils");
|
| var _mobile = require("../utils/validate/mobile");
|
| var _cell = _interopRequireDefault(require("../cell"));
|
| var _field = _interopRequireDefault(require("../field"));
|
| var _button = _interopRequireDefault(require("../button"));
|
| var _dialog = _interopRequireDefault(require("../dialog"));
|
| var _switch = _interopRequireDefault(require("../switch"));
|
| // Utils
| // Components
| var _createNamespace = (0, _utils.createNamespace)('contact-edit'),
| createComponent = _createNamespace[0],
| bem = _createNamespace[1],
| t = _createNamespace[2];
|
| var defaultContact = {
| tel: '',
| name: ''
| };
|
| var _default2 = createComponent({
| props: {
| isEdit: Boolean,
| isSaving: Boolean,
| isDeleting: Boolean,
| showSetDefault: Boolean,
| setDefaultLabel: String,
| contactInfo: {
| type: Object,
| default: function _default() {
| return (0, _extends2.default)({}, defaultContact);
| }
| },
| telValidator: {
| type: Function,
| default: _mobile.isMobile
| }
| },
| data: function data() {
| return {
| data: (0, _extends2.default)({}, defaultContact, this.contactInfo),
| errorInfo: {
| name: '',
| tel: ''
| }
| };
| },
| watch: {
| contactInfo: function contactInfo(val) {
| this.data = (0, _extends2.default)({}, defaultContact, val);
| }
| },
| methods: {
| onFocus: function onFocus(key) {
| this.errorInfo[key] = '';
| },
| getErrorMessageByKey: function getErrorMessageByKey(key) {
| var value = this.data[key].trim();
|
| switch (key) {
| case 'name':
| return value ? '' : t('nameInvalid');
|
| case 'tel':
| return this.telValidator(value) ? '' : t('telInvalid');
| }
| },
| onSave: function onSave() {
| var _this = this;
|
| var isValid = ['name', 'tel'].every(function (item) {
| var msg = _this.getErrorMessageByKey(item);
|
| if (msg) {
| _this.errorInfo[item] = msg;
| }
|
| return !msg;
| });
|
| if (isValid && !this.isSaving) {
| this.$emit('save', this.data);
| }
| },
| onDelete: function onDelete() {
| var _this2 = this;
|
| _dialog.default.confirm({
| title: t('confirmDelete')
| }).then(function () {
| _this2.$emit('delete', _this2.data);
| });
| }
| },
| render: function render() {
| var _this3 = this;
|
| var h = arguments[0];
| var data = this.data,
| errorInfo = this.errorInfo;
|
| var onFocus = function onFocus(name) {
| return function () {
| return _this3.onFocus(name);
| };
| };
|
| return h("div", {
| "class": bem()
| }, [h("div", {
| "class": bem('fields')
| }, [h(_field.default, {
| "attrs": {
| "clearable": true,
| "maxlength": "30",
| "label": t('name'),
| "placeholder": t('nameEmpty'),
| "errorMessage": errorInfo.name
| },
| "on": {
| "focus": onFocus('name')
| },
| "model": {
| value: data.name,
| callback: function callback($$v) {
| _this3.$set(data, "name", $$v);
| }
| }
| }), h(_field.default, {
| "attrs": {
| "clearable": true,
| "type": "tel",
| "label": t('tel'),
| "placeholder": t('telEmpty'),
| "errorMessage": errorInfo.tel
| },
| "on": {
| "focus": onFocus('tel')
| },
| "model": {
| value: data.tel,
| callback: function callback($$v) {
| _this3.$set(data, "tel", $$v);
| }
| }
| })]), this.showSetDefault && h(_cell.default, {
| "attrs": {
| "title": this.setDefaultLabel,
| "border": false
| },
| "class": bem('switch-cell')
| }, [h(_switch.default, {
| "attrs": {
| "size": 24
| },
| "slot": "right-icon",
| "on": {
| "change": function change(event) {
| _this3.$emit('change-default', event);
| }
| },
| "model": {
| value: data.isDefault,
| callback: function callback($$v) {
| _this3.$set(data, "isDefault", $$v);
| }
| }
| })]), h("div", {
| "class": bem('buttons')
| }, [h(_button.default, {
| "attrs": {
| "block": true,
| "round": true,
| "type": "danger",
| "text": t('save'),
| "loading": this.isSaving
| },
| "on": {
| "click": this.onSave
| }
| }), this.isEdit && h(_button.default, {
| "attrs": {
| "block": true,
| "round": true,
| "text": t('delete'),
| "loading": this.isDeleting
| },
| "on": {
| "click": this.onDelete
| }
| })])]);
| }
| });
|
| exports.default = _default2;
|
|