<template>
        <div class="dialog-content dialog-office-batch">
            <div class="p-16">
                <div class="flex-row align-items-center justify-content-between mb-16 case-batch-num">
                    <span>系统将对当前案件中，符合签字条件（已经完成文书生成）的文书发起电子签字！</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.type" :key="index" :disabled="item.documentStaus.code != 2 ? true : false">{{ item.documentType.desc }}</el-checkbox>
                                </el-checkbox-group>
                            </div>
                            <!-- :disabled="item.documentStaus.code != 2 ? true : false" -->
                        </el-col>
                        <el-col :span="24">
                            <div class="flex-row-center align-items-center height-40">
                                <span class="tabs__search-criteria-title flex-shrink-0 pr-16" style="width:100px">签字有效时间</span>
                                <el-select v-model="ObjectInfo.deadNum" size="small"
                                        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>
            <span class="dialog-footer">
                <el-button size="small" @click="handleClose()">取消</el-button>
                <el-button size="small" type="primary" @click="handleSubmit()">发起签字</el-button>
            </span>
        </div>
</template>
<script>
import api from "@/services/caseManagement";
    export default {
        components: {
        },
        props: {
            eventTraDialog: {
                type: Object,
                default: () => {
                    return {}
                },
            },
            caseId: {
                type: String,
                default: () => {},
            },
            singleofficevisible: {
                type: Boolean,
                default: () => {return false},
            },
            
        },
        data() {
            return {
                officeOptions:[],
                ObjectInfo:{
                    fileTypes:[],
                    caseId:'',
                    deadline:'1',
                    deadNum:'1',
                },
                tableData:[]

            };
        },
        watch: {
            singleofficevisible: {
                deep: true,
                handler: function (val) {
                    if (this.singleofficevisible){
                        this.getWritCaseList()
                    }
                }
            }
        },
        mounted () {
            // this.getWritCaseList()
        },
        methods: {
            // 列表数据
            getWritCaseList() {
                let dataJson = {
                    id: this.caseId
                }
                api.getCaseGenerateList(dataJson).then(res => {
                    if (!res.code) {
                        this.officeOptions = res
                    }
                })
            },
            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.caseId = this.caseId
                api.traceSignCreate(this.ObjectInfo).then((res) => {
                    this.$message.success("发起签字成功");
                    this.handleClose()
                    this.$emit('handleUpdate',null)
                });
            },

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

<style scoped lang="scss">
.dialog-office-batch {
  width: 495px;
  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;
    height: 220px;
    .el-checkbox {
      width: 180px;
      margin: 10px;
    }
  }
  .dialog-footer{
    display: inline-block;
    width: 500px;
    text-align: right;
    border-top: solid 1px #E5E6EB;
    padding: 10px;
  }
}
</style>