<template>
    <global-page
        title="后续措施反馈"
        navLeftType="text"
        :showNavRight="true"
        navRightType="button"
        navRightText="保存"
        @handleRightClick="handleSave"
    >
        <view class="mocp-form">
            <up-form labelPosition="left" labelWidth="auto" :model="formData" :rules="rules" ref="formRef">
                <up-form-item label="反馈内容" :borderBottom="true" labelPosition="top" prop="followUpFeedbackContent" required>
                    <up-textarea v-model="formData.followUpFeedbackContent" placeholder="请输入" :height="40" border="none"></up-textarea>
                </up-form-item>
                <up-form-item label="验证材料" labelPosition="top" :borderBottom="true">
                    <view style="margin-top: 24rpx">
                        <global-upload
                            :fileList="arrangeWorkExtend.followUpFeedbackFileVoList"
                            v-model="formData.followUpFeedbackFile"
                            mapFieldName="id"
                        ></global-upload>
                    </view>
                </up-form-item>
                <up-form-item label="应用分类" :borderBottom="true" prop="appType" required>
                    <global-picker pickAlign="right" v-model="formData.appType" clearable paramsType="ApplicationType"></global-picker>
                </up-form-item>
            </up-form>
        </view>
    </global-page>
</template>

<script setup>
import { reactive, ref } from 'vue'
import useAssignWorkStore from 'mocp/store/assign-work'
import { storeToRefs } from 'pinia'
import { onLoad } from '@dcloudio/uni-app'
import { savaFollowUpFeedbackApi } from 'mocp/api/assign-work'

const assignWorkStore = useAssignWorkStore()
const { arrangeWorkExtend } = storeToRefs(assignWorkStore)
const formData = reactive({
    followUpFeedbackContent: '',
    followUpFeedbackFile: '',
    appType: ''
})
const rules = reactive({
    followUpFeedbackContent: [
        {
            required: true,
            message: '请输入反馈内容',
            trigger: ['blur', 'change']
        }
    ],
    appType: [
        {
            required: true,
            message: '请选择应用分类',
            trigger: ['blur', 'change']
        }
    ]
})
//页面初始化
onLoad(() => {
    formData.id = arrangeWorkExtend.value.id
    formData.workId = arrangeWorkExtend.value.workId
    formData.company = arrangeWorkExtend.value.company
    formData.followUpFeedbackContent = arrangeWorkExtend.value.followUpFeedbackContent
    formData.followUpFeedbackFile = arrangeWorkExtend.value.followUpFeedbackFile
    formData.appType = arrangeWorkExtend.value.appType
})
//保存
const formRef = ref()
const handleSave = async () => {
    await formRef.value?.validate()
    const res = await savaFollowUpFeedbackApi(formData, { loading: true })
    if (res.code == 200) {
        uni.$mocpJump.navigateBack()
        uni.$mocpMessage.success(res.message)
        //更新当前责任单位详情
        assignWorkStore.setState('arrangeWorkExtend', res.data)
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
</script>
<style lang="scss" scoped>
.mocp-form {
    background: #fff;
    padding: 0 32rpx;
}
</style>
