<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>
        </el-col>

        <!--列表-->
        <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
            <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="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="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('C', scope.row)">合同预览</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">
                      {{version}}
                </el-form-item>
                <el-form-item label="签约单价：" label-width="150px">
                    <el-input size="small" controls-position="right" v-model="contractUnitPrice" style="width: 100px"></el-input> 元
                </el-form-item>
                <el-form-item label="签约折扣：" label-width="150px">
                    <el-input-number size="small" controls-position="right" max="1" v-model="contractDiscount" :step="0.1" style="width: 100px"></el-input-number> 折
                </el-form-item>
                <el-form-item label="开单金额：" label-width="150px">
                     <el-input size="small" controls-position="right" v-model="billingAmount" style="width: 100px"></el-input> 元
                </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="完善合同信息" width="1200px">
            <el-form :inline="true" :model="formInline" :rules="rulesFormInline" ref="formInline" class="heClass">
                <el-form-item label="甲方名称：" label-width="150px">
                    南京火石闪信网络科技有限公司
                </el-form-item>
                <el-form-item  label="乙方名称：" label-width="150px" prop="secondParty">
                    <el-input size="small" controls-position="right" v-model="formInline.secondParty" :disabled="finalize"  style="width: 300px"></el-input>
                </el-form-item>
                <el-form-item label="甲方地址：" label-width="150px">
                    南京市江宁区秣周东路12号悠谷软件园2号楼3楼P346室
                </el-form-item>
                <el-form-item label="乙方地址：" label-width="150px" prop="secondPartyAddr">
                    <el-input size="small" controls-position="right" v-model="formInline.secondPartyAddr" :disabled="finalize" style="width: 400px"></el-input>
                </el-form-item>
                <el-form-item label="甲方联系人：" label-width="150px">
                    屈跃庭
                </el-form-item>
                <el-form-item label="乙方联系人：" label-width="150px" prop="secondPartyContacts">
                    <el-input size="small" controls-position="right" v-model="formInline.secondPartyContacts" :disabled="finalize" style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item label="甲方电话：" label-width="150px">
                    15895914665
                </el-form-item>
                <el-form-item label="乙方电话：" label-width="150px" prop="secondPartyTel">
                    <el-input size="small" controls-position="right"  maxlength="11" v-model="formInline.secondPartyTel" :disabled="finalize" style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item label="软件名称：" label-width="150px" prop="softwareName">
                    <el-input size="small" controls-position="right" v-model="formInline.softwareName" :disabled="finalize" style="width: 200px"></el-input>
                </el-form-item>
                <el-form-item label="服务周期：" label-width="150px" prop="serviceDate">
                     <el-input-number size="small" controls-position="right" :min="0" v-model.number="formInline.serviceDate" :disabled="finalize" style="width: 100px"></el-input-number> 年
                </el-form-item>
                <el-form-item label="服务开始日期：" label-width="150px" prop="startDate">
                    <el-date-picker
                        v-model="formInline.startDate"
                        :disabled="finalize"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="年服务费：" label-width="150px" prop="serviceChargeOfYear">
                    <el-input size="small" controls-position="right" v-model.number="formInline.serviceChargeOfYear" :disabled="finalize" style="width: 100px"></el-input> 元
                </el-form-item>
                <el-form-item label="定制开发费：" label-width="150px" prop="customDevelopmentCosts">
                    <el-input size="small" controls-position="right" v-model.number="formInline.customDevelopmentCosts" :disabled="finalize" style="width: 100px"></el-input> 元
                </el-form-item>
                <el-form-item label="标准单价：" label-width="150px" prop="standardUnitPrice">
                    <el-input size="small" controls-position="right" v-model.number="formInline.standardUnitPrice" :disabled="finalize" style="width: 100px"></el-input> 元每人每年
                </el-form-item>
                <el-form-item label="首次开通人数：" label-width="150px" prop="firstOpenNum" style="width: 100%">
                    <el-input-number size="small" :min="0" controls-position="right" v-model.number="formInline.firstOpenNum" :disabled="finalize" style="width: 100px"></el-input-number> 人
                </el-form-item>
                <el-divider><i class="el-icon-s-check"></i></el-divider>
                <el-form-item label="甲方账号：" label-width="150px">
                    32050188143600000075
                </el-form-item>
                <el-form-item label="乙方账号：" label-width="150px" prop="secondPartyAccount">
                    <el-input size="small" controls-position="right" v-model="formInline.secondPartyAccount" :disabled="finalize" style="width: 300px"></el-input> 
                </el-form-item>
                <el-form-item label="甲方开户行：" label-width="150px">
                    建设银行股份有限公司南京湖北路支行
                </el-form-item>
                <el-form-item label="乙方开户行：" label-width="150px" prop="secondPartyBankOfDeposit">
                    <el-input size="small" controls-position="right" v-model="formInline.secondPartyBankOfDeposit" :disabled="finalize" style="width: 300px"></el-input> 
                </el-form-item>
                <!-- <el-form-item label="乙方开票名称：" label-width="150px" prop="secondPartyBillingName">
                    <el-input size="small" controls-position="right" v-model="formInline.secondPartyBillingName" :disabled="finalize" style="width: 200px"></el-input> 
                </el-form-item> -->
                <el-form-item label="乙方纳税人识别号：" label-width="150px" prop="secondPartyTIN">
                    <el-input size="small" controls-position="right" v-model="formInline.secondPartyTIN" :disabled="finalize" style="width: 200px"></el-input> 
                </el-form-item>
                <el-form-item label="乙方开具发票类型：" label-width="150px" prop="invoiceType">
                    <el-select v-model="formInline.invoiceType" placeholder="请选择" :disabled="finalize">
                        <el-option
                        v-for="invoiceItem in invoiceOptions"
                        :key="invoiceItem.value"
                        :label="invoiceItem.label"
                        :value="invoiceItem.value">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogB = false">取 消</el-button>
                <el-button type="primary" @click="ConfirmB('formInline')" :loading="listLoading" v-if="!finalize">确定</el-button>
                <!-- <el-button type="primary" @click="ConfirmC()" :loading="listLoading" v-if="!finalize">合同定稿</el-button> -->
                <el-popconfirm confirm-button-text='确定' cancel-button-text='取消' icon="el-icon-info" icon-color="#E6A23C" title="合同定稿将无法再继续编辑 是否确认？" @confirm="ConfirmC()">
                    <el-button slot="reference" :loading="listLoading" v-if="!finalize&&this.contractData.secondParty!=null">合同定稿</el-button>
                </el-popconfirm>
            </span>
        </el-dialog>
        <!-- 合同预览/下载 -->
        <el-dialog v-if="editDialogC" :visible.sync="editDialogC" title="合同预览">
            <!-- <el-link  type="primary" :underline="false" :href="downloadUrl2" id="moban" :download=" this.softwareName+'销售合同-'+this.secondParty+ '.docx'">下载合同</el-link> -->
            <el-link  type="primary" :underline="false" :href="downloadUrl2" ref="moban" :download=" this.formInline.softwareName+'销售合同-'+this.formInline.secondParty+ '.docx'">下载合同</el-link>
            <el-link  type="primary" :underline="false" @click="preview2()">点击预览</el-link>
        </el-dialog>
    </section>
</template>
<script>
import axios from 'axios'
    export default {
        data() {
            return {
                dingdingSync:false,
                isMeal:1, //只看已签约
                editDialogA: false,
                editDialogB: false,
                editDialogC: false,
                editDialogD: false,
                editDialogF: false,
                editDialogG: false,
                editDialogH: false,

                downloadUrl2:null,

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

                formInline: {
                    //甲方名称
                    firstParty: null,
                    //乙方名称
                    secondParty: null,
                    //甲方地址
                    firstPartyAddr: null,
                    //乙方地址
                    secondPartyAddr: null,
                    //甲方联系人
                    firstPartyContacts: null,
                    //乙方联系人
                    secondPartyContacts: null,
                    //甲方电话
                    firstPartyTel: null,
                    //乙方电话
                    secondPartyTel: null,
                    //软件名称
                    softwareName: null,
                    //服务周期
                    serviceDate:0,
                    //服务开始日期
                    startDate:null,
                    //年服务费
                    serviceChargeOfYear:0,
                    //定制开发费
                    customDevelopmentCosts:0,
                    //标准单价
                    standardUnitPrice:0,
                    //首次开通人数
                    firstOpenNum:0,
                    //甲方账号
                    firstPartyAccount:null,
                    //甲方开户行
                    firstPartyBankOfDeposit:null,
                    //乙方账号
                    secondPartyAccount:null,
                    //乙方开户行
                    secondPartyBankOfDeposit:null,
                    //乙方开票名称
                    secondPartyBillingName:null,
                    //乙方纳税人识别号
                    secondPartyTIN:null,
                    //乙方开具发票类型
                    invoiceType:'',
                },

                
                //合同定稿
                finalize:false,


                // 开通版本
                version: "未开通", 
                // 签约单价
                contractUnitPrice: 0,
                // 签约折扣
                contractDiscount: 0,
                // 开单金额
                billingAmount: 0,   
                reportFormList: [],





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

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

                invoiceOptions: [{
                    value: '增值税普通发票',
                    label: '增值税普通发票'
                    }, {
                    value: '增值税专用发票',
                    label: '增值税专用发票'
                    },
                ],

                // 规则校验
                rulesFormInline: {
                    secondParty: [{ required: true, message: '请输入乙方名称', trigger: 'blur' }],
                    secondPartyAddr: [{ required: true, message: '请输入乙方地址', trigger: 'blur' }],
                    secondPartyContacts: [{ required: true, message: '请输入乙方联系人', trigger: 'blur' }],
                    secondPartyTel: [
                        { required: true, message: '请输入乙方电话', trigger: 'blur' },
                         { required: true, pattern:/^[0-9]{1,16}$/, message: '请输入正确的电话号码', trigger: 'change' },
                    ],
                    softwareName: [{ required: true, message: '请输入软件名称', trigger: 'blur' }],
                    serviceDate: [
                        { required: true, message: '请确认服务周期', trigger: 'blur' },
                    ],
                    startDate: [{ required: true, message: '请选择服务开始日期', trigger: 'blur' }],
                    serviceChargeOfYear: [
                        { required: true, message: '请输入年服务费', trigger: 'blur' },
                        { required: true, pattern:/^[0-9]{1,16}$/, message: '请输入数字', trigger: 'change' },
                    ],
                    customDevelopmentCosts: [
                        { required: true, message: '请输入定制开发费', trigger: 'blur' },
                        { required: true, pattern:/^[0-9]{1,16}$/, message: '请输入数字', trigger: 'change' },
                    ],
                    standardUnitPrice: [
                        { required: true, message: '请输入标准单价', trigger: 'blur' },
                        { required: true, pattern:/^[0-9]{1,16}$/, message: '请输入数字', trigger: 'change' },
                    ],
                    firstOpenNum: [
                        { required: true, message: '请输入首次开通人数', trigger: 'blur' },
                        { required: true, pattern:/^[0-9]{1,16}$/, message: '请输入数字', trigger: 'change' },
                    ],
                    secondPartyAccount: [{ required: true, message: '请输入乙方账号', trigger: 'blur' }],
                    secondPartyBankOfDeposit: [{ required: true, message: '请输入乙方开户行', trigger: 'blur' }],
                    secondPartyBillingName: [{ required: true, message: '请输入乙方开票名称', trigger: 'blur' }],
                    secondPartyTIN: [{ required: true, message: '请输入乙方纳税人识别号', trigger: 'blur' }],
                    invoiceType: [{ 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.getListWithsigning()}
                else if(i == 'B'){ this.editDialogB = true ,this.getcontractDetail()}
                else if(i == 'C'){ this.editDialogC = true,
                    this.getcontractDetail()
                }
                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)
                        }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)
                }
                
            },

            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'
                    })
                })
            },
            // 获取签约信息
            getListWithsigning(){
                this.listLoading = true;
                this.http.post('/company-signing/getList', { companyId:this.dialogData.id},
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        this.signingData = res.data;
                        if(this.signingData){
                            this.version=this.signingData.version;
                            this.contractUnitPrice=this.signingData.contractUnitPrice;
                            this.contractDiscount=this.signingData.contractDiscount;
                            this.billingAmount=this.signingData.billingAmount;
                        }
                        console.log(this.signingData);
                        this.getList()
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            }, 
            
            //完善签约信息
            ConfirmA(){
                this.listLoading = true;
                this.http.post('/company-signing/update', { companyId:this.dialogData.id , 
                version:this.version,contractUnitPrice:this.contractUnitPrice,contractDiscount:this.contractDiscount,billingAmount:this.billingAmount},
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        this.editDialogA = false
                        this.$message({
                            message: "签约信息完善成功",
                            type: "success"
                        })
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },

            // 获取合同信息
            getcontractDetail(){
                this.listLoading = true;
                this.http.post('/contract-detail/detail', { companyId:this.dialogData.id},
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        this.contractData = res.data;
                        if(this.contractData){
                            this.formInline.secondParty=this.contractData.secondParty;
                            this.formInline.secondPartyAddr=this.contractData.secondPartyAddr;
                            this.formInline.secondPartyContacts=this.contractData.secondPartyContacts;
                            this.formInline.secondPartyTel=this.contractData.secondPartyTel;
                            this.formInline.softwareName=this.contractData.softwareName;
                            this.formInline.serviceDate=this.contractData.serviceDate;
                            this.formInline.startDate=this.contractData.startDate;
                            this.formInline.serviceChargeOfYear=this.contractData.serviceChargeOfYear;
                            this.formInline.customDevelopmentCosts=this.contractData.customDevelopmentCosts;
                            this.formInline.standardUnitPrice=this.contractData.standardUnitPrice;
                            this.formInline.firstOpenNum=this.contractData.firstOpenNum;
                            this.formInline.secondPartyAccount=this.contractData.secondPartyAccount;
                            this.formInline.secondPartyBankOfDeposit=this.contractData.secondPartyBankOfDeposit;
                            this.formInline.secondPartyBillingName=this.contractData.secondPartyBillingName;
                            this.formInline.secondPartyTIN=this.contractData.secondPartyTIN;
                            this.formInline.billingAmount=this.contractData.billingAmount;
                            this.formInline.invoiceType=this.contractData.invoiceType;
                            this.finalize=this.contractData.finalize ? true : false;
                        }
                        console.log(this.signingData);
                        this.downloadUrl2 = `/upload/${this.formInline.softwareName}销售合同-${this.formInline.secondParty}.docx`
                        console.log(this.downloadUrl2)
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            }, 
            // 完善合同信息
            ConfirmB(formName){
                this.$refs[formName].validate((valid) => {
                    console.log(valid)
                    if (valid) {
                        this.listLoading = true;
                        this.http.post('/contract-detail/update', {
                            companyId:this.dialogData.id,
                            secondParty:this.formInline.secondParty,
                            secondPartyAddr:this.formInline.secondPartyAddr,
                            secondPartyContacts:this.formInline.secondPartyContacts,
                            secondPartyTel:this.formInline.secondPartyTel,
                            softwareName:this.formInline.softwareName,
                            serviceDate:this.formInline.serviceDate,
                            startDate:this.formInline.startDate,
                            serviceChargeOfYear:this.formInline.serviceChargeOfYear,
                            customDevelopmentCosts:this.formInline.customDevelopmentCosts,
                            standardUnitPrice:this.formInline.standardUnitPrice,
                            firstOpenNum:this.formInline.firstOpenNum,
                            secondPartyAccount:this.formInline.secondPartyAccount,
                            secondPartyBankOfDeposit:this.formInline.secondPartyBankOfDeposit,
                            secondPartyBillingName:this.formInline.secondPartyBillingName,
                            secondPartyTIN:this.formInline.secondPartyTIN,
                            billingAmount:this.formInline.billingAmount,
                            invoiceType:this.formInline.invoiceType,
                        },
                        res => {
                            this.listLoading = false;
                            if (res.code == "ok") {
                                this.editDialogB = false
                                this.downloadUrl2=res.data
                                this.$message({
                                    message: "合同信息完善成功,合同模板已重新生成",
                                    type: "success"
                                })
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: "error"
                                });
                            }
                        },
                        error => {
                            this.listLoading = false;
                            this.$message({
                                message: error,
                                type: "error"
                            });
                        });
                    } else {
                        return false;
                    }
                });
            },
            // 合同定稿
            ConfirmC(){ 
                this.listLoading = true;
                this.http.post('/contract-detail/finalize',{companyId:this.dialogData.id,},
                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"
                    });
                });
            },
            preview(){
                this.downloadUrl2 = `/upload/${this.softwareName}销售合同-${this.secondParty}.pdf`
                window.open(this.downloadUrl2, '_blank');
            },
            preview2(){                
                this.http.previewFile('/contract-detail/preview', { companyId:this.dialogData.id}, res => {
                    const blob = new Blob([res], { type: "application/pdf" });
                    let elink = {
                        href: window.URL.createObjectURL(blob)
                    }
                    window.open(elink.href, '_blank');
                });

            },
            // 设为已签约
            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,
                },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'
                    })
                })
            },




            //分页
            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].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>
.heClass .el-form-item {
    width: 48%
}
.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>