<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
                        :options="baseStore.getParamsByType('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 useBaseStore from 'mocp/store/base'
import { savaFollowUpFeedbackApi } from 'mocp/api/assign-work'

const baseStore = useBaseStore()
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>
