<template>
    <div class="app-container">
        <div class="flexBet searchTop">
            <div class="title flex m20">
                <div class="bar"></div>
                <div class="text">{{ $route.meta.title }}</div>
            </div>
            <el-row :gutter="10" class="mb8">
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
        </div>
        <div class="bg">
            <div class="rig flex m20">
                <div>
                    入金统计：<span class="#197CFE">{{ sum.incomeTotal }}</span>
                </div>
                <div>
                    出金统计：<span class="#197CFE">{{ sum.expendTotal }}</span>
                </div>
            </div>
            <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="86px"
                class="flex form" style="padding:0 20px">
                <el-form-item label="商户名称" prop="storeName">
                    <el-input size="small" v-model="queryParams.storeName" placeholder="请输入商户名称"
                        @keyup.enter.native="handleQuery" style="width: 215px;border-color: #E6F1FF;" />
                </el-form-item>


                <el-form-item label="业务单号" prop="witNo">
                    <el-input size="small" v-model="queryParams.witNo" placeholder="请输入业务单号"
                        @keyup.enter.native="handleQuery" style="width: 215px;border-color: #E6F1FF;" />
                </el-form-item>

                <el-form-item label="账户编号" prop="accountNo">
                    <el-input size="small" v-model="queryParams.accountNo" placeholder="请输入账户编号"
                        @keyup.enter.native="handleQuery" style="width: 215px;border-color: #E6F1FF;" />
                </el-form-item>

                <el-form-item label="类型" prop="isIncome">
                    <el-select v-model="queryParams.isIncome" placeholder="请选择类型" size="small">
                        <el-option v-for="dict in typeCon" :key="dict.value" :label="dict.label" :value="dict.value" />
                    </el-select>
                </el-form-item>

                <el-form-item label="业务类型" prop="witType">
                    <el-select v-model="queryParams.witType" placeholder="请选择业务类型" size="small">
                        <el-option v-for="dict in dict.type.capital_type" :key="dict.value" :label="dict.label"
                            :value="dict.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="用户类型" prop="userType">
                    <el-select v-model="queryParams.userType" placeholder="请选择用户类型" size="small">
                        <el-option v-for="dict in userCon" :key="dict.value" :label="dict.label" :value="dict.value" />
                    </el-select>
                </el-form-item>

                <el-form-item label="交易时间">
                    <el-date-picker v-model="dateRange" size="small" style="width: 340px; height: 32px;"
                        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']" :picker-options="pickerOptions"></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="small" @click="handleQuery">搜索</el-button>
                            <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
                        </el-row>

                        <el-row :gutter="10" class="mb8" style="margin-left:20px">
                            <el-col :span="1.5">
                                <el-button type="primary" plain icon="" size="small" @click="handleExport" style="height: 32px;"
                                    v-hasPermi="['order:rechargeRecord:export']">导出</el-button>
                            </el-col>
                        </el-row>
                    </div>
                </el-form-item>
            </el-form>
            <el-table stripe v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
                <el-table-column :label="'业务单号'" align="left" prop="witNo" min-width="180" />
                <el-table-column :label="'账户名称'" align="left" prop="storeNo" min-width="150">
                    <template slot-scope="scope">
                        {{ scope.row.userType == 'agent' ? scope.row.name : scope.row.storeName }}
                    </template>
                </el-table-column>

                <el-table-column :label="'账号编号'" align="left" prop="accountNo" min-width="150" />
                <el-table-column label="用户类型" align="center" prop="userType" min-width="120">
                    <template slot-scope="scope">
                        <el-tag :type="scope.row.userType == 'store'
                                ? 'success' : 'primary'
                            ">
                            {{ scope.row.userType == 'store' ? '商户' : '代理商' }}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column :label="'变动前金额'" align="center" prop="beforeAmt" />
                <el-table-column :label="'变动金额'" align="center" prop="tranAmt" />
                <el-table-column :label="'变动后金额'" align="center" prop="afterAmt" />

                <el-table-column :label="'是否收入'" align="center" prop="storeNo" min-width="150">
                    <template slot-scope="scope">
                        <el-tag :type="scope.row.isIncome == 'yes' ? 'success' : 'primary'
                            ">
                            {{ scope.row.isIncome == 'yes' ? '是（入金）' : '否（出金）' }}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column :label="'业务类型'" align="center" prop="storeNo" min-width="80">
                    <template slot-scope="scope">
                        {{ scope.row.witType == 'recharge' ? '充值' :
                            scope.row.witType == 'manual' ? '内充' :
                                scope.row.witType == 'withdrawals' ? '提现' :
                                    scope.row.witType == 'withdrawals_reject' ? '提现返还' :
                                        scope.row.witType == 'frozen' ? '冻结' :
                                            scope.row.witType == 'transfer' ? '资金划转' :
                                                scope.row.witType == 'unfrozen' ? '解冻' :
                                                    scope.row.witType == 'withdrawals_frozen' ? '冻结出款' :
                                                        scope.row.witType == 'agent_divide' ? '代理分成' :
                                                            scope.row.witType == 'income' ? '收益'
                                                                : '后台修改'
                        }}
                    </template>
                </el-table-column>

                <el-table-column :label="'备注'" align="left" prop="remarks" min-width="150"/>


                <el-table-column label="添加日期" align="left" prop="createTime" width="180" />
                <el-table-column label="修改日期" align="left" prop="updateTime" width="180" />
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div>

        <!-- 处理当前代付订单 -->
        <el-dialog v-dialogDrag :close-on-click-modal="false" title="信息" :visible.sync="isShowDetail" width="18%"
            append-to-body>
            <div class="m20">确认要处理当前代付订单？</div>
            <el-form ref="form" :model="form" :rules="rules" label-width="0px">
                <el-form-item label="" prop="googleCode">
                    <el-input v-model="form.googleCode" placeholder="请输入谷歌动态验证码" />
                </el-form-item>
            </el-form>
            <el-button type="primary" icon="" size="small" @click="submitForm('pay_success')">置为成功</el-button>
            <el-button plain size="small" @click="submitForm('pay_failure')">置为取消</el-button>
            <el-button plain size="small" @click="isShowDetail = false">取消</el-button>
        </el-dialog>
    </div>
