<template>
    <div>
        <el-card class="!border-none mb-4" shadow="never">
            <el-form class="mb-[-16px]" :model="queryParams" inline>
                <el-form-item label="商品名称" prop="store_name">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.store_name"
                        clearable
                        placeholder="请输入商品名称"
                    />
                </el-form-item>
                <el-form-item label="订单id" prop="bhoid">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.bhoid"
                        clearable
                        placeholder="请输入订单id"
                    />
                </el-form-item>
                <el-form-item label="日期" prop="create_time">
                    <el-date-picker
                        v-model="startEndTime"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        unlink-panels
                        @change="changeStartEndTime"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                    <export-data
                        class="ml-2.5"
                        :fetch-fun="apiBeforehandOrderCartInfoLists"
                        :params="queryParams"
                        :page-size="pager.size"
                    />
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none" v-loading="pager.loading" shadow="never">
            <div class="mt-4">
                <el-table :data="pager.lists" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55" />
                    <el-table-column label="订单id" prop="bhoid" show-overflow-tooltip>
                        <template #default="{ row }">
                            <router-link
                                class="ml-4 text-[#63c869]"
                                :to="{ path: 'beforehand_order_details', query: { id: row.bhoid } }"
                            >
                                {{ row.bhoid }}
                            </router-link>
                        </template>
                    </el-table-column>
                    <el-table-column label="商品" prop="store_name" show-overflow-tooltip />
                    <el-table-column label="单位" prop="unit_name" show-overflow-tooltip />
                    <!-- <el-table-column label="包装" prop="package" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="型号" prop="marques" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="押金" prop="deposit" show-overflow-tooltip /> -->
                    <el-table-column label="供货价" prop="purchase" show-overflow-tooltip />
                    <el-table-column label="单价" prop="price" show-overflow-tooltip />
                    <el-table-column label="总价" prop="total_price" show-overflow-tooltip />
                    <!-- <el-table-column label="支付金额" prop="pay_price" show-overflow-tooltip /> -->
                    <el-table-column label="数量" prop="cart_num" show-overflow-tooltip />
                    <!-- <el-table-column label="验收数量" prop="accept_num" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="毛重" prop="gross_weight" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="净重" prop="net_weight" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="采购状态" prop="is_buyer_name" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="售后" prop="after_sales" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="损耗" prop="loss" show-overflow-tooltip /> -->
                    <el-table-column label="备注" prop="mark" show-overflow-tooltip />
                    <el-table-column label="创建时间" prop="create_time" show-overflow-tooltip />
                </el-table>
            </div>
            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>

<script lang="ts" setup name="beforehandOrderCartInfoLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import {
    apiBeforehandOrderCartInfoLists,
    apiBeforehandOrderCartInfoDelete
} from '@/api/beforehand_order_cart_info'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import moment from 'moment'

// 查询条件
const queryParams = reactive({
    store_name: '',
    bhoid: '',
    start_time: '',
    end_time: ''
})

// 选中数据
const selectData = ref<any[]>([])

// 表格选择后回调事件
const handleSelectionChange = (val: any[]) => {
    selectData.value = val.map(({ id }) => id)
}

const startEndTime = ref([])

const changeStartEndTime = () => {
    if (startEndTime.value[0] && startEndTime.value[1]) {
        queryParams.start_time = moment(startEndTime.value[0]).format('YYYY-MM-DD') + ' 00:00:00'
        queryParams.end_time = moment(startEndTime.value[1]).format('YYYY-MM-DD') + ' 23:59:59'
    } else {
        queryParams.start_time = ''
        queryParams.end_time = ''
    }
    getLists()
}

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiBeforehandOrderCartInfoLists,
    params: queryParams
})

onMounted(() => {
    getLists()
})
</script>
