<template>
    <div class="app-container">
        <div class="flexBet searchTop">
            <!-- <div class="title flex m20">
                <div class="bar"></div>
                <div class="text">商户实时统计</div>
            </div> -->

        </div>

        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="76px"
            class="flex form" style="position: relative">
            <el-form-item label="时间">
                <el-date-picker v-model="dateRange" size="small" style="width: 340px" value-format="yyyy-MM-dd HH:mm:ss"
                    type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                    :unlink-panels="true" :default-time="['00:00:00', '23:59:59']"></el-date-picker>
            </el-form-item>
            <el-form-item>
                <div class="searchTop flexBet" style="align-items: center">
                    <el-row :gutter="10" class="mb8">
                        <el-button type="primary" icon="" size="medium" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" size="medium" @click="resetQuery">重置</el-button>
                        <el-button type="primary" plain icon="" size="medium" @click="handleExport"
                            v-hasPermi="['platform:statistics:exportMerchantRealStatistics']">导出</el-button>
                    </el-row>
                    <div style="color:red;margin-left:20px;margin-bottom:8px;font-size:12px">统计是按照订单时间统计</div>

                </div>
            </el-form-item>
        </el-form>

        <!-- <div class="searchTop flexBet">
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="" size="medium" @click="handleExport">导出</el-button>
                </el-col>
            </el-row>

            <el-row :gutter="10" class="mb8">
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
        </div> -->

        <div class="bg">


            <el-table stripe :data="infoList" v-loading="loading">
                <el-table-column label="商户" align="center" prop="merchantName" />
                <el-table-column label="总订单数" align="center" prop="payTotalQty" />
                <el-table-column label="代收成功订单数" align="center" prop="paySuccessQty" />
                <el-table-column label="隔天补单数" align="center" prop="paySuccessQtyNoYesterday" />

                <el-table-column :label="'代收成功总金额'" align="center" prop="payeeRealAmount">
                    <template slot-scope="scope">
                        {{ parseFloat(NumberDiv(scope.row.paySuccessAmount, 100)).toFixed(2) }}
                    </template>
                </el-table-column>

                <el-table-column :label="'代收补单总金额'" align="center" prop="payeeRealAmount">
                    <template slot-scope="scope">
                        {{ parseFloat(NumberDiv(scope.row.paySuccessAmountAndYesterday, 100)).toFixed(2) }}
                    </template>
                </el-table-column>

                <el-table-column :label="'代收成功总金额（不含补单）'" align="center" prop="payeeRealAmount">
                    <template slot-scope="scope">
                        {{ parseFloat(NumberDiv(scope.row.paySuccessAmountNoYesterday, 100)).toFixed(2) }}
                    </template>
                </el-table-column>

                <el-table-column :label="'代收补单手续费'" align="center" prop="payeeRealAmount">
                    <template slot-scope="scope">
                        {{ parseFloat(NumberDiv(scope.row.payReturnAmountNoYesterday, 100)).toFixed(2) }}
                    </template>
                </el-table-column>

                <el-table-column :label="'代收手续费（不含补单）'" align="center" prop="payeeRealAmount">
                    <template slot-scope="scope">
                        {{ parseFloat(NumberDiv(scope.row.payReturnAmount, 100)).toFixed(2) }}
                    </template>
                </el-table-column>

                <el-table-column :label="'代收结算金额（不含补单）'" align="center" prop="payeeRealAmount">
                    <template slot-scope="scope">
                        {{ parseFloat(NumberDiv(scope.row.paySettlementAmountNoYesterday, 100)).toFixed(2) }}
                    </template>
                </el-table-column>

                <el-table-column :label="'代收成功率/%'" align="center" prop="payeeRealAmount">
                    <template slot-scope="scope">
                        {{ (isNaN(NumberDiv(scope.row.paySuccessQty, scope.row.payTotalQty)) || scope.row.payTotalQty == 0)
                            ? 0
                            : Number(NumberMul(NumberDiv(scope.row.paySuccessQty, scope.row.payTotalQty), 100).toFixed(2)) }}%
                    </template>
                </el-table-column>

                <el-table-column label="总代付订单数" align="center" prop="transferTotalQty" />
                <el-table-column label="总代付成功订单数" align="center" prop="transferSuccessQty" />

                <el-table-column :label="'代付成功总金额'" align="center" prop="payeeRealAmount">
                    <template slot-scope="scope">
                        {{ parseFloat(NumberDiv(scope.row.transferSuccessAmount, 100)).toFixed(2) }}
                    </template>
                </el-table-column>

                <el-table-column :label="'代付手续费总和'" align="center" prop="payeeRealAmount">
                    <template slot-scope="scope">
                        {{ parseFloat(NumberDiv(scope.row.transferReturnAmount, 100)).toFixed(2) }}
                    </template>
                </el-table-column>
                <!-- <el-table-column label="代付成功率/%" align="center" prop="transferReturnAmount" /> -->


                <!-- <el-table-column :label="'金额'" align="center" prop="amountIntervalMax">
            <template slot-scope="scope">
              {{ NumberDiv(scope.row.amount, 100) }}
            </template>
          </el-table-column>
        -->




            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList">
            </pagination>
        </div>




    </div>
