<template>
    <global-page
        :title="formData.isDuty == 0 ? '公司值班经理意见' : '品质中心经理意见'"
        navLeftType="text"
        showNavRight
        navRightType="button"
        navRightText="保存"
        @handleRightClick="handleRightClick"
    >
        <view class="mocp-form">
            <up-form labelPosition="left" labelWidth="auto">
                <up-form-item :label="formData.isDuty == 0 ? '公司值班经理' : '品质中心经理'" :borderBottom="true">
                    <custom-admin-picker
                        pickAlign="right"
                        clearable
                        v-model="formData.mid"
                        :searchValue="searchValue"
                        emptyValue="-1"
                    ></custom-admin-picker>
                </up-form-item>
                <up-form-item :label="formData.isDuty == 0 ? '公司值班经理意见' : '品质中心经理意见'" :borderBottom="true">
                    <global-radio
                        radioAlign="right"
                        clearable
                        v-model="formData.opinionType"
                        dictkey="ar_opinionType"
                        :emptyValue="-1"
                    ></global-radio>
                </up-form-item>
                <up-form-item
                    :label="formData.isDuty == 0 ? '公司值班经理意见描述' : '品质中心经理意见描述'"
                    :borderBottom="true"
                    labelPosition="top"
                >
                    <up-textarea placeholder="请输入" :height="40" border="none" v-model="formData.msg"></up-textarea>
                </up-form-item>
            </up-form>
        </view>
    </global-page>
</template>

<script setup>
import { saveRqmOpinionApi } from 'mocp/api/appraisal-record'
import { onLoad } from '@dcloudio/uni-app'
import { reactive, ref } from 'vue'
import useAppraisalRecordStore from 'mocp/store/appraisal-record'

const appraisalRecordStore = useAppraisalRecordStore()
//表单数据
const formData = reactive({
    id: '',
    isDuty: 0,
    mid: '-1',
    opinionType: -1,
    msg: ''
})
const searchValue = ref('')
onLoad(() => {
    uni.$once('appraisalRecordOpinionEdit', (data, realName) => {
        Object.assign(formData, data)
        searchValue.value = realName
    })
})
const handleRightClick = async () => {
    const res = await saveRqmOpinionApi(formData, { loading: true })
    if (res.code == 200) {
        uni.$mocpJump.navigateBack()
        appraisalRecordStore.getRqmDetails()
        uni.$mocpMessage.success(res.message)
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
</script>

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