<template>
  <div>
    <!-- 现场审核及校验 -->
    <div style="padding: 10px 0px">
      <el-row>
        <el-col :span="1"><div class="grid-content ep-bg-purple" /></el-col>
        <el-col :span="22">
          <div class="grid-content ep-bg-purple-light">
            <div
              style="
                text-align: center;
                width: 920px;
                font-weight: 700;
                font-size: 22px;
              "
            >
              现场审核及校验
            </div>
            <div
              style="
                width: 98%;
                margin-top: 20px;
                padding-top: 20px;
                border: 1px solid #dcdfe6;
              "
            >
              <el-form
                style="margin-left: 0.5vw"
                :model="form"
                label-width="180px"
              >
                <div style="display: flex">
                  <el-form-item label="事项名称">
                    <el-input
                      :disabled="deskWork !== undefined"
                      v-model="form.title"
                      placeholder="请输入事项名称"
                      style="width: 13vw"
                    />
                  </el-form-item>
                  <el-form-item style="margin-left: 1vw" label="添加时间">
                    <el-date-picker
                      :disabled="deskWork !== undefined"
                      @change="getTime(form.createTime)"
                      style="width: 12.5vw"
                      v-model="form.createTime"
                      type="datetime"
                      placeholder="请选择时间"
                    />
                  </el-form-item>
                </div>
                <div style="display: flex">
                  <el-form-item label="添加部门">
                    <el-input
                      :disabled="deskWork !== undefined"
                      v-model="form.deptname"
                      placeholder="请输入所属部门"
                      style="width: 13vw"
                    />
                  </el-form-item>
                  <el-form-item style="margin-left: 1vw" label="添加人员">
                    <el-input
                      :disabled="deskWork !== undefined"
                      v-model="form.createBy"
                      placeholder="请输入人员姓名"
                      style="width: 12.5vw"
                    />
                  </el-form-item>
                </div>
                <div style="display: flex">
                  <el-form-item align="center" label="现场审核及校验的时间">
                    <el-date-picker
                      :disabled="deskWork !== undefined"
                      @change="getTime1(form.checkTime)"
                      style="width: 13vw"
                      v-model="form.checkTime"
                      type="datetime"
                      placeholder="请选择时间"
                    />
                  </el-form-item>
                  <el-form-item style="margin-left: 1vw" label="审核及校验单位">
                    <el-input
                      :disabled="deskWork !== undefined"
                      v-model="form.checkDept"
                      placeholder=""
                      style="width: 12.5vw"
                    />
                  </el-form-item>
                </div>
                <el-form-item
                  style="margin-top: 20px"
                  align="center"
                  label="监督执法处室及人员"
                >
                  <el-input
                    :disabled="deskWork !== undefined"
                    v-model="form.deptPerson"
                    style="width: 35.5vw"
                    type="textarea"
                    :rows="4"
                  >
                  </el-input>
                </el-form-item>
                <el-form-item
                  v-if="deskWork == undefined"
                  label="运行状态"
                  style="margin-top: 20px"
                  ><el-radio-group v-model="form.status">
                    <el-radio
                      :disabled="deskWork !== undefined"
                      @click.prevent="getCurrentRow(1)"
                      :label="1"
                      >公示中</el-radio
                    >
                    <el-radio
                      :disabled="deskWork !== undefined"
                      @click.prevent="getCurrentRow(0)"
                      :label="0"
                      >已完成</el-radio
                    >
                    <!-- <el-radio :label="2">未公示</el-radio> -->
                  </el-radio-group></el-form-item
                >
                <el-form-item
                  v-else
                  v-model="form.status"
                  label="运行状态"
                  style="margin-top: 20px"
                >
                  <div v-if="form.status == 1">公示中</div>
                  <div v-if="form.status == 0">已完成</div>
                </el-form-item>
                <el-form-item v-if="deskWork == undefined">
                  <div
                    style="
                      text-align: center;
                      margin-top: 20px;
                      margin-left: 14vw;
                    "
                  >
                    <el-button
                      style="padding: 0 40px"
                      type="primary"
                      @click="onSubmit"
                      >保 存</el-button
                    >
                  </div>
                  <!-- <el-button>Cancel</el-button> -->
                </el-form-item>
              </el-form>
            </div>
          </div>
        </el-col>
        <el-col :span="1"><div class="grid-content ep-bg-purple" /> </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import {
  listCatagory,
  getCatagory,
  delCatagory,
  addCatagory,
  updateCatagory,
} from "@/api/aleave/catagory";
import { getAleaves } from "@/api/aleave/aleaves";
import { getInfo } from "@/api/login";
import { getToken } from "@/utils/auth";
import { Base64 } from "js-base64";
import { addAleave } from "@/api/aGodGod/submitEdit";
export default {
  name: "YinetoaWjwWebIndex",
  props: ["Id1", "deskWork"],
  data() {
    return {
      form: {
        title: "",
        status: null,
        createBy: "",
        createTime: "",
        deptPerson: "",
        checkTime: "",
        checkDept: "",
      },
    };
  },
  created() {
    this.getList();
    this.editOrheadleUpdate();
    this.getInfo();
    this.currentTime();
  },
  watch: {
    Id1: {
      handler(newValue, oldValue) {
        if (newValue) {
          this.Id = newValue;
          this.getList();
        }
      },
      deep: true,
      immediate: true,
    },
  },
  mounted() {},

  methods: {
    currentTime() {
      var date = new Date();
      this.form.createTime = date;
      this.getTime(this.form.createTime);
    },
    //基本信息
    async getInfo() {
      let { user } = await getInfo();
      this.form.deptname = user.dept.deptName;
      this.form.createBy = user.nickName;
    },
    editOrheadleUpdate() {
      if (this.$route.query.id !== undefined || this.Id !== undefined) {
        // this.edit();
        const _id = this.$route.query.id || this.Id;
        getAleaves(_id).then((response) => {
          this.form = response.data;
        });
      }
    },
    reset() {
      this.form = {
        id: null,
        title: "",
        status: null,
        createBy: "",
        createTime: "",
        deptPerson: "",
        checkTime: "",
        checkDept: "",
      };
    },
    getCurrentRow(row) {
      if (this.form.status === row) {
        this.form.status = "";
        return;
      }
      // 不是选中，选中当前点击 Radio
      this.form.status = row;
      // 选中操作
    },
    getTime(time) {
      var date = new Date(time);
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      var h = date.getHours();
      h = h < 10 ? "0" + h : h;
      var minute = date.getMinutes();
      minute = minute < 10 ? "0" + minute : minute;
      var s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      this.form.createTime =
        y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + s;
      return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + s;
    },
    getTime1(time) {
      var date = new Date(time);
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      var h = date.getHours();
      h = h < 10 ? "0" + h : h;
      var minute = date.getMinutes();
      minute = minute < 10 ? "0" + minute : minute;
      var s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      this.form.checkTime =
        y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + s;
      return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + s;
    },
    getList() {
      listCatagory(this.queryParams).then((response) => {
        this.catagoryList = response;

        this.id = response.rows[4].id;
        this.form.title = response.rows[4].title;
      });
    },
    async onSubmit() {
      this.form.catagory = this.id;
      let { code } = await addAleave(this.form);
      if (code == 200) {
        if (this.$route.query.id !== undefined) {
          this.$modal.msgSuccess("编辑成功");
          this.form.id = this.$route.query.id;
        } else {
          this.$modal.msgSuccess("保存成功");
          this.reset();
          this.getInfo();
          this.currentTime();
          this.$route.query.id = undefined;
          this.Id = undefined;
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
