repeatMethods.js 1.7 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.searchForm.hasOwnProperty('selectedArea') && this.$set(this.searchForm, 'selectedArea', []);
            this.handleSearch()
        },
        handleExport(apiName) {
            const params = this.getParams()
            this.$apis.redenvelope[apiName](params).then(res => {
                exportFn(res)
            })
        },
        getParams() {
            let params = JSON.parse(JSON.stringify(this.searchForm))

            return params
        },
        handleProvinceParams(params){
            const { selectedArea } = params;

            // 只有当 selectedArea 存在时,才更新省市区 ID
            if (selectedArea && selectedArea.length > 0) {
                params.provincesId = selectedArea[0] || '';
                params.cityId = selectedArea[1] || '';
                params.districtsId = selectedArea[2] || '';
            }

            // 删除 selectedArea 属性
            delete params.selectedArea;
            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
        }
    },

}