<template>
    <global-page title="MCO主任意见" navLeftType="text" showNavRight navRightType="button" navRightText="保存" @handleRightClick="handleRightClick">
        <view class="mocp-form">
            <up-form labelPosition="left" labelWidth="auto">
                <up-form-item label="MCO主任" :borderBottom="true">
                    <global-picker pickAlign="right" clearable v-model="formData.mcoDirector" :options="selectList" filter></global-picker>
                </up-form-item>
                <up-form-item label="MCP主任意见" :borderBottom="true">
                    <global-radio radioAlign="right" clearable v-model="formData.mcoDirectorDecisionState" dictkey="md_decisionState"></global-radio>
                </up-form-item>
                <up-form-item label="MCP主任意见描述" :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 useBaseStore from 'mocp/store/base'
import { storeToRefs } from 'pinia'
import useMoveDecisionStore from 'mocp/store/move-decision'
import { updateMcoDirectorInfoApi } from 'mocp/api/move-decision'

const baseStore = useBaseStore()
const moveDecisionStore = useMoveDecisionStore()
const { details } = storeToRefs(moveDecisionStore)
//表单数据
const formData = reactive({
    id: '',
    mcoDirector: '',
    mcoDirectorDecisionState: '',
    mcoDirectorOpinion: ''
})
//获取下拉框列表
const selectList = ref([])
onLoad(() => {
    formData.id = details.value.id
    formData.mcoDirector = details.value.mcoDirector
    formData.mcoDirectorDecisionState = details.value.mcoDirectorDecisionState
    formData.mcoDirectorOpinion = details.value.mcoDirectorOpinion
    baseStore.getAdminList().then((res) => {
        selectList.value = res
    })
})
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 = selectList.value.find((item) => item.value == formData.mcoDirector)?.label.split('(')[0] || ''
        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>
