PreferencePage.vue 14.2 KB
<template>

    <!--查询栏-->
    <m-pagination-query-render :fields="pagination.filterFields" :form="pagination.queryForm"
        @onSearch="handlePageReload" @onReset="handleReset" :simpleFieldNum="4">
        <template #cityCodeName="{ record }">
            <a-cascader v-model:value="carProvinceCity" :options="areaData" @change="handleChangeCity"
                placeholder="请选择省/市" />
        </template>
    </m-pagination-query-render>

    <div class="table-download">
        <div class="selectedList">已选 {{ selectIds.length }} 项</div>
        <div class="selectedBut">
            <a-button type="primary" @click="modalVisible = true, excelValue = '1'" :disabled="exporting">
                导出
            </a-button>
        </div>
    </div>

    <a-table :columns="columns" :data-source="pagination.content" :loading="loading" :bordered="false"
        @change="pageRefresh" @resizeColumn="this.$filters.tableResizeColumn" size="small" :pagination="pageState"
        :row-key="record => record.id" :scroll="{ y: 'calc(100vh - 288px)' }"
        :row-selection="{ selectedRowKeys: selectIds, onChange: onSelectChange, type: 'checkbox', preserveSelectedRowKeys: true, }">

        <template #customFilterDropdown="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }">
            <m-filter-text-render :pagination="pagination" :column="column" :confirm="confirm"></m-filter-text-render>
            <m-filter-checkbox-group-render :pagination="pagination" :column="column"
                :confirm="confirm"></m-filter-checkbox-group-render>
        </template>

        <template #bodyCell="{ column, record }">

            <template v-if="column.key === 'operationAction'">
                <router-link
                    :to="{ path: '/finance/preference/view', query: { preferenceId: record.id, action: 'VIEW' } }">
                    <a-button type="link" size="small">详情</a-button>
                </router-link>
                <router-link
                    :to="{ path: '/finance/preference/edit', query: { preferenceId: record.id, action: 'EDIT' } }">
                    <a-button type="link" size="small">编辑</a-button>
                </router-link>
            </template>

            <template v-if="column.key === 'businessModel'">
                {{ record.businessModel == '1' ? '批发' : record.businessModel == '2' ? '零售' : '--' }}
            </template>

            <template v-if="column.key === 'cityName'">
                {{ record.provinceName }}-{{ record.cityName }}
            </template>

            <template v-if="column.key === 'vehicleCondition'">
                <PageMultipleTag :listValue="'vehicleConditionList'" :tagValue="record.vehicleCondition" />
            </template>

            <template v-if="column.key === 'vehicleAge'">
                <PageMultipleTag :listValue="'vehicleAgeList'" :tagValue="record.vehicleAge" />
            </template>

            <template v-if="column.key === 'vehicleFuelType'">
                <PageMultipleTag :listValue="'vehicleFuelTypeList'" :tagValue="record.vehicleFuelType" />
            </template>

            <template v-if="column.key === 'vehicleType'">
                <PageMultipleTag :listValue="'vehicleTypeList'" :tagValue="record.vehicleType" />
            </template>

            <template v-if="column.key === 'brandList'">
                <PageMultipleTag :listValue="record.brandList || []" :tagValue="record.brandList" />
            </template>

            <template v-if="column.key === 'status'">
                <div v-if="record.status == '1'" class="tag1">已完成</div>
                <div v-else class="tag2">未完成</div>
            </template>
        </template>
    </a-table>

    <a-modal :visible="modalVisible" @ok="handleVisibleOk" @cancel="modalVisible = false" title="导出范围" width="420px">
        <div>
            <div class="visible-title">请选择导出范围 <span class="validate">*</span> </div>
            <a-select v-model:value="excelValue" style="width: 100%" placeholder="请选择导出范围">
                <a-select-option value="1">导出全部</a-select-option>
                <a-select-option value="2">导出当前勾选的结果</a-select-option>
            </a-select>
        </div>
    </a-modal>

</template>
<script lang="ts">
import { Component } from 'vue-facing-decorator';
import { EyeFilled } from "@ant-design/icons-vue";
import { PaginationComponent } from "autumn-vue/lib/core/page/PaginationComponent";
import { Deposit } from "lib/src/entity/finance/entity/Deposit";
import { message, TableColumnsType } from "ant-design-vue";
import { Operator, Order, Pagination } from "autumn-vue/lib/core/page/Pagination";
import { PreferenceController } from "@/api/PreferenceController";
import { ExportUtil } from "@/common/ExportUtil";
import { Security } from "@/store";
import PageMultipleTag from "@/views/finance/preference/PageMultipleTag.vue";
import { returnPreferenceList } from "@/views/finance/preference/listData";
import { convertToTree } from "@/common/chinaarea";
import { DefaultOptionType } from "ant-design-vue/es/vc-cascader/Cascader";


