<template>
    <global-page
        title="经理或授权人意见"
        navLeftType="text"
        :showNavRight="true"
        navRightType="button"
        navRightText="保存"
        @handleRightClick="handleSave"
    >
        <view class="mocp-form">
            <up-form labelPosition="left" labelWidth="auto">
                <up-form-item label="机队经理或其授权人" :borderBottom="true">
                    <custom-admin-picker
                        ref="adminPickerRef"
                        pickAlign="right"
                        clearable
                        v-model="formData.otherName"
                        :searchValue="details.otherFullName"
                    ></custom-admin-picker>
                </up-form-item>
                <up-form-item label="机队经理或其授权人意见" :borderBottom="true">
                    <global-picker pickAlign="right" v-model="formData.opinionType" clearable dictkey="te_opinionType" emptyValue="0"></global-picker>
                </up-form-item>
            </up-form>
        </view>
    </global-page>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app'
import useTechnologyEvaluationStore from 'mocp/store/technology-evaluation'
import { storeToRefs } from 'pinia'
import { reactive, ref } from 'vue'
import { addOpinionApi } from 'mocp/api/technology-evaluation'

const technologyEvaluationStore = useTechnologyEvaluationStore()
const { details } = storeToRefs(technologyEvaluationStore)
const formData = reactive({
    id: '',
    num: '',
    otherName: '',
    opinionType: ''
})
//页面初始化
onLoad(() => {
    formData.id = details.value.id
    formData.num = details.value.num
    formData.otherName = details.value.otherName
    formData.opinionType = details.value.opinionType
})
//保存
const adminPickerRef = ref()
const handleSave = async () => {
    const res = await addOpinionApi(formData, { loading: true })
    if (res.code == 200) {
        uni.$mocpJump.navigateBack()
        uni.$mocpMessage.success(res.message)
        res.data.otherFullName = adminPickerRef.value?.getName()
        //更新详情
        technologyEvaluationStore.setState('details', res.data)
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
</script>
<style lang="scss" scoped>
.mocp-form {
    background: #fff;
    margin-bottom: 24rpx;
    padding: 0 32rpx;
}
</style>
