<template>
    <global-page title="批示">
        <view class="mocp-form">
            <up-form labelPosition="top" labelWidth="auto" :model="formData" ref="formRef">
                <up-form-item label="批示意见" :borderBottom="true">
                    <up-textarea placeholder="请输入批示意见" :height="40" border="none" v-model="formData.content"></up-textarea>
                </up-form-item>
            </up-form>
        </view>
        <template #bottom>
            <view class="footer-btn">
                <up-row gutter="10">
                    <up-col span="6">
                        <global-button type="danger" plain size="large" :radius="5" @tap="handleSubmit(0)">不同意</global-button>
                    </up-col>
                    <up-col span="6"><global-button type="primary" size="large" :radius="5" @tap="handleSubmit(1)">同意</global-button></up-col>
                </up-row>
            </view>
        </template>
    </global-page>
</template>

<script setup>
import { onShow } from '@dcloudio/uni-app'
import { storeToRefs } from 'pinia'
import { reactive } from 'vue'
import useOperationalSurveyStore from 'mocp/store/operationalSurvey'
import { saveAudit2Api } from 'mocp/api/operationalSurvey'

const operationalSurveyStore = useOperationalSurveyStore()
const { details } = storeToRefs(operationalSurveyStore)
// 表单数据
const formData = reactive({
    id: '',
    workbenchId: '',
    content: ''
})
// 页面初始化
onShow(() => {
    if (details.value) {
        formData.id = details.value.id
        formData.workbenchId = details.value.workbenchId
        formData.opinion = details.value.audit?.opinion
        formData.content = details.value.audit?.content
    }
})
//提交表单
const handleSubmit = async (opinion) => {
    if (opinion == 0 && !formData.content) {
        return uni.$mocpMessage.warning('请填写批示意见!')
    }
    const res = await saveAudit2Api({ ...formData, opinion }, { loading: true })
    if (res.code == 200) {
        uni.$mocpJump.navigateBack()
        operationalSurveyStore.getRsData2()
        uni.$mocpMessage.success(res.message)
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
</script>
<style lang="scss" scoped>
.mocp-form {
    background: #fff;
    padding: 0 32rpx;
}
.footer-btn {
    padding: 24rpx 32rpx;
    background-color: #fff;
}
</style>
