deliveryCount.vue 6.7 KB
<!-- 店端实际交车数 -->
<template>
    <d2-container class="delivery-count">
        <template #header>
            <div class="header">
                <d2-search class="show-search"
                           :form-data="showFormData"
                           label-width="140px"
                           :search-form="searchForm"
                           :search-select-obj="searchSelectObj">
                    <template #reportDate>
                        <el-date-picker v-model="searchForm.reportDate"
                                        end-placeholder="结束日期"
                                        :picker-options="pickerOptions"
                                        range-separator="至"
                                        size="mini"
                                        start-placeholder="开始日期"
                                        type="daterange"
                                        value-format="yyyy-MM-dd" />
                    </template>
                    <div class="up-btns">
                        <el-button :id="tableParams.btnId"
                                   size="small"
                                   type="primary">
                            查询
                        </el-button>
                        <el-button size="small" @click="handleReset">
                            重置
                        </el-button>
                    </div>
                </d2-search>
            </div>
        </template>
        <div class="d2-container-content">
            <div class="table-header">
                <div class="table-title">
                    {{ merchantName || '店端实际交车数' }}
                </div>
                <!-- <auth-button category="Button" :show-btn-ids="['9070901']" /> -->
                <el-button size="small"
                           type="primary"
                           @click="handleExport">
                    导出
                </el-button>
            </div>
            <d2-table ref="recordTable"
                      :before-search-fn="beforeSearchFn"
                      :get-list-api="getListApi"
                      :search-form="searchFormSearch"
                      :table-data="tableData"
                      :table-params="tableParams" />

        </div>
        <div class="table-footer">
            <el-button size="small"
                       type="primary"
                       @click="handleBack">
                返回
            </el-button>
        </div>
    </d2-container>
</template>

<script>
import dayjs from "dayjs";
import { mapActions, mapState } from "vuex";
import { permeabilityDetail } from "@/api/permeation.js";
import { rangePickerOptions_oneYearNoFuture } from "@/common/format";
import { deepClone } from "@/common/util";

export default {
	name: "DeliveryCount",
	data() {
		return {
			getListApi: permeabilityDetail,
			searchForm: {
				merchantId: "",
				staffName: "",
				createdDate: "",
				reportDate: "",
			},
			searchFormSearch: {},
			searchSelectObj: {},
			showFormData: [
				{
					label: "员工名称",
					name: "staffName",
					type: "input",
					isClear: true,
				},
				{
					label: "填报日期",
					name: "createdDate",
					type: "datePicker",
					isClear: true,
					valueFormat: "yyyy-MM-dd",
					pickerOptions: "rangePickerOptions_oneYearNoFuture",
				},
				{
					label: "日报时间",
					name: "reportDate",
					addHtml: "reportDate",
				},
			],
			tableData: [],
			tableParams: {
				btnId: new Date().getTime() + Number.parseInt(Math.random() * 1000, 10),
				listName: "list",
				tableOption: false,
				tableColumns: [
					{
						label: "员工名称",
						prop: "staffName",
					},
					{
						label: "店端实际交车数",
						prop: "deliveryCount",
						formatter: (cellValue) => {
							return (cellValue.deliveryCount ?? "") === ""
								? "-"
								: cellValue.deliveryCount;
						},
					},
					{
						label: "填报时间",
						prop: "createdDate",
					},
					{
						label: "日报时间",
						prop: "reportDate",
					},
				],
			},
			sceneType: "0",
			pickerOptions: rangePickerOptions_oneYearNoFuture,
		};
	},

	computed: {
		...mapState({
			dowloadList: state => state.d2admin.user.dowloadList,
		}),
		merchantName() {
			return this.$route.query.merchantName || "";
		},
	},

	created() {
		const { merchantId, startDate, endDate } = this.$route.query;
		if (merchantId) {
			this.searchForm.merchantId = merchantId;
		}
		if (startDate && endDate) {
			this.searchForm.reportDate = [startDate, endDate];
		}
	},

	methods: {
		...mapActions("d2admin/user", ["actionSetDownloadList"]),
		beforeSearchFn() {
			return new Promise((resolve) => {
				this.searchFormSearch = this.getParams();
				resolve();
			});
		},
		getParams() {
			this.searchFormSearch = deepClone(this.searchForm);
			if (this.searchFormSearch.createdDate) {
				this.searchFormSearch.createdStartDate
					= dayjs(this.searchFormSearch.createdDate[0]).format("YYYY-MM-DD")
						+ " 00:00:00";
				this.searchFormSearch.createdEndDate
					= dayjs(this.searchFormSearch.createdDate[1]).format("YYYY-MM-DD")
						+ " 23:59:59";
			}
			if (this.searchFormSearch.reportDate) {
				this.searchFormSearch.reportStartDate = dayjs(
					this.searchFormSearch.reportDate[0],
				).format("YYYY-MM-DD");
				this.searchFormSearch.reportEndDate = dayjs(
					this.searchFormSearch.reportDate[1],
				).format("YYYY-MM-DD");
			}
			this.searchFormSearch.sceneType = this.sceneType;
			return this.searchFormSearch;
		},
		handleExport() {
			const params = this.getParams();
			params.method
				= "dj.api.smartcarlife.permeability.report.detail.exportAsync";
			const list = [
				...this.dowloadList,
				{
					name: `填报明细 ${dayjs().format("YYYY-MM-DD")}`,
					exportParam: JSON.stringify(params),
					status: "waiting",
					timeid: new Date().getTime(),
				},
			];
			this.actionSetDownloadList({ list, type: "dowloadList" });
		},
		handleReset() {
			const { merchantId, startDate, endDate } = this.$route.query;
			this.searchForm = {
				merchantId: merchantId || "",
				staffName: "",
				createdDate: "",
				reportDate: startDate && endDate ? [startDate, endDate] : "",
			};
			this.$refs.recordTable.refreshTable();
		},
		handleBack() {
			this.$router.go(-1);
		},
	},
};
</script>

<style lang="scss" scoped>
.delivery-count {
	// .header {
	// 	display: flex;
	// 	align-items: center;
	// 	::v-deep {
	// 		.el-date-editor {
	// 			width: 220px;
	// 		}
	// 	}
	// }
	.table-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 10px;
		.table-title {
			font-size: 16px;
			color: #333333;
			font-weight: 600;
		}
	}
	.table-footer {
		margin-top: 16px;
		text-align: center;
	}
}
</style>