<template>
    <div>
        <el-dialog title="批量文书签字" :visible="true" width="600px" append-to-body :close-on-click-modal="false" 
            @close="handleClose">
            <div class="dialog-content dialog-office-batch">
                <div class="pt-8">
                    <div class="flex-row align-items-center justify-content-between mb-16 case-batch-num">
                        <span>选中<a>{{eventTraDialog.caseids.length}}</a>个案件，系统将对您选择的案件中，符合签字条件（已经完成文书生成）的文书发起批量电子签字！</span>
                    </div>
                    <el-collapse-transition>
                        <el-row :gutter="56">
                            <el-col :span="24">
                                <div class="flex-row-center align-items-center height-40 mb-8">
                                    <span class="tabs__search-criteria-title flex-shrink-0 pr-16 f18">选择文书类型（多选）</span>
                                </div>
                            </el-col>
                            <el-col :span="24">
                                <div class="mb-24 officelist">
                                    <el-checkbox-group v-model="ObjectInfo.fileTypes">
                                        <el-checkbox border v-for="(item,index) in officeOptions" :label="item.value" :key="index" >{{item.label}}</el-checkbox>
                                    </el-checkbox-group>
                                </div>
                                    
                            </el-col>
                            <el-col :span="24">
                                <div class="flex-row-center align-items-center height-40 mb-24">
                                    <span class="tabs__search-criteria-title flex-shrink-0 pr-16" style="width:100px">签字有效时间</span>
                                    <el-select v-model="ObjectInfo.deadNum"
                                            placeholder="请选择签字有效期限" class="width100">
                                        <el-option label="1天" value="1"></el-option>
                                        <el-option label="2天" value="2"></el-option>
                                        <el-option label="3天" value="3"></el-option>
                                        <el-option label="4天" value="4"></el-option>
                                        <el-option label="5天" value="5"></el-option>
                                    </el-select>
                                </div>
                            </el-col>
                            
                            
                        </el-row>
                    </el-collapse-transition>
                </div>

            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="handleClose()">取消</el-button>
                <el-button type="primary" @click="handleSubmit()">批量发起</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import api from "@/services/caseManagement";
    export default {
        components: {
        },
        props: {
            eventTraDialog: {
                type: Object,
                default: () => {
                    return {}
                },
            },
        },
        data() {
            return {
                officeOptions:[
                    {label: '调解告知书', value: 'MEDIATE_NOTE'},
                    {label: '调解申请书', value: 'MEDIATE_APPLICATION'},
                    {label: '送达地址确认书', value: 'CONFIRMATION_OF_ADDRESS'},
                    {label: '调解询问笔录', value: 'MEDIATE_RECORD'},
                    {label: '调解协议', value: 'MEDIATE_AGREEMENT'},
                ],

                
                ObjectInfo:{
                    fileTypes:['MEDIATE_NOTE','MEDIATE_APPLICATION','CONFIRMATION_OF_ADDRESS'],
                    deadline:'1',
                    deadNum:'1',
                    caseIdList:[]
                },
                tableData:[],
                total:0,

            };
        },
        mounted () {
            
        },
        methods: {
            smsChange(){
                let jsonData = this.smsOptions.find(item=>{
                    return this.ObjectInfo.methodId == item.value
                })
                this.ObjectInfo.users = jsonData.users
                this.ObjectInfo.content = jsonData.content
            },
            handleSubmit(){
                if(!this.$clickThrottle()) { return }//防止重复点击
                if (this.ObjectInfo.fileTypes.length == 0){
                    this.$message.warning("请选择文书类型！");
                    return
                }
                // 获取当前日期
                let currentDate = new Date();
                // 获取昨天的日期
                const nextDate = currentDate
                currentDate.setDate(currentDate.getDate() + (this.ObjectInfo.deadNum*1))
                const year = nextDate.getFullYear();
                const month = (nextDate.getMonth() + 1).toString().padStart(2, '0');
                const day = nextDate.getDate().toString().padStart(2, '0');
                const nowtime = nextDate.getHours().toString().padStart(2, '0')+':'+
                nextDate.getMinutes().toString().padStart(2, '0')+':'+nextDate.getSeconds().toString().padStart(2, '0');
                // this.ObjectInfo.deadline = year +'-'+ month +'-'+ day + ' 23:23:59'
                this.ObjectInfo.deadline = year +'-'+ month +'-'+ day + ' '+ nowtime
                
                this.ObjectInfo.caseIdList = this.eventTraDialog.caseids;
                api.traceSignBatchCreate(this.ObjectInfo).then((res) => {
                    this.$message.success("批量发起签字成功");
                    this.handleClose()
                    this.$parent.getCaseInfoList(this.eventTraDialog.current)
                });
            },

            // traceSignBatchCreate

            handleClose() {
                this.$emit('update:eventTraDialog', null)
            },
        }
    };
</script>

<style scoped lang="scss">
.dialog-office-batch{
    padding: 16px 30px;
    max-height:500px;
    .tabs__search-criteria-title{
        width: 100%;
    }
    .case-batch-num{
        background-color: rgba(236, 238, 241, 0.8196078431);
        padding: 15px 20px;
        border-radius: 4px;
        a{font-size: 16px;font-weight: 500;color: #C66A5B;}
    }
    .officelist{
        background-color: rgba(236, 238, 241, 0.8196078431);
        padding: 20px 20px;
        .el-checkbox
        {
            width: 230px;
            margin: 10px;
        }
    }
    
}
</style>