<template>
    <div class="app-container">
        <div class="search_con m-b-28">
            <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="108px">
                <el-form-item label="账户名" prop="accountName">
                    <el-input v-model="queryParams.accountName" placeholder="请输入账户名" clearable size="medium"
                        @keyup.enter.native="handleQuery" />
                </el-form-item>

                <el-form-item label="金额类型" prop="amountType">
                    <el-select v-model="queryParams.amountType" placeholder="请选择金额类型" clearable size="medium">
                        <el-option v-for="dict in amountTypeStatus" :key="dict.dictValue" :label="dict.dictLabel"
                            :value="dict.dictValue" />
                    </el-select>
                </el-form-item>

                <el-form-item label="变动来源" prop="source">
                    <el-select v-model="queryParams.source" placeholder="请选择变动来源" clearable size="medium">
                        <el-option v-for="dict in sysOrderStatus" :key="dict.dictValue" :label="dict.dictLabel"
                            :value="dict.dictValue" />
                    </el-select>
                </el-form-item>

                <el-form-item label="变动类型" prop="opType">
                    <el-select v-model="queryParams.opType" placeholder="请选择变动类型" clearable size="medium">
                        <el-option v-for="dict in sourceTypeOptions" :key="dict.dictValue" :label="dict.dictLabel"
                            :value="dict.dictValue" />
                    </el-select>
                </el-form-item>

                <el-form-item label="创建时间">
                    <el-date-picker v-model="dateRange" size="medium" 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>
                    <el-button type="primary" size="medium" @click="handleQuery">搜索</el-button>
                    <el-button size="medium" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </div>


        <div class="bg bg-white">
            <el-row :gutter="10" class="m-b-16">
                <el-col :span="1.5">
                    <el-button type="primary" size="medium" @click="handleExport">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>

            <el-table v-loading="loading" :data="otcCoinList" @selection-change="handleSelectionChange">
                <!-- <el-table-column type="selection" width="55" align="center" /> -->
                <el-table-column label="账户名" align="center" prop="accountName" />
                <el-table-column label="商户订单号" align="center" prop="merchantOrderNo" />
                <el-table-column label="业务单号" align="center" prop="businessNo" />

                <el-table-column :label="'变动金额'" align="center" prop="changeAmount">
                    <template slot-scope="scope">
                        {{ scope.row.changeAmount }}
                    </template>
                </el-table-column>
                <el-table-column :label="'变动后余额'" align="center" prop="afterBalance">
                    <template slot-scope="scope">
                        {{ scope.row.afterBalance }}
                    </template>
                </el-table-column>

                <el-table-column label="金额类型" align="center" prop="amountType" :formatter="amountTypeFormat" />
                <el-table-column label="变动类型" align="center" prop="opType" :formatter="sourceTypeFormat" />
                <el-table-column label="订单状态" align="center" prop="orderStatus" :formatter="sysOrderStatusFormat" />
                <el-table-column label="备注" align="center" prop="remark" />

                <el-table-column label="创建时间" align="center" prop="createTime" min-width="180" />


            </el-table>

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



    </div>
</template>
  
<script>
import { merchantWalletLog, common_api } from "@/api/form";
export default {
    name: "otcStoreRechargeOrder",
    components: {
    },
    data() {
        return {
            // 所有商户
            merchantCon: [],
            dateRange: [],
            sourceTypeOptions: [],
            sysOrderStatus: [],
            amountTypeStatus: [],

            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // OTC币种表格数据
            otcCoinList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            openTest: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                accountName: null,
                source: null,
                opType: null,
                amountType: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
            },
        };
    },
    created() {
        this.getList();
        this.getDicts("amount_type").then(response => {
            this.amountTypeStatus = response.data;
            this.amountTypeStatus.unshift({
                dictLabel: '全部',
                dictValue: null,
            });
        });
        this.getDicts("op_type").then(response => {
            this.sourceTypeOptions = response.data;
            this.sourceTypeOptions.unshift({
                dictLabel: '全部',
                dictValue: null,
            });
        });
        this.getDicts("source_type_finance").then(response => {
            this.sysOrderStatus = response.data;
            this.sysOrderStatus.unshift({
                dictLabel: '全部',
                dictValue: null,
            });
        });
    },
    methods: {
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 查询OTC币种列表 */
        getList() {
            this.loading = true;
            merchantWalletLog.listInfo(this.addSESDateRange(this.queryParams, this.dateRange)).then(response => {
                this.otcCoinList = response.rows;
                this.total = Number(response.total);
                this.loading = false;
            });
        },
        sourceTypeFormat(row, column) {
            return this.selectDictLabel(this.sourceTypeOptions, row.opType);
        },
        sysOrderStatusFormat(row, column) {
            return this.selectDictLabel(this.sysOrderStatus, row.source);
        },
        amountTypeFormat(row, column) {
            return this.selectDictLabel(this.amountTypeStatus, row.amountType);
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.openTest = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm("queryForm");
            this.handleQuery();
        },

        /** 导出按钮操作 */
        handleExport() {
            const queryParams = this.queryParams;
            this.$confirm('是否确认导出所有数据项?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return merchantWalletLog.exportList(queryParams);
            }).then(response => {
                this.download(response.msg);
            })
        }
    }
};
</script>
  