<template>
    <hc-card-item class="hc-test-sample-card-item">
        <template #header>
            <div class="w-200px">
                <el-select v-model="searchForm.contractId" placeholder="选择合同段" filterable clearable block>
                    <el-option label="测试1" value="1" />
                    <el-option label="测试2" value="2" />
                </el-select>
            </div>
            <div class="ml-2 w-150px">
                <el-date-picker v-model="searchForm.date" class="block" type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD" clearable placeholder="入库时间" />
            </div>
            <div class="ml-2 w-250px">
                <hc-search-input v-model="searchForm.queryValue" @search="searchClick" />
            </div>
        </template>
        <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" :index-style="{ width: 60 }">
            <template #action="{ row }">
                <el-link type="primary" @click="reportsShow(row)">创建报告</el-link>
                <el-link type="warning" @click="detectionShow(row)">等待检测</el-link>
            </template>
        </hc-table>
        <template #action>
            <hc-pages :pages="searchForm" @change="pageChange" />
        </template>

        <!-- 创建报告 / 等待检测 -->
        <hc-new-dialog v-model="rowActionModal" is-footer-center :title="rowActionTitle" widths="40rem" @close="rowActionModalClose">
            <el-form ref="formRef" :model="formModel" :rules="formRules" label-position="top" label-width="auto">
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="委托单位：" prop="key1">
                            <el-input v-model="formModel.key1" placeholder="委托单位" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="委托单位名称：" prop="key2">
                            <el-input v-model="formModel.key2" placeholder="委托单位名称" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="取样名称：" prop="key3">
                            <el-input v-model="formModel.key3" placeholder="取样名称" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="取样数量：" prop="key4">
                            <el-input v-model="formModel.key4" placeholder="取样数量" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="样品编号：" prop="key5">
                            <el-input v-model="formModel.key5" placeholder="样品编号" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="试验数量：" prop="key6">
                            <el-input v-model="formModel.key6" placeholder="试验数量" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="规格型号：" prop="key7">
                            <el-input v-model="formModel.key7" placeholder="规格型号" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="计算单位：" prop="key8">
                            <el-input v-model="formModel.key8" placeholder="计算单位" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col v-if="rowActionTitle === '等待检测'" :span="24">
                        <el-form-item label="试验检测时间：" prop="key9">
                            <el-date-picker v-model="formModel.key9" class="block" type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <el-button @click="rowActionModalClose">取消</el-button>
                <el-button hc-btn type="primary" @click="rowActionSave">创建</el-button>
            </template>
        </hc-new-dialog>
    </hc-card-item>
</template>

<script setup>
import { onMounted, ref, watch } from 'vue'
import { useAppStore } from '~src/store'
import { getObjValue } from 'js-fast-way'

//参数
const props = defineProps({
    tree: {
        type: Object,
        default: () => ({}),
    },
})

//变量
const store = useAppStore()
const projectId = ref(store.getProjectId)
const contractId = ref(store.getContractId)

//渲染完成
onMounted(() => {

})

//监听数据
const treeInfo = ref({})
watch(() => props.tree, (obj) => {
    treeInfo.value = getObjValue(obj)
})

//搜索表单
const searchForm = ref({ current: 1, size: 20, total: 0 })

//搜索
const searchClick = () => {
    searchForm.value.current = 1
    getTableData()
}

//分页被点击
const pageChange = ({ current, size }) => {
    searchForm.value.current = current
    searchForm.value.size = size
    getTableData()
}

//表格数据
const tableColumn = ref([
    { key: 'key1', name: '取样名称' },
    { key: 'key2', name: '规格型号', align: 'center' },
    { key: 'key3', name: '试样数量', align: 'center' },
    { key: 'key4', name: '计算单位', align: 'center' },
    { key: 'key5', name: '拟用部位' },
    { key: 'key6', name: '代表数量', align: 'center' },
    { key: 'key7', name: '取样人', align: 'center' },
    { key: 'key8', name: '入库时间', align: 'center' },
    { key: 'action', name: '操作', width: 150, align: 'center' },
])
const tableData = ref([
    {},
])

//获取表格数据
const tableLoading = ref(false)
const getTableData = async () => {

}

//表单数据
const formRef = ref(null)
const formModel = ref({})
const formRules = {
    meterPeriodId: {
        required: true,
        trigger: 'blur',
        message: '请选择计量期',
    },
}

//弹窗
const rowActionModal = ref(false)
const rowActionTitle = ref('')

//创建报告
const reportsShow = (row) => {
    formModel.value = row
    rowActionTitle.value = '创建报告'
    rowActionModal.value = true
}

//等待检测
const detectionShow = (row) => {
    formModel.value = row
    rowActionTitle.value = '等待检测'
    rowActionModal.value = true
}

//提交保存
const rowActionSave = async () => {
    const title = rowActionTitle.value
    console.log(title)
    rowActionModalClose()
}

//关闭弹窗
const rowActionModalClose = () => {
    rowActionModal.value = false
    formModel.value = {}
    rowActionTitle.value = ''
}
</script>
