<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.customName"
                        :searchValue="details.customFullName"
                    ></custom-admin-picker>
                </up-form-item>
                <up-form-item label="客户工程授权人意见" :borderBottom="true">
                    <global-picker pickAlign="right" v-model="formData.customType" clearable dictkey="te_customType" 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 { addRatifyApi } from 'mocp/api/technology-evaluation'

const technologyEvaluationStore = useTechnologyEvaluationStore()
const { details } = storeToRefs(technologyEvaluationStore)
const formData = reactive({
    id: '',
    num: '',
    customName: '',
    customType: ''
})
//页面初始化
onLoad(() => {
    formData.id = details.value.id
    formData.num = details.value.num
    formData.customName = details.value.customName
    formData.customType = details.value.customType
})
//保存
const adminPickerRef = ref()
const handleSave = async () => {
    const res = await addRatifyApi(formData, { loading: true })
    if (res.code == 200) {
        uni.$mocpJump.navigateBack()
        uni.$mocpMessage.success(res.message)
        res.data.customFullName = 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>