@Component({
    components: { EyeFilled, PageMultipleTag }
})

export default class PreferencePage extends PaginationComponent<Deposit> {

    areaData: DefaultOptionType[] = [];
    carProvinceCity = ''

    selectedRowKeys = [];


    selectIds: number[] = [];
    selectedItems = [];

    exporting = false;
    modalVisible = false;
    excelValue = '1';

    businessModelList = [
        { label: '全部', value: '' },
        { label: '批发', value: '1' },
        { label: '零售', value: '2' }
    ]

    researchStatusList = [
        { label: '未完成', value: '0' },
        { label: '已完成', value: '1' },
    ]

    brands = [];

    @Security.Getter hasPrivilege;
    /**
     * 表格列配置
     */
    columns: TableColumnsType = [
        {
            title: '序号', key: 'index', width: 70, align: 'center', sorter: false,
            customRender: ({ index }) => {
                return (this.getPagination().pageIndex - 1) * this.getPagination().pageSize + index + 1;
            },
        },
        { title: '车商ID', dataIndex: 'accountId', key: 'accountId', align: 'center', width: 160, resizable: true, ellipsis: true, sorter: false },
        { title: '车商手机号', dataIndex: 'mobile', key: 'mobile', align: 'center', width: 160, resizable: true, ellipsis: true, sorter: false },
        { title: '车商昵称', dataIndex: 'nickName', key: 'nickName', align: 'center', width: 160, resizable: true, ellipsis: true, sorter: false },
        { title: '实名姓名', dataIndex: 'accountName', key: 'accountName', align: 'center', width: 160, resizable: true, ellipsis: true, sorter: false },
        { title: '经营模式', dataIndex: 'businessModel', key: 'businessModel', align: 'center', width: 160, resizable: true, ellipsis: true, sorter: false },
        { title: '注册地区', dataIndex: 'cityName', key: 'cityName', align: 'center', width: 160, resizable: true, ellipsis: true, sorter: false },
        { title: '偏好车况', dataIndex: 'vehicleCondition', key: 'vehicleCondition', align: 'center', width: 224, resizable: true, ellipsis: true, sorter: false },
        { title: '偏好车龄', dataIndex: 'vehicleAge', key: 'vehicleAge', align: 'center', width: 224, resizable: true, ellipsis: true, sorter: false },
        { title: '燃油类型', dataIndex: 'vehicleFuelType', key: 'vehicleFuelType', align: 'center', width: 224, resizable: true, ellipsis: true, sorter: false },
        { title: '收车车型', dataIndex: 'vehicleType', key: 'vehicleType', align: 'center', width: 224, resizable: true, ellipsis: true, sorter: false },
        { title: '品牌偏好', dataIndex: 'brandList', key: 'brandList', align: 'center', width: 224, resizable: true, ellipsis: true, sorter: false },
        { title: '调研状态', dataIndex: 'status', key: 'status', align: 'center', width: 160, resizable: true, ellipsis: true, sorter: false },
        { title: '更新时间', dataIndex: 'updateTime', key: 'updateTime', align: 'center', width: 160, resizable: true, ellipsis: true, sorter: true },
        { title: '编辑人', dataIndex: 'updatedBy', key: 'updatedBy', align: 'center', width: 160, resizable: true, ellipsis: true, sorter: false },
        { title: '操作', dataIndex: 'operationAction', key: 'operationAction', width: 120, align: 'center', fixed: 'right' },
    ];

