<template>
    <global-page title="MOC主任意见" navLeftType="text" showNavRight navRightType="button" navRightText="保存" @handleRightClick="handleRightClick">
        <view class="mocp-form">
            <up-form labelPosition="left" labelWidth="auto">
                <up-form-item label="MOC主任" :borderBottom="true">
                    <custom-admin-picker
                        ref="adminPickerRef"
                        pickAlign="right"
                        clearable
                        v-model="formData.mcoDirector"
                        :searchValue="details.mcoDirectorName"
                    ></custom-admin-picker>
                </up-form-item>
                <up-form-item label="MOC主任意见" :borderBottom="true">
                    <global-radio radioAlign="right" clearable v-model="formData.mcoDirectorDecisionState" dictkey="md_decisionState"></global-radio>
                </up-form-item>
                <up-form-item label="MOC主任意见描述" :borderBottom="true" labelPosition="top">
                    <up-textarea placeholder="请输入" :height="40" border="none" v-model="formData.mcoDirectorOpinion"></up-textarea>
                </up-form-item>
            </up-form>
        </view>
    </global-page>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app'
import { reactive, ref } from 'vue'
import { storeToRefs } from 'pinia'
import useMoveDecisionStore from 'mocp/store/move-decision'
import { updateMcoDirectorInfoApi } from 'mocp/api/move-decision'

const moveDecisionStore = useMoveDecisionStore()
const { details } = storeToRefs(moveDecisionStore)
//表单数据
const formData = reactive({
    id: '',
    mcoDirector: '',
    mcoDirectorDecisionState: '',
    mcoDirectorOpinion: ''
})
onLoad(() => {
    formData.id = details.value.id
    formData.mcoDirector = details.value.mcoDirector
    formData.mcoDirectorDecisionState = details.value.mcoDirectorDecisionState
    formData.mcoDirectorOpinion = details.value.mcoDirectorOpinion
})
const adminPickerRef = ref()
const handleRightClick = async () => {
    const res = await updateMcoDirectorInfoApi(formData, { loading: true })
    if (res.code == 200) {
        uni.$mocpJump.navigateBack()
        uni.$mocpMessage.success(res.message)
        res.data.mcoDirector = formData.mcoDirector
        res.data.mcoDirectorName = adminPickerRef.value?.getName()
        res.data.mcoDirectorDecisionState = formData.mcoDirectorDecisionState
        res.data.mcoDirectorOpinion = formData.mcoDirectorOpinion
        //更新详情
        moveDecisionStore.setState('details', res.data)
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
</script>

<style lang="scss" scoped>
.mocp-form {
    background: #fff;
    padding: 0 32rpx;
}
</style>
