repeatMethods.js 1.74 KB
import {exportFn} from "@/common/constant";

export default {
    methods: {
        handleSearch() {
            this.tableSearchForm = this.getParams()
            this.$refs.listRef.refreshTable()
        },
        handleReset() {
            this.searchForm = this.$options.data.call(this).searchForm
            this.handleSearch()
        },
        handleExport(apiName) {
            const params = this.getParams()
            this.$apis.redenvelope[apiName](params).then(res => {
                exportFn(res)
            })
        },
        beforeSearchFn() {
            return new Promise((resolve) => {
                const { selectedArea } = this.searchForm;

                // 清除旧的省市区 ID
                this.searchForm.provincesId = '';
                this.searchForm.cityId = '';
                this.searchForm.districtsId = '';

                // 根据 selectedArea 的长度设置相应的 ID
                if (selectedArea) {
                    [this.searchForm.provincesId, this.searchForm.cityId, this.searchForm.districtsId] = selectedArea;
                }

                delete this.searchForm.selectedArea;
                resolve();
            });
        },
        getParams() {
            let params = JSON.parse(JSON.stringify(this.searchForm))

            return params
        },
        updateParams(params, paramKey, formKey, beginKey, endKey) {
            if (params[paramKey]) {
                params[beginKey] = this.searchForm[formKey][0];
                params[endKey] = this.searchForm[formKey][1];
                delete params[paramKey];
            } else {
                delete params[beginKey];
                delete params[endKey];
            }
            return params
        }
    },

}