</template>
  
<script>
import { listCarddealerSms, getCarddealerSms, delCarddealerSms, addCarddealerSms, updateCarddealerSms, exportCarddealerSms } from "@/api/carddealer/carddealerSms";
import Editor from '@/components/Editor';
import { payRecordStatics } from "@/api/form";
import cardMerchantOrderRefreshMixin from "@/api/cardMerchantOrderRefresh.mixin";

export default {
    name: "CarddealerSms",
    components: {
        Editor,
    },
    mixins: [cardMerchantOrderRefreshMixin],

    data() {
        return {
            dateRange: [],
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 短信列表格数据
            infoList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                content: null,
                phone: null,
                devKey: null,
                bankName: null,
                amount: null,
                recvTime: null,
                cardNumber: null,
                cardHolder: null,
                verifyStatus: null,
                smsTime: null,
                smsType: null,
                payType: null,
                orderNo: null,
                carddealerId: null,
                verifyRemarks: null,
                md5: null,
                ver: null,
                carddealerName: null,
                id: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                content: [
                    { required: true, message: "内容不能为空", trigger: "blur" }
                ],
                phone: [
                    { required: true, message: "发送号码不能为空", trigger: "blur" }
                ],
                devKey: [
                    { required: true, message: "设备key不能为空", trigger: "blur" }
                ],
                createTime: [
                    { required: true, message: "入库时间不能为空", trigger: "blur" }
                ],
            }
        };
    },
    $autoRefresh: {
        // 刷新间隔时间
        interval: 3000 * 10,
        // 立即执行一次
        immediate: false,
        // 被回调的函数, 不保证顺序执行
        handles: ["getList"],
        /**
         * 调用 handles 后的回调函数
         * 这个字段为数组类型, 数组中的每个元素都是一个函数, 在对应索引的 handle 执行后被调用
         */
        callbacks: [],
        // 是否启用调试模式
        debug: true,
    },
    created() {
        this.addDate()
        this.getList();
    },
    methods: {

        // 获取今天
        addDate() {
            let nowDate = this.BeiJingDate()
            let date = {
                year: nowDate.getFullYear(),
                month: nowDate.getMonth() + 1,
                date: nowDate.getDate(),
            }
            if (date.date <= 9) {
                this.systemDate = date.year + '-' + 0 + date.month + '-' + 0 + date.date;
            } else {
                this.systemDate = date.year + '-' + 0 + date.month + '-' + date.date;
            }
            this.dateRange = [this.systemDate + ' ' + '00' + ':' + '00' + ':' + '00', this.systemDate + ' ' + '23' + ':' + '59' + ':' + '59']
            this.$forceUpdate()
        },
        timerHandler() {
            payRecordStatics.listInfo(this.addSESDateRange(this.queryParams, this.dateRange)).then(response => {
                this.infoList = response.rows;
                this.total = Number(response.total);
            });
        },
        /** 查询短信列列表 */
        getList() {
            this.loading = true;
            payRecordStatics.listInfo(this.addSESDateRange(this.queryParams, this.dateRange)).then(response => {
                this.infoList = response.rows;
                this.total = Number(response.total);
                this.loading = false;
                this.startTimer(this.queryParams)
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {

            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加短信列";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids
            getCarddealerSms(id).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改短信列";
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        updateCarddealerSms(this.form).then(response => {
                            this.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addCarddealerSms(this.form).then(response => {
                            this.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },

        /** 导出按钮操作 */
        handleExport() {
            if (this.dateRange.length) {
                this.queryParams.beginTime = this.dateRange[0]
                this.queryParams.endTime = this.dateRange[1]
            } else {
                this.queryParams.beginTime = null
                this.queryParams.endTime = null
            }
            const queryParams = this.queryParams;
            this.$confirm('是否确认导出所有数据项?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return payRecordStatics.exportMerchant(queryParams);
            }).then(response => {
                this.download(response.msg);
            })
        }
    }
};
</script>
  