<template>
    <div class="app-container">
        <div class="title-container">
            <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
            <div class="form-container">
                <y-detail-page-layout ref="addAssetsOrder" @save="handleCreate" :editStatus="couldEdit" @doRecall="doRecall"
                    :couldBack="couldBack">
                    <el-form ref="assetsForm" :model="assetsForm" :rules="assetsFormRules">
                        <div class="createMajor-main-container">
                            <div class="postInfo-container">
                                <div>
                                    <el-divider content-position="left">
                                        <h3 class="title">
                                            <div class="avatar-wrapper icon-title">订单</div>
                                            <div class="icon-info">资产订单</div>
                                        </h3>
                                    </el-divider>
                                </div>
                                <el-row class="row-style">
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="客户经理：" prop="clientManager"
                                            :rules="assetsFormRules.clientManager" label-width="120px"
                                            class="postInfo-container-item">
                                            <el-input :value="assetsForm.clientManager" class="filter-item" readonly
                                                disabled style=" width: 225px" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="4" :span="6">
                                        <el-form-item label="接单部门：" prop="departmentId"
                                            :rules="assetsFormRules.departmentId" label-width="120px"
                                            class="postInfo-container-item">
                                            <el-select v-model="assetsForm.departmentId">
                                                <el-option v-for="(d, id) in allotDepartment" :label="d.name"
                                                    :value="d.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row class="row-style">
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item prop="name" :rules="assetsFormRules.name" label-width="120px"
                                            class="postInfo-container-item" label="项目名称：">
                                            <el-input v-model="assetsForm.name" class="filter-item" />
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row class="row-style">
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="业务类型：" prop="assetsBusinessGener"
                                            :rules="assetsFormRules.assetsBusinessGener" label-width="120px"
                                            class="postInfo-container-item">
                                            <el-select v-model="assetsForm.assetsBusinessGener" filterable
                                                placeholder="业务类型">
                                                <el-option v-for="(s, value) in assetsBusinessGeners" :label="s.label"
                                                    :value="s.value"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="客户再次委托：" prop="entrustAgain"
                                            :rules="assetsFormRules.entrustAgain" label-width="140px"
                                            class="postInfo-container-item">
                                            <el-radio v-model="assetsForm.entrustAgain" :label="false" border
                                                size="medium">否</el-radio>
                                            <el-radio v-model="assetsForm.entrustAgain" :label="true" border
                                                size="medium">是</el-radio>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row class="row-style">
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="客户类型：" prop="clienteleType"
                                            :rules="assetsFormRules.clienteleType" label-width="120px"
                                            class="postInfo-container-item">
                                            <el-select v-model="assetsForm.clienteleType" placeholder="请选择"
                                                @change="changeCustomerType(assetsForm.clienteleType)">
                                                <el-option label="企业" value="企业"></el-option>
                                                <el-option label="个人" value="个人"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="客户名称：" prop="clienteleId" label-width="120px"
                                            :rules="assetsFormRules.clienteleId" class="postInfo-container-item"
                                            v-if="itemHideStatus">
                                            <el-select v-model="assetsForm.clienteleId" placeholder="请选择(可搜索)"
                                                @change="findSubClientele(0)" clearable filterable>
                                                <el-option v-for="(c, id) in customerCompany" :label="c.name"
                                                    :value="c.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="业务来源：" prop="clienteleSubId" label-width="120px"
                                            :rules="assetsFormRules.clienteleSubId" class="postInfo-container-item"
                                            v-if="itemHideStatus">
                                            <el-select v-model="assetsForm.clienteleSubId" placeholder="请选择(可搜索)"
                                                @change="getCustomerContract" clearable filterable>
                                                <el-option v-for="(s, id) in subCustomerCompany" :label="s.name"
                                                    :value="s.id"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row class="row-style">
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="客户联系人：" prop="clienteleContactId"
                                            :rules="assetsFormRules.clienteleContactId" label-width="120px"
                                            class="postInfo-container-item">
                                            <div>
                                                <el-select v-model="assetsForm.clienteleContactId" placeholder="请选择(可搜索)"
                                                    clearable filterable @change="getContactInfo" style="width:60%">
                                                    <el-option v-for="(c, id) in customerContract" :label="c.name"
                                                        :value="c.id"></el-option>
                                                </el-select>
                                                <el-tooltip class="item" effect="dark" content="没有联系人？点击新增"
                                                    placement="top-end">
                                                    <span style="margin-left:5%;color:RGB(64,158,255);cursor:pointer"
                                                        @click="createLinkman(false)">新增</span>
                                                </el-tooltip>
                                            </div>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="联系人电话：" prop="mobile" label-width="120px"
                                            class="postInfo-container-item">
                                            <el-input :value="linkmanInfo.mobile" class="filter-item" readonly disabled
                                                style=" width: 225px" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="联系人部门：" prop="department" label-width="120px"
                                            class="postInfo-container-item">
                                            <el-input :value="linkmanInfo.department" class="filter-item" readonly disabled
                                                style=" width: 225px" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="联系人职务：" prop="duty" label-width="120px"
                                            class="postInfo-container-item">
                                            <el-input :value="linkmanInfo.duty" class="filter-item" readonly disabled
                                                style=" width: 225px" />
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row class="row-style">
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="是否证券项目：" prop="security" :rules="assetsFormRules.security"
                                            label-width="140px" class="postInfo-container-item">
                                            <el-radio v-model="assetsForm.security" :label="false" border
                                                size="medium">否</el-radio>
                                            <el-radio v-model="assetsForm.security" :label="true" border
                                                size="medium">是</el-radio>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="是否资产重组项目：" prop="significantAssetsReorganization"
                                            :rules="assetsFormRules.significantAssetsReorganization" label-width="200px"
                                            class="postInfo-container-item">
                                            <el-radio v-model="assetsForm.significantAssetsReorganization" :label="false"
                                                border size="medium">否</el-radio>
                                            <el-radio v-model="assetsForm.significantAssetsReorganization" :label="true"
                                                border size="medium">是</el-radio>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label=" 是否国资项目：" prop="stateAssets"
                                            :rules="assetsFormRules.stateAssets" label-width="140px"
                                            class="postInfo-container-item">
                                            <el-radio v-model="assetsForm.stateAssets" :label="false" border
                                                size="medium">否</el-radio>
                                            <el-radio v-model="assetsForm.stateAssets" :label="true" border
                                                size="medium">是</el-radio>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="是否涉及境外资产：" prop="foreignAssetsInvolved"
                                            :rules="assetsFormRules.foreignAssetsInvolved" label-width="200px"
                                            class="postInfo-container-item">
                                            <el-radio v-model="assetsForm.foreignAssetsInvolved" :label="false" border
                                                size="medium">否</el-radio>
                                            <el-radio v-model="assetsForm.foreignAssetsInvolved" :label="true" border
                                                size="medium">是</el-radio>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="是否分配产值：" prop="dispenseBenefit"
                                            :rules="assetsFormRules.dispenseBenefit" label-width="140px"
                                            class="postInfo-container-item">
                                            <el-radio v-model="assetsForm.dispenseBenefit" :label="false" border
                                                size="medium">否</el-radio>
                                            <el-radio v-model="assetsForm.dispenseBenefit" :label="true" border
                                                size="medium">是</el-radio>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row class="row-style">
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="委托人：" prop="bailor" label-width="120px"
                                            class="postInfo-container-item">
                                            <el-input v-model="assetsForm.bailor" class="filter-item"
                                                style=" width: 225px" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="委托联系人：" prop="bailorContactName" label-width="120px"
                                            class="postInfo-container-item">
                                            <el-input v-model="assetsForm.bailorContactName" class="filter-item"
                                                style=" width: 225px" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="委托人联系人电话：" prop="bailorContactTel" label-width="160px"
                                            class="postInfo-container-item">
                                            <el-input v-model="assetsForm.bailorContactTel" class="filter-item"
                                                style=" width: 225px" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="委托人地址：" prop="bailorAddress" label-width="120px"
                                            class="postInfo-container-item">
                                            <el-input v-model="assetsForm.bailorAddress" class="filter-item"
                                                style=" width: 225px" />
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row class="row-style">
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="终端客户类型：" prop="terminalClienteleType"
                                            :rules="assetsFormRules.terminalClienteleType" label-width="140px"
                                            class="postInfo-container-item">
                                            <el-select v-model="assetsForm.terminalClienteleType" placeholder="请选择"
                                                style="width:205px">
                                                <el-option label="企业" value="企业"></el-option>
                                                <el-option label="个人" value="个人"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6"
                                        v-if="assetsForm.terminalClienteleType === '企业'">
                                        <el-form-item label="终端客户名称：" prop="terminalClienteleId" label-width="140px"
                                            :rules="assetsFormRules.terminalClienteleId" class="postInfo-container-item">
                                            <div v-if="couldEdit">
                                                <el-select v-model="assetsForm.terminalClienteleId" placeholder="请选择(可搜索)"
                                                    @change="findSubClientele(1)" clearable filterable style="width:80%">
                                                    <el-option v-for="(c, id) in tCustomerCompany" :label="c.name"
                                                        :value="c.id"></el-option>
                                                </el-select>
                                                <el-tooltip class="item" effect="dark" content="没有终端客户？点击新增"
                                                    placement="top-end">
                                                    <span style="margin-left:5%;color:RGB(64,158,255);cursor:pointer"
                                                        @click="createTerminalClient()">新增</span>
                                                </el-tooltip>
                                            </div>
                                            <el-input :value="assetsForm.tterminalClienteleName" class="filter-item"
                                                style=" width: 225px" v-else />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6"
                                        v-if="assetsForm.terminalClienteleType === '个人'">
                                        <el-form-item label="终端联系人：" prop="terminalClienteleContactId" label-width="120px"
                                            :rules="assetsFormRules.terminalClienteleContactId"
                                            class="postInfo-container-item">
                                            <div v-if="couldEdit">
                                                <el-select v-model="assetsForm.terminalClienteleContactId"
                                                    placeholder="请选择(可搜索)" clearable filterable @change="getTcontactInfo"
                                                    style="width:80%">
                                                    <el-option v-for="(c, id) in tCustomerContract" :label="c.name"
                                                        :value="c.id"></el-option>
                                                </el-select>
                                                <el-tooltip class="item" effect="dark" content="没有联系人？点击新增"
                                                    placement="top-end">
                                                    <span style="margin-left:5%;color:RGB(64,158,255);cursor:pointer"
                                                        @click="createTlinkman()">新增</span>
                                                </el-tooltip>
                                            </div>
                                            <el-input :value="assetsForm.tterminalClienteleContactName" class="filter-item"
                                                style=" width: 225px" v-else />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :xs="24" :sm="12" :lg="6" :span="6">
                                        <el-form-item label="终端联系电话：" prop="clienteleType" label-width="150px"
                                            class="postInfo-container-item">
                                            <el-input :value="assetsForm.tmobile" class="filter-item" readonly disabled
                                                style=" width: 215px" />
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row class="row-style">
                                    <el-col :xs="24" :sm="12" :lg="23" :span="12">
                                        <el-form-item label="备注：" prop="remark" label-width="120px"
                                            class="postInfo-container-item">
                                            <el-input v-model="assetsForm.remark" :autosize="{ minRows: 4, maxRows: 4 }"
                                                class="filter-item" type="textarea" />
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </div>
                        </div>
                    </el-form>
                </y-detail-page-layout>
            </div>
            <!-- 新增客户联系人 -->
            <el-dialog :visible.sync="createLinkmanVisible" width="70%" custom-class="createLinkman">
                <el-divider content-position="left">新增客户联系人</el-divider>
                <el-form ref="linkmanForm" :model="linkmanForm" :rules="linkmanRules">
                    <el-row>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="客户类型：" prop="clienteleType" :rules="linkmanRules.clienteleType"
                                label-width="120px" class="postInfo-container-item">
                                <el-select v-model="linkmanForm.clienteleType">
                                    <el-option label="企业" value="企业"></el-option>
                                    <el-option label="个人" value="个人"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6" v-if="assetsForm.clienteleType === '企业'">
                            <el-form-item label="客户名称：" prop="clienteleId" :rules="linkmanRules.clienteleId"
                                label-width="120px" class="postInfo-container-item">
                                <el-select v-model="linkmanForm.clienteleId">
                                    <el-option v-for="(c, id) in customerCompany" :label="c.name" :value="c.id"></el-option>
                                </el-select>

                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6" v-if="assetsForm.clienteleType === '企业'">
                            <el-form-item label="业务来源：" prop="clienteleSubId" :rules="linkmanRules.clienteleSubId"
                                label-width="120px" class="postInfo-container-item">
                                <el-select v-model="linkmanForm.clienteleSubId">
                                    <el-option v-for="(s, id) in subCustomerCompany" :label="s.name"
                                        :value="s.id"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="联系人姓名：" prop="name" :rules="linkmanRules.name" label-width="120px"
                                class="postInfo-container-item">
                                <el-input v-model.trim="linkmanForm.name" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="联系电话：" prop="mobile" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="linkmanForm.mobile" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="性别：" prop="sex" label-width="120px" class="postInfo-container-item">
                                <el-select v-model=linkmanForm.sex>
                                    <el-option label="男" value="男">男</el-option>
                                    <el-option label="女" value="女">女</el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="身份证号：" prop="idNo" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="linkmanForm.idNo" class="filter-item" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="微信号：" prop="wechatNo" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="linkmanForm.wechatNo" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="QQ号：" prop="qqNo" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="linkmanForm.qqNo" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="毕业院校：" prop="school" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="linkmanForm.school" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="毕业专业：" prop="industry" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="linkmanForm.industry" class="filter-item" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="所在部门：" prop="department" label-width="120px"
                                class="postInfo-container-item">
                                <el-input v-model.trim="linkmanForm.department" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="职位：" prop="duty" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="linkmanForm.duty" class="filter-item" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :xs="24" :sm="12" :lg="24" :span="6">
                            <el-form-item label="备注：" prop="description" label-width="120px"
                                class="postInfo-container-item">
                                <el-input v-model.trim="linkmanForm.description" class="filter-item" type="textarea" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-button type="primary" @click="saveLinkman()"
                        style="position:absolute;top:45px;right:20px">保存</el-button>
                </el-form>
            </el-dialog>
            <!-- 新增终端客户联系人 -->
            <el-dialog :visible.sync="createTlinkmanVisible" width="70%" custom-class="createLinkman">
                <el-divider content-position="left">新增终端客户联系人</el-divider>
                <el-form ref="tLinkmanForm" :model="tLinkmanForm" :rules="tLinkmanFormRules">
                    <el-row>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="联系人姓名：" prop="name" :rules="tLinkmanFormRules.name" label-width="120px"
                                class="postInfo-container-item">
                                <el-input v-model.trim="tLinkmanForm.name" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="联系电话：" prop="mobile" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="tLinkmanForm.mobile" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="性别：" prop="sex" label-width="120px" class="postInfo-container-item">
                                <el-select v-model=tLinkmanForm.sex>
                                    <el-option label="男" value="男">男</el-option>
                                    <el-option label="女" value="女">女</el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="身份证号：" prop="idNo" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="tLinkmanForm.idNo" class="filter-item" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="微信号：" prop="wechatNo" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="tLinkmanForm.wechatNo" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="QQ号：" prop="qqNo" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="tLinkmanForm.qqNo" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="毕业院校：" prop="school" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="tLinkmanForm.school" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="毕业专业：" prop="industry" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="tLinkmanForm.industry" class="filter-item" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="所在部门：" prop="department" label-width="120px"
                                class="postInfo-container-item">
                                <el-input v-model.trim="tLinkmanForm.department" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="6" :span="6">
                            <el-form-item label="职位：" prop="duty" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="tLinkmanForm.duty" class="filter-item" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :xs="24" :sm="12" :lg="24" :span="6">
                            <el-form-item label="备注：" prop="description" label-width="120px"
                                class="postInfo-container-item">
                                <el-input v-model.trim="tLinkmanForm.description" class="filter-item" type="textarea" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-button type="primary" @click="saveTlinkman()"
                        style="position:absolute;top:45px;right:20px">保存</el-button>
                </el-form>
            </el-dialog>
            <!-- 新增终端客户 -->
            <el-dialog :visible.sync="createTerminalClientVisible" width="70%" custom-class="createLinkman">
                <el-divider content-position="left">新增终端客户</el-divider>
                <el-form ref="terminalClientForm" :model="terminalClientForm" :rules="terminalClientFormRules">
                    <el-row>
                        <el-col :xs="24" :sm="12" :lg="8" :span="6">
                            <el-form-item label="客户名称：" prop="name" :rules="terminalClientFormRules.name"
                                label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="terminalClientForm.name" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="8" :span="6">
                            <el-form-item label="企业类型：" prop="companyType" :rules="terminalClientFormRules.companyType"
                                label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="terminalClientForm.companyType" class="filter-item" />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :lg="8" :span="6">
                            <el-form-item label="联系电话：" prop="phone" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="terminalClientForm.phone" class="filter-item" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :xs="24" :sm="12" :lg="24" :span="6">
                            <el-form-item label="客户地址：" prop="address" label-width="120px" class="postInfo-container-item">
                                <el-input v-model.trim="terminalClientForm.address" class="filter-item" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-button type="primary" @click="saveClient()"
                        style="position:absolute;top:45px;right:20px">保存</el-button>
                </el-form>
            </el-dialog>
        </div>
    </div>
