<template>
  <q-dialog v-model="persistent" persistent content-class="bg-grey-1" transition-show="scale" transition-hide="scale">
    <q-card style="width: 480px;max-width:480px;">
      <q-card-section>
        <div class="text-h6">
          {{ addMsg.HolidayId > 0 ? "修改计划表" : "新增计划表" }}
        </div>
      </q-card-section>
      <q-card-section class="q-pt-none scroll" style="max-height: 70vh">
        <div class="row wrap">
          <q-select filled class="col-12" option-value="value" option-label="label" ref="DayType"
            v-model="addMsg.DayType" :options="typeOpts" :rules="[val => !!val || '请选择计划类型']" emit-value map-options
            label="计划类型" />
        </div>
        <div class="row wrap">
          <div class="col-12 Sysuser_Date">
            <q-field filled>
               <template v-slot:control>
                <el-date-picker v-model="date" value-format="yyyy-MM-dd" type="daterange"  range-separator="至"
                   start-placeholder="开始日期"  end-placeholder="结束日期">
                   </el-date-picker>       
              </template>
            </q-field>
          </div>
        </div>
      </q-card-section>
      <q-separator />
      <q-card-actions align="right" class="bg-white">
        <q-btn label="取消" flat color="grey-10" style="font-weight:400 !important" @click="closeVisitForm" />
        <q-btn label="保存" color="accent q-px-md" style="font-weight:400 !important" :loading="saveCourseLoading"
          @click="saveCourse" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>

<script>
  import {
    setHolidayPlan,
  } from '../../api/scheduling/schedu'
  export default {
    components: {},
    props: {
      saveObj: {
        type: Object,
        default: null
      }
    },

    data() {
      return {
        persistent: true,
        addMsg: {
          HolidayId: 0,
          DayType: 1, //类型
          StartTime: "", //开始时间
          EndTime: "", //结束时间
        },
        date: [],
        typeOpts: [{
            label: '节假日',
            value: 1
          },
          {
            label: '工作日',
            value: 2
          }
        ],
        saveCourseLoading: false,
      };
    },
    created() {
      if (this.saveObj && this.saveObj.HolidayId > 0) {
        this.addMsg = this.saveObj
        this.date[0] = this.saveObj.StartTime
        this.date[1] = this.saveObj.EndTime
      }
    },
    methods: {
      //关闭弹窗
      closeVisitForm() {
        this.$emit("close");
        this.persistent = false;
      },
      //保存菜单
      saveCourse() {
        if (!this.date) {
          this.date = ["", ""]
        }
        this.addMsg.StartTime = this.date[0]
        this.addMsg.EndTime = this.date[1]
        if (this.addMsg.StartTime == "" || this.addMsg.EndTime == "" || !this.addMsg.StartTime || !this.addMsg
          .EndTime) {
          this.$q.notify({
            icon: "error",
            color: "negative",
            message: '请选择时间',
            position: "top"
          })
          return
        }
        setHolidayPlan(this.addMsg).then(res => {
          if (res.Code === 1) {
            this.Success(res.Message)
            this.closeVisitForm();
            this.$emit("success")
          }
        })
      },
    }
  };

</script>
