<template>
    <div v-if="datas && datas.length > 0">

        <el-tabs type="card" v-model="activeNames">
            <el-tab-pane :label="'第' + it.quarterly + '季度'" :name="'' + it.quarterly" v-for="(it, idx) in datas" :key="idx">
                <el-form label-width="120px" :ref="'frm' + it.quarterly" :model="it" :rules="rules">
                    <el-row v-if="1==2">
                        <el-col :span="12">
                            <el-form-item label="计划完成时间" prop="planDate">
                                <el-date-picker v-model="it.planDate" type="date" :default-value="getDefaultDate(it, 1)"
                                    value-format="yyyy-MM-dd"
                                    placeholder="选择日期" :picker-options="{ disabledDate: t => checkDate(t, it, 'start') }">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="实际完成时间" prop="finishDate">
                                <el-date-picker v-model="it.finishDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"
                                    :picker-options="{ disabledDate: t => checkDate(t, it, 'end') }"
                                    :default-value="getDefaultDate(it, 2)">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-form-item label="考核目标" prop="planTarget">
                            <el-input type="textarea" :rows="5" placeholder="请输入内容" v-model="it.planTarget">
                            </el-input>
                        </el-form-item>
                    </el-row>
                    <el-row v-if="1==2">
                        <el-form-item label="目前进展" prop="curProgress">
                            <el-input type="textarea" :rows="5" placeholder="请输入内容" v-model="it.curProgress">
                            </el-input>
                        </el-form-item>
                    </el-row>
                    <el-row v-if="1==2">
                        <el-form-item label="滞后事项" prop="laggingMatters">
                            <el-input type="textarea" :rows="5" placeholder="请输入内容" v-model="it.laggingMatters">
                            </el-input>
                        </el-form-item>
                    </el-row>
                    <el-row v-if="1==2">
                        <el-form-item label="存在问题" prop="problem">
                            <el-input type="textarea" :rows="5" placeholder="请输入内容" v-model="it.problem">
                            </el-input>
                        </el-form-item>
                    </el-row>
                    <div style="text-align: center;margin-bottom: 12px;">
                        <el-button type="primary" @click="doSave(it)">保存</el-button>
                    </div>
                </el-form>
            </el-tab-pane>
        </el-tabs>


    </div>
</template>

<script>
export default {
    name: 'RuoyiUiAssessItem',
    props: {
        datas: {
            type: Array,
            default: () => []
        }
    },
    data() {
        return {
            activeNames: "1",
            rules: {
                //planDate: [{ required: true, trigger: "blur", message: "请选择日期" }],
                planTarget: [{ required: true, trigger: "blur", message: "请输入内容" }],
            }
        };
    },

    mounted() {

    },

    methods: {
        getDefaultDate(dt, o) {
            if (o == 1) {
                let y = dt.year;
                if (dt.quarterly == 2) {
                    return this.$dt(y + "-4-1");
                }
                if (dt.quarterly == 3) {
                    return this.$dt(y + "-7-1");
                }
                if (dt.quarterly == 4) {
                    return this.$dt(y + "-10-1");
                }
                return this.$dt(y + "-1-1");
            } else {
                return this.$dt(dt.planDate)
            }

        },
        checkDate(d, dt, o) {
            if (o == 'start') {
                let y = dt.year;
                let dt1 = new Date();
                let dt2 = new Date();
                if (dt.quarterly == 1) {
                    dt1 = this.$dt(y + "-1-1");
                    dt2 = this.$dt(y + "-3-31");
                }
                if (dt.quarterly == 2) {
                    dt1 = this.$dt(y + "-4-1");
                    dt2 = this.$dt(y + "-6-31");
                }
                if (dt.quarterly == 3) {
                    dt1 = this.$dt(y + "-7-1");
                    dt2 = this.$dt(y + "-9-31");
                }
                if (dt.quarterly == 4) {
                    dt1 = this.$dt(y + "-10-1");
                    dt2 = this.$dt(y + "-12-31");
                }
                if (+d < +dt1) {
                    return true;
                }
                if (+d > +dt2) {
                    return true;
                }
            }
            if (o == "end") {
                if (+d < +this.$dt(dt.planDate)) {
                    return true
                }
            }
            return false;
        },
        doSave(it) {
            this.$refs["frm" + it.quarterly][0].validate(v => {
                if (v) {
                    this.toSave(it);
                }
            })
        },
        toSave(it) {            
            this.$api.projectAsscess.updateAssess(it).then(d => {                
                this.$message({
                    message: '保存成功',
                    type: 'success'
                })
            })
        }
    },
};
</script>
