<template>
  <div class="app-container" style="min-height: 100%;">
    <el-form :model="day" :rules="rules" ref="day" label-width="130px">
      <div class="form-item">
        <el-row>
          <el-col :xs="24" :sm="12" :md="8" :lg="4">
            <div class="item-title">
              每日履职
            </div>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="5">
            <el-form-item label="营业前提醒时间：" prop="front">

                <template >
                  <el-time-select
                    :picker-options="pickerOptions"
                    style="width: 70%;"  v-model="day.front"/>
                </template>
            
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="5">
            <el-form-item label="营业中：" prop="centre">
              <!-- <el-input-number size="mini" style="width: 70%;" v-model="day.centre" @change="handleChange" :min="1"
                :max="24" label="描述文字"></el-input-number>
              点提醒 -->
              <template >
                  <el-time-select
                    :picker-options="pickerOptions"
                    style="width: 70%;"  v-model="day.centre"/>
                </template>
            </el-form-item>
          </el-col>

          <el-col :xs="24" :sm="12" :md="8" :lg="5">
            <el-form-item label="营业后：" prop="after">
              <!-- <el-input-number size="mini" style="width: 70%;" v-model="day.after" @change="handleChange" :min="1"
                :max="24" label="描述文字"></el-input-number>
                点提醒 -->
                <template >
                  <el-time-select
                    :picker-options="pickerOptions"
                    style="width: 70%;"  v-model="day.after"/>
                </template>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="5">
            <el-form-item label="全天提醒：" prop="allDay">
              <!-- <el-input-number size="mini" style="width: 70%;" v-model="day.allDay" @change="handleChange" :min="1"
                :max="24" label="描述文字"></el-input-number>
                点提醒 -->
                <template >
                  <el-time-select
                    :picker-options="pickerOptions"
                    style="width: 70%;"  v-model="day.allDay"/>
                </template>
            </el-form-item>
          </el-col>
        </el-row>

      </div>
    </el-form>

    <el-form :model="week" :rules="rules" ref="week" label-width="130px">
      <div class="form-item">
        <el-row>
          <el-col :xs="24" :sm="12" :md="8" :lg="4">
            <div class="item-title">
              每周履职
            </div>
          </el-col>
          <el-col>
            <el-form-item label="提前" prop="allDay">
              <el-input-number size="mini" style="width: 30%;" v-model="week.allDay" @change="handleChange" :min="1"
                :max="100" label="描述文字"></el-input-number>
              天提醒
            </el-form-item>


          </el-col>
        </el-row>
      </div>
    </el-form>

    <el-form :model="month" :rules="rules" ref="month" label-width="130px">
      <div class="form-item">
        <el-row>
          <el-col :xs="24" :sm="12" :md="8" :lg="4">
            <div class="item-title">
              每月履职
            </div>
          </el-col>
          <el-col>
            <el-form-item label="提前" prop="allDay">
              <el-input-number size="mini" style="width: 30%;" v-model="month.allDay" @change="handleChange" :min="1"
                :max="10" label="描述文字"></el-input-number>
              天提醒
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
    <el-form :model="season" :rules="rules" ref="season" label-width="130px">
      <div class="form-item">
        <el-row>
          <el-col :xs="24" :sm="12" :md="8" :lg="4">
            <div class="item-title">
              每季履职
            </div>
          </el-col>
          <el-col>
            <el-form-item label="提前" prop="allDay">
              <el-input-number size="mini" style="width: 30%;" v-model="season.allDay" @change="handleChange" :min="1"
                :max="10" label="描述文字"></el-input-number>
              天提醒
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
    <el-form :model="halfYear" :rules="rules" ref="halfYear" label-width="130px">
      <div class="form-item">
        <el-row>
          <el-col :xs="24" :sm="12" :md="8" :lg="4">
            <div class="item-title">
              半年履职
            </div>
          </el-col>
          <el-col>
            <el-form-item label="提前：" prop="allDay">
              <el-input-number size="mini" style="width: 30%;" v-model="halfYear.allDay" @change="handleChange" :min="1"
                :max="10" label="描述文字"></el-input-number>
              天提醒
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
    <el-form :model="year" :rules="rules" ref="year" label-width="130px">
      <div class="form-item">
        <el-row>
          <el-col :xs="24" :sm="12" :md="8" :lg="4">
            <div class="item-title">
              每年履职
            </div>
          </el-col>
          <el-col>
            <el-form-item label="提前：" prop="allDay">
              <el-input-number size="mini" style="width: 30%;" v-model="year.allDay" @change="handleChange" :min="1"
                :max="10" label="描述文字"></el-input-number>
              天提醒
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
    <div style="margin-top: 50px; margin-left: 42%">
      <el-button type="primary" @click="saveExtend" size="small">提交</el-button>
      <!--    <el-button type="primary" @click="nosaveExtend" size="small">取消</el-button> -->
    </div>
  </div>
