<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">

              <el-input-number size="mini" style="width: 70%;" v-model="day.front" @change="handleChange" :min="1"
                :max="10" label="描述文字"></el-input-number>
              分钟


            </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="10" label="描述文字"></el-input-number>
              分钟
            </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="10" label="描述文字"></el-input-number>
              分钟
            </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="10" label="描述文字"></el-input-number>
              分钟
            </el-form-item>
          </el-col>
        </el-row>

      </div>
    </el-form>

    <el-form :model="week" :rules="rules" ref="week" label-width="200px">
      <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="10" 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: {
        resumptionCycle: 1,
        allDay: null,
        front: null,
        centre: null,
        after: null,
        timeUnit: 1,
      },
      week: {
        resumptionCycle: 2,
        allDay: null,
        timeUnit: 2
      },
      month: {
        resumptionCycle: 3,
        allDay: null,
        timeUnit: 2
      },
      season: {
        resumptionCycle: 4,
        allDay: null,
        timeUnit: 2
      },
      halfYear: {
        resumptionCycle: 5,
        allDay: null,
        timeUnit: 2
      },
      year: {
        resumptionCycle: 6,
        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: {},
  beforeCreate() { },

  beforeMount() { },
  mounted() { },
  beforeUpdate() { },
  updated() { },
  destroyed() { },
  created() {
    this.selectInfo();
  },
  methods: {
    request() { },
    handleChange(value) { },
    selectInfo(){
      getInfo().then(response=>{
        this.coreResumptionConfigurationDTO = response.rows;
      })
    },
    checkForm(form) {
      let val
      this.$refs[form].validate(valid => {
        console.log(valid, 'valid')
        val = valid
      });
      return val;
    },
    saveExtend() {

      let arr = ['day', 'week', 'month', 'season', 'halfYear', 'year'];
      let flags = [];
      arr.forEach(v => {
        flags.push(this.checkForm(v));
      });
      console.log(flags, 'flags')
      let flag = flags.every(v => {
        console.log(v, 'valid')
        return v == true;
      })
      console.log(flag, 'flag')
      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;

      })
    }
  },
  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>
