| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- "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 _button = _interopRequireDefault(require("../button"));
- var _field = _interopRequireDefault(require("../field"));
- var _toast = _interopRequireDefault(require("../toast"));
- var _dialog = _interopRequireDefault(require("../dialog"));
- var _mobile = require("../utils/validate/mobile");
- var _use = (0, _utils.use)('contact-edit'),
- sfc = _use[0],
- bem = _use[1],
- t = _use[2];
- var defaultContact = {
- tel: '',
- name: ''
- };
- var _default2 = sfc({
- props: {
- isEdit: Boolean,
- isSaving: Boolean,
- isDeleting: Boolean,
- 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: false,
- tel: false
- }
- };
- },
- watch: {
- contactInfo: function contactInfo(val) {
- this.data = (0, _extends2["default"])({}, defaultContact, val);
- }
- },
- methods: {
- onFocus: function onFocus(key) {
- this.errorInfo[key] = false;
- },
- getErrorMessageByKey: function getErrorMessageByKey(key) {
- var value = this.data[key].trim();
- switch (key) {
- case 'name':
- return value ? '' : t('nameEmpty');
- 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] = true;
- (0, _toast["default"])(msg);
- }
- return !msg;
- });
- if (isValid && !this.isSaving) {
- this.$emit('save', this.data);
- }
- },
- onDelete: function onDelete() {
- var _this2 = this;
- _dialog["default"].confirm({
- message: t('confirmDelete')
- }).then(function () {
- _this2.$emit('delete', _this2.data);
- });
- }
- },
- render: function render(h) {
- var _this3 = this;
- var data = this.data,
- errorInfo = this.errorInfo;
- var onFocus = function onFocus(name) {
- return function () {
- return _this3.onFocus(name);
- };
- };
- return h("div", {
- "class": bem()
- }, [h(_field["default"], {
- "attrs": {
- "clearable": true,
- "maxlength": "30",
- "label": t('name'),
- "placeholder": t('nameEmpty'),
- "error": errorInfo.name
- },
- "on": {
- "focus": onFocus('name')
- },
- "model": {
- value: data.name,
- callback: function callback($$v) {
- data.name = $$v;
- }
- }
- }), h(_field["default"], {
- "attrs": {
- "clearable": true,
- "type": "tel",
- "label": t('tel'),
- "placeholder": t('telEmpty'),
- "error": errorInfo.tel
- },
- "on": {
- "focus": onFocus('tel')
- },
- "model": {
- value: data.tel,
- callback: function callback($$v) {
- data.tel = $$v;
- }
- }
- }), h("div", {
- "class": bem('buttons')
- }, [h(_button["default"], {
- "attrs": {
- "block": true,
- "type": "danger",
- "text": t('save'),
- "loading": this.isSaving
- },
- "on": {
- "click": this.onSave
- }
- }), this.isEdit && h(_button["default"], {
- "attrs": {
- "block": true,
- "text": t('delete'),
- "loading": this.isDeleting
- },
- "on": {
- "click": this.onDelete
- }
- })])]);
- }
- });
- exports["default"] = _default2;
|