<template>
    <global-page title="结论" showFooterBtn @handleFooterClick="handleSubmit">
        <view class="mocp-form">
            <up-cell-group>
                <up-cell title="是否有异常">
                    <template #value>
                        <view>
                            <global-radio radioAlign="right" v-model="formData.isAbnormal" clearable dictkey="wdm_isAbnormal"></global-radio>
                        </view>
                    </template>
                </up-cell>
                <up-cell>
                    <template #label>
                        <up-textarea placeholder="请输入" v-model="formData.content" :height="40" border="none"></up-textarea>
                    </template>
                </up-cell>
                <up-cell title="附件">
                    <template #label>
                        <view style="margin-top: 16rpx">
                            <global-upload v-model="formData.files" :file-list="getConclusionVo.files"></global-upload>
                        </view>
                    </template>
                </up-cell>
            </up-cell-group>
        </view>
    </global-page>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app'
import { reactive } from 'vue'
import { savePwdConclusionApi } from 'mocp/api/windDamageManagement'
import { storeToRefs } from 'pinia'
import useWindDamageManagementStore from 'mocp/store/windDamageManagement'

const windDamageManagementStore = useWindDamageManagementStore()
const { getConclusionVo, basicId, tabIndex } = storeToRefs(windDamageManagementStore)
// 表单数据
const formData = reactive({
    basicId: '',
    content: '',
    files: '',
    id: '',
    isAbnormal: undefined,
    type: undefined
})
// 页面初始化
onLoad(() => {
    Object.assign(formData, getConclusionVo.value)
    formData.basicId = basicId.value
    formData.type = tabIndex.value + 1
})
//提交表单
const handleSubmit = async () => {
    const res = await savePwdConclusionApi(formData, { loading: true })
    if (res.code == 200) {
        uni.$mocpJump.navigateBack()
        uni.$mocpMessage.success(res.message)
        windDamageManagementStore.getAllTaskInfoByWeather()
        uni.$emit('windDamageManagementReload')
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
</script>
<style lang="scss" scoped>
.mocp-form {
    background: #fff;
    padding: 0 32rpx;
}
</style>
