<template>
    <div class="app-container">
        <el-row>
            <el-col :span="22">
                <!-- 搜索表单 -->
                <el-form ref="queryFormRef" :model="queryParams" :inline="true">
                    <el-form-item prop="coinSymbol">
                        <el-tooltip
                            content="请输入交易币标识搜索"
                            placement="bottom"
                            effect="light"
                        >
                            <el-input
                                v-model="queryParams.coinSymbol"
                                placeholder="请输入交易币标识搜索"
                                style="width: 260px"
                                clearable
                                @keyup.enter="handleQuery"
                            />
                        </el-tooltip>
                    </el-form-item>
                    <!-- <el-form-item prop="orderId">
                        <el-tooltip
                            content="请输入订单ID搜索"
                            placement="bottom"
                            effect="light"
                        >
                            <el-input
                                v-model="queryParams.orderId"
                                placeholder="请输入订单ID搜索"
                                style="width: 260px"
                                clearable
                                @keyup.enter="handleQuery"
                            />
                        </el-tooltip>
                    </el-form-item> -->
                    <el-form-item prop="enable" v-show="searchBox.expand">
                        <span>已开启：</span>
                        <el-select
                            v-model="queryParams.enable"
                            class="filter-item"
                            placeholder="请选择"
                            style="width: 110px"
                        >
                            <el-option
                                v-for="(key, value) in state.enableMap"
                                :key="key"
                                :label="key"
                                :value="value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item prop="enableBuy" v-show="searchBox.expand">
                        <span>允许买：</span>
                        <el-select
                            v-model="queryParams.enableBuy"
                            class="filter-item"
                            placeholder="请选择"
                            style="width: 110px"
                        >
                            <el-option
                                v-for="(key, value) in state.enableBuyMap"
                                :key="key"
                                :label="key"
                                :value="value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item
                        prop="enableMarketBuy"
                        v-show="searchBox.expand"
                    >
                        <span>启用市价买：</span>
                        <el-select
                            v-model="queryParams.enableMarketBuy"
                            class="filter-item"
                            placeholder="请选择"
                            style="width: 110px"
                        >
                            <el-option
                                v-for="(key, value) in state.enableMarketBuyMap"
                                :key="key"
                                :label="key"
                                :value="value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item
                        prop="enableMarketSell"
                        v-show="searchBox.expand"
                    >
                        <span>启用市价卖：</span>
                        <el-select
                            v-model="queryParams.enableMarketSell"
                            class="filter-item"
                            placeholder="请选择"
                            style="width: 110px"
                        >
                            <el-option
                                v-for="(
                                    key, value
                                ) in state.enableMarketSellMap"
                                :key="key"
                                :label="key"
                                :value="value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item prop="enableSell" v-show="searchBox.expand">
                        <span>允许卖：</span>
                        <el-select
                            v-model="queryParams.enableSell"
                            class="filter-item"
                            placeholder="请选择"
                            style="width: 110px"
                        >
                            <el-option
                                v-for="(key, value) in state.enableSellMap"
                                :key="key"
                                :label="key"
                                :value="value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item prop="exchangeable" v-show="searchBox.expand">
                        <span>可交易：</span>
                        <el-select
                            v-model="queryParams.exchangeable"
                            class="filter-item"
                            placeholder="请选择"
                            style="width: 110px"
                        >
                            <el-option
                                v-for="(key, value) in state.exchangeableMap"
                                :key="key"
                                :label="key"
                                :value="value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item prop="flag" v-show="searchBox.expand">
                        <span>推荐：</span>
                        <el-select
                            v-model="queryParams.flag"
                            class="filter-item"
                            placeholder="请选择"
                            style="width: 110px"
                        >
                            <el-option
                                v-for="(key, value) in state.flagMap"
                                :key="key"
                                :label="key"
                                :value="value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item prop="sort">
                        <span>排列顺序：</span>
                        <el-select
                            v-model="queryParams.sort"
                            class="filter-item"
                            placeholder="请选择"
                            style="width: 110px"
                        >
                            <el-option
                                v-for="(key, value) in state.sortMap"
                                :key="key"
                                :label="key"
                                :value="value"
                            />
                        </el-select>
                    </el-form-item>

                    <el-form-item>
                        <el-button
                            type="primary"
                            :icon="Search"
                            @click="handleQuery"
                            >搜索</el-button
                        >
                        <el-button :icon="Refresh" @click="resetQuery"
                            >重置</el-button
                        >
                        <el-button
                            link
                            @click="closeSearch"
                            style="border: 0"
                            size="small"
                        >
                            {{ searchBox.title }}
                            <template v-if="searchBox.expand"
                                ><el-icon class="el-icon--right"
                                    ><ArrowUp /></el-icon
                            ></template>
                            <template v-else
                                ><el-icon class="el-icon--right"
                                    ><ArrowDown /></el-icon
                            ></template>
                        </el-button>
                    </el-form-item>
                </el-form>
            </el-col>
            <el-col :span="2">
                <el-button type="success" @click="coinOperateFun('add')"
                    >添加交易对</el-button
                >
            </el-col>
        </el-row>
        <el-table
            :data="listdata"
            v-loading="state.loading"
            highlight-current-row
            border
        >
            <el-table-column
                align="center"
                prop="symbol"
                label="交易对标识"
                min-width="100"
            />
            <el-table-column
                align="center"
                prop="baseSymbol"
                label="基准币标识"
            />
            <el-table-column
                align="center"
                prop="coinSymbol"
                label="交易币标识"
            />
            <el-table-column align="center" prop="zone" label="地区" />
            <el-table-column align="center" prop="fee" label="交易手续费">
                <template #default="scope">{{ scope.row?.fee }} </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="maxBuyPrice"
                label="最高买单价"
            >
                <template #default="scope">
                    {{ truncation(scope.row.maxBuyPrice) }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="maxTradingOrder"
                label="最大允许同时交易的订单数"
                min-width="170"
            >
                <template #default="scope">
                    {{ scope.row.maxTradingOrder || "无限制" }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="maxTradingTime"
                label="委托超时自动下架时间"
                min-width="150"
            >
                <template #default="scope">
                    {{ scope.row.maxTradingTime || "永不过期" }}
                </template>
            </el-table-column>
            <el-table-column align="center" prop="maxVolume" label="最大下单量">
                <template #default="scope">
                    {{ truncation(scope.row.maxVolume) }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="minSellPrice"
                label="最低挂单卖价"
                min-width="100"
            >
                <template #default="scope">
                    {{ truncation(scope.row.minSellPrice) }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="minTurnover"
                label="最小挂单成交额"
                min-width="110"
            >
                <template #default="scope">
                    {{ truncation(scope.row.minTurnover) }}
                </template>
            </el-table-column>
            <el-table-column align="center" prop="minVolume" label="最小下单量">
                <template #default="scope">
                    {{ truncation(scope.row.minVolume) }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="publishAmount"
                label="活动发行数量"
                min-width="100"
            >
                <template #default="scope">
                    {{ truncation(scope.row.publishAmount) }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="publishPrice"
                label="分摊发行价格"
                min-width="100"
            >
                <template #default="scope">
                    {{ truncation(scope.row.publishPrice) }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="robotType"
                label="机器人类型"
            />

            <el-table-column align="center" prop="sellFee" label="卖手续费">
            </el-table-column>
            <el-table-column
                align="center"
                prop="visible"
                label="前台可见状态"
                min-width="100"
            />
            <el-table-column
                align="center"
                prop="instrument"
                label="交易类型"
            />
            <el-table-column
                align="center"
                prop="startTime"
                label="开始时间"
                min-width="130"
            >
                <template #default="scope">
                    {{ timestampToTime(scope.row.startTime) }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="endTime"
                label="结束时间"
                min-width="130"
            >
                <template #default="scope">
                    {{ timestampToTime(scope.row.endTime) }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="clearTime"
                label="清盘时间"
                min-width="130"
            >
                <template #default="scope">
                    {{ timestampToTime(scope.row.clearTime) }}
                </template>
            </el-table-column>
            <el-table-column align="center" prop="direction" label="开启">
                <template #default="scope">
                    {{ state.enableMap[scope.row.enable] }}
                </template>
            </el-table-column>
            <el-table-column align="center" prop="enableBuy" label="允许买">
                <template #default="scope">
                    {{ state.enableBuyMap[scope.row.enableBuy] }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="enableMarketBuy"
                label="启用市价买"
            >
                <template #default="scope">
                    {{ state.enableMarketBuyMap[scope.row.enableMarketBuy] }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="enableMarketSell"
                label="启用市价卖"
            >
                <template #default="scope">
                    {{ state.enableMarketSellMap[scope.row.enableMarketSell] }}
                </template>
            </el-table-column>
            <el-table-column align="center" prop="enableSell" label="允许卖">
                <template #default="scope">
                    {{ state.enableSellMap[scope.row.enableSell] }}
                </template>
            </el-table-column>
            <el-table-column align="center" prop="exchangeable" label="可交易">
                <template #default="scope">
                    {{ state.exchangeableMap[scope.row.exchangeable] }}
                </template>
            </el-table-column>
            <el-table-column align="center" prop="flag" label="推荐">
                <template #default="scope">
                    {{ state.flagMap[scope.row.flag] }}
                </template>
            </el-table-column>
            <el-table-column
                align="center"
                prop="publishType"
                label="发行活动类型"
                min-width="100"
            >
                <template #default="scope">
                    {{ state.publishTypeMap[scope.row.publishType] }}
                </template>
            </el-table-column>
            <el-table-column
                fixed="right"
                align="center"
                prop="publishType"
                label="操作"
                min-width="150"
            >
                <template #default="scope">
                    <el-button
                        type="primary"
                        @click="coinOperateFun('update', scope.row)"
                        >修改</el-button
                    >
                    <el-button type="danger" @click="delectCoin(scope.row.id)"
                        >删除</el-button
                    >
                </template>
            </el-table-column>
        </el-table>
        <el-dialog
            v-model="coinOperate.coinOperateStatus"
            :title="coinOperate.coinOperateTitle"
            width="800"
        >
            <el-form ref="operateFromRef" :model="operateFrom" :inline="true">
                <el-form-item prop="symbol" label="币标识">
                    <el-tooltip
                        content="请输入币标识"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.symbol"
                            placeholder="请输入币标识"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="baseSymbol" label="基准币标识">
                    <el-tooltip
                        content="请输入基准币标识"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.baseSymbol"
                            placeholder="请输入基准币标识"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="baseCoinScale" label="基准币比例">
                    <el-tooltip
                        content="请输入基准币比例"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.baseCoinScale"
                            placeholder="请输入基准币比例"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="coinSymbol" label="交易币标识">
                    <el-tooltip
                        content="请输入交易币标识"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.coinSymbol"
                            placeholder="请输入交易币标识"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="coinScale" label="交易币比例">
                    <el-tooltip
                        content="请输入交易币比例"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.coinScale"
                            placeholder="请输入交易币比例"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="fee" label="交易手续费">
                    <el-tooltip
                        content="请输入交易手续费"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.fee"
                            placeholder="请输入交易手续费"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="maxBuyPrice" label="最高买单价">
                    <el-tooltip
                        content="请输入最高买单价"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.maxBuyPrice"
                            placeholder="请输入最高买单价"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item
                    prop="maxTradingOrder"
                    label="最大允许同时交易的订单数"
                >
                    <el-tooltip
                        content="最大允许同时交易的订单数，0表示不限制"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.maxTradingOrder"
                            placeholder="请输入订单数"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item
                    prop="maxTradingTime"
                    label="委托超时自动下架时间"
                >
                    <el-tooltip
                        content="委托超时自动下架时间，单位为秒，0表示不过期"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.maxTradingTime"
                            placeholder="请输入委托超时自动下架时间"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="maxVolume" label="最大下单量">
                    <el-tooltip
                        content="请输入最大下单量"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.maxVolume"
                            placeholder="请输入最大下单量"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="minSellPrice" label="最低挂单卖价">
                    <el-tooltip
                        content="请输入最低挂单卖价"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.minSellPrice"
                            placeholder="请输入最低挂单卖价"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="minTurnover" label="最小挂单成交额">
                    <el-tooltip
                        content="请输入最小挂单成交额"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.minTurnover"
                            placeholder="请输入最小挂单成交额"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="minVolume" label="最小下单量">
                    <el-tooltip
                        content="请输入最小下单量"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.minVolume"
                            placeholder="请输入最小下单量"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="publishAmount" label="活动发行数量">
                    <el-tooltip
                        content="请输入活动发行数量"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.publishAmount"
                            placeholder="请输入活动发行数量"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="publishPrice" label="分摊发行价格">
                    <el-tooltip
                        content="请输入分摊发行价格"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.publishPrice"
                            placeholder="请输入分摊发行价格"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="sellFee" label="卖手续费">
                    <el-tooltip
                        content="请输入卖手续费"
                        placement="bottom"
                        effect="light"
                    >
                        <el-input
                            v-model="operateFrom.sellFee"
                            placeholder="请输入卖手续费"
                            style="width: 260px"
                            clearable
                        />
                    </el-tooltip>
                </el-form-item>
                <el-form-item prop="enable" label="已开启: ">
                    <el-select
                        v-model="operateFrom.enable"
                        class="filter-item"
                        placeholder="请选择"
                        style="width: 110px"
                    >
                        <el-option
                            v-for="(key, value) in state.enableMap"
                            :key="key"
                            :label="key"
                            :value="value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item prop="enableBuy" label="允许买: ">
                    <el-select
                        v-model="operateFrom.enableBuy"
                        class="filter-item"
                        placeholder="请选择"
                        style="width: 110px"
                    >
                        <el-option
                            v-for="(key, value) in state.enableBuyMap"
                            :key="key"
                            :label="key"
                            :value="value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item prop="enableMarketBuy" label="启用市价买：">
                    <el-select
                        v-model="operateFrom.enableMarketBuy"
                        class="filter-item"
                        placeholder="请选择"
                        style="width: 110px"
                    >
                        <el-option
                            v-for="(key, value) in state.enableMarketBuyMap"
                            :key="key"
                            :label="key"
                            :value="value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item prop="enableMarketSell" label="启用市价卖：">
                    <el-select
                        v-model="operateFrom.enableMarketSell"
                        class="filter-item"
                        placeholder="请选择"
                        style="width: 110px"
                    >
                        <el-option
                            v-for="(key, value) in state.enableMarketSellMap"
                            :key="key"
                            :label="key"
                            :value="value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item prop="enableSell" label="允许卖: ">
                    <el-select
                        v-model="operateFrom.enableSell"
                        class="filter-item"
                        placeholder="请选择"
                        style="width: 110px"
                    >
                        <el-option
                            v-for="(key, value) in state.enableSellMap"
                            :key="key"
                            :label="key"
                            :value="value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item prop="exchangeable" label="可交易：">
                    <el-select
                        v-model="operateFrom.exchangeable"
                        class="filter-item"
                        placeholder="请选择"
                        style="width: 110px"
                    >
                        <el-option
                            v-for="(key, value) in state.exchangeableMap"
                            :key="key"
                            :label="key"
                            :value="value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item prop="flag" label="推荐:">
                    <el-select
                        v-model="operateFrom.flag"
                        class="filter-item"
                        placeholder="请选择"
                        style="width: 110px"
                    >
                        <el-option
                            v-for="(key, value) in state.flagMap"
                            :key="key"
                            :label="key"
                            :value="value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item prop="sort" label="排序:">
                    <el-select
                        v-model="operateFrom.sort"
                        class="filter-item"
                        placeholder="请选择"
                        style="width: 110px"
                    >
                        <el-option
                            v-for="(key, value) in state.sortMap"
                            :key="key"
                            :label="key"
                            :value="value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item prop="publishType" label="发行活动类型:">
                    <el-select
                        v-model="operateFrom.publishType"
                        class="filter-item"
                        placeholder="请选择"
                        style="width: 110px"
                    >
                        <el-option
                            v-for="(key, value) in state.publishTypeMap"
                            :key="key"
                            :label="key"
                            :value="value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button
                        type="primary"
                        @click="
                            sumbitOperate(state.coinOperate.coinOperateTitle)
                        "
                        >确认</el-button
                    >
                    <el-button type="danger" @click="close">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <pagination
            v-if="state.total > 0"
            :total="state.total"
            v-model:page="state.queryParams.currentPage"
            v-model:limit="state.queryParams.pageSize"
            @pagination="handleQuery"
        />
    </div>
</template>
<script lang="ts">
name: "documentaryRecord";
</script>
<script lang="ts" setup>
import { CoinsQueryForm, CoinsPageResult } from "../../../types/api/coinspot";
import { BaseResult } from "../../../types/api/base";
import {
    exchange_coins,
    exchange_coin_add,
    exchange_coin_delete,
    exchange_coin_update,
} from "../../../api/coinSpot";
import { timestampToTime, truncation } from "@/utils/filter";
import { reactive, onMounted, toRefs, ref } from "vue";
import { Search, Refresh, ArrowUp, ArrowDown } from "@element-plus/icons-vue";
import { ElForm, ElMessage } from "element-plus";

const queryFormRef = ref(ElForm);
const operateFromRef = ref(ElForm);
const state = reactive({
    loading: true,
    total: 0,
    queryParams: {
        baseSymbol: "",
        // coinSymbol: "",
        currentPage: 1,
        // enable: 0,
        // enableBuy: 0,
        // enableMarketBuy: 0,
        // enableMarketSell: 0,
        // enableSell: 0,
        // exchangeable: 0,
        // flag: 0,
        pageSize: 15,
        // sort: 0,
        // symbol: "string",
        // zone: 0,
    } as CoinsQueryForm,
    operateFrom: {} as CoinsPageResult,
    listdata: [] as CoinsPageResult[],
    searchBox: {
        title: "展开搜索",
        expand: false,
    },
    enableMap: {
        "1": "是",
        "0": "否",
    },
    enableBuyMap: {
        "1": "是",
        "0": "否",
    },
    enableMarketBuyMap: {
        "1": "是",
        "0": "否",
    },
    enableMarketSellMap: {
        "1": "是",
        "0": "否",
    },
    enableSellMap: {
        "1": "是",
        "0": "否",
    },
    exchangeableMap: {
        "1": "是",
        "0": "否",
    },
    flagMap: {
        "1": "推荐",
        "0": "默认",
    },
    sortMap: {
        "1": "asc",
        "2": "desc",
    },
    publishTypeMap: {
        "1": "无活动",
        "2": "抢购发行",
        "3": "分摊发行",
    },
    coinOperate: {
        coinOperateStatus: false,
        coinOperateTitle: "新增",
    },
});
const { listdata, queryParams, searchBox, coinOperate, operateFrom } =
    toRefs(state);
const handleQuery = () => {
    exchange_coins(state.queryParams).then((res: any) => {
        state.listdata = res.data.records;
        state.total = res.data.total;
        state.loading = false;
    });
};

/**
 * 展开/收起搜索
 */
const closeSearch = () => {
    state.searchBox.expand = !state.searchBox.expand;
    state.searchBox.title = !state.searchBox.expand ? "展开搜索" : "收起搜索";
};

const coinOperateFun = (index: string, row?: CoinsPageResult) => {
    state.coinOperate.coinOperateStatus = true;
    state.coinOperate.coinOperateTitle = index == "add" ? "新增" : "修改";
    state.operateFrom = row || ({} as any);
    if (row) {
        const propertiesToCopy = [
            "enable",
            "enableBuy",
            "enableMarketBuy",
            "enableMarketSell",
            "enableSell",
            "exchangeable",
            "publishType",
            "flag",
            "sort",
            "baseCoinScale",
            "coinScale",
        ];
        propertiesToCopy.forEach((property) => {
            state.operateFrom[property] = String(row[property]) || "";
        });
    }
};

/**
 * 查询重置
 */
function resetQuery() {
    queryFormRef.value.resetFields();
    handleQuery();
}

const sumbitOperate = async (index: string) => {
    const api = index == "新增" ? exchange_coin_add : exchange_coin_update;
    const propertiesToCopy = [
        "enable",
        "enableBuy",
        "enableMarketBuy",
        "enableMarketSell",
        "enableSell",
        "exchangeable",
        "publishType",
        "flag",
        "sort",
        "baseCoinScale",
        "coinScale",
    ];
    propertiesToCopy.forEach((property) => {
        state.operateFrom[property] = Number(state.operateFrom[property]);
    });
    const data = (await api(state.operateFrom as any)) as any;
    if (data.data) {
        close();
        ElMessage.success(data.msg);
        handleQuery();
    } else {
        ElMessage.error(data.msg);
    }
};

const delectCoin = (id: number) => {
    exchange_coin_delete(id).then((res: any) => {
        if (res.data) {
            close();
            ElMessage.success(res.msg);
            handleQuery();
        } else {
            ElMessage.error(res.msg);
        }
    });
};

const close = () => {
    state.coinOperate.coinOperateStatus = false;
    operateFromRef.value.resetFields();
};

onMounted(() => handleQuery());
</script>

<style lang="less" scoped></style>
