<template>
    <global-page
        title="第二类超出持续适航文件的缺陷，需完成工程评估"
        navLeftType="text"
        :showNavRight="true"
        navRightType="button"
        navRightText="保存"
        @handleRightClick="handleSave"
    >
        <view class="mocp-form">
            <up-form labelPosition="left" labelWidth="auto">
                <up-form-item label="授权工程师" :borderBottom="true">
                    <custom-admin-picker
                        ref="adminPickerRef"
                        pickAlign="right"
                        clearable
                        v-model="formData.estimateEngineer"
                        :searchValue="details.estimateEngineerName"
                    ></custom-admin-picker>
                </up-form-item>
                <up-form-item label="日期" :borderBottom="true">
                    <global-date pickAlign="right" v-model="formData.engineerTime" clearable :timestamp="false"></global-date>
                </up-form-item>
                <up-form-item label="缺陷对飞机重要系统/结构的影响" :borderBottom="true" labelPosition="top">
                    <up-textarea placeholder="请输入" :height="40" v-model="formData.estimateEffect" border="none"></up-textarea>
                </up-form-item>
                <up-form-item label="缺陷的扩展可能造成的潜在影响" :borderBottom="true" labelPosition="top">
                    <up-textarea placeholder="请输入" :height="40" v-model="formData.estimatePotential" border="none"></up-textarea>
                </up-form-item>
                <up-form-item
                    label="历史上对类似缺陷的处理经验, 包括厂家已发布的超出持续适航文件范围的技术支援类文件"
                    :borderBottom="true"
                    labelPosition="top"
                >
                    <up-textarea placeholder="请输入" :height="40" border="none" v-model="formData.estimateHandle"></up-textarea>
                </up-form-item>
                <up-form-item label="评估结论" :borderBottom="true">
                    <global-picker
                        pickAlign="right"
                        v-model="formData.estimateType"
                        clearable
                        paramsType="EvaluateEstimateType"
                        emptyValue="0"
                    ></global-picker>
                </up-form-item>
            </up-form>
        </view>
    </global-page>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app'
import useTechnologyEvaluationStore from 'mocp/store/technology-evaluation'
import { storeToRefs } from 'pinia'
import { reactive, ref } from 'vue'
import { addEngineeringApi } from 'mocp/api/technology-evaluation'

const technologyEvaluationStore = useTechnologyEvaluationStore()
const { details } = storeToRefs(technologyEvaluationStore)
const formData = reactive({
    id: '',
    num: '',
    estimateEffect: '',
    estimatePotential: '',
    estimateHandle: '',
    estimateEngineer: '',
    estimateType: null,
    engineerTime: null
})
onLoad(() => {
    formData.id = details.value.id
    formData.num = details.value.num
    formData.estimateEffect = details.value.estimateEffect
    formData.estimatePotential = details.value.estimatePotential
    formData.estimateHandle = details.value.estimateHandle
    formData.estimateEngineer = details.value.estimateEngineer
    formData.estimateType = details.value.estimateType
    formData.engineerTime = details.value.engineerTime
})
//保存
const adminPickerRef = ref()
const handleSave = async () => {
    const res = await addEngineeringApi(formData, { loading: true })
    if (res.code == 200) {
        uni.$mocpJump.navigateBack()
        uni.$mocpMessage.success(res.message)
        res.data.estimateEngineerName = adminPickerRef.value?.getName()
        //更新详情
        technologyEvaluationStore.setState('details', res.data)
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
</script>
<style lang="scss" scoped>
.mocp-form {
    background: #fff;
    margin-bottom: 24rpx;
    padding: 0 32rpx;
}
</style>
