<template>
    <!-- 弹出框表单 -->
    <el-drawer
            :title="title"
            :visible.sync="open"
            :direction="direction"
            size="40%">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
              <Field :span="20" label="会议名称" prop="meetName" v-model="form.meetName" placeholder="请输入会议名称"/>
              <Field :span="20" label="选择房间" prop="roomId" v-model="form.roomId" type="select" :enumData="dict.roomId" placeholder="请选择开会房间"/>
              <Field :span="20" label="会议日期" prop="meetDate" v-model="form.meetDate" type="date" />
              <Field :span="20" label="开会开始时间" prop="meetTimeStart" v-model="form.meetTimeStart">
              <el-time-select
                  placeholder="起始时间"
                  v-model="form.meetTimeStart"
                  value-format="HH:mm"
                  format="HH:mm"
                  :key="form.meetTimeStart"
                  :picker-options="{
                                        start: '07:00',
                                        step: '00:30',
                                        end: '20:00'
                                      }">
              </el-time-select>

              </Field>
              <Field :span="20" label="开会结束时间" prop="meetTimeEnd" v-model="form.meetTimeEnd">
                <el-time-select
                    placeholder="结束时间"
                    v-model="form.meetTimeEnd"
                    value-format="HH:mm"
                    format="HH:mm"
                    :key="form.meetTimeEnd"
                    :picker-options="{
                                        start: '07:00',
                                        step: '00:30',
                                        end: '20:00',
                                        minTime:form.meetTimeStart
                                      }">
                </el-time-select>

              </Field>

<!--              <Field :span="20" label="开会结束时间" prop="meetTimeEnd" v-model="form.meetTimeEnd" type="datetime" />
             -->               <Field :span="20" label="开会部门名称" prop="meetDeptName" v-model="form.meetDeptName" placeholder="请输入开会部门名称"/>
                           <Field :span="20" v-if="pageInfo.type=='view'" label="会议结束方式" prop="finishMethod" v-model="form.finishMethod" type="radio" :enumData="dict.finishMethod" placeholder="请选择会议结束方式"/>
                            <Field :span="20" label="备注" prop="remark" v-model="form.remark" type="textarea" placeholder="请输入备注"/>

            </el-row>

            <form-buttons @submit='submitForm' v-if="pageInfo.type!='view'" noCancelBtn />
        </el-form>

    </el-drawer>
</template>

<script>
    import form from "@/assets/mixins/formdialog";
    import moment from "moment/moment";
    export default {
        name: "MettingRecordDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("metting/record")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "会议记录",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "roomId",
                    "meetStatus",
                    "finishMethod",
                ],
                toDate:[
                    "meetDate",
                ],
                // 表单校验
                rules: {
                    meetName: [
                        {required: true,message: "请输入会议名称", trigger: "blur" },
                        {max: 128,message: "最多只能录入128个字符",trigger: "blur",},
                    ],
                    meetDate: [
                        {required: true,message: "请选择会议日期" },
                    ],
                    meetTimeStart: [
                        {required: true,message: "请选择开会开始时间" },
                    ],
                    meetTimeEnd: [
                        {required: true,message: "请选择开会结束时间" },
                    ],
                    roomName: [
                        {required: true,message: "请输入开会房间名称", trigger: "blur" },
                        {max: 128,message: "最多只能录入128个字符",trigger: "blur",},
                    ],
                  roomId: [
                    {required: true,message: "请选择开会房间", trigger: "blur" }
                  ],
                    meetDeptName: [
                        {required: true,message: "请输入开会部门名称", trigger: "blur" },
                        {max: 128,message: "最多只能录入128个字符",trigger: "blur",},
                    ],
                    meetStatus: [
                        {required: true,message: "请输入会议状态", trigger: "blur" },
                    ],
                    finishMethod: [
                        {required: true,message: "请输入会议结束方式", trigger: "blur" },
                    ],
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="metting/record/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改会议记录";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "metting/record/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增会议记录";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="metting/record/view";
                this.getData();
                this.pageInfo.type="view"
                this.title = "会议记录详细";
            },
            /**取消按钮 */
            cancel() {
                this.open = false;
            },
            /**获取数据后弹框 */
            afterRender(data) {
                this.form.meetTimeStart = moment(data.entity.meetTimeStart).format('HH:mm');
                this.form.meetTimeEnd = moment(data.entity.meetTimeEnd).format('HH:mm');
                this.open = true;
            },

          beforeSubmit(data) {

            data.roomName=this.dict.roomId[data.roomId]
            const serviceTimeStart = moment(data.meetTimeStart, 'HH:mm');
            const serviceTimeEnd = moment(data.meetTimeEnd, 'HH:mm');
            data.meetTimeStart =  moment().set({hour: serviceTimeStart.hour(), minute: serviceTimeStart.minute()}).format('yyyy-MM-DD HH:mm:ss');
            data.meetTimeEnd = moment().set({hour: serviceTimeEnd.hour(), minute: serviceTimeEnd.minute()}).format('yyyy-MM-DD HH:mm:ss');
            return data
          },

            afterSubmit(data) {
                this.open = false;
                this.$emit("ok");
            },

            // 表单重置
            reset() {
                this.form = {
                    meetName : "",
                    meetDate : null,
                    meetTimeStart : null,
                    meetTimeEnd : null,
                    roomId : null,
                    roomName : "",
                    meetDeptName : "",
                    meetStatus : 0,
                    finishMethod : 0,
                    remark : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
