
<template>
    <base-dialog :title="prop.title" width="60%" :visible="prop.visible" :autoHeight="false" @open="handleOpen"
        @handleConfirm="handleConfirm" @close="handleClose">
        <div class="body">
            <el-form ref="formRef" :model="prop.form" label-width="120px">
                <el-form-item label="设备名称" prop="name">
                    <el-input v-model="prop.form.name" disabled placeholder="设备名称" />
                </el-form-item>
                <el-form-item label="装配组">
                    <el-input v-model="prop.form.assemblyGroup" placeholder="装配组" />
                </el-form-item>
                <el-form-item label="电装组">
                    <el-input v-model="prop.form.electricGroup" placeholder="电装组" />
                </el-form-item>
                <el-form-item label="检验员">
                    <el-input v-model="prop.form.inspector" placeholder="检验员" />
                </el-form-item>
                <!-- <el-form-item label="异常原因" prop="name">
                    <el-input v-model="prop.form.name" type="textarea" placeholder="异常原因" />
                </el-form-item>
                <el-form-item label="异常情况反馈" prop="name">
                    <el-input v-model="prop.form.name" type="textarea" placeholder="异常情况反馈" />
                </el-form-item>
                <el-form-item label="机器状态" prop="name">
                    <el-input v-model="prop.form.name" type="textarea" placeholder="机器状态" />
                </el-form-item>
                <el-form-item label="安装具体阶段">
                    <el-radio-group v-model="prop.form.isExhibition" class="ml-4">
                        <el-radio label="1" size="large">开始装配</el-radio>
                        <el-radio label="2" size="large">装配完成</el-radio>
                        <el-radio label="3" size="large">检验完成</el-radio>
                        <el-radio label="4" size="large">内包完成</el-radio>
                    </el-radio-group>
                </el-form-item> -->
            </el-form>
        </div>
    </base-dialog>
</template>

<script setup>
import { ref, watch, getCurrentInstance } from 'vue'
import { updateDevice } from '@/api/big/device'


const prop = defineProps({
    visible: {
        type: Boolean,
        default: false,
    },
    title: {
        type: String,
        default: '提示',
    },
    form: {
        type: Object,
        default: {
            id: '',
            inspector: '',
            assemblyGroup: '',
            electricGroup: ''
        },
    }
})

const formRef = ref(null)
const rule = {
    name: [
        { required: true, message: '请输入设备名称', trigger: 'blur' },
    ]
}
const { proxy: ctx } = getCurrentInstance()
const getwayList = ref([])
const typeList = ref([])
const deptList = ref([])
const handleClose = () => {
    //baseFormRef.value.reset()
    emit('closeDialog')
    emit('refreshTable')
}



// 弹窗弹出
const handleOpen = () => {
    // getAddFormOptions()
}



// 刷新表格事件
const emit = defineEmits(['refreshTable', 'closeDialog'])
// 添加/修改
async function addDeductionInfo() {
    if (!formRef.value) return
    let isValid = false
    await formRef.value.validate((valid, fields) => {
        if (valid) {
            isValid = true
            console.log('submit!')
        } else {
            console.log('error submit!', fields)
            isValid = false
        }
    })
    if (!isValid) return
    let { code, msg } = await updateDevice(prop.form)
    ctx.$message({
        type: code === 200 ? 'success' : 'warning',
        message: code === 200 ? '修改成功' : '修改失败',
    })
    if (code === 200) {
        // 刷新表格
        emit('refreshTable')
        emit('closeDialog')
    }


}
// 点击确定
const handleConfirm = () => {
    addDeductionInfo()
}


</script>
   
<style lang="scss" scoped>
.body {
    height: 100%;
}

.img-preview {
    max-width: 100%;
    max-height: 100%;
    display: block;
    margin: 0 auto;
    padding-top: 10px;
}
</style>