<template>
  <div class="fullHeight">
    <div class="searchBox whiteBlock">
      <el-form :inline="true" :model="noticeForm" ref="noticeForm" label-width="100px" class="demo-form-inline">
        <el-form-item prop="noticeSwitch">
          <div style="padding: 0 0px 0 0;display: flex;align-items: center">
            <span style="padding: 0 10px 0 0;">是否开启通知提醒</span>
            <el-switch v-model="noticeForm.noticeSwitch" active-color="green" inactive-color="black" :active-value="'1'" :inactive-value="'0'"></el-switch>
          </div>
        </el-form-item>
        <el-form-item label="考试前" prop="examTimeNumber" :rules="[
          
          { type: 'number', message: '必须为数字值', trigger: 'change'}] ">
          <div style="width: 80px">
            <el-input v-model.number="noticeForm.examTimeNumber" :disabled="isdisabled" autocomplete="off"></el-input>
          </div>
        </el-form-item>
        <el-form-item prop="examTimeType">
          <div style="width: 80px">
            <el-select v-model="noticeForm.examTimeType" :disabled="isdisabled">
              <el-option v-for="item in examYmd" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item label="学习前" prop="studyTimeNumber" :rules="[
          
          { type: 'number', message: '必须为数字值', trigger: 'change'}] ">
          <div style="width: 80px">
            <el-input v-model.number="noticeForm.studyTimeNumber" autocomplete="off"></el-input>
          </div>
        </el-form-item>
        <el-form-item prop="studyTimeType">
          <div style="width: 80px">
            <el-select v-model="noticeForm.studyTimeType">
              <el-option v-for="item in studyYmd" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitNoticeForm('noticeForm')">保 存</el-button>
          <el-button type="primary" plain @click="isdisabled=false">编 辑</el-button>
        </el-form-item>
        
      </el-form>
      <!-- <el-button type="primary" size="medium" @click="add">新增</el-button> -->
    </div>
    <div class="table_wrap whiteBlock">
      <el-table class="tables" :data="tableData">
        <el-table-column prop="workerName" align="center" label="姓名" width="180"></el-table-column>
        <el-table-column prop="noticeWay" align="center" label="提醒方式"></el-table-column>
        <el-table-column prop="noticeEvent" align="center" label="提醒事件"></el-table-column>
        <el-table-column prop="noticeTime" align="center" label="时间" width="180"></el-table-column>
      </el-table>
      <el-pagination class="pagerBox" @size-change="SizeChange" @current-change="CurrentChange" :current-page="pagInfo.pageNo" :page-sizes="$store.state.PAGESIZRS" :page-size="pagInfo.pageSize" layout="total, sizes, prev, pager, next" :total="Number(pagInfo.total)" background>
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { rtToolPage } from '@/assets/js/api/workTicketManage.js'
import {} from '@/assets/js/api/devicePosition/deviceCentral.js'
import {
  addConfigApi,queryBySnConfigApi
} from '@/assets/js/api/examSystem/examSystem'


export default {
  mounted() {},
  created() {
    this.getList()
    console.log('👇')
    console.log(this.$store.state.UPLOADURL)
  },
  data() {
    return {
      studyYmd: [
        {value: '1', label: '年'},
        {value: '2', label: '月'},
        {value: '3', label: '日'},
      ],
      examYmd: [
        {value: '1', label: '年'},
        {value: '2', label: '月'},
        {value: '3', label: '日'},
      ],
      noticeForm: {
        noticeSwitch: '1',
        examTimeNumber: 0,
        examTimeType: '3',
        studyTimeNumber: 0,
        studyTimeType: '3',
      },
      fileList: [],
      title: '',
      dialogShow: false,
      pagInfo: {
        pageNo: 1, //页数
        pageSize: 10, //条数
        total: 0, //总条数
      },
      tableData: [],
      addEditForm: {
        id: '',
        fileName: '',
        pbulicStatus: '',
        uploadFile: '',
      },
      addEditRules: {
        fileName: [{ required: true, message: '必填', trigger: 'blur' }],
        uploadFile: [{ required: true, message: '上传文件', trigger: 'blur' }],
      },
      isdisabled:true,
    }
  },
  methods: {
    getList() {
      queryBySnConfigApi({
        // pageNo: this.pagInfo.pageNo,
        // pageSize: this.pagInfo.pageSize,
        sn: this.$store.state.projectSn,
      }).then((result) => {
        if (result.success) {
          console.log(result);
          this.tableData = result.result.records
          this.pagInfo.total = result.result.total
        }
      })
      // this.tableData = [
      //   { workerName: '1', noticeWay: '1',noticeEvent: '距考试还有31天', noticeTime: '2024-04-30 00:00:00' },
      //   { workerName: '2', noticeWay: '0',noticeEvent: '距考试还有31天', noticeTime: '2024-04-30 00:00:00' },
      //   { workerName: '3', noticeWay: '1',noticeEvent: '距考试还有31天', noticeTime: '2024-04-30 00:00:00' },
      //   { workerName: '4', noticeWay: '0',noticeEvent: '距考试还有31天', noticeTime: '2024-04-30 00:00:00' },
      //   { workerName: '5', noticeWay: '1',noticeEvent: '距考试还有31天', noticeTime: '2024-04-30 00:00:00' },
      // ]
    },
    submitNoticeForm(noticeForm) {
      this.$refs[noticeForm].validate((valid) => {
        if (valid) {
          addConfigApi({
            enable:parseInt(this.noticeForm.noticeSwitch),
            examNum:this.noticeForm.examTimeNumber,
            examType:parseInt(this.noticeForm.examTimeType),
            courseNum:this.noticeForm.studyTimeNumber,
            courseType:parseInt(this.noticeForm.studyTimeType),
            projectSn: this.$store.state.projectSn,
          }).then(result => {
              if (result.success) {
                  console.log('信息编辑成功', result);
                  this.$message.success(result.message);
              }
          })
        } else {
          alert('error submit!!')
          return false
        }
      })
    },
    SizeChange(val) {
      this.pagInfo.pageSize = val
      this.getList()
    },
    CurrentChange(val) {
      this.pagInfo.pageNo = val
      this.getList()
    },
    refresh() {
      this.pagInfo.pageNo = 1 //页数
      this.pagInfo.pageSize = 10 //条数
      this.getList()
    },
  },
}
</script>
<style lang="less" scoped>
.tables2 {
  min-height: auto;
}
.textStyle {
  width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tableBtns {
  display: flex;
  justify-content: center;
  align-item: center;
}
</style>