</template>

<script>
import { insertConfiguration, getInfo } from "@/api/resumption/configuration";
export default {
  props: [],
  components: {},
  data() {
    return {
      coreResumptionConfigurationDTO: [],
      num: 1,
      day: {
        id:null,
        resumptionCycle: 2,
        front: null,
        centre: null,
        after: null,
        allDay: null,
        timeUnit: 1,
      },
      week: {
        id:null,
        resumptionCycle: 3,
        allDay: null,
        timeUnit: 2
      },
      month: {
        id:null,
        resumptionCycle: 4,
        allDay: null,
        timeUnit: 2
      },
      season: {
        id:null,
        resumptionCycle: 5,
        allDay: null,
        timeUnit: 2
      },
      halfYear: {
        id:null,
        resumptionCycle: 6,
        allDay: null,
        timeUnit: 2
      },
      year: {
        id:null,
        resumptionCycle: 7,
        allDay: null,
        timeUnit: 2
      },

      rules: {
        name: [
          {
            required: true,
            message: "请输入活动名称",
            trigger: "blur",
          },
          {
            min: 3,
            max: 5,
            message: "长度在 3 到 5 个字符",
            trigger: "blur",
          },
        ],
        region: [
          {
            required: true,
            message: "请选择活动区域",
            trigger: "change",
          },
        ],
        date1: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
        date2: [
          {
            type: "date",
            required: true,
            message: "请选择时间",
            trigger: "change",
          },
        ],
        type: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个活动性质",
            trigger: "change",
          },
        ],
        resource: [
          {
            required: true,
            message: "请选择活动资源",
            trigger: "change",
          },
        ],
        desc: [
          {
            required: true,
            message: "请填写活动形式",
            trigger: "blur",
          },
        ],
      },
    }
  },

  watch: {},
  computed: {
    pickerOptions() {
      return {
        start: "00:00",
        end: "24:00",
        step: "01:00",
      };
    },
  },
  beforeCreate() { },

  beforeMount() { },
  mounted() { },
  beforeUpdate() { },
  updated() { },
  destroyed() { },
  created() {
    this.selectInfo();
  },
  methods: {
    request() { },
    handleChange(value) { },
    selectInfo() {
      this.loading = true;
      getInfo().then(response => {
        if (response.data.coreResumptionConfiguration.length > 0) {
          this.coreResumptionConfigurationDTO = response.data.coreResumptionConfiguration;
          this.day = this.coreResumptionConfigurationDTO[0],
            this.week = this.coreResumptionConfigurationDTO[1],
            this.month = this.coreResumptionConfigurationDTO[2],
            this.season = this.coreResumptionConfigurationDTO[3],
            this.halfYear = this.coreResumptionConfigurationDTO[4],
            this.year = this.coreResumptionConfigurationDTO[5]
        }
      });
    },



    checkForm(form) {
      let val
      this.$refs[form].validate(valid => {
        
        val = valid
      });
      return val;
    },
    saveExtend() {
      let arr = ['day', 'week', 'month', 'season', 'halfYear', 'year'];
      let flags = [];
      arr.forEach(v => {
        flags.push(this.checkForm(v));
      });
     
      let flag = flags.every(v => {
      
        return v == true;
      })
    
      if (!flag) return;
      let data = {
      
        coreResumptionConfiguration: [this.day, this.week, this.month, this.season, this.halfYear, this.year]
      };
      insertConfiguration(data).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.open = false;
      this.  selectInfo();
      })
    }
  },
  fillter: {},
}
</script>

<style lang="scss" scoped>
.form-item {
  border: 1px solid #f1f1f1;
  margin-bottom: 2px;
  min-height: 100px;
  display: flex;
  align-items: center;
}

.item-title {
  width: 100px;
  color: #fff;
  background-color: #ccc;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}
</style>
