<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">
                    <global-picker pickAlign="right" v-model="formData.customName" clearable :options="customNameOpts" filter></global-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 useBaseStore from 'mocp/store/base'
import { addRatifyApi } from 'mocp/api/technology-evaluation'

const baseStore = useBaseStore()
const technologyEvaluationStore = useTechnologyEvaluationStore()
const { details } = storeToRefs(technologyEvaluationStore)
const formData = reactive({
    id: '',
    num: '',
    customName: '',
    customType: ''
})
//页面初始化
const customNameOpts = ref([])
onLoad(() => {
    formData.id = details.value.id
    formData.num = details.value.num
    formData.customName = details.value.customName
    formData.customType = details.value.customType
    baseStore.getAdminList().then((res) => {
        customNameOpts.value = res
    })
})
//保存
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 = customNameOpts.value.find((item) => item.value == formData.customName)?.label.split('(')[0] || ''
        //更新详情
        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>
