|  |  | 
 |  |  | export default { | 
 |  |  |   name: 'BaseTable', | 
 |  |  |   extends: BasePage, | 
 |  |  |   data () { | 
 |  |  |   data() { | 
 |  |  |     return { | 
 |  |  |       // 接口 | 
 |  |  |       api: null, | 
 |  |  | 
 |  |  |      * | 
 |  |  |      * @param extParams 配置参数 | 
 |  |  |      */ | 
 |  |  |     config (extParams) { | 
 |  |  |     config(extParams) { | 
 |  |  |       if (extParams == null) { | 
 |  |  |         throw new Error('Parameter can not be null of method \'config\' .') | 
 |  |  |       } | 
 |  |  | 
 |  |  |     /** | 
 |  |  |      * 搜索(点击搜索按钮时触发) | 
 |  |  |      */ | 
 |  |  |     search () { | 
 |  |  |     search() { | 
 |  |  |       this.handlePageChange(1) | 
 |  |  |     }, | 
 |  |  |     /** | 
 |  |  |      * 导出Excel(点击导出按钮时触发) | 
 |  |  |      */ | 
 |  |  |     exportExcel () { | 
 |  |  |     exportExcel() { | 
 |  |  |       this.__checkApi() | 
 |  |  |       this.$dialog.exportConfirm('确认导出吗?') | 
 |  |  |         .then(() => { | 
 |  |  | 
 |  |  |     /** | 
 |  |  |      * 重置搜索条件(点击重置按钮时触发) | 
 |  |  |      */ | 
 |  |  |     reset () { | 
 |  |  |     reset() { | 
 |  |  |       this.$refs.searchForm.resetFields() | 
 |  |  |       this.search() | 
 |  |  |     }, | 
 |  |  | 
 |  |  |      * | 
 |  |  |      * @param pageSize 页容量 | 
 |  |  |      */ | 
 |  |  |     handleSizeChange (pageSize) { | 
 |  |  |     handleSizeChange(pageSize) { | 
 |  |  |       this.tableData.pagination.pageSize = pageSize | 
 |  |  |       this.search() | 
 |  |  |     }, | 
 |  |  | 
 |  |  |      * | 
 |  |  |      * @param selectedRows 已选中的行数组 | 
 |  |  |      */ | 
 |  |  |     handleSelectionChange (selectedRows) { | 
 |  |  |     handleSelectionChange(selectedRows) { | 
 |  |  |       this.tableData.selectedRows = selectedRows | 
 |  |  |     }, | 
 |  |  |     /** | 
 |  |  | 
 |  |  |      * | 
 |  |  |      * @param sortData 排序参数 | 
 |  |  |      */ | 
 |  |  |     handleSortChange (sortData) { | 
 |  |  |     handleSortChange(sortData) { | 
 |  |  |       this.tableData.sorts = [] | 
 |  |  |       if (sortData.order != null) { | 
 |  |  |         this.tableData.sorts.push({ | 
 |  |  | 
 |  |  |      * | 
 |  |  |      * @param pageIndex 新页码 | 
 |  |  |      */ | 
 |  |  |     handlePageChange (pageIndex) { | 
 |  |  |     handlePageChange(pageIndex) { | 
 |  |  |       this.__checkApi() | 
 |  |  |       this.tableData.pagination.pageIndex = pageIndex || this.tableData.pagination.pageIndex | 
 |  |  |       this.isWorking.search = true | 
 |  |  | 
 |  |  |      * @param row 行对象 | 
 |  |  |      * @param childConfirm 删除子节点时是否进行二次确认 | 
 |  |  |      */ | 
 |  |  |     deleteById (row, childConfirm = true) { | 
 |  |  |     deleteById(row, childConfirm = true) { | 
 |  |  |       this.__checkApi() | 
 |  |  |       let message = `确认删除${this.module}【${row[this.configData['field.main']]}】吗?` | 
 |  |  |       if (childConfirm && row.children != null && row.children.length > 0) { | 
 |  |  | 
 |  |  |               this.isWorking.delete = false | 
 |  |  |             }) | 
 |  |  |         }) | 
 |  |  |         .catch(() => {}) | 
 |  |  |         .catch(() => { }) | 
 |  |  |     }, | 
 |  |  |     /** | 
 |  |  |      * 批量删除(点击批量删除时触发) | 
 |  |  |      * | 
 |  |  |      * @param childConfirm 删除子节点时是否进行二次确认 | 
 |  |  |      */ | 
 |  |  |     deleteByIdInBatch (childConfirm = true) { | 
 |  |  |     deleteByIdInBatch(childConfirm = true) { | 
 |  |  |       this.__checkApi() | 
 |  |  |       if (this.tableData.selectedRows.length === 0) { | 
 |  |  |         this.$tip.warning('请至少选择一条数据') | 
 |  |  | 
 |  |  |               this.isWorking.delete = false | 
 |  |  |             }) | 
 |  |  |         }) | 
 |  |  |         .catch(() => {}) | 
 |  |  |         .catch(() => { }) | 
 |  |  |     }, | 
 |  |  |     /** | 
 |  |  |      * 删除后处理,在单行删除或多行删除后调用 | 
 |  |  | 
 |  |  |      * @param deleteCount 删除数量 | 
 |  |  |      * @private | 
 |  |  |      */ | 
 |  |  |     __afterDelete (deleteCount = 1) { | 
 |  |  |     __afterDelete(deleteCount = 1) { | 
 |  |  |       this.$tip.apiSuccess('删除成功') | 
 |  |  |       // 删除当前页最后一条记录时查询上一页数据 | 
 |  |  |       if (this.tableData.list.length - deleteCount === 0) { | 
 |  |  | 
 |  |  |      * | 
 |  |  |      * @private | 
 |  |  |      */ | 
 |  |  |     __checkApi () { | 
 |  |  |     __checkApi() { | 
 |  |  |       console.log(this.api); | 
 |  |  |       if (this.api == null) { | 
 |  |  |         throw new Error('The page is not initialized, you can use method \'this.config\' to initialize this page.') | 
 |  |  |       } | 
 |  |  |     }, | 
 |  |  |     /** | 
 |  |  |  * 数字相加 | 
 |  |  |  * @param {*} arg1  | 
 |  |  |  * @param {*} arg2  | 
 |  |  |  * @returns  | 
 |  |  |  */ | 
 |  |  |     accAdd(arg1, arg2) { | 
 |  |  |       return this.changeNum(arg1, arg2) | 
 |  |  |     }, | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 数字相减 | 
 |  |  |      * @param {*} arg1  | 
 |  |  |      * @param {*} arg2  | 
 |  |  |      * @returns  | 
 |  |  |      */ | 
 |  |  |     accSub(arg1, arg2) { | 
 |  |  |       return this.changeNum(arg1, arg2, false) | 
 |  |  |     }, | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 数字相乘 | 
 |  |  |      * @param {*} arg1  | 
 |  |  |      * @param {*} arg2  | 
 |  |  |      * @returns  | 
 |  |  |      */ | 
 |  |  |     accMul(arg1, arg2) { | 
 |  |  |       let m = 0; | 
 |  |  |       m = accAdd(m, getDecimalLength(arg1)) | 
 |  |  |       m = accAdd(m, getDecimalLength(arg2)) | 
 |  |  |       return getNum(arg1) * getNum(arg2) / Math.pow(10, m) | 
 |  |  |     }, | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 数字相除 | 
 |  |  |      * @param {*} arg1  | 
 |  |  |      * @param {*} arg2  | 
 |  |  |      * @returns  | 
 |  |  |      */ | 
 |  |  |     accDiv(arg1, arg2) { | 
 |  |  |       let t1, t2; | 
 |  |  |       t1 = this.getDecimalLength(arg1) | 
 |  |  |       t2 = this.getDecimalLength(arg2) | 
 |  |  |       if (t1 - t2 > 0) { | 
 |  |  |         return (this.getNum(arg1) / this.getNum(arg2)) / Math.pow(10, t1 - t2) | 
 |  |  |       } else { | 
 |  |  |         return (this.getNum(arg1) / this.getNum(arg2)) * Math.pow(10, t2 - t1) | 
 |  |  |       } | 
 |  |  |     }, | 
 |  |  |  | 
 |  |  |     changeNum(arg1 = '', arg2 = '', isAdd = true) { | 
 |  |  |       function changeInteger(arg, r, maxR) { | 
 |  |  |         if (r != maxR) { | 
 |  |  |           let addZero = '' | 
 |  |  |           for (let i = 0; i < maxR - r; i++) { | 
 |  |  |             addZero += '0' | 
 |  |  |           } | 
 |  |  |           arg = Number(arg.toString().replace('.', '') + addZero) | 
 |  |  |         } else { | 
 |  |  |           arg = this.getNum(arg) | 
 |  |  |         } | 
 |  |  |         return arg | 
 |  |  |       } | 
 |  |  |       let r1, r2, maxR, m; | 
 |  |  |       r1 = this.getDecimalLength(arg1) | 
 |  |  |       r2 = this.getDecimalLength(arg2) | 
 |  |  |       maxR = Math.max(r1, r2) | 
 |  |  |       arg1 = changeInteger(arg1, r1, maxR) | 
 |  |  |       arg2 = changeInteger(arg2, r2, maxR) | 
 |  |  |       m = Math.pow(10, maxR) | 
 |  |  |       if (isAdd) { | 
 |  |  |         return (arg1 + arg2) / m | 
 |  |  |       } else { | 
 |  |  |         return (arg1 - arg2) / m | 
 |  |  |       } | 
 |  |  |     }, | 
 |  |  |  | 
 |  |  |     getDecimalLength(arg = '') { | 
 |  |  |       try { | 
 |  |  |         return arg.toString().split(".")[1].length | 
 |  |  |       } catch (e) { | 
 |  |  |         return 0 | 
 |  |  |       } | 
 |  |  |     }, | 
 |  |  |  | 
 |  |  |     getNum(arg = '') { | 
 |  |  |       return Number(arg.toString().replace(".", "")) | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |   } | 
 |  |  | } | 
 |  |  | </script> |