</template>

<script>
import Breadcrumb from '@/components/Breadcrumb'
import YDetailPageLayout from '@/components/YDetailPageLayout/index_detail'
import { isNumber, phoneNumber, postiveInteger, isIdNumber } from '@/utils/validate'

export default {
    name: 'addAssetsOrder',
    components: {
        Breadcrumb,
        YDetailPageLayout
    },
    watch: {
    },
    computed: {

    },
    data() {
        return {
            couldEdit: null,
            couldBack: null,
            // 页面传参
            pageParams: {
                back: null,
                row: null
            },
            // 表单项目隐藏字段
            itemHideStatus: false,
            createLinkmanVisible: false,
            // 资产业务下单表单校验规则
            assetsFormRules: {
                clientManager: [
                    { required: true, message: '客户经理不能为空', trigger: 'blur' }
                ],
                departmentId: [
                    { required: true, message: '请选择接单部门', trigger: 'change' }
                ],
                name: [
                    { required: true, message: '项目名称不能为空', trigger: 'blur' }
                ],
                assetsBusinessGener: [
                    { required: true, message: '请选择业务类型', trigger: 'change' }
                ],
                entrustAgain: [
                    { required: true, message: '请选择客户是否再次委托', trigger: 'change' }
                ],
                clienteleType: [
                    { required: true, message: '请选择客户类型', trigger: 'change' }
                ],
                clienteleId: [
                    { required: true, message: '请选择客户名称', trigger: 'change' }
                ],
                clienteleSubId: [
                    { required: true, message: '请选择业务来源', trigger: 'change' }
                ],
                clienteleContactId: [
                    { required: true, message: '请选择客户联系人', trigger: 'change' }
                ],
                security: [
                    { required: true, message: '请选择是否证券项目', trigger: 'change' }
                ],
                significantAssetsReorganization: [
                    { required: true, message: '请选择是否资产重组项目', trigger: 'change' }
                ],
                stateAssets: [
                    { required: true, message: '请选择是否是否国资项目', trigger: 'change' }
                ],
                foreignAssetsInvolved: [
                    { required: true, message: '请选择是否 是否涉及境外资产', trigger: 'change' }
                ],
                dispenseBenefit: [
                    { required: true, message: '请选择是否是否分配产值', trigger: 'change' }
                ],
                terminalClienteleType: [
                    { required: true, message: '请选择终端客户类型', trigger: 'change' }
                ],
                terminalClienteleId: [
                    { required: true, message: '终端客户名称不能为空', trigger: 'blur' }
                ],
                terminalClienteleContactId: [
                    { required: true, message: '终端联系人不能为空', trigger: 'blur' }
                ]
            },
            // 新增客户联系人表单校验规则 
            linkmanRules: {
                clienteleType: [
                    { required: true, message: '客户类型不能为空', trigger: 'blur' }
                ],
                clienteleId: [
                    { required: true, message: '客户名称不能为空', trigger: 'blur' }
                ],
                clienteleSubId: [
                    { required: true, message: '业务来源不能为空', trigger: 'blur' }
                ],
                name: [
                    { required: true, message: '联系人姓名不能为空', trigger: 'blur' }
                ]
            },
            // 新增终端客户联系人表单校验规则
            tLinkmanFormRules: {
                name: [
                    { required: true, message: '联系人姓名不能为空', trigger: 'blur' }
                ]
            },
            // 新增终端客户表单校验规则
            terminalClientFormRules: {
                name: [
                    { required: true, message: '联系人姓名不能为空', trigger: 'blur' }
                ],
                companyType: [
                    { required: true, message: '联系电话不能为空', trigger: 'blur' }, { validator: phoneNumber, trigger: 'blur' }
                ]
            },
            // 业务类型下拉列表
            assetsBusinessGeners: [
                {
                    value: '单项资产',
                    label: '单项资产'
                }, {
                    value: '整体资产',
                    label: '整体资产'
                }, {
                    value: '无形资产',
                    label: '无形资产'
                }, {
                    value: '债权',
                    label: '债权'
                }, {
                    value: '其他',
                    label: '其他'
                }
            ],
            // 接单部门
            allotDepartment: [],
            // 客户信息
            customerCompany: [],
            // 业务信息(二级客户)
            subCustomerCompany: [],
            // 客户联系人下拉列表
            customerContract: [],
            // 终端客户下拉列表
            tCustomerCompany: [],
            // 终端联系人下拉列表
            tCustomerContract: [],
            // 资产业务订单
            assetsForm: {
                // 项目名
                name: null,
                // 客户经理id
                clientManagerId: this.$store.getters.userInfo.id,
                // 客户经理
                clientManager: this.$store.getters.userInfo.name,
                // 接单部门id
                departmentId: null,
                // 资产业务类型
                assetsBusinessGener: null,
                // 客户再次委托
                entrustAgain: null,
                // 客户类型（企业，个人）
                clienteleType: null,
                // 客户id
                clienteleId: null,
                // 业务来源（下级客户id）
                clienteleSubId: null,
                // 客户联系人id
                clienteleContactId: null,
                // 是否证券项目
                security: null,
                // 是否资产重组项目
                significantAssetsReorganization: null,
                // 是否国资项目
                stateAssets: null,
                // 是否涉及境外资产
                foreignAssetsInvolved: null,
                // 是否分配产值
                dispenseBenefit: null,
                // 委托人
                bailor: null,
                // 委托人地址
                bailorAddress: null,
                // 委托联系人姓名
                bailorContactName: null,
                // 委托人联系人电话
                bailorContactTel: null,
                // 终端客户id
                terminalClienteleId: null,
                // 终端客户类型
                terminalClienteleType: null,
                // 终端联系人id
                terminalClienteleContactId: null,
                // 备注
                remark: null,
                // 终端联系电话
                tmobile: null,
                // 分单类型
                allotType: "指派"
            },
            // 新增客户联系人表单
            linkmanForm: {
                clienteleType: null,
                clienteleSubId: null,
                clienteleId: null,
                ccId: null,
                name: null,
                mobile: null,
                phone: null,
                sex: null,
                idNo: null,
                wechatNo: null,
                qqNo: null,
                school: null,
                industry: null,
                department: null,
                duty: null,
                terminal: false,
                description: null
            },
            createTlinkmanVisible: false,
            // 新增终端联系人表单
            tLinkmanForm: {
                ccId: null,
                name: null,
                mobile: null,
                phone: null,
                sex: null,
                idNo: null,
                wechatNo: null,
                qqNo: null,
                school: null,
                industry: null,
                department: null,
                duty: null,
                terminal: false,
                description: null
            },
            createTerminalClientVisible: false,
            // 终端客户联系人信息
            terminalClientForm: {
                name: null,
                companyType: null,
                address: null,
                phone: null,
                terminal: true
            },
            // 客户联系人信息
            linkmanInfo: {

            }
        }
    },
    created() {
        this.couldEdit = this.$route.query.couldEdit === 'true';
        this.couldBack = this.$route.query.couldBack === 'true';
        this.pageParams.back = this.$route.query.back;
        if (this.$route.query.row != null || this.$route.query.row != undefined) {
            this.pageParams.row = JSON.parse(this.$route.query.row);
        }
        this.getAllotDepartment();
        this.getCustomerCompany(0);
        this.getCustomerCompany(1);
        if (this.pageParams.row.assetsId !== null && this.pageParams.row.assetsId !== undefined && this.pageParams.row.assetsId !== '') {
            this.getAssetsDetailById(this.pageParams.row.assetsId);
        }
    },
    methods: {
        handleCreate() {
            this.$refs.assetsForm.validate(valid => {
                if (valid) {
                    this.$api.assets.add(this.assetsForm).then(res => {
                        if (res.code === 200) {
                            if (res.data && res.data.instanceNodeId && res.data.state) {
                                this.$api.workflow.commit(res.data).then(result => {
                                    if (result.code === 200 && result.data) {
                                        this.$notify({
                                            title: '成功',
                                            message: '下单并提交流程成功',
                                            type: 'success',
                                            duration: 2000
                                        });
                                    }
                                })
                            } else {
                                this.$notify({
                                    title: '成功',
                                    message: '下单成功,需要手动提交流程。',
                                    type: 'warning',
                                    duration: 2000
                                });
                            }
                            const back = this.$route.query.back;
                            if (back) {
                                this.$router.push(back)
                            }
                        } else {
                            this.$notify({
                                title: '失败',
                                message: '下单失败，请稍后再试。',
                                type: 'error',
                                duration: 2000
                            });
                        }
                    })
                }
            })
        },
        // 获取部门下拉列表
        getAllotDepartment() {
            this.$api.department.allot().then(res => {
                if (res.code === 200) {
                    this.allotDepartment = res.data;
                }
            })
        },
        // 撤回订单
        doRecall() {
            this.$confirm('请确认是否撤回此个贷订单的业务流程?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                if (this.assetsForm.id) {
                    this.$api.assetsForm.doRecall(this.assetsForm.id).then(res => {
                        if (res.code === 200 && res.data) {
                            this.$notify({
                                title: '成功',
                                message: '业务流程撤回成功',
                                type: 'success',
                                duration: 2000
                            });
                            this.$refs.myPersonalOrder.initPageStatus(true, true);
                            this.couldEdit = true;
                            //this.$refs.myPersonalOrder.forceUpdate();
                        } else {
                            this.$notify({
                                title: '失败',
                                message: '业务流程撤回失败',
                                type: 'error',
                                duration: 2000
                            });
                        }
                    })
                }
            })
        },
        // 改变客户类型时进行值重置的操作
        changeCustomerType(val) {
            // 清空联系人下拉列表
            this.assetsForm.clienteleContactId = null;
            this.assetsForm.clienteleSubId = null;
            this.customerContract = [];
            if (val === "企业") {
                this.getCustomerCompany(0);
                this.itemHideStatus = true;
            } else {
                this.getCustomerContract(1);
                this.itemHideStatus = false;
            }
        },
        // 获取客户信息
        getCustomerCompany(val) {
            if (val === 0) {
                let simpleAll = new Object();
                simpleAll.terminal = val;
                this.$api.customerCompany.simpleAll(simpleAll).then(res => {
                    if (res.code === 200) {
                        this.customerCompany = res.data;
                    }
                })
            } else {
                let simpleAll = new Object();
                simpleAll.terminal = val;
                this.$api.customerCompany.simpleAll(simpleAll).then(res => {
                    if (res.code === 200) {
                        this.tCustomerCompany = res.data;
                    }
                })
            }
        },
        // 获取二级客户信息(业务来源)
        findSubClientele(val) {
            if (val === 0) {
                if (this.assetsForm.clienteleId) {
                    let simpleAll = new Object();
                    simpleAll.terminal = val;
                    simpleAll.parentId = this.assetsForm.clienteleId;
                    this.$api.customerCompany.simpleAll(simpleAll).then(res => {
                        if (res.code === 200) {
                            this.subCustomerCompany = res.data;
                            if (this.assetsForm.clienteleSubId) {
                                this.assetsForm.clienteleSubId = null
                            }
                            if (this.assetsForm.clienteleContactId) {
                                this.assetsForm.clienteleContactId = null
                                this.customerContract = [];
                            }
                        }
                    })
                }
            } else {
                if (this.assetsForm.terminalClienteleId) {
                    let simpleAll = new Object();
                    simpleAll.terminal = val;
                    simpleAll.ccId = this.assetsForm.terminalClienteleId;
                    this.$api.customerCompany.detail(this.assetsForm.terminalClienteleId).then(res => {
                        if (res.code === 200) {
                            this.assetsForm.tmobile = res.data.phone;
                        }
                    })
                }
            }
        },
        // 获取客户联系人列表
        getCustomerContract(val) {
            // if (this.assetsForm.clienteleSubId) {
            let simpleAll = new Object();
            simpleAll.terminal = 0;
            if (val === 1) {
                simpleAll.ccId = val;
            } else {
                simpleAll.ccId = this.assetsForm.clienteleSubId;
            }
            this.$api.customerLinkman.simpleAll(simpleAll).then(res => {
                if (res.code === 200) {
                    this.customerContract = res.data;
                    if (this.assetsForm.clienteleContactId) {
                        this.assetsForm.clienteleContactId = null
                    }
                }
            })
            // }
        },
        // 打开新建客户联系人弹窗
        createLinkman(val) {
            // 打开前判断是否已经选择客户信息
            if (this.assetsForm.clienteleType === "个人" || this.assetsForm.clienteleType != null && this.assetsForm.clienteleId != null && this.assetsForm.clienteleSubId != null) {
                this.createLinkmanVisible = true;
                this.linkmanForm.terminal = val;
                this.linkmanForm.clienteleType = this.assetsForm.clienteleType;
                this.linkmanForm.clienteleId = this.assetsForm.clienteleId;
                this.linkmanForm.clienteleSubId = this.assetsForm.clienteleSubId;
                if (this.assetsForm.clienteleType === '企业') {
                    this.linkmanForm.ccId = this.assetsForm.clienteleSubId
                } else {
                    this.assetsForm.clienteleSubId = 1;
                    this.linkmanForm.ccId = this.assetsForm.clienteleSubId;
                }
            } else {
                this.$notify({
                    title: '警告',
                    message: '请先选择客户！',
                    type: 'warning',
                    duration: 2000
                });
            }

        },
        // 保存客户联系人信息
        saveLinkman() {
            this.$refs.linkmanForm.validate(valid => {
                if (valid) {
                    this.$api.customerLinkman.add(this.linkmanForm).then(res => {
                        if (res.code === 200) {
                            this.$notify({
                                title: '成功',
                                message: '新增客户联系人成功',
                                type: 'success',
                                duration: 2000
                            });
                        }
                        this.getCustomerContract();
                        setTimeout(() => {
                            this.assetsForm.clienteleContactId = this.customerContract[0].id;
                            this.getContactInfo();
                        }, 2000)
                        this.createLinkmanVisible = false;
                    })
                }
            })
        },
        // 获取联系信息
        getContactInfo() {
            if (this.assetsForm.clienteleContactId) {
                this.$api.customerLinkman.detail(this.assetsForm.clienteleContactId).then(res => {
                    if (res.code === 200) {
                        console.log(res.data)
                        this.linkmanInfo = res.data;
                    }
                })
            }
        },
        // 获取终端联系人信息
        getTcontactInfo() {
            if (this.assetsForm.terminalClienteleContactId) {
                this.$api.customerLinkman.detail(this.assetsForm.terminalClienteleContactId).then(res => {
                    if (res.code === 200) {
                        this.assetsForm.tmobile = res.data.mobile;
                    }
                })
            }
        },
        // 打开新增终端联系人弹窗
        createTlinkman() {
            this.createTlinkmanVisible = true;
            this.tLinkmanForm.terminal = 1;
            this.assetsForm.clienteleSubId = 1;
            this.tLinkmanForm.ccId = this.assetsForm.clienteleSubId;
        },
        // 打开新增终端客户弹窗
        createTerminalClient() {
            this.createTerminalClientVisible = true;
        },
        // 保存终端联系信息
        saveClient() {
            this.$refs.terminalClientForm.validate(valid => {
                if (valid) {
                    this.$api.customerCompany.add(this.terminalClientForm).then(res => {
                        if (res.code === 200) {
                            this.$notify({
                                title: '成功',
                                message: '新增客户成功',
                                type: 'success',
                                duration: 2000
                            });
                        }
                        this.getCustomerCompany(1);
                        setTimeout(() => {
                            this.assetsForm.terminalClienteleId = this.tCustomerCompany[0].id;
                            this.findSubClientele(1);
                        }, 2000)
                        this.createTerminalClientVisible = false;
                    })
                }
            })
        },
        // 新增终端联系人
        saveTlinkman() {
            this.$refs.tLinkmanForm.validate(valid => {
                if (valid) {
                    this.$api.customerLinkman.add(this.tLinkmanForm).then(res => {
                        if (res.code === 200) {
                            this.$notify({
                                title: '成功',
                                message: '新增终端联系人成功',
                                type: 'success',
                                duration: 2000
                            });
                        }
                        let simpleAll = new Object();
                        simpleAll.ccId = 1;
                        simpleAll.terminal = 1;
                        this.$api.customerLinkman.simpleAll(simpleAll).then(res => {
                            if (res.code === 200) {
                                this.tCustomerContract = res.data;
                            }
                        })
                        setTimeout(() => {
                            this.assetsForm.terminalClienteleContactId = this.tCustomerContract[0].id;
                            this.getTcontactInfo();
                        }, 2000)
                        this.createTlinkmanVisible = false;
                    })
                }
            })
        },
        // 根据id查询资产订单信息
        getAssetsDetailById(id) {
            this.$api.assets.getAssetsDetailById(id).then(res => {
                if (res.code === 200) {
                    this.assetsForm.clientManagerId = this.$store.getters.userInfo.id;
                    this.assetsForm.clientManager = this.$store.getters.userInfo.name;
                    this.assetsForm.name = res.data.name;
                    this.assetsForm.departmentId = res.data.departmentId;
                    this.assetsForm.assetsBusinessGener = res.data.assetsBusinessGener;
                    this.assetsForm.entrustAgain = res.data.entrustAgain;
                    this.assetsForm.security = res.data.security;
                    this.assetsForm.significantAssetsReorganization = res.data.significantAssetsReorganization;
                    this.assetsForm.stateAssets = res.data.stateAssets;
                    this.assetsForm.foreignAssetsInvolved = res.data.foreignAssetsInvolved;
                    this.assetsForm.dispenseBenefit = res.data.dispenseBenefit;
                    this.assetsForm.remark = res.data.remark;
                    this.initCustomerSelect(this.assetsForm.clienteleType);
                    this.getPrincipalByAllotDepartment();
                    this.getAllUser();
                    this.getCustomerCompany(1);
                }
            })
            console.log(this.assetsForm);
        },
        initCustomerSelect(val) {
            if (val === "企业") {
                this.getCustomerCompany(0);
                this.getCustomerContract();
                this.itemHideStatus = true;
            } else {
                this.getCustomerContract(1);
                this.itemHideStatus = false;
            }
        },
        // 根据部门id获取项目负责人列表
        getPrincipalByAllotDepartment() {
            let departmentId = this.assetsForm.departmentId;
            if (departmentId) {
                this.$api.user.usersByDepartmentId(departmentId).then(res => {
                    if (res.code === 200) {
                        this.principals = res.data;
                    }
                })
            }
        },
        // 获取用户下拉列表
        getAllUser() {
            this.$api.user.simpleAll().then(res => {
                if (res.code === 200) {
                    this.allUsers = res.data;
                }
            })
        }

    }
}
</script>

<style lang="scss" scoped>
.form-container {
    margin-top: 50px;
}

.row-style {
    margin-left: 40px;
    margin-right: 1%;
}

.task-class {
    /deep/ .el-form-item__label {
        color: red;
    }
}

.table {
    /deep/ thead {
        .el-table-column--selection {
            .cell {
                display: none;
            }
        }
    }
}

/deep/.doWarehouseClass {
    border-radius: 10px;
}
</style>