<template>
    <el-dialog v-model="props.modelValue" :destroy-on-close="true" @open="openDialog" :title="props.title"
        @close="close" width="800">
        <el-form ref="formRef" :model="form" :rules="rules" label-width="100px" :disabled="true">
            <el-row>
                <el-col :span="8">
                    <el-form-item :label="tLang('pms','计划编码')" prop="planCode">
                        <el-input v-model="form.planCode" :placeholder="tLang('common', '请输入') + tLang('pms', '计划编码')" disabled />
                    </el-form-item>
                </el-col>
                <el-col :span="4">
                    <!-- <el-form-item label-width="10">
              <el-switch v-model="autoGenFlag" active-color="#13ce66" active-text="自动生成"
                @change="handleAutoGenChange(autoGenFlag)" v-if="optType != 'view'&&optType != 'edit'">
              </el-switch>
            </el-form-item> -->
                </el-col>
                <el-col :span="12">
                    <el-form-item :label="tLang('pms','计划名称')" prop="planName">
                        <el-input v-model="form.planName" :placeholder="tLang('common', '请输入') + tLang('pms', '计划名称')" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item :label="tLang('pms','计划类型')" prop="planType">
                        <el-select v-model="form.planType" :placeholder="tLang('common', '请选择') + tLang('pms', '计划类型')" @change="changePlanType">
                            <el-option v-for="dict in pms_plan_type" :key="dict.value" :label="tLang('pms', dict.label)"
                                :value="dict.value"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item :label="tLang('pms','频率')" prop="cycleCount">
                        <el-input-number :min="1" :step="1" v-model="form.cycleCount" :placeholder="tLang('common', '请输入') + tLang('pms', '频率')" />
                    </el-form-item>
                </el-col>
                <el-col :span="4">
                    <el-form-item prop="cycleType" label-width="00">
                        <el-select v-model="form.cycleType" :placeholder="请选择频率">
                            <el-option v-for="dict in pms_cycle_type" :key="dict.value" :label="tLang('pms', dict.label)"
                                :value="dict.value"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="8">
                    <el-form-item :label="tLang('device','设备名称')" prop="deviceId">
                        <!-- <el-input v-model="form.deviceId" :placeholder="请选择设备" disabled>
                                <el-button style="border-color: #46a6ff; background-color: #46a6ff;color: white;"
                                    slot="append" @click="handleMachineryAdd" icon="el-icon-search"></el-button>
                            </el-input> -->
                        <el-select v-model="form.deviceId"
                            :placeholder="tLang('common', '请选择') + tLang('device', '设备')">
                            <el-option v-for="item in deviceList" :key="item.value" :label="item.label"
                                :value="item.value" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="4">
                    <!-- <el-form-item label="设备名称" prop="machineryName">
              <el-input v-model="form.machineryName" :placeholder="请选择设备" disabled />
            </el-form-item> -->
                </el-col>
                <el-col :span="12">
                    <!-- <el-form-item label="执行人" prop="userId">
                        <el-select v-model="form.userId" filterable
                            :placeholder="tLang('common', '请选择') + tLang('produce', '执行人')" style="width: 240px">
                            <el-option v-for="item in userList" :key="item.value" :label="item.label"
                                :value="item.value" />
                        </el-select>
                    </el-form-item> -->
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="8">
                    <el-form-item :label="tLang('pms','开始日期')" prop="startDate">
                        <el-date-picker clearable v-model="form.startDate" type="date" value-format="YYYY-MM-DD"
                            :placeholder="tLang('common', '请选择') + tLang('pms', '开始日期')">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item :label="tLang('pms','结束日期')" prop="endDate">
                        <el-date-picker clearable v-model="form.endDate" type="date" value-format="YYYY-MM-DD"
                            :placeholder="tLang('common', '请选择') + tLang('pms', '结束日期')">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <!-- <el-form-item label="状态" prop="status">
                        <el-select v-model="form.status" disabled>
                            <el-option v-for="dict in pms_order_status" :key="dict.value" :label="dict.label"
                                :value="dict.value"></el-option>
                        </el-select>
                    </el-form-item> -->
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item :label="tLang('device','备注')" prop="remark">
                        <el-input v-model="form.remark" type="textarea" :placeholder="tLang('common', '请输入') + tLang('device', '备注')" />
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <el-tabs type="border-card">
            <el-tab-pane :label="form.planType == 'CHECK' ? tLang('pms','点检') : tLang('pms','保养')">
                <Checksubject ref="subjectlist" :checksubjectList="form.subjects"></Checksubject>
            </el-tab-pane>
        </el-tabs>
        <template #footer>
            <div class="dialog-footer">
                <!-- <el-button type="primary" @click="submitForm">{{ tLang('common', '确 定') }}</el-button> -->
                <el-button @click="cancel">{{ tLang('common', '关 闭') }}</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup>
import { ref } from "vue";
import Checksubject from "./subject.vue"
const { proxy } = getCurrentInstance();

const { pms_cycle_type, pms_order_status, pms_plan_type } = proxy.useDict("pms_cycle_type", "pms_order_status", "pms_plan_type");

const emit = defineEmits();
const props = defineProps({
    modelValue: Boolean,
    title: String,
    form: {
        type: Object,
        default: () => ({}),
    },
});
const formRef = ref(null);
const baseUrl = import.meta.env.VITE_APP_BASE_API;

function close() {
    emit("update:modelValue", false);
}
function cancel() {
    emit("update:form", {});
    close();
}
</script>

<style lang="scss" scoped></style>