text: "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _table=_interopRequireDefault(require("../../table")),_xeUtils=_interopRequireDefault(require("xe-utils/methods/xe-utils")),_conf=_interopRequireDefault(require("../../conf")),_vXETable=_interopRequireDefault(require("../../v-x-e-table")),_tools=require("../../tools");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _iterableToArray(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,o=new Array(t);r<t;r++)o[r]=e[r];return o}function ownKeys(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,o)}return r}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(r),!0).forEach(function(e){_defineProperty(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}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}var methods={},propKeys=Object.keys(_table.default.props);function getOffsetHeight(e){return e?e.offsetHeight:0}function renderDefaultForm(e,t){var r=t.$scopedSlots,o=t.proxyConfig,i=t.proxyOpts,n=t.formData,s=t.formConfig,a=t.formOpts;return r.form?r.form.call(t,{$grid:t},e):a.items&&a.items.length?(a.inited||(a.inited=!0,i&&i.beforeItem&&a.items.forEach(function(e){i.beforeItem.apply(t,[{$grid:t,item:e}])})),[e("vxe-form",{props:Object.assign({},a,{data:o&&i.form?n:s.data}),on:{submit:t.submitEvent,reset:t.resetEvent,"submit-invalid":t.submitInvalidEvent,"toggle-collapse":t.togglCollapseEvent},ref:"form"})]):[]}function getToolbarSlots(e){var t=e.$scopedSlots,r=e.toolbarOpts.slots,o=t.buttons,i=t.tools,n={};return r&&(o||(o=r.buttons),i||(i=r.tools),o&&t[o]&&(o=t[o]),i&&t[i]&&(i=t[i])),o&&(n.buttons=o),i&&(n.tools=i),n}function getPagerSlots(e){var t,r,o=e.$scopedSlots,i=e.pagerOpts.slots,n={};return i&&(t=i.left,r=i.right,t&&o[t]&&(t=o[t]),r&&o[r]&&(r=o[r])),t&&(n.left=t),r&&(n.right=r),n}Object.keys(_table.default.methods).forEach(function(t){methods[t]=function(){var e;return this.$refs.xTable&&(e=this.$refs.xTable)[t].apply(e,arguments)}});var _default2={name:"VxeGrid",props:_objectSpread(_objectSpread({},_table.default.props),{},{columns:Array,pagerConfig:[Boolean,Object],proxyConfig:Object,toolbar:[Boolean,Object],formConfig:[Boolean,Object],size:{type:String,default:function(){return _conf.default.grid.size||_conf.default.size}}}),provide:function(){return{$xegrid:this}},data:function(){return{isCloak:!1,tableLoading:!1,isZMax:!1,tableData:[],pendingRecords:[],filterData:[],formData:{},sortData:{},tZindex:0,tablePage:{total:0,pageSize:10,currentPage:1}}},computed:{vSize:function(){return this.size||this.$parent.size||this.$parent.vSize},isMsg:function(){return!1!==this.proxyOpts.message},proxyOpts:function(){return Object.assign({},_conf.default.grid.proxyConfig,this.proxyConfig)},pagerOpts:function(){return Object.assign({},_conf.default.grid.pagerConfig,this.pagerConfig)},formOpts:function(){return Object.assign({},_conf.default.grid.formConfig,this.formConfig)},toolbarOpts:function(){return Object.assign({},_conf.default.grid.toolbar,this.toolbar)},zoomOpts:function(){return Object.assign({},_conf.default.grid.zoomConfig,this.zoomConfig)},renderClass:function(){var e,t=this.vSize,r=this.isZMax;return["vxe-grid",(e={},_defineProperty(e,"size--".concat(t),t),_defineProperty(e,"t--animat",!!this.animat),_defineProperty(e,"is--maximize",r),_defineProperty(e,"is--loading",this.isCloak||this.loading||this.tableLoading),e)]},renderStyle:function(){return this.isZMax?{zIndex:this.tZindex}:null},tableExtendProps:function(){var t=this,r={};return propKeys.forEach(function(e){r[e]=t[e]}),r},tableProps:function(){var e=this.isZMax,t=this.seqConfig,r=this.pagerConfig,o=this.loading,i=this.isCloak,n=this.editConfig,s=this.proxyConfig,a=this.proxyOpts,l=this.tableExtendProps,c=this.tableLoading,d=this.tablePage,f=this.tableData,u=Object.assign({},l);return e&&(l.maxHeight?u.maxHeight="auto":u.height="auto"),s&&(Object.assign(u,{loading:i||o||c,data:f,rowClassName:this.handleRowClassName}),(a.seq||a.index)&&r&&(u.seqConfig=Object.assign({},t,{startIndex:(d.currentPage-1)*d.pageSize}))),n&&(u.editConfig=Object.assign({},n,{activeMethod:this.handleActiveMethod})),u},pagerProps:function(){return Object.assign({},this.pagerOpts,this.proxyConfig?this.tablePage:{})}},watch:{columns:function(e){var t=this;this.$nextTick(function(){return t.loadColumn(e)})},proxyConfig:function(){this.initProxy()},pagerConfig:function(){this.initPages()}},created:function(){var e=this,t=this.customs,r=this.data,o=this.formOpts,i=this.proxyConfig,n=this.proxyOpts,s=n.props;t&&_tools.UtilTools.warn("vxe.error.removeProp",["customs"]),i&&(r||n.form&&o.data)&&console.warn("[vxe-grid] There is a conflict between the props proxy-config and data."),n.index&&_tools.UtilTools.warn("vxe.error.delProp",["proxy-config.index","proxy-config.seq"]),s&&s.data&&_tools.UtilTools.warn("vxe.error.delProp",["proxy-config.props.data","proxy-config.props.result"]),this.cloak&&(this.isCloak=!0,setTimeout(function(){e.isCloak=!1},_tools.DomTools.browse?500:300)),_tools.GlobalEvent.on(this,"keydown",this.handleGlobalKeydownEvent)},mounted:function(){this.columns&&this.columns.length&&this.loadColumn(this.columns),this.initPages(),this.initProxy()},destroyed:function(){_tools.GlobalEvent.off(this,"keydown")},render:function(e){var t=this.$scopedSlots;return e("div",{class:this.renderClass,style:this.renderStyle},[t.form||this.formConfig?e("div",{ref:"xForm",class:"vxe-grid--form-wrapper"},t.form?t.form.call(this,{$grid:this},e):renderDefaultForm(e,this)):null,t.toolbar||this.toolbar?e("div",{ref:"xToolbar",class:"vxe-grid--toolbar-wrapper"},t.toolbar?t.toolbar.call(this,{$grid:this},e):[e("vxe-toolbar",{props:this.toolbarOpts,scopedSlots:getToolbarSlots(this)})]):null,t.top?e("div",{ref:"xTop",class:"vxe-grid--top-wrapper"},t.top.call(this,{$grid:this},e)):null,e("vxe-table",{props:this.tableProps,on:this.getTableOns(),scopedSlots:t,ref:"xTable"},this.$slots.default),t.bottom?e("div",{ref:"xBottom",class:"vxe-grid--bottom-wrapper"},t.bottom.call(this,{$grid:this},e)):null,t.pager||this.pagerConfig?e("div",{ref:"xPager",class:"vxe-grid--pager-wrapper"},t.pager?t.pager.call(this,{$grid:this},e):[e("vxe-pager",{props:this.pagerProps,on:{"page-change":this.pageChangeEvent},scopedSlots:getPagerSlots(this)})]):null])},methods:_objectSpread(_objectSpread({},methods),{},{getParentHeight:function(){return(this.isZMax?_tools.DomTools.getDomNode().visibleHeight:this.$el.parentNode.clientHeight)-this.getExcludeHeight()},getExcludeHeight:function(){var e=this.$refs,t=this.$el,r=e.xForm,o=e.xToolbar,i=e.xTop,n=e.xBottom,s=e.xPager,a=0,l=0;if(t){var c=getComputedStyle(t);a=_xeUtils.default.toNumber(c.paddingTop),l=_xeUtils.default.toNumber(c.paddingBottom)}return a+l+getOffsetHeight(r)+getOffsetHeight(o)+getOffsetHeight(i)+getOffsetHeight(n)+getOffsetHeight(s)},handleRowClassName:function(t){var e=this.rowClassName,r=[];return this.pendingRecords.some(function(e){return e===t.row})&&r.push("row--pending"),r.concat(e?e(t):[])},handleActiveMethod:function(e){var t=this.editConfig.activeMethod;return-1===this.pendingRecords.indexOf(e.row)&&(!t||t(e))},loadColumn:function(e){var o=this.$scopedSlots;_xeUtils.default.eachTree(e,function(e){e.slots&&_xeUtils.default.each(e.slots,function(e,t,r){_xeUtils.default.isFunction(e)||(o[e]?r[t]=o[e]:(r[t]=null,_tools.UtilTools.error("vxe.error.notSlot",[e])))})}),this.$refs.xTable.loadColumn(e)},reloadColumn:function(e){return this.clearAll(),this.loadColumn(e)},getTableOns:function(){var i=this,e=this.$listeners,t=this.proxyConfig,r=this.proxyOpts,n={};return _xeUtils.default.each(e,function(e,o){n[o]=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];i.$emit.apply(i,[o].concat(t))}}),t&&(r.sort&&(n["sort-change"]=this.sortChangeEvent),r.filter&&(n["filter-change"]=this.filterChangeEvent)),n},initPages:function(){this.pagerConfig&&this.pagerOpts.pageSize&&(this.tablePage.pageSize=this.pagerOpts.pageSize)},initProxy:function(){var e=this,t=this.proxyInited,r=this.proxyConfig,o=this.proxyOpts,i=this.formConfig,n=this.formOpts;if(r&&(t||!1===o.autoLoad||(this.proxyInited=!0,this.$nextTick(function(){return e.commitProxy("reload")})),i&&o.form&&n.items)){var s={};n.items.forEach(function(e){var t=e.field,r=e.itemRender;t&&(s[t]=r&&!_xeUtils.default.isUndefined(r.defaultValue)?r.defaultValue:void 0)}),this.formData=s}},handleGlobalKeydownEvent:function(e){27===e.keyCode&&this.isZMax&&!1!==this.zoomOpts.escRestore&&this.triggerZoomEvent(e)},commitProxy:function(o){for(var i=this,e=arguments.length,n=new Array(1<e?e-1:0),t=1;t<e;t++)n[t-1]=arguments[t];var s,r=this.$refs,a=this.toolbar,l=this.toolbarOpts,c=this.proxyOpts,d=this.tablePage,f=this.pagerConfig,u=this.sortData,g=this.filterData,h=this.formData,p=this.isMsg,m=c.beforeQuery,b=c.afterQuery,v=c.beforeDelete,x=c.afterDelete,y=c.beforeSave,_=c.afterSave,O=c.ajax,C=void 0===O?{}:O,P=c.props,$=void 0===P?{}:P,T=r.xTable;if(_xeUtils.default.isString(o)){var w=a?_xeUtils.default.findTree(l.buttons,function(e){return e.code===o},{children:"dropdowns"}):null;s=w?w.item:null}else o=(s=o).code;var S=s?s.params:null;switch(o){case"insert":this.insert();break;case"insert_actived":this.insert().then(function(e){var t=e.row;return i.setActiveRow(t)});break;case"mark_cancel":this.triggerPendingEvent(o);break;case"remove":case"remove_selection":this.handleDeleteRow(o,"vxe.grid.removeSelectRecord",function(){return i.removeCheckboxRow()});break;case"import":this.importData(S);break;case"open_import":this.openImport(S);break;case"export":this.exportData(S);break;case"open_export":this.openExport(S);break;case"reset_custom":this.resetColumn(!0);break;case"reload":case"query":var E=C.query;if(E){var R={code:o,button:s,$grid:this,sort:u,filters:g,form:h,options:E};if(f&&(R.page=d),"reload"===o){var j=T.sortOpts.defaultSort,D={};f&&(d.currentPage=1),j&&(D={property:j.field,order:j.order}),this.sortData=R.sort=D,this.filterData=R.filters=[],this.pendingRecords=[],this.clearAll()}var k=[R].concat(n);return this.tableLoading=!0,Promise.resolve((m||E).apply(this,k)).catch(function(e){return e}).then(function(e){i.tableLoading=!1,e?f?(d.total=_xeUtils.default.get(e,$.total||"page.total")||0,i.tableData=_xeUtils.default.get(e,$.result||$.data||"result")||[]):i.tableData=($.list?_xeUtils.default.get(e,$.list):e)||[]:i.tableData=[],b&&b.apply(void 0,_toConsumableArray(k))})}_tools.UtilTools.error("vxe.error.notFunc",["query"]);break;case"delete_selection":case"delete":this.handleDeleteRow(o,"vxe.grid.deleteSelectRecord",function(){var e=C.delete;if(e){var t=i.getCheckboxRecords(),r=[{$grid:i,code:o,button:s,body:{removeRecords:t},options:e}].concat(n);if(t.length)return i.tableLoading=!0,Promise.resolve((v||e).apply(i,r)).then(function(){i.tableLoading=!1,i.pendingRecords=i.pendingRecords.filter(function(e){return-1===t.indexOf(e)}),p&&_vXETable.default.modal.message({message:_conf.default.i18n("vxe.grid.delSuccess"),status:"success"}),x?x.apply(void 0,_toConsumableArray(r)):i.commitProxy("query")}).catch(function(){i.tableLoading=!1,p&&_vXETable.default.modal.message({id:o,message:_conf.default.i18n("vxe.grid.operError"),status:"error"})});p&&_vXETable.default.modal.message({id:o,message:_conf.default.i18n("vxe.grid.selectOneRecord"),status:"warning"})}else _tools.UtilTools.error("vxe.error.notFunc",[o])});break;case"save":var z=C.save;if(z){var U=Object.assign({pendingRecords:this.pendingRecords},this.getRecordset()),A=U.insertRecords,M=U.removeRecords,Z=U.updateRecords,q=U.pendingRecords,I=[{$grid:this,code:o,button:s,body:U,options:z}].concat(n);return A.length&&(U.pendingRecords=q.filter(function(e){return-1===A.indexOf(e)})),q.length&&(U.insertRecords=A.filter(function(e){return-1===q.indexOf(e)})),this.validate(U.insertRecords.concat(Z)).then(function(){if(U.insertRecords.length||M.length||Z.length||U.pendingRecords.length)return i.tableLoading=!0,Promise.resolve((y||z).apply(i,I)).then(function(){i.tableLoading=!1,i.pendingRecords=[],p&&_vXETable.default.modal.message({message:_conf.default.i18n("vxe.grid.saveSuccess"),status:"success"}),_?_.apply(void 0,_toConsumableArray(I)):i.commitProxy("query")}).catch(function(){i.tableLoading=!1,p&&_vXETable.default.modal.message({id:o,message:_conf.default.i18n("vxe.grid.operError"),status:"error"})});p&&_vXETable.default.modal.message({id:o,message:_conf.default.i18n("vxe.grid.dataUnchanged"),status:"info"})}).catch(function(e){return e})}_tools.UtilTools.error("vxe.error.notFunc",[o]);break;default:var L=_vXETable.default.commands.get(o);L&&L.apply(this,[{code:o,button:s,$grid:this,$table:T}].concat(n))}return this.$nextTick()},handleDeleteRow:function(e,t,r){var o=this.getCheckboxRecords();this.isMsg?o.length?_vXETable.default.modal.confirm(_conf.default.i18n(t)).then(function(e){"confirm"===e&&r()}):_vXETable.default.modal.message({id:e,message:_conf.default.i18n("vxe.grid.selectOneRecord"),status:"warning"}):o.length&&r()},getFormItems:function(e){var t=this.formConfig,r=t&&t.items?t.items:[];return arguments.length?r[e]:r},getPendingRecords:function(){return this.pendingRecords},triggerToolbarBtnEvent:function(e,t){this.commitProxy(e,t),this.$emit("toolbar-button-click",{code:e.code,button:e,$grid:this,$event:t},t)},triggerPendingEvent:function(e){var r=this.pendingRecords,t=this.isMsg,o=this.getCheckboxRecords();if(o.length){var i=[],n=[];o.forEach(function(t){r.some(function(e){return t===e})?n.push(t):i.push(t)}),n.length?this.pendingRecords=r.filter(function(e){return-1===n.indexOf(e)}).concat(i):i.length&&(this.pendingRecords=r.concat(i)),this.clearCheckboxRow()}else t&&_vXETable.default.modal.message({id:e,message:_conf.default.i18n("vxe.grid.selectOneRecord"),status:"warning"})},pageChangeEvent:function(e){var t=this.proxyConfig,r=this.tablePage,o=e.currentPage,i=e.pageSize;r.currentPage=o,r.pageSize=i,"current-change"===e.type?this.$listeners["current-page-change"]&&(_tools.UtilTools.warn("vxe.error.delEvent",["current-page-change","page-change"]),this.$emit("current-page-change",o)):this.$listeners["page-size-change"]&&(_tools.UtilTools.warn("vxe.error.delEvent",["page-size-change","page-change"]),this.$emit("page-size-change",i)),this.$emit("page-change",Object.assign({$grid:this},e)),t&&this.commitProxy("query")},sortChangeEvent:function(e){var t=this.proxyConfig,r=this.remoteSort,o=e.$table,i=e.column,n=_xeUtils.default.isBoolean(i.remoteSort)?i.remoteSort:o.sortOpts.remote||r,s=e.order?e.property:null;n&&(this.sortData=s?{property:s,field:s,prop:s,order:e.order,sortBy:e.sortBy}:{},t&&this.commitProxy("query")),this.$emit("sort-change",Object.assign({$grid:this},e))},filterChangeEvent:function(e){var t=this.remoteFilter,r=e.$table,o=e.filters;(r.filterOpts.remote||t)&&(this.filterData=o,this.commitProxy("query")),this.$emit("filter-change",Object.assign({$grid:this},e))},submitEvent:function(e,t){this.proxyConfig&&this.commitProxy("reload"),this.$emit("form-submit",Object.assign({$grid:this},e),t)},resetEvent:function(e,t){this.proxyConfig&&this.commitProxy("reload"),this.$emit("form-reset",Object.assign({$grid:this},e),t)},submitInvalidEvent:function(e,t){this.$emit("form-submit-invalid",Object.assign({$grid:this},e),t)},togglCollapseEvent:function(e,t){this.recalculate(!0),this.$emit("form-toggle-collapse",Object.assign({$grid:this},e),t)},triggerZoomEvent:function(e){this.zoom(),this.$emit("zoom",{$grid:this,maximize:this.isZMax,type:this.isZMax?"max":"revert",$event:e})},zoom:function(){return this[this.isZMax?"revert":"maximize"]()},isMaximized:function(){return this.isZMax},maximize:function(){return this.handleZoom(!0)},revert:function(){return this.handleZoom()},handleZoom:function(e){var t=this,r=this.isZMax;return(e?!r:r)&&(this.isZMax=!r,this.tZindex<_tools.UtilTools.getLastZIndex()&&(this.tZindex=_tools.UtilTools.nextZIndex())),this.$nextTick().then(function(){return t.recalculate(!0)}).then(function(){return t.isZMax})},getProxyInfo:function(){return this.proxyConfig?{data:this.tableData,filter:this.filterData,form:this.formData,sort:this.sortData,pager:this.tablePage,pendingRecords:this.pendingRecords}:null}})};exports.default=_default2;