<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">
                    <global-picker pickAlign="right" v-model="formData.estimateEngineer" clearable :options="estimateOpts" filter></global-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
                        :options="baseStore.getParamsByType('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 useBaseStore from 'mocp/store/base'
import { addEngineeringApi } from 'mocp/api/technology-evaluation'

const baseStore = useBaseStore()
const technologyEvaluationStore = useTechnologyEvaluationStore()
const { details } = storeToRefs(technologyEvaluationStore)
const formData = reactive({
    id: '',
    num: '',
    estimateEffect: '',
    estimatePotential: '',
    estimateHandle: '',
    estimateEngineer: '',
    estimateType: null,
    engineerTime: null
})
//页面初始化
const estimateOpts = ref([])
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
    baseStore.getAdminList().then((res) => {
        estimateOpts.value = res
    })
})
//保存
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 = estimateOpts.value.find((item) => item.value == formData.estimateEngineer)?.label.split('(')[0] || ''
        //更新详情
        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>
