<script setup lang="ts">
    import { ref } from 'vue'
    import PagingComponent from 'components/PagingComponent/index.vue'
    import { useRouter } from 'vue-router'
    import { getOrderListApi } from 'http/api/usercenter/seekorder'
    const queryParams = ref({})
    const router = useRouter()
    const pageSize = 20
    const pageNumber = 1
    const total: any = ref(0)

    // 获取数据列表
    const getList = async () => {
        const res: any = await getOrderListApi()
        console.log('获取数据列表***', res)
        tableData.value = res.rows
        total.value = res.total
    }

    getList()

    // 查询按钮
    const queryTableList = () => {
        getList()
    }

    const tableData = ref([])

    /* 退租按钮 */
    const clickRentingTermination = () => {
        router.push({ name: 'rentinTermination' })
        console.log('退租')
    }

    /* 查看按钮 */
    const clickPreviewDetails = (row: any) => {
        console.log('查看', row)
        router.push({
            name: 'orderDetails',
            query: {
                orderId: row.orderId
            }
        })
    }

    /* 续租按钮 */
    const clickRenewalOfLease = ({ row }: any) => {
        console.log('续租', row)
        router.push({
            name: 'renewalOfLease',
            query: {
                orderId: row.orderId
            }
        })
    }

    /* 确认收货 */
    const clickConfirmReceipt = (row: any) => {
        console.log('确认收货')
        router.push({
            name: 'orderDetails',
            query: {
                orderId: row.orderId,
                confirm: 'true'
            }
        })
    }

    const time = ref([])
</script>

<template>
    <!-- 订单管理 -->
    <el-form :model="queryParams" :inline="true" size="small">
        <el-form-item label="订单编号：" prop="menuName">
            <el-input />
        </el-form-item>
        <el-form-item label="创建时间：" prop="menuName">
            <el-date-picker
                v-model="time"
                type="daterange"
                unlink-panels
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                style="width: 180px" />
        </el-form-item>
        <el-form-item label="状态：" prop="menuName">
            <el-input />
        </el-form-item>
        <el-form-item label="装备类型：" prop="menuName">
            <el-input />
        </el-form-item>
        <el-form-item label="装备名称：" prop="menuName">
            <el-input />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="queryTableList">查询</el-button>
            <el-button type="success">保存</el-button>
        </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table
        :data="tableData"
        style="width: 100%"
        show-overflow-tooltip
        :header-cell-style="{
            background: '#3E98FF',
            color: '#fff'
        }">
        <el-table-column align="center" prop="code" label="订单编号" />
        <el-table-column align="center" prop="supplierCompany" label="供应商" />
        <el-table-column align="center" prop="time" label="订单创建日期" />
        <el-table-column align="center" prop="payType" label="装备类型" />
        <el-table-column align="center" prop="deviceName" label="装备名称" />
        <el-table-column align="center" label="订单状态">
            <template #default="{ row }">
                <el-tag v-if="row.orderStatus == 31">待确认</el-tag>
                <el-tag v-if="row.orderStatus == 32">待合同上传</el-tag>
                <el-tag v-if="row.orderStatus == 35">待收货</el-tag>
                <el-tag v-if="row.orderStatus == 36">进行中</el-tag>
            </template>
        </el-table-column>
        <el-table-column align="left" prop="name" label="操作" width="160px">
            <template #default="scope">
                <el-button size="small" type="primary" @click="clickPreviewDetails(scope.row)">
                    查看
                </el-button>
                <el-button
                    size="small"
                    type="danger"
                    @click="clickRentingTermination"
                    v-if="scope.row.orderStatus == 36">
                    退租
                </el-button>
                <el-button
                    size="small"
                    type="warning"
                    @click="clickRenewalOfLease"
                    v-if="scope.row.orderStatus == 36">
                    续租
                </el-button>
                <el-button
                    size="small"
                    type="success"
                    @click="clickConfirmReceipt(scope.row)"
                    v-if="scope.row.orderStatus == 35">
                    确认收货
                </el-button>
            </template>
        </el-table-column>
    </el-table>

    <PagingComponent
        @getList="getList"
        :pageSize="pageSize"
        :pageNumber="pageNumber"
        :total="total" />
</template>

<style>
    .el-form {
        margin: 15px 0;
    }
</style>
