<template>
    <section>
        <!--工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true" @submit.native.prevent>
                <el-form-item label="企业列表">
                </el-form-item>
                <el-form-item >
                    <div>
                    <el-input style="float:left;" v-model="keyword" class="input-with-select" placeholder="请输入企业名称关键字" clearable @change="searchList">
                        <el-button slot="append" @click.stop="searchList" icon="el-icon-search"></el-button>
                    </el-input>
                    </div>
                </el-form-item>
                <el-form-item >
                        <el-radio-group v-model="isMeal" size="small" @change="selIsmeal()">
                            <el-radio-button :label="0">全部</el-radio-button>
                            <el-radio-button :label="1">已签约</el-radio-button>
                            <el-radio-button :label="2">即将到期</el-radio-button>
                        </el-radio-group>
                        <el-checkbox v-model="onlyContract" v-if="isMeal == 2" style="margin-left: 20px" @change="selIsmeal()">仅显示已签约</el-checkbox>
                        <!-- <el-checkbox style="margin-left:20px" size="small" v-model="checked" @change="selIsmeal()">即将到期</el-checkbox> -->
                </el-form-item>
                <el-form-item>
                    <el-button type="text" @click="addFeishuDig=true">新增飞书企业</el-button>
                </el-form-item>
            </el-form>
        </el-col>

        <!--列表-->
        <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
            <el-table-column prop="id" label="企业ID" min-width="180" align="center"></el-table-column>
            <el-table-column prop="companyName" label="企业名称" min-width="240" align="center">
            </el-table-column>
            <el-table-column prop="setMeal" label="是否签约"  min-width="80" align="center">
                <template slot-scope="scope">{{scope.row.setMeal ? "已签约" : "未签约"}}</template>
            </el-table-column>
            
            <el-table-column prop="expirationDate" label="有效期"  min-width="160" align="center">
            </el-table-column>
            <el-table-column prop="remainingValidDays" label="剩余有效天数"  min-width="160" align="center">
            </el-table-column>
            <el-table-column prop="wxCorpid" label="企业微信"  min-width="160" align="center">
            </el-table-column>
            <el-table-column prop="dingdingCorpid" label="钉钉"  min-width="160" align="center">
            </el-table-column>
            <el-table-column prop="feishuInfoid" label="飞书"  min-width="160" align="center">
            </el-table-column>
            <el-table-column prop="staffCountMax" label="人数上限"  min-width="80" align="center">
            </el-table-column>
            <el-table-column prop="activeUserCount" label="在职人数"  min-width="80" align="center">
                <template slot-scope="scope">
                    <div :style="'color:'+(parseInt(scope.row.activeUserCount)>parseInt(scope.row.staffCountMax)?'red':'')">{{scope.row.activeUserCount}}</div>
                </template>
            </el-table-column>
            <el-table-column prop="packageWorktime" label="使用版本" align="left" min-width="500" header-align="center">
                <template slot-scope="scope">
                    <!-- <span>{{scope.row.packageWorktime ? "工时 +" : ""}}</span>
                    <span>{{scope.row.packageProject ? "项目协作 +" : ""}}</span>
                    <span>{{scope.row.packageContract ? "合同 +" : ""}}</span>
                    <span>{{scope.row.packageOa ? "OA +" : ""}}</span>
                    <span>{{scope.row.packageEtimecard ? "生产车间 +" : ""}}</span>
                    <span>{{scope.row.packageExpense ? "费用报销 +" : ""}}</span>
                    <span>{{scope.row.packageCustomer ? "客户管理 +" : ""}}</span>
                    <span>{{scope.row.packageEngineering ? "工程专业 +" : ""}}</span>
                    <span>{{scope.row.packageSimple ? "简单表格 +" : ""}}</span>
                    <span>{{scope.row.packageFinance ? "财务核算" : ""}}</span> -->
                    <span v-for="(item, index) in scope.row.arrList" :key="index">
                        {{item}} <span v-if="scope.row.arrList.length != 1 && scope.row.arrList.length - 1 != index">+</span>
                    </span>
                </template>
            </el-table-column>
            
            <el-table-column label="操作" width="360" class-name="btns" header-align="center" fixed="right">
                <template slot-scope="scope">
                    <el-button size="mini"  @click="editClick('A', scope.row)">增加人数</el-button>
                    <el-button size="mini"  @click="editClick('B', scope.row)">修改有效期</el-button>
                    <el-button size="mini"  @click="editClick('F', scope.row)" :disabled="!(scope.row.dingdingCorpid || scope.row.wxCorpid)">考勤同步设置</el-button>
                    <el-button size="mini"  @click="editClick('C', scope.row)">修改版本</el-button>
                    <el-button size="mini"  @click="editClick('D', scope.row)">{{scope.row.setMeal ? '设为未签约' : '设为已签约'}}</el-button>
                    <el-button size="mini"  @click="editClick('G', scope.row)">其他设置</el-button>
                    <el-button size="mini"  @click="editClick('H', scope.row)">报表配置</el-button>
                    <el-button size="mini"  @click="editClick('K', scope.row)" v-if="user.phone=='15895914665'">登录系统</el-button>
                    <el-button size="mini"  @click="editClick('I', scope.row)"  v-if="scope.row.canDelete">删除企业</el-button>
                    <el-button size="mini"  @click="editClick('E', scope.row)" v-loading="dingdingSync" v-if="scope.row.dingdingCorpid">同步钉钉人员</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--工具条-->
        <el-col :span="24" class="toolbar">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :page-sizes="[20 , 50 , 80 , 100]"
                :page-size="20"
                layout="total, sizes, prev, pager, next"
                :total="total"
                style="float:right;"
            ></el-pagination>
        </el-col>

        <!--编辑界面-->
        <!-- 增加人数上限 -->
        <el-dialog v-if="editDialogA" :visible.sync="editDialogA" title="增加人数上限">
            <el-form @submit.native.prevent>
                <el-form-item label="企业名称" label-width="150px">{{dialogData.companyName}}</el-form-item>
                <el-form-item label="当前人数上限" label-width="150px">{{dialogData.staffCountMax}}人</el-form-item>
                <el-form-item label="本次增加人数" label-width="150px">
                    <el-input-number size="small" controls-position="right" v-model="addStaffCountMaxNum" :step="5"></el-input-number> 人
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogA = false">取 消</el-button>
                <el-button type="primary" @click="ConfirmA()">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 修改有效期 -->
        <el-dialog v-if="editDialogB" :visible.sync="editDialogB" title="修改有效期">
            <el-form>
                <el-form-item label="企业名称" label-width="150px">{{dialogData.companyName}}</el-form-item>
                <el-form-item label="当前有效期至" label-width="150px">{{dialogData.expirationDate}}</el-form-item>
                <el-form-item label="修改有效期至" label-width="150px">
                    <el-date-picker
                        size="small"
                        v-model="expirationNewDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择日期">
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogB = false">取 消</el-button>
                <el-button type="primary" @click="ConfirmB()">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 编辑版本 -->
        <el-dialog v-if="editDialogC" :visible.sync="editDialogC" title="修改版本">
            <el-form>
                <el-form-item label="企业名称" label-width="150px">{{dialogData.companyName}}</el-form-item>
                <el-form-item label="版本" label-width="150px">
                    <div style="width:80%">
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageWorktime">工时平台</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageProject">项目协作平台</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageContract">合同平台</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageOa">OA平台</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageEtimecard">生产车间平台</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageExpense">费用报销</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageCustomer">客户管理</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageEngineering">工程专业</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageSimple">简单表格</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageFinance">财务核算</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageProvider">供应商管理</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageProjectApproval">立项管理</el-checkbox></div>
                        <div style="width:33%; float:left;"><el-checkbox v-model="dialogData.packageDevice">设备管理</el-checkbox></div>
                    </div>
                    
                    <!-- <span>{{scope.row.packageWorktime ? "工时 +" : ""}}</span>
                    <span>{{scope.row.packageProject ? "项目协作 +" : ""}}</span>
                    <span>{{scope.row.packageContract ? "合同 +" : ""}}</span>
                    <span>{{scope.row.packageOa ? "OA +" : ""}}</span>
                    <span>{{scope.row.packageEtimecard ? "生产车间 +" : ""}}</span>
                    <span>{{scope.row.packageExpense ? "费用报销 +" : ""}}</span>
                    <span>{{scope.row.packageCustomer ? "客户管理 +" : ""}}</span>
                    <span>{{scope.row.packageEngineering ? "工程专业 +" : ""}}</span>
                    <span>{{scope.row.packageSimple ? "简单表格 +" : ""}}</span>
                    <span>{{scope.row.packageFinance ? "财务核算" : ""}}</span> -->
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogC = false">取 消</el-button>
                <el-button type="primary" @click="ConfirmC()">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 设为已签约 -->
        <el-dialog v-if="editDialogD" :visible.sync="editDialogD" :title="dialogData.setMeal ? '设为未签约' : '设为已签约'">
            <el-form label-width="150px">
                <el-form-item label="企业名称">{{dialogData.companyName}}</el-form-item>
                <el-form-item label="当前是否签约">{{dialogData.setMeal ? "已签约" : "未签约"}}</el-form-item>
                <el-form-item label="即将设置为">{{dialogData.setMeal ? "未签约" : "已签约"}}</el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogD = false">取 消</el-button>
                <el-button type="primary" @click="ConfirmD(dialogData.setMeal)">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 考勤同步 -->
        <el-dialog v-if="editDialogF" :visible.sync="editDialogF" title="考勤同步">
            <el-form label-width="200px">
                <el-form-item label="企业名称"><span>{{dialogData.companyName}}</span></el-form-item>
                <el-form-item label="企业微信" v-if="dialogData.wxCorpid">
                    <!-- <el-button @click="ConfirmF(1)" :loading='FLoading1' size="small" style="margin:0 40px 0">同步</el-button> -->
                    <el-checkbox v-model="dialogData.syncCorpwxTime" style="margin:0 40px 0">考勤同步</el-checkbox>
                    <el-checkbox v-model="dialogData.showCorpwxCardtime">显示打卡时长</el-checkbox>
                </el-form-item>
                <el-form-item label="钉钉" v-if="dialogData.dingdingCorpid">
                    <el-checkbox v-model="dialogData.syncDingding" style="margin:0 40px 0">考勤同步</el-checkbox>
                    <el-checkbox v-model="dialogData.showDdCardtime">显示打卡时长</el-checkbox>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogF = false">取 消</el-button>
                <el-button type="primary" @click="ConfirmF()">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 其他设置 -->
        <el-dialog v-if="editDialogG" :visible.sync="editDialogG" title="其他设置" width="850px">
            <div style="height: 430px">
                <el-form label-width="100px" class="otherForm">
                    <el-form-item><el-checkbox v-model="dialogData.reportWorkflow">是否开启审批流设置</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.needEvaluate">审核通过需输入评价</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.mainProjectState">是否启用主项目模式</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.isSecretSalary">是否秘薪模式</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.showFillauditTime">是否显示日报审批流程</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.isCro">是否CRO企业</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.onlyImportreport">是否仅使用导入日报审核（不要项目审核）</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.projectLevelState">是否开启项目级别自定义</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.outputValueStatus">是否开启项目产值字段</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.choseFromAlbum">是否开启从相册选择</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.reportApproveMsgpush">日报审核通过是否推送消息</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.projectWithDept">项目是否有所属部门</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.financeJobnumEnabled">财务导入薪资是否支持工号</el-checkbox></el-form-item>
                    <!-- <el-form-item><el-checkbox v-model="dialogData.reportAutoApprove">是否开启日报自动审核</el-checkbox></el-form-item> -->
                    <el-form-item><el-checkbox v-model="dialogData.notAllowedNoAttendance">是否开启考勤为0不可填报</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.stageHasEvtime">是否开启预估工时</el-checkbox></el-form-item>
                    <!-- <el-form-item><el-checkbox v-model="dialogData.pushReportData">是否开通【推送工时数据】</el-checkbox></el-form-item> -->
                    <el-form-item><el-checkbox v-model="dialogData.financeAudit">财务导入是否需要审核</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.includeWeekends">批量填报是否包含周末</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.multiWorktime">一个项目下可填报多个时间段工时</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.restartTaskNeedReason">重启任务是否需要原因</el-checkbox></el-form-item>
                    <el-form-item>
                        日报审核模式：
                        <el-select v-model="dialogData.reportAuditType" size="small">
                            <el-option :value="0" label="0-项目审核人审核"></el-option>
                            <el-option :value="1" label="1-任务分组负责人审核"></el-option>
                            <el-option :value="2" label="2-先分组审核再PM审核"></el-option>
                            <el-option :value="3" label="3-员工自由选择审批人"></el-option>
                            <el-option :value="4" label="4-项目所属BU审核"></el-option>
                            <el-option :value="5" label="5-所属部门负责人审核"></el-option>
                            <el-option :value="6" label="6-直属或部门负责人审核->项目日报审核人审核"></el-option>
                            <el-option :value="7" label="7-项目和部门并行审核"></el-option>
                            <el-option :value="8" label="8-项目设置复审人"></el-option>
                            <el-option :value="9" label="9-分组负责人审核->项目日报审核人审核;"></el-option>
                            <el-option :value="10" label="10-普通员工到项目经理，项目经理到单独审核人"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-checkbox v-model="dialogData.reportAutoApprove">是否开启日报自动审核</el-checkbox>
                        <el-input-number v-if="dialogData.reportAutoApprove" v-model.number="dialogData.reportAutoApproveDays" controls-position="right" size="mini" style="margin: 0 10px 0 10px;width: 90px;" :min="0"></el-input-number>
                        <el-tooltip effect="dark" :content="`${dialogData.reportAutoApproveDays}天后自动审核`" placement="top-start" v-if="dialogData.reportAutoApprove">
                            <i class="el-icon-question"></i>
                        </el-tooltip>
                    </el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.subProMustFill">子项目是否必填</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.projectManDay">是否开启项目人天字段</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.projectCustom">是否开启项目自定义表单</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.easyExpense">是否开启简易费用报销</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.enableNewWeeklyfill">是否启用新的按周填报模式</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.hideSubproject">是否去除子项目</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.userWithMultiDept">是否开启人员设置可填报部门</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.importReportAuditNormal">导入的日报正常审批</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.onlyShowPercent">工时报告页面，工时仅显示比例</el-checkbox></el-form-item>
                    <el-form-item><el-checkbox v-model="dialogData.taskFileCharge">任务文件支持审核</el-checkbox></el-form-item>
                    
                </el-form>
            </div>
            <!-- 是否开启审批流设置，是否启用主项目模式，是否秘薪模式，是否显示日报审批流程，是否CRO企业，是否仅使用导入日报审核（不要项目审核） reportAuditType-->
            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogG = false">取 消</el-button>
                <el-button type="primary" @click="ConfirmG()">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 报表配置 -->
        <el-dialog v-if="editDialogH" :visible.sync="editDialogH" title="报表配置">
            <el-form label-width="50px" style="">
                <el-form-item v-for="item in reportFormList" :key="item.id" style="width:33%;display:inline-block;">
                    <el-checkbox v-model="item.owned">{{item.reportFormName}}</el-checkbox>
                </el-form-item>
            </el-form>
            <div style="margin:0 50px">
                <span>开通角色</span>
                <el-select v-model="roleIdArr" multiple clearable style="width:75%;margin-left:5%">
                    <el-option v-for="item in roleList" :key="item.id" :label="item.rolename" :value="item.id"></el-option>
                </el-select>
            </div>
            
            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogH = false">取 消</el-button>
                <el-button type="primary" @click="ConfirmH()">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 新增飞书企业 -->
        <el-dialog v-if="addFeishuDig" :visible.sync="addFeishuDig" title="新增飞书客户">
            <el-form :model="feishuInfo" :rules="feishuInfoRules" ref="feishuInfo" label-width="100px" class="demo-ruleForm">
                <el-form-item label="公司名称" prop="companyName">
                    <el-input v-model="feishuInfo.companyName"></el-input>
                </el-form-item>
                <el-form-item label="corpId" prop="corpId">
                    <el-input v-model="feishuInfo.corpId"></el-input>
                </el-form-item>
                <el-form-item label="appId" prop="appId">
                    <el-input v-model="feishuInfo.appId"></el-input>
                </el-form-item>
                <el-form-item label="appSecret" prop="appSecret">
                    <el-input v-model="feishuInfo.appSecret"></el-input>
                </el-form-item>
                <el-form-item label="管理员" prop="managerName">
                    <el-input v-model="feishuInfo.managerName"></el-input>
                </el-form-item>
            </el-form>
            
            <span slot="footer" class="dialog-footer">
                <el-button @click="addFeishuDig = false">取 消</el-button>
                <el-button type="primary" @click="addFeishuInfo('feishuInfo')">确 定</el-button>
            </span>
        </el-dialog>
    </section>
