<template>
    <div class="susDetail">
        <div class="firstPage">
            <ul>
                <li class="titleLi">
                    姓名：
                    <input
                        type="text"
                        placeholder=""
                        readonly
                        v-model="worker.xm"
                    />
                </li>
                <li class="titleLi">
                    手机号：
                    <input
                        type="text"
                        placeholder=""
                        readonly
                        v-model="worker.sjhm"
                    />
                </li>
                <li class="titleLi">
                    异常说明：
                    <input
                        type="text"
                        placeholder=""
                        readonly
                        v-model="worker.ycyy"
                    />
                </li>
                <li class="titleLi">
                    最后一次进出时间：
                    <input type="text" placeholder="" readonly v-model="time" />
                </li>
            </ul>
        </div>
        <div class="secendPage">
            <div>请确认该员工是否离职？</div>
            <van-radio-group v-model="commit.qysfqr">
                <van-radio name="1">是</van-radio>
                <van-radio name="2">否</van-radio>
            </van-radio-group>
            <div v-show="commit.qysfqr == '2'">
                <p class="resonBox">
                    缺勤原因：
                    <van-dropdown-menu>
                        <van-dropdown-item
                            v-model="commit.qqyy"
                            :options="option1"
                            @change="selectReson"
                        />
                    </van-dropdown-menu>
                </p>
                <p>
                    <van-cell
                        title="请选择缺勤日期"
                        :value="date"
                        @click="show = true"
                    />
                    <van-calendar
                        v-model="show"
                        type="range"
                        @confirm="onConfirm"
                        :min-date="minDate"
                        :max-date="maxDate"
                    />
                </p>
            </div>
        </div>
        <div class="buttonBox">
            <button class="preservation btn2" @click="submit">
                提交
            </button>
        </div>
    </div>
</template>
<script>
import { getWarnEdit } from "@/service/api_company.js";
import { Toast } from "vant";
export default {
    data() {
        return {
            worker: {},
            time: "",
            commit: {
                id: "",
                qysfqr: "1",
                qqyy: "出长差",
                qqstart: "",
                qqend: ""
            },

            option1: [
                { text: "出长差", value: "出长差" },
                { text: "长病假", value: "长病假" },
                { text: "产假", value: "产假" },
                { text: "陪产假", value: "陪产假" },
                { text: "其他", value: "其他" }
            ],
            date: "",
            show: false,
            minDate: new Date(2019, 0, 1),
            maxDate: new Date(2025, 0, 1)
        };
    },
    mounted() {
        console.log(JSON.parse(this.$route.query.item));
        this.worker = JSON.parse(this.$route.query.item);
        this.commit.id = this.worker.id;
        console.log(this.commit);
        this.getTime();
    },
    methods: {
        getTime() {
            let dayjs = require("dayjs");
            this.time = dayjs(this.worker.jcsj).format("YYYY-MM-DD");
        },
        submit() {
            if (this.commit.qysfqr == "2") {
                if (!this.commit.qqstart || !this.commit.qqend) {
                    Toast("请选择缺勤日期");
                    return;
                }
            }
            getWarnEdit(this.commit).then(res => {
                Toast(res.errmsg);
                this.$router.push("/suspected");
            });
        },
        formatDate(date) {
            return `${date.getMonth() + 1}/${date.getDate()}`;
        },
        onConfirm(date) {
            const [start, end] = date;
            this.show = false;
            this.date = `${this.formatDate(start)} - ${this.formatDate(end)}`;
            let dayjs = require("dayjs");
            this.commit.qqstart = dayjs(date[0]).format("YYYY-MM-DD");
            this.commit.qqend = dayjs(date[1]).format("YYYY-MM-DD");
        }
    }
};
</script>
<style lang="scss">
.susDetail {
    font-size: 4vw;
    margin: 5vw 2vw;
    .firstPage {
        background: white;
        padding: 3vw 3vw 3vw 3vw;
        margin-top: 5vw;
        border-radius: 15px;
        li {
            display: flex;
            align-items: center;
            height: 10vw;
            padding: 3vw 0;
            border-bottom: 1px solid rgb(243, 236, 236);
        }
        .titleLi {
            font-size: 3.5vw;
            font-weight: 700;
            white-space: nowrap;
            .required {
                color: red;
            }
            .van-uploader {
                padding: 3vw 0;
            }
        }
    }
    .secendPage {
        background: white;
        padding: 3vw 5vw 3vw 5vw;
        margin-top: 5vw;
        border-radius: 15px;
        font-size: 5vw;
        div {
            margin: 2vw 0;
        }
    }
    .buttonBox {
        background: white;
        display: flex;
        align-items: center;
        justify-content: space-evenly;
        margin-top: 5vw;
        margin-bottom: 0;
        padding: 5vw 0;

        button {
            padding: 3vw 20vw;
            border-radius: 15px;
        }
        .btn2 {
            background-color: rgb(0, 47, 167);
            color: white;
            border: white solid 1px;
        }
    }
    .resonBox {
        display: flex;
        align-items: center;
        .van-cell {
            margin: 0 !important;
        }
    }
    .van-dropdown-menu {
        margin: 0 !important;
        display: flex !important;
        align-items: center !important;
    }
    .van-dropdown-menu__bar {
        box-shadow: none !important;
        margin: 0 !important;
        .van-ellipsis {
            margin: 0 !important;
        }
        .van-dropdown-menu__item {
            margin: 0 !important;
        }
    }
}
</style>
