text: "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _xeUtils=_interopRequireDefault(require("xe-utils/methods/xe-utils")),_conf=_interopRequireDefault(require("../../conf")),_tools=require("../../tools");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),e}var Rule=function(){function t(e){_classCallCheck(this,t),Object.assign(this,{$options:e,required:e.required,min:e.min,max:e.max,type:e.type,pattern:e.pattern,validator:e.validator,trigger:e.trigger,maxWidth:e.maxWidth})}return _createClass(t,[{key:"message",get:function(){return _tools.UtilTools.getFuncText(this.$options.message)}}]),t}(),_default={methods:{_fullValidate:function(e,t){return this.beginValidate(e,t,!0)},_validate:function(e,t){return this.beginValidate(e,t)},handleValidError:function(e){var t=this;!1===this.validOpts.autoPos?this.emitEvent("valid-error",e):this.handleActived(e,{type:"valid-error",trigger:"call"}).then(function(){return t.showValidTooltip(e)})},beginValidate:function(e,u,c){var d=this,f={},h=!0,t=this.editRules,g=this.afterFullData,p=this.treeConfig,r=this.treeOpts,i=g;e&&(_xeUtils.default.isFunction(e)?u=e:i=_xeUtils.default.isArray(e)?e:[e]);var l=[];if(this.lastCallTime=Date.now(),this.clearValidate(),t){var n=this.getColumns(),o=function(o){var e=[];n.forEach(function(n){_xeUtils.default.has(t,n.property)&&e.push(new Promise(function(i,l){d.validCellRules("all",o,n).then(i).catch(function(e){var t,r=(_defineProperty(t={rule:e.rule,rules:e.rules},"".concat(p?"$":"","rowIndex"),d.getRowIndex(o)),_defineProperty(t,"row",o),_defineProperty(t,"columnIndex",d.getColumnIndex(n)),_defineProperty(t,"column",n),_defineProperty(t,"$table",d),t);return c?(f[n.property]||(f[n.property]=[]),f[n.property].push(r),i()):l(r)})}))}),l.push(Promise.all(e))};return p?_xeUtils.default.eachTree(i,o,r):i.forEach(o),Promise.all(l).then(function(){var e=Object.keys(f);if(e.length)return Promise.reject(f[e[0]][0]);u&&("obsolete"===_conf.default.validArgs?u(h):u())}).catch(function(a){var s=c?f:_defineProperty({},a.column.property,a);return new Promise(function(e,t){function r(){h=!1,u?("obsolete"===_conf.default.validArgs?u(h,s):u(s),e()):t(s)}function i(){a.cell=_tools.DomTools.getCell(d,a),d.handleValidError(a),r()}var l=a.row,n=g.indexOf(l),o=0<n?g[n-1]:l;_tools.DomTools.toView(d.$el),!1===d.validOpts.autoPos?r():p?d.scrollToTreeRow(o).then(i):d.scrollToRow(o).then(i)})})}return u&&("obsolete"===_conf.default.validArgs?u(h):u()),Promise.resolve()},hasCellRules:function(t,e,r){var i=this.editRules,l=r.property;if(l&&i){var n=_xeUtils.default.get(i,l);return n&&_xeUtils.default.find(n,function(e){return"all"===t||!e.trigger||t===e.trigger})}return!1},validCellRules:function(l,n,o,e){var a=this,t=this.editRules,r=o.property,s=[],u=[];if(r&&t){var c=_xeUtils.default.get(t,r);if(c){var d=_xeUtils.default.isUndefined(e)?_xeUtils.default.get(n,r):e;c.forEach(function(i){u.push(new Promise(function(r){if("all"!==l&&i.trigger&&l!==i.trigger)r();else if(_xeUtils.default.isFunction(i.validator))"obsolete"===_conf.default.validArgs?i.validator(i,d,function(e){if(_xeUtils.default.isError(e)){var t={type:"custom",trigger:i.trigger,message:e.message,rule:new Rule(i)};s.push(new Rule(t))}return r()},{rule:i,rules:c,row:n,column:o,rowIndex:a.getRowIndex(n),columnIndex:a.getColumnIndex(o),$table:a}):Promise.resolve(i.validator({cellValue:d,rule:i,rules:c,row:n,rowIndex:a.getRowIndex(n),column:o,columnIndex:a.getColumnIndex(o),$table:a})).catch(function(e){s.push(new Rule({type:"custom",trigger:i.trigger,message:e?e.message:i.message,rule:new Rule(i)}))}).then(r);else{var e="number"===i.type,t=e?_xeUtils.default.toNumber(d):_xeUtils.default.getSize(d);null==d||""===d?i.required&&s.push(new Rule(i)):(e&&isNaN(d)||!isNaN(i.min)&&t<parseFloat(i.min)||!isNaN(i.max)&&t>parseFloat(i.max)||i.pattern&&!(i.pattern.test?i.pattern:new RegExp(i.pattern)).test(d))&&s.push(new Rule(i)),r()}}))})}}return Promise.all(u).then(function(){if(s.length){var e={rules:s,rule:s[0]};return Promise.reject(e)}})},_clearValidate:function(){var e=this.$refs.validTip;return Object.assign(this.validStore,{visible:!1,row:null,column:null,content:"",rule:null}),e&&e.visible&&e.close(),this.$nextTick()},triggerValidate:function(i){var l=this,e=this.editConfig,t=this.editStore,r=this.editRules,n=this.validStore,o=t.actived;if(o.row&&r){var a=o.args,s=a.row,u=a.column,c=a.cell;if(this.hasCellRules(i,s,u))return this.validCellRules(i,s,u).then(function(){"row"===e.mode&&n.visible&&n.row===s&&n.column===u&&l.clearValidate()}).catch(function(e){var t=e.rule;if(t.trigger&&i!==t.trigger)return Promise.resolve();var r={rule:t,row:s,column:u,cell:c};return l.showValidTooltip(r),Promise.reject(r)})}return Promise.resolve()},showValidTooltip:function(e){var t=this,r=this.$refs,i=this.height,l=this.tableData,n=this.validOpts,o=e.rule,a=e.row,s=e.column,u=e.cell,c=r.validTip,d=o.message;this.$nextTick(function(){Object.assign(t.validStore,{row:a,column:s,rule:o,content:d,visible:!0}),c&&("tooltip"===n.message||"default"===n.message&&!i&&l.length<2)&&c.toVisible(u,d),t.emitEvent("valid-error",e)})}}};exports.default=_default;