<template>
    <z-paging class="" ref="paging" bgColor="#fff" paging-class="paging-btm-shadow" safe-area-inset-bottom scroll-with-animation>
        <template #top>
            <ut-navbar :title="did ? '编辑种源入库信息' : '添加种源入库信息'" :fixed="false" border></ut-navbar>
        </template>
        <view class="pd-24">
            <up-form class="p-rtv" labelPosition="top" :model="form" :rules="rules" labelWidth="auto" ref="upFormRef">
                <!-- 基本信息 -->
                <up-form-item borderBottom label="种源类型" required prop="seedType">
                    <up-input v-model="form.seedType" placeholder="请输入种源类型" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="物种基原" required prop="varietyId">
                    <up-input v-model="form.varietyId" placeholder="请输入物种基原" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="具体品种/品系名称" prop="seedName">
                    <up-input v-model="form.seedName" placeholder="请输入具体品种/品系名称" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="种源来源" required prop="seedSource">
                    <up-input v-model="form.seedSource" placeholder="请输入种源来源" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="受托单位" prop="entrustId">
                    <up-input v-model="form.entrustId" placeholder="请输入受托单位" border="none" clearable></up-input>
                </up-form-item>

                <!-- 入库数量与单位 -->
                <up-form-item borderBottom label="入库量" prop="capacity">
                    <up-input v-model="form.capacity" type="number" placeholder="请输入入库量" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="计量单位" prop="unit">
                    <up-input v-model="form.unit" placeholder="请输入计量单位" border="none" clearable></up-input>
                </up-form-item>

                <!-- 检验报告与供应商信息 -->
                <up-form-item borderBottom label="检验报告" prop="examinReport">
                    <up-input v-model="form.examinReport" placeholder="请输入检验报告编号或说明" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="供应商" prop="supplierId">
                    <up-input v-model="form.supplierId" placeholder="请输入供应商" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="供应商名称" prop="supplier">
                    <up-input v-model="form.supplier" placeholder="请输入供应商名称" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="生产商" prop="producer">
                    <up-input v-model="form.producer" placeholder="请输入生产商名称" border="none" clearable></up-input>
                </up-form-item>

                <!-- 菌种编码信息 -->
                <up-form-item borderBottom label="菌种/菌株编号" prop="fungusCode">
                    <up-input v-model="form.fungusCode" placeholder="请输入菌种/菌株编号" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="菌种编码类型" prop="fungusCodeType">
                    <up-input v-model="form.fungusCodeType" placeholder="请输入菌种编码类型" border="none" clearable></up-input>
                </up-form-item>

                <!-- 个体标识：此处仅占位，后续可改为多选列表 -->
                <up-form-item borderBottom label="是否有个体标识" prop="animalIds">
                    <up-input v-model="form.animalIds" placeholder="如有个体标识，请稍后补充明细" border="none" disabled></up-input>
                </up-form-item>

                <!-- 媒体与附件 -->
                <up-form-item borderBottom label="种源图片" prop="imgs">
                    <ut-upload v-model="form.imgs" :max-count="9"></ut-upload>
                </up-form-item>
                <up-form-item borderBottom label="种源视频" prop="vedios">
                    <ut-upload v-model="form.vedios" :max-count="3" accept="video" valueType="array"></ut-upload>
                </up-form-item>

                <!-- 产地与繁殖信息 -->
                <up-form-item borderBottom label="种源产地" prop="adcode">
                    <up-input v-model="form.adcode" placeholder="请输入种源产地行政编码" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="繁殖材料" prop="generationMaterial">
                    <up-input v-model="form.generationMaterial" placeholder="请输入繁殖材料" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="繁殖地点/采集地点" prop="generationAdcode">
                    <up-input v-model="form.generationAdcode" placeholder="请输入繁殖/采集地点编码或名称" border="none" clearable></up-input>
                </up-form-item>

                <!-- 资质证明附件（暂按上传控件处理，可后续细化） -->
                <up-form-item borderBottom label="物种鉴定证书" prop="spCert">
                    <ut-upload v-model="form.spCert" :max-count="9" valueType="array" accept="file"></ut-upload>
                </up-form-item>
                <up-form-item borderBottom label="新品种证书" prop="newSpCert">
                    <ut-upload v-model="form.newSpCert" :max-count="9" valueType="array" accept="file"></ut-upload>
                </up-form-item>
                <up-form-item borderBottom label="引种证明" prop="importCert">
                    <ut-upload v-model="form.importCert" :max-count="9" valueType="array" accept="file"></ut-upload>
                </up-form-item>

                <!-- 检疫信息 -->
                <up-form-item borderBottom label="种源检疫证号" prop="seedCheckSn">
                    <up-input v-model="form.seedCheckSn" placeholder="请输入种源检疫证号" border="none" clearable></up-input>
                </up-form-item>
                <up-form-item borderBottom label="种源检疫证书" prop="seedCheckCert">
                    <ut-upload v-model="form.seedCheckCert" :max-count="9" valueType="array" accept="file"></ut-upload>
                </up-form-item>
            </up-form>
        </view>
        <template #bottom>
            <view class="pd-20 d-flex">
                <up-button @click="submitForm" type="primary">保存</up-button>
            </view>
        </template>
    </z-paging>
</template>
<script setup lang="ts">
import { useClientRequest } from '@/utils/request';
import { seedInfoListType } from '../models/type';

const paging = ref<any>(null);
const upFormRef = ref<any>(null);
const form = ref<seedInfoListType>({
    imgs: [],
    vedios: [],
    spCert: [],
    newSpCert: [],
    importCert: [],
    seedCheckCert: [],
});
const rules = reactive({});

const submitForm = async () => {
    uni.$u.debounce(
        async () => {
            try {
                await upFormRef.value?.validate();
            } catch (error: any) {
                // 滚动到第一个错误字段
                const firstErrorField = error && error[0].prop + 'pppp';
                paging.value?.scrollIntoViewById(firstErrorField, 30, true);
                return;
            }
            // 提交表单
            uni.showLoading({
                title: '提交中...',
            });
            try {
            } catch (error) {
                uni.hideLoading();
            }
        },
        500,
        true
    );
};

const did = ref('');
onLoad((optins: any) => {
    if (optins.id) {
        // 编辑加载详
        did.value = optins.id;
    } else {
    }
});
</script>
<style lang="scss" scoped></style>
