<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">
                    <global-picker pickAlign="right" clearable v-model="formData.mid" :options="selectList" emptyValue="-1" filter></global-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'
import useBaseStore from 'mocp/store/base'

const baseStore = useBaseStore()
const appraisalRecordStore = useAppraisalRecordStore()
//表单数据
const formData = reactive({
    id: '',
    isDuty: 0,
    mid: '-1',
    opinionType: -1,
    msg: ''
})
//获取下拉框列表
const selectList = ref([])
onLoad(() => {
    uni.$once('appraisalRecordOpinionEdit', (data) => {
        Object.assign(formData, data)
        baseStore.getAdminList().then((res) => {
            selectList.value = res
        })
    })
})
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>