</template>

<script>
import { common_api, capitalDtlList } from "@/api/form";

export default {
    name: "PkAdWeiList",
    dicts: ['capital_type', 'audit_status'],
    data() {
        return {
            sum: {
                incomeTotal: 0,
                expendTotal: 0
            },
            userCon: [
                {
                    label: '商户',
                    value: 'store',
                },
                {
                    label: '代理商',
                    value: 'agent',
                },
            ],
            typeCon: [
                {
                    label: '收入',
                    value: '1',
                },
                {
                    label: '支出',
                    value: '0',
                }
            ],
            detailData: {},
            isShowDetail: false,
            pickerOptions: {
                shortcuts: [
                    {
                        text: '最近一天',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', [start, end]);
                        }
                    },
                    {
                        text: '最近三天',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 3);
                            picker.$emit('pick', [start, end]);
                        }
                    },
                    {
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    },
                    {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    },
                    {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30 * 3);
                            picker.$emit('pick', [start, end]);
                        }
                    },
                    {
                        text: '最近半年',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30 * 6);
                            picker.$emit('pick', [start, end]);
                        }
                    },
                    {
                        text: '最近一年',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30 * 12);
                            picker.$emit('pick', [start, end]);
                        }
                    },
                    {
                        text: '最近两年',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30 * 24);
                            picker.$emit('pick', [start, end]);
                        }
                    },
                    {
                        text: '最近三年',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30 * 36);
                            picker.$emit('pick', [start, end]);
                        }
                    },
                ]
            },
            userLevType: [

            ],
            sortLevType: [],
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            dateRange: [],
            // 新增广告图片地址
            imageUrl: "",
            // 遮罩层
            loading: true,
            // 导出遮罩层
            exportLoading: false,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 广告表格数据
            infoList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                storeName: null,
                accountNo: null,
                isIncome: null,
                witType: null,
                userType: null,
                witNo: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                positionName: [
                    { required: true, message: "请输入广告名称", trigger: "blur" },
                ]
            }
        };
    },
    created() {
        this.getList();
        this.init();
    },
    methods: {
         /** 导出按钮操作 */
         handleExport() {
            const queryParams = this.queryParams;
            this.$confirm("是否确认导出资金流水?", "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(function () {
                    return capitalDtlList.export(queryParams);
                })
                .then((response) => {
                    this.download(response.msg);
                    this.queryParams.pageNum = 1;
                    this.queryParams.pageSize = 20;
                });
        },
        /** 手工处理 */
        handleOrder(row) {
            this.reset()
            this.detailData = row
            this.isShowDetail = true
        },
        // 通知
        handleSay() {
            this.loading = true;
            capitalDtlList.reissueNotice(this.ids[0]).then((response) => {
                if (response.code == 200) {
                    this.$message.success('补发成功')
                    this.loading = false;
                }
            }).catch(() => {
                this.loading = false;
            });
        },
        init() {
            common_api.payChannelAll().then((response) => {
                this.userLevType = response.data
            });
            common_api.payTypeAll().then((response) => {
                this.sortLevType = response.data
            });
        },

        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.storeId)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        getList() {
            this.loading = true;
            capitalDtlList
                .listInfo(this.addSESDateRange(this.queryParams, this.dateRange))
                .then((response) => {
                    if (response.data) {
                        this.sum = response.data
                    }
                    this.infoList = response.rows;
                    this.total = Number(response.total);
                    this.loading = false;
                });
        },
        // 取消按钮
        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();
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加广告位信息";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids;
            pkUserInfo.getInfo(id).then((response) => {
                this.form = response.data;
                this.open = true;
                this.title = "修改广告位信息";
            });
        },
        /** 提交按钮 */
        submitForm(type) {
            if (!this.form.googleCode) {
                this.$message.error('请输入谷歌动态验证码')
                return;
            }
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    const loading = this.$loading({
                        lock: true,
                        text: `正在手动处理`,
                        spinner: "el-icon-loading",
                        background: "rgba(0, 0, 0, 0.7)",
                    });
                    let form = {
                        id: this.detailData.id,
                        status: type,
                        googleCode: this.form.googleCode
                    }
                    capitalDtlList.platform_payment_handle(form).then((response) => {
                        loading.close();
                        this.isShowDetail = false;
                        this.msgSuccess("处理成功");
                        this.getList();
                    }).catch(() => {
                        loading.close();
                        this.isShowDetail = false;
                    })
                }
            });
        },

    },
};
</script>
<style scoped lang="scss">
::v-deep .el-form-item {
  margin-bottom: 16px;
}
::v-deep .el-dialog__body {
    padding: 20px 20px;
}

::v-deep .el-dialog__headerbtn {
    top: 10px;
}

::v-deep .el-dialog__header {
    background: #F8F8F8;
    padding: 8px;

    .el-dialog__title {
        font-size: 14px;
    }
}

::v-deep .el-dialog:not(.is-fullscreen) {
    margin-top: 33vh !important;
}
</style>
