<template>
    <div class="app-container">
        <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="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item label="金额类型" prop="amountType">
                <el-select v-model="queryParams.amountType" placeholder="请选择金额类型" clearable size="small">
                    <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="small">
                    <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="small">
                    <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="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>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="otcCoinList">
            <el-table-column label="商户id" align="center" prop="merchantId" />
            <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">
                    {{ (NumberDiv(scope.row.changeAmount, 100)) }}
                </template>
            </el-table-column>
            <el-table-column :label="'变动后余额'" align="center" prop="afterBalance">
                <template slot-scope="scope">
                    {{ (NumberDiv(scope.row.afterBalance, 100)) }}
                </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-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="small" type="text" style="color: #006EFF;" v-if="scope.row.orderStatus == 1"
                        @click="handleOrder(scope.row)">手工处理</el-button>
                </template>
            </el-table-column> -->
        </el-table>

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




    </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.getDicts("op_type").then(response => {
            this.sourceTypeOptions = response.data;
        });
        this.getDicts("source_type_finance").then(response => {
            this.sysOrderStatus = response.data;
        });
    },
    methods: {
        init() {

        },
        /** 手工处理 */
        handleOrder(row) {
            this.reset()
            this.form = row
            this.open = true
        },
        /** 查询OTC币种列表 */
        getList() {
            this.loading = true;
            let queryParams = {
                pageNum: this.queryParams.pageNum,
                pageSize: this.queryParams.pageSize,
                accountName: this.queryParams.accountName,
                source: this.queryParams.source,
                opType: this.queryParams.opType,
                amountType: this.queryParams.amountType,
            }
            merchantWalletLog.listInfo(this.addSESDateRange(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;
            // let changeAmount;
            // this.queryParams.changeAmount ? changeAmount = this.NumberMul(this.queryParams.changeAmount, 100) : changeAmount = null
            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>
  