<template>
  <div class="app-container" style="min-height: 100%;">
    <div class="business-options">
      <div class="item-title">
        每日履职
      </div>
      <div class="form-item">
        <el-form ref="day" :model="day" :rules="rules">
            <el-row :gutter="10">
              <el-col :lg="6" :md="12" :sm="12" :xs="24">
                <el-form-item label="营业前：" prop="front" >
                  <el-time-select
                    v-model="day.front"
                    :picker-options="pickerOptions" />
                </el-form-item>
              </el-col>
              <el-col :lg="6" :md="12" :sm="12" :xs="24">
                <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>
                  点提醒 -->
                  <el-time-select
                    v-model="day.centre"
                    :picker-options="pickerOptions" />
                </el-form-item>
              </el-col>
              <el-col :lg="6" :md="12" :sm="12" :xs="24">
                <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>
                    点提醒 -->
                  <el-time-select
                    v-model="day.after"
                    :picker-options="pickerOptions" />
                </el-form-item>
              </el-col>
              <el-col :lg="6" :md="12" :sm="12" :xs="24">
                <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>
                    点提醒 -->
                  <el-time-select
                    v-model="day.allDay"
                    :picker-options="pickerOptions" />
                </el-form-item>
              </el-col>
            </el-row>
        </el-form>
      </div>
      <div class="item-title">
        每周履职
      </div>
      <el-form ref="week" :model="week" :rules="rules">
        <div class="form-item">
          <el-row>
            <el-col>
              <el-form-item label="提醒设置" prop="allDay">
                提前
                <el-input-number
                  v-model="week.allDay"
                  :max="100"
                  :min="1"
                  label="描述文字"
                  size="small"
                  @change="handleChange">
                </el-input-number>
                天
              </el-form-item>


            </el-col>
          </el-row>
        </div>
      </el-form>
      <div class="item-title">
        每月履职
      </div>
      <el-form ref="month" :model="month" :rules="rules">
        <div class="form-item">
          <el-row>
            <el-col>
              <el-form-item label="提醒设置" prop="allDay">
                提前
                <el-input-number
                  v-model="month.allDay"
                  :max="10"
                  :min="1"
                  label="描述文字"
                  size="small"
                  @change="handleChange">
                </el-input-number>
                天
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <div class="item-title">
        每季履职
      </div>
      <el-form ref="season" :model="season" :rules="rules">
        <div class="form-item">
          <el-row>
            <el-col>
              <el-form-item label="提醒设置" prop="allDay">
                提前
                <el-input-number
                  v-model="season.allDay"
                  :max="10"
                  :min="1"
                  label="描述文字"
                  size="small"
                  @change="handleChange">
                </el-input-number>
                天
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <div class="item-title">半年履职</div>
      <el-form ref="halfYear" :model="halfYear" :rules="rules" >
        <div class="form-item">
          <el-row>
            <el-col>
              <el-form-item label="提醒设置" prop="allDay">
                提前
                <el-input-number
                  v-model="halfYear.allDay"
                  :max="10"
                  :min="1"
                  label="描述文字"
                  size="small"
                  @change="handleChange">
                </el-input-number>
                天
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <div class="item-title">每年履职</div>
      <el-form ref="year" :model="year" :rules="rules" >
        <div class="form-item">
          <el-row>
            <el-col>
              <el-form-item label="提醒设置" prop="allDay">
                提前
                <el-input-number
                  v-model="year.allDay"
                  :max="10"
                  :min="1"
                  label="描述文字"
                  size="small"
                  @change="handleChange">
                </el-input-number>
                天
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
    </div>
    <div class="button-box">
      <el-button size="small" type="primary" @click="saveExtend">保存配置</el-button>
      <!--    <el-button type="primary" @click="nosaveExtend" size="small">取消</el-button> -->
    </div>
  </div>
</template>

<script>
import {getInfo, insertConfiguration} 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>
.business-options {

}
::v-deep{
  .el-form-item{
    margin-bottom: 10px;
  }
}
.form-item {
  width: 100%;
  border: 1px solid #f1f1f1;
  padding: 20px;
  margin-bottom: 10px;
  min-height: 70px;
  background-color: #fff;
  box-shadow: 0 5px 10px #eaeaea;
}

.item-title {
  width: 100px;
  color: #fff;
  background-color: #1ea8e9;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;

}
.button-box{
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
}
</style>