    getPagination(): Pagination<Deposit> {
        return this.pagination;
    }
    /**
     * 初始化配置
     */
    created(): void {
        this.init(this.axios, PreferenceController.PAGE_PREFERENCE);
        this.buildQueryForm({
            key: [null, { label: '车商信息', field: 'key', placeholder: '请输入用户ID/手机号/昵称', operator: Operator.like }],
            cityCode: [null, {
                name: 'cityCodeName', label: '注册地区', field: 'cityCode', type: 'slot', placeholder: '请选择省/市', operator: Operator.eq
            }],
            businessModel: ['', {
                label: '经营模式', field: 'businessModel', type: 'select', placeholder: '请选择经营模式', optionItems: this.businessModelList, operator: Operator.eq
            }],
            vehicleCondition: [[], {
                label: '偏好车况', field: 'vehicleCondition', type: 'select', mode: 'multiple', allowClear: true, optionItems: returnPreferenceList('vehicleConditionList'), operator: Operator.eq
            }],
            vehicleAge: [[], {
                label: '偏好车龄', field: 'vehicleAge', type: 'select', mode: 'multiple', allowClear: true, optionItems: returnPreferenceList('vehicleAgeList'), operator: Operator.eq
            }],
            vehicleFuelType: [[], {
                label: '燃油类型', field: 'vehicleFuelType', type: 'select', mode: 'multiple', allowClear: true, optionItems: returnPreferenceList('vehicleFuelTypeList'), operator: Operator.eq
            }],
            vehicleType: [[], {
                label: '收车车型', field: 'vehicleType', type: 'select', mode: 'multiple', allowClear: true, optionItems: returnPreferenceList('vehicleTypeList'), operator: Operator.eq
            }],
            brandName: [null, { label: '品牌偏好', field: 'brandName', placeholder: '请输入品牌名称', operator: Operator.like }],
            status: [null, {
                label: '调研状态', field: 'status', type: 'select', allowClear: true, optionItems: this.researchStatusList, operator: Operator.eq
            }],
            createTime: [null, { label: '更新时间', field: 'updateTime', operator: Operator.dateBetween, type: 'date-range' }],
        });
        this.pagination.setDefaultSort('createTime', Order.desc);
        this.pageLoad();
        this.areaData = convertToTree(false);
    }

    //区域数据发生变化
    handleChangeCity(value: string[], e: any) {
        let code = ''
        if (e && e.length > 0) {
            const cityObj = e[e.length - 1];
            code = cityObj.value || '';
        }
        this.pagination.queryForm.cityCode = code;
    }

    handlePageReload() {
        this.selectIds = [];
        this.selectedItems = [];
        this.pageReload();
    }

    //重置查询条件
    handleReset() {
        this.carProvinceCity = '';
        this.pagination.queryForm.businessModel = '';
        this.selectIds = [];
        this.selectedItems = [];
        this.pageReset();
    }

    handleVisibleOk() {
        this.modalVisible = false;
        this.downloadExcel();
    }

    downloadExcel(): void {
        this.exporting = true;
        let paramsData = {
            ...this.pagination.requestParams,
        }
        if (this.excelValue == '2') {
            if (!this.selectIds.length) {
                message.error('请选择需要导出的数据');
                this.exporting = false;
                return false
            } else {
                if (!paramsData.filters) {
                    paramsData.filters = []
                }
                paramsData.filters.push({ field: "id", logic: "and", operator: "in", value: this.selectIds, })
            }
        }
        PreferenceController.exportPreference(this.axios, paramsData, { responseType: 'blob' }).then(response => {
            message.success('导出任务已创建,请在下载中心查看');
            ExportUtil.downloadExcelFile(response.data, '收车偏好列表' + this.getNewTime()); 
        }).catch(error => {
            console.error('Error downloading Word file:', error);
        }).finally(() => {
            this.exporting = false;
        });
    } 

    getNewTime() {
        //获取当前年月日时分秒
        const date = new Date();
        const year = date.getFullYear();
        const month = date.getMonth() + 1;
        const monthStr = month < 10 ? '0' + month : month;
        const day = date.getDate();
        const dayStr = day < 10 ? '0' + day : day;
        const hour = date.getHours();
        const minute = date.getMinutes();
        const minuteStr = minute < 10 ? '0' + minute : minute;
        return `${year}-${monthStr}-${dayStr}-${hour}-${minuteStr}`
    }

    onSelectChange(selectedRowKeys: number[], selectedRows: []): void {
        this.selectIds = selectedRowKeys;
        this.selectedItems = selectedRows;
    }
}
</script>


<style scoped lang="less">
:deep(.ant-form-item-control) {
    min-width: 120px;
}

.table-download {
    width: 100%;
    height: 32px;
    margin-bottom: 12px;
}

.selectedList {
    float: left;
    height: 32px;
    line-height: 32px;
    color: #777c85;
    font-size: 14px;
    font-weight: 400;
}

.selectedBut {
    float: right;
}

.tag1 {
    width: 52px;
    height: 24px;
    border-radius: 3px;
    border: 1px solid #e8f8f2;
    background: #e8f8f2;
    color: #00ad74;
    font-size: 12px;
    font-weight: 400;
    text-align: center;
    line-height: 24px;
    margin: 0 auto;
}

.tag2 {
    width: 52px;
    height: 24px;
    border: 1px solid #f0f2f5;
    border-radius: 3px;
    background: #f0f2f5;
    color: #777c85;
    font-size: 12px;
    font-weight: 400;
    text-align: center;
    line-height: 24px;
    margin: 0 auto;
}

.visible-title {
    width: 100%;
    height: 32px;
    line-height: 32px;
    color: #777C85FF;
}

.validate {
    color: #ee3040;
    font-size: 16px;
    padding-left: 2px;
}
</style>