<template>
    <div>
        <el-card class="!border-none" shadow="never">
            <el-form class="mb-[-16px]" :model="queryParams" inline>
                <el-form-item label="查询" prop="name">
                    <el-input class="w-[280px]" v-model="queryParams.name" clearable placeholder="请输入内容" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </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" @cell-click="handleCurrentChange">
                    <el-table-column type="selection" width="55" />
                    <el-table-column label="序号" type="index" width="55" />
                    <el-table-column label="项目名称" prop="project_name" show-overflow-tooltip />
                    <el-table-column label="供应商名称" prop="supplier_name" show-overflow-tooltip />

                    <el-table-column label="合同编号" prop="contract_no" show-overflow-tooltip />
                    <el-table-column label="合同名称" prop="contract_name" show-overflow-tooltip />

                    <el-table-column label="合同类型" prop="contract_type">
                        <template #default="{ row }">
                            <dict-value :options="dictData.procurement_contract_type" :value="row.contract_type" />
                        </template>
                    </el-table-column>
                    <el-table-column label="签订日期" prop="signing_date" show-overflow-tooltip />
                    <el-table-column label="付款方式" prop="pay_type" show-overflow-tooltip />
                    <el-table-column label="账期" prop="account_period">
                        <template #default="{ row }">
                            <dict-value :options="dictData.account_period" :value="row.account_period" />
                        </template>
                    </el-table-column>
                    <el-table-column label="合同金额" prop="amount" show-overflow-tooltip />
                    <el-table-column label="金额大写" prop="amount_daxie" show-overflow-tooltip />
                    <el-table-column label="税率" prop="tax_rate">
                        <template #default="{ row }">
                            <dict-value :options="dictData.tax_rate" :value="row.tax_rate" />
                        </template>
                    </el-table-column>
                    <el-table-column label="不含税金额" prop="amount_excluding_tax" show-overflow-tooltip />
                    <el-table-column label="质保金比例" prop="retention_money" show-overflow-tooltip />
                    <el-table-column label="质保金" prop="retention_money_rate" show-overflow-tooltip />
                </el-table>

            </div>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>
  
<script lang="ts" setup>
import { usePaging } from "@/hooks/usePaging"
import { useDictData } from "@/hooks/useDictOptions"
import { apiSubcontractingContractLists } from '@/api/subcontracting_contract'
import { defineEmits, defineProps } from "vue"
const props = defineProps({
    project_id: Number
})

// 查询条件
const queryParams = reactive({
    name: '',
    project_id: props.project_id
});

const { dictData } = useDictData('procurement_contract_type,account_period,tax_rate,pay_type,pay_period ')
// 选中数据
const emits = defineEmits(["customEvent"]);

// 选中数据子父传递
const handleCurrentChange = (value: any) => {
    emits("customEvent", value);
};

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

getLists();
</script>