<template>
    <global-page title="申诉状态" showFooterBtn @handleFooterClick="handleSubmit">
        <view class="mocp-form">
            <up-form labelPosition="left" labelWidth="auto" :model="formData" ref="formRef">
                <up-form-item label="申诉情况" :borderBottom="true">
                    <global-picker pickAlign="right" dictkey="ar_appealInfo" v-model="formData.appealInfo" clearable :emptyValue="-1"></global-picker>
                </up-form-item>
                <up-form-item label="申诉附件" :borderBottom="true" labelPosition="top">
                    <view style="margin-top: 24rpx">
                        <global-upload :fileList="getFileList" v-model="formData.file"></global-upload>
                    </view>
                </up-form-item>
            </up-form>
        </view>
    </global-page>
</template>

<script setup>
import { onShow } from '@dcloudio/uni-app'
import useAppraisalRecordStore from 'mocp/store/appraisal-record'
import { storeToRefs } from 'pinia'
import { updateRqmDataApi } from 'mocp/api/appraisal-record'
import { reactive } from 'vue'
import { cloneDeep } from 'lodash'

const appraisalRecordStore = useAppraisalRecordStore()
const { details, getFileList } = storeToRefs(appraisalRecordStore)
// 表单数据
const formData = reactive({
    id: '',
    ac: '',
    acOwn: '',
    acType: '',
    appealInfo: '-1',
    appraisee: '-1',
    department: '-1',
    dmUid: '-1',
    eventMsg: '',
    eventSource: '',
    eventTime: -1,
    eventType: -1,
    examineBasis: '',
    examineType: '-1',
    onDutyUser: '',
    opinionMsg: '',
    opinionType: -1,
    score: null,
    qmUid: '',
    qualityOpinionMsg: '',
    qualityOpinionType: -1,
    status: '',
    emailSendTime: -1,
    file: []
})
// 页面初始化
onShow(() => {
    Object.assign(formData, cloneDeep(details.value))
    formData.file = JSON.parse(formData.file)
})
//提交表单
const handleSubmit = async () => {
    const params = { ...formData, file: JSON.stringify(formData.file) }
    const res = await updateRqmDataApi(params, { 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>