</template>
<script>
import App from '../../App.vue';
    export default {
  components: { App },
        data() {
            return {
                dingdingSync:false,
                isMeal:0, //是否已签约

                editDialogA: false,
                editDialogB: false,
                editDialogC: false,
                editDialogD: false,
                editDialogF: false,
                editDialogG: false,
                editDialogH: false,

                user: JSON.parse(sessionStorage.user),

                dialogData: null,
                // 增加人数上限
                addStaffCountMaxNum: 0,
                // 修改有效期
                expirationNewDate: null,

                reportFormList: [],



                keyword:null,
                tableHeight: 0,
                listLoading: false,
                total: 0,
                page: 1,
                size: 20,
                list: [],
                roleList: [],
                roleIdArr: [],

                onlyContract: false, // 仅显示已签约

                addFeishuDig:false,
                feishuInfo:{
                    companyName:'',
                    corpId:'',
                    appId:'',
                    appSecret:'',
                    managerName:'',
                },
                feishuInfoRules:{
                    companyName: [
                        { required: true, message: '请输入客户名称', trigger: 'blur' },
                    ],
                    corpId: [
                        { required: true, message: '请输入corpId', trigger: 'blur' },
                    ],
                    appId: [
                        { required: true, message: '请输入appId', trigger: 'blur' },
                    ],
                    appSecret: [
                        { required: true, message: '请输入appSecret', trigger: 'blur' },
                    ],
                    managerName: [
                        { required: true, message: '请输入管理员名称', trigger: 'blur' },
                    ],
                }
            };
        },
        // 过滤器
        filters: {
        },
        methods: {
            // 名称搜索
            searchList() {
                this.page = 1;
                this.getList();
            },
            // 是否签约筛选
            selIsmeal(){
                this.page = 1
                this.getList()
            },
            // 编辑按钮
            editClick(i,obj){
                this.dialogData = JSON.parse(JSON.stringify(obj))
                console.log("data",this.dialogData);
                if(i == 'A'){ this.editDialogA = true, this.addStaffCountMaxNum = 0 }
                else if(i == 'B'){ this.editDialogB = true, this.expirationNewDate = this.dialogData.expirationDate }
                else if(i == 'C'){ this.editDialogC = true,
                    this.dialogData.packageWorktime = this.dialogData.packageWorktime ? true : false,
                    this.dialogData.packageProject = this.dialogData.packageProject ? true : false,
                    this.dialogData.packageContract = this.dialogData.packageContract ? true : false,
                    this.dialogData.packageOa = this.dialogData.packageOa ? true : false,
                    this.dialogData.packageEtimecard = this.dialogData.packageEtimecard ? true : false,
                    this.dialogData.packageExpense = this.dialogData.packageExpense ? true : false,
                    this.dialogData.packageCustomer = this.dialogData.packageCustomer ? true : false,
                    this.dialogData.packageEngineering = this.dialogData.packageEngineering ? true : false,
                    this.dialogData.packageSimple = this.dialogData.packageSimple ? true : false,
                    this.dialogData.packageFinance = this.dialogData.packageFinance ? true : false,
                    this.dialogData.packageProvider = this.dialogData.packageProvider ? true : false,
                    this.dialogData.financeAudit = this.dialogData.financeAudit ? true : false
                    this.dialogData.packageProjectApproval = this.dialogData.packageProjectApproval ? true : false
                    this.dialogData.packageDevice = this.dialogData.packageDevice ? true : false
                }
                else if(i == 'D'){ this.editDialogD = true }
                else if (i=='E') {
                    //同步钉钉的组织架构人员
                    this.startSyncDDMembs(obj);
                }
                else if(i == 'F'){
                    // 考勤同步
                    this.editDialogF = true
                    this.http.post('/time-type/get',{
                        companyId: this.dialogData.id
                    },res => {
                        if(res.code == 'ok'){
                            this.$set(this.dialogData,'showCorpwxCardtime',res.data.showCorpwxCardtime ? true : false)
                            this.$set(this.dialogData,'showDdCardtime',res.data.showDdCardtime ? true : false)
                            this.$set(this.dialogData,'syncCorpwxTime',res.data.syncCorpwxTime ? true : false)
                            this.$set(this.dialogData,'syncDingding',res.data.syncDingding ? true : false)
                        }else{
                            this.$message({
                                message: res.msg,
                                type: 'error'
                            })
                        }
                    },err => {
                        this.$message({
                            message: err,
                            type: 'error'
                        })
                    })
                    

                }
                else if(i == 'G'){
                    // 其他设置
                    this.editDialogG = true
                    this.http.post('/time-type/get',{
                        companyId: this.dialogData.id
                    },res => {
                        if(res.code == 'ok'){
                            this.$set(this.dialogData,'reportWorkflow',res.data.reportWorkflow ? true : false)
                            this.$set(this.dialogData,'needEvaluate',res.data.needEvaluate ? true : false)
                            this.$set(this.dialogData,'mainProjectState',res.data.mainProjectState ? true : false)
                            this.$set(this.dialogData,'isSecretSalary',res.data.isSecretSalary ? true : false)
                            this.$set(this.dialogData,'showFillauditTime',res.data.showFillauditTime ? true : false)
                            this.$set(this.dialogData,'isCro',res.data.isCro ? true : false)
                            this.$set(this.dialogData,'onlyImportreport',res.data.onlyImportreport ? true : false)
                            this.$set(this.dialogData,'projectLevelState',res.data.projectLevelState ? true : false)
                            this.$set(this.dialogData,'outputValueStatus',res.data.outputValueStatus ? true : false)
                            this.$set(this.dialogData,'choseFromAlbum',res.data.choseFromAlbum ? true : false)
                            this.$set(this.dialogData,'reportApproveMsgpush',res.data.reportApproveMsgpush ? true : false)
                            this.$set(this.dialogData,'projectWithDept',res.data.projectWithDept ? true : false)
                            this.$set(this.dialogData,'financeJobnumEnabled',res.data.financeJobnumEnabled ? true : false)
                            this.$set(this.dialogData,'reportAutoApprove',res.data.reportAutoApprove ? true : false)
                            this.$set(this.dialogData,'notAllowedNoAttendance',res.data.notAllowedNoAttendance ? true : false)
                            this.$set(this.dialogData,'stageHasEvtime',res.data.stageHasEvtime ? true : false)
                            // this.$set(this.dialogData,'pushReportData',res.data.pushReportData ? true : false)
                            this.$set(this.dialogData,'financeAudit',res.data.financeAudit ? true : false)
                            this.$set(this.dialogData,'includeWeekends',res.data.includeWeekends ? true : false)
                            this.$set(this.dialogData,'multiWorktime',res.data.multiWorktime ? true : false)
                            this.$set(this.dialogData,'reportAuditType',res.data.reportAuditType)
                            this.$set(this.dialogData,'reportAutoApproveDays',res.data.reportAutoApproveDays)
                            this.$set(this.dialogData,'restartTaskNeedReason',res.data.restartTaskNeedReason ? true : false)
                            this.$set(this.dialogData,'subProMustFill',res.data.subProMustFill ? true : false)
                            this.$set(this.dialogData,'projectManDay',res.data.projectManDay ? true : false)
                            this.$set(this.dialogData,'projectCustom',res.data.projectCustom ? true : false)
                            this.$set(this.dialogData,'easyExpense',res.data.easyExpense ? true : false)
                            this.$set(this.dialogData,'enableNewWeeklyfill',res.data.enableNewWeeklyfill ? true : false)
                            this.$set(this.dialogData,'hideSubproject',res.data.hideSubproject ? true : false)
                            this.$set(this.dialogData,'userWithMultiDept',res.data.userWithMultiDept ? true : false)
                            this.$set(this.dialogData,'taskFileCharge',res.data.taskFileCharge ? true : false)
                        }else{
                            this.$message({
                                message: res.msg,
                                type: 'error'
                            })
                        }
                    },err => {
                        this.$message({
                            message: err,
                            type: 'error'
                        })
                    })
                    
                }
                else if(i == 'H'){
                    this.editDialogH = true
                    this.roleIdArr = []
                    this.getReoprtFormList(obj)
                    this.getRoleList(obj)
                }
                else if(i == 'I'){
                    this.$confirm('此操作将永久删除该企业及相关数据, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                        }).then(() => {
                        this.http.post('/company/deleteCompany', { companyId:this.dialogData.id},
                        res => {
                            if (res.code == "ok") {
                                this.$message({
                                    message: "删除成功",
                                    type: "success"
                                });
                                this.getList();
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: "error"
                                });
                            }
                        },
                        error => {
                            this.$message({
                                message: error,
                                type: "error"
                            });
                        });
                        }).catch(() => {
                            this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });          
                    });
                }else if (i == 'K') {
                    this.http.post('/company/getSuperManagerId', { companyId:this.dialogData.id},
                        res => {
                            if (res.code == "ok") {
                                var sid = res.data;
                                // 打开一个新窗口，并导航到指定的网址
                                window.open('https://worktime.ttkuaiban.com?userId='+sid, '_blank');
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: "error"
                                });
                            }
                        },
                        error => {
                            this.$message({
                                message: error,
                                type: "error"
                            });
                        });
                }
                
            },

            startSyncDDMembs(row) {
                this.dingdingSync = true;

                this.http.post('/company/syncDindDingMembs', { corpid:row.dingdingCorpid},
                res => {
                    this.dingdingSync = false;
                    if (res.code == "ok") {
                        this.editDialogA = false
                        this.$message({
                            message: "同步完成",
                            type: "success"
                        })
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.dingdingSync = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            getReoprtFormList(row){
                this.http.post('/company-report/list',{
                    companyId: row.id
                },res => {
                    if(res.code == 'ok'){
                        this.reportFormList = res.data
                        for(let i in this.reportFormList){
                            this.reportFormList[i].owned = this.reportFormList[i].owned ? true : false
                        }
                    }else {
                        this.$message({
                            message: res.msg,
                            type: 'error'
                        })
                    }
                },err => {
                    this.$message({
                        message: err,
                        type: 'error'
                    })
                })
            },
            getRoleList(row){
                this.http.post('/permission/getRoleList',{
                    companyId: row.id
                },res => {
                    if(res.code == 'ok'){
                        this.roleList = res.data
                    }else {
                        this.$message({
                            message: res.msg,
                            type: 'error'
                        })
                    }
                },err => {
                    this.$message({
                        message: err,
                        type: 'error'
                    })
                })
            },

            // 增加人数上限
            ConfirmA(){
                this.listLoading = true;
                this.http.post('/company/addMembCount', { companyId:this.dialogData.id , addCount:this.addStaffCountMaxNum },
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        this.editDialogA = false
                        this.$message({
                            message: "人数上限修改成功",
                            type: "success"
                        })
                        this.getList()
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            // 修改有效期
            ConfirmB(){
                this.listLoading = true;
                this.http.post('/company/setExpDate', { companyId:this.dialogData.id , date:this.expirationNewDate },
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        this.editDialogB = false
                        this.$message({
                            message: "有效期修改成功",
                            type: "success"
                        })
                        this.getList()
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            // 修改版本
            ConfirmC(){
                this.listLoading = true;
                this.http.post('/company/setPackageList',
                    {
                        id:this.dialogData.id,
                        packageWorktime: this.dialogData.packageWorktime ? 1 : 0,
                        packageProject: this.dialogData.packageProject ? 1 : 0,
                        packageContract: this.dialogData.packageContract ? 1 : 0,
                        packageOa: this.dialogData.packageOa ? 1 : 0,
                        packageEtimecard: this.dialogData.packageEtimecard ? 1 : 0,
                        packageExpense: this.dialogData.packageExpense ? 1 : 0,
                        packageCustomer: this.dialogData.packageCustomer ? 1 : 0,
                        packageEngineering: this.dialogData.packageEngineering ? 1 : 0,
                        packageSimple: this.dialogData.packageSimple ? 1 : 0,
                        packageFinance: this.dialogData.packageFinance ? 1 : 0,
                        packageProvider: this.dialogData.packageProvider ? 1 : 0,
                        packageProjectApproval: this.dialogData.packageProjectApproval ? 1 : 0,
                        packageDevice: this.dialogData.packageDevice ? 1 : 0,
                    },
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        this.editDialogC = false
                        this.$message({
                            message: "版本修改成功",
                            type: "success"
                        })
                        this.getList()
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            // 设为已签约
            ConfirmD(setMeal){
                this.listLoading = true;
                this.http.post('/company/setMeal', { companyId:this.dialogData.id,meal: setMeal ? 0 : 1 },
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        this.editDialogD = false
                        this.$message({
                            message: setMeal ? "取消签约成功" : "签约成功",
                            type: "success"
                        })
                        this.getList()
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            // 考勤同步
            ConfirmF(){
                let parameter = {
                    companyId: this.dialogData.id
                }
                if(this.dialogData.wxCorpid){
                    parameter.syncCorpwxTime = this.dialogData.syncCorpwxTime ? 1 : 0
                    parameter.showCorpwxCardtime = this.dialogData.showCorpwxCardtime ? 1 : 0
                }
                if(this.dialogData.dingdingCorpid){
                    parameter.syncDingding = this.dialogData.syncDingding ? 1 : 0
                    parameter.showDdCardtime = this.dialogData.showDdCardtime ? 1 : 0
                }
                
                this.http.post('/company/setTimeTypeSetting',parameter,
                res => {
                    if(res.code == 'ok'){
                        this.editDialogF = false
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        })
                    }else{
                        this.editDialogF = false
                        this.$message({
                            message: res.msg,
                            type: 'error'
                        })
                    }
                },err => {
                    this.editDialogF = false
                    this.$message({
                        message: err,
                        type: 'error'
                    })
                })
            },
            // 其他设置
            ConfirmG(){
                this.http.post('/company/setTimeTypeSetting',{
                    companyId: this.dialogData.id,
                    reportWorkflow: this.dialogData.reportWorkflow ? 1 : 0,
                    needEvaluate: this.dialogData.needEvaluate ? 1 : 0,
                    mainProjectState: this.dialogData.mainProjectState ? 1 : 0,
                    isSecretSalary: this.dialogData.isSecretSalary ? 1 : 0,
                    showFillauditTime: this.dialogData.showFillauditTime ? 1 : 0,
                    isCro: this.dialogData.isCro ? 1 : 0,
                    onlyImportreport: this.dialogData.onlyImportreport ? 1 : 0,
                    projectLevelState: this.dialogData.projectLevelState ? 1 : 0,
                    outputValueStatus: this.dialogData.outputValueStatus ? 1 : 0,
                    choseFromAlbum: this.dialogData.choseFromAlbum ? 1 : 0,
                    reportApproveMsgpush: this.dialogData.reportApproveMsgpush ? 1 : 0,
                    projectWithDept: this.dialogData.projectWithDept ? 1 : 0,
                    financeJobnumEnabled: this.dialogData.financeJobnumEnabled ? 1 : 0,
                    reportAutoApprove: this.dialogData.reportAutoApprove ? 1 : 0,
                    notAllowedNoAttendance: this.dialogData.notAllowedNoAttendance ? 1 : 0,
                    stageHasEvtime: this.dialogData.stageHasEvtime ? 1 : 0,
                    // pushReportData: this.dialogData.pushReportData ? 1 : 0,
                    includeWeekends: this.dialogData.includeWeekends ? 1 : 0,
                    multiWorktime: this.dialogData.multiWorktime ? 1 : 0,
                    reportAuditType: this.dialogData.reportAuditType,
                    reportAutoApproveDays: this.dialogData.reportAutoApproveDays, // 自动审核的天数
                    restartTaskNeedReason: this.dialogData.restartTaskNeedReason ? 1 : 0,
                    subProMustFill: this.dialogData.subProMustFill ? 1 : 0,
                    projectManDay: this.dialogData.projectManDay ? 1 : 0,
                    projectCustom: this.dialogData.projectCustom ? 1 : 0,
                    easyExpense: this.dialogData.easyExpense ? 1 : 0,
                    enableNewWeeklyfill: this.dialogData.enableNewWeeklyfill ? 1 : 0,
                    hideSubproject:this.dialogData.hideSubproject ? 1: 0, 
                    userWithMultiDept:this.dialogData.userWithMultiDept ? 1: 0, 
                    taskFileCharge:this.dialogData.taskFileCharge ? 1: 0, 
                },res => {
                    if(res.code == 'ok'){
                        this.editDialogG = false
                        this.$message({
                            message: '成功',
                            type: 'success'
                        })
                    }else{
                        this.editDialogG = false
                        this.$message({
                            message: res.msg,
                            type: 'error'
                        })
                    }
                },err => {
                    this.editDialogG = false
                    this.$message({
                        message: err,
                        type: 'error'
                    })
                })
            },
            // 报表配置
            ConfirmH(){
                let ids = ''
                for(let i in this.reportFormList){
                    if(this.reportFormList[i].owned){
                        ids += this.reportFormList[i].id + ','
                    }
                }
                if(ids){ids = ids.substring(0,ids.length - 1)}

                let roleIds = ''
                for(let m in this.roleIdArr){
                    roleIds += this.roleIdArr[m] + ','
                }
                if(roleIds){
                    roleIds = roleIds.substring(0,roleIds.length - 1)
                }else{
                    this.$message({
                        message: '请选择要开通的角色',
                        type: 'error'
                    })
                    return
                }
                this.http.post('/company-report/update',{
                    companyId: this.dialogData.id,
                    formIds: ids,
                    roleIds: roleIds
                },res => {
                    if(res.code == 'ok'){
                        this.editDialogH = false
                        this.$message({
                            message: '更新成功',
                            type: 'success'
                        })
                    }else {
                        this.$message({
                            message: res.msg,
                            type: 'error'
                        })
                    }
                },err => {
                    this.$message({
                        message: err,
                        type: 'error'
                    })
                })
            },

            addFeishuInfo(formName){
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.http.post('/company/addFeiShuInfo',{
                            companyName:this.feishuInfo.companyName,
                            corpId:this.feishuInfo.corpId,
                            appId:this.feishuInfo.appId,
                            appSecret:this.feishuInfo.appSecret,
                            managerName:this.feishuInfo.managerName,
                        },res => {
                            if(res.code == 'ok'){
                                this.addFeishuDig = false
                                this.feishuInfo={}
                                this.$message({
                                    message: '新增飞书客户初始化成功',
                                    type: 'success'
                                })
                            }else {
                                this.$message({
                                    message: res.msg,
                                    type: 'error'
                                })
                            }
                        },err => {
                            this.$message({
                                message: err,
                                type: 'error'
                            })
                        })
                    } else {
                        return false;
                    }
                });
            },

            //分页
            handleCurrentChange(val) {
                this.page = val;
                this.getList();
            },
            handleSizeChange(val) {
                this.size = val;
                this.getList();
            },

            //获取项目列表
            getList() {
                this.listLoading = true;
                this.http.post('/company/getList', {
                    pageIndex: this.page,
                    pageSize: this.size,
                    companyName: this.keyword,
                    isMeal: this.isMeal == 2 ? 0 : this.isMeal,
                    key: this.isMeal == 2 ? 1 : 0,
                    keyForIsMeal: this.onlyContract
                },
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        for(var i in res.data.records) {
                            var arrList = []
                            res.data.records[i].packageWorktime == 1 ? arrList.push('工时') : ''
                            res.data.records[i].packageProject == 1 ? arrList.push('项目协作') : ''
                            res.data.records[i].packageContract == 1 ? arrList.push('合同') : ''
                            res.data.records[i].packageOa == 1 ? arrList.push('OA') : ''
                            res.data.records[i].packageEtimecard == 1 ? arrList.push('生产车间') : ''
                            res.data.records[i].packageExpense == 1 ? arrList.push('费用报销') : ''
                            res.data.records[i].packageCustomer == 1 ? arrList.push('客户管理') : ''
                            res.data.records[i].packageEngineering == 1 ? arrList.push('工程专业') : ''
                            res.data.records[i].packageSimple == 1 ? arrList.push('简单表格') : ''
                            res.data.records[i].packageFinance == 1 ? arrList.push('财务核算') : ''
                            res.data.records[i].packageProjectApproval == 1 ? arrList.push('立项管理') : ''
                            res.data.records[i].packageDevice == 1 ? arrList.push('设备管理') : ''
                            res.data.records[i].arrList = arrList
                        }
                        var list = res.data.records;
                        this.list = list;
                        this.total = res.data.total;
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
        },
        created() {
            let height = window.innerHeight;
            this.tableHeight = height - 195;
            const that = this;
            window.onresize = function temp() {
                that.tableHeight = window.innerHeight - 195;
            };
        },
        mounted() {
            this.getList();
        }
    };
</script>

<style lang="scss" scoped>
.rg_span{
    display: inline-block;
}
.rg_span span {
    text-align: right;
    box-sizing: border-box;
    padding-right: 10px;
}
.el-dialog__title {
    display: inline-table;
    margin-top: 20px;
}
.btns .el-button{
    margin-left: 10px;
    margin-bottom: 5px;
}
</style>
<style>
.otherForm .el-form-item{
    float: left;
    width: 50%;
    margin: 0;
}
</style>