<template>
    <div class="app-container">
      <div class="title-container">
        <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
      </div>
      <div class="form-container">
        <y-detail-page-layout ref="myPersonalOrder" @save="handleCreate" :editStatus="couldEdit" @doRecall="doRecall" :couldBack="couldBack" :rules="rules">
          <el-form ref="personalForm" :model="personal">
            <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="{required: true, message: '客户经理不能为空', trigger: 'blur'}"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                      <el-input :value="personal.clientManager" 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="evaluateAim"
                      :rules="{required: true, message: '评估目的不能为空', trigger: 'blur'}"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-select v-model="personal.evaluateAim" placeholder="请选择">
                            <el-option label="按揭" value="按揭"></el-option> 
                            <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="12" :span="6">
                    <el-form-item
                      label="房屋用途："
                      prop="purpose"
                      label-width="160px"
                      :rules="{required: true, message: '房屋用途不能为空', trigger: 'blur'}"
                      class="postInfo-container-item"
                    >
                      <el-checkbox-group v-model="personal.purpose">
                        <el-checkbox-button label="HOUSE" name="purpose">住宅</el-checkbox-button>
                        <el-checkbox-button label="BUSINESS" name="purpose">商业</el-checkbox-button>
                        <el-checkbox-button label="OFFICE" name="purpose">办公</el-checkbox-button>
                        <el-checkbox-button label="INDUSTRIAL" name="purpose">工业</el-checkbox-button>
                        <el-checkbox-button label="OTHER" name="purpose">其他</el-checkbox-button>
                      </el-checkbox-group>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row class="row-style">
                  <el-col :xs="12" :sm="12" :lg="23" :span="6">
                    <el-form-item
                      label="坐落："
                      prop="location"
                      :rules="{required: true, message: '坐落不能为空', trigger: 'blur'}"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                      <el-input v-model="personal.location" class="filter-item" style=" width: 100%"/>
                    </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="{required: true, message: '客户类型不能为空', trigger: 'blur'}"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-select v-model="personal.clienteleType" placeholder="请选择" @change="changeCustomerType(0)" >
                            <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="{required: true, message: '客户名称不能为空', trigger: 'blur'}"
                      class="postInfo-container-item"
                    >
                    <el-select v-model="personal.clienteleId" placeholder="请选择(可搜索)" @change="findSubClientele(0)" clearable filterable  v-if="couldEdit">
                          <el-option v-for="(c,id) in customerCompany" :label="c.name" :value="c.id"></el-option> 
                        </el-select>
                        <el-input :value="personal.cclienteleName" 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="clienteleSubId"
                      label-width="120px"
                      :rules="{required: true, message: '业务来源不能为空', trigger: 'blur'}"
                      class="postInfo-container-item"
                    >
                    <el-select v-model="personal.clienteleSubId" placeholder="请选择(可搜索)"  @change="getCustomerContract" clearable filterable  v-if="couldEdit">
                          <el-option v-for="(s,id) in subCustomerCompany" :label="s.name" :value="s.id"></el-option> 
                        </el-select>
                        <el-input :value="personal.cclienteleSubName" 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="clienteleContactId"
                      :rules="{required: true, message: '客户联系人不能为空', trigger: 'blur'}"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <div  v-if="couldEdit">
                        <el-select v-model="personal.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-input :value="personal.cclienteleContactName" class="filter-item"  style=" width: 225px" v-else/>
                    </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"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-input :value="personal.cmobile" 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="clienteleContactId"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-input :value="personal.cdepartment" 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="clienteleContactId"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-input :value="personal.cduty" 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="agent"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-input :value="personal.agent" 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="loanNature"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-input v-model="personal.loanNature" 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="loanAim"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-input v-model="personal.loanAim" 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="loanLimit"
                      label-width="120px"
                      :rules="{required: true, message: '贷款额度不能为空', trigger: 'blur'}"
                      class="postInfo-container-item"
                    >
                    <el-input v-model="personal.loanLimit" class="filter-item" style=" width: 225px" >
                      <template slot="append">万元</template>
                    </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :xs="24" :sm="12" :lg="6" :span="6">
                    <el-form-item
                      label="贷款期限："
                      prop="loanPeriod"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-input v-model="personal.loanPeriod" class="filter-item" style=" width: 225px" >
                      <template slot="append">年</template>
                    </el-input>
                    </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="loanExpire"
                      label-width="140px"
                      class="postInfo-container-item"
                    >
                    <el-radio  v-model="personal.loanExpire" :label="false" border size="medium" >否</el-radio>
                    <el-radio  v-model="personal.loanExpire" :label="true" border size="medium" >是</el-radio>
                    </el-form-item>
                  </el-col>
                  <el-col :xs="24" :sm="12" :lg="12" :span="6">
                    <el-form-item
                      label="资料说明："
                      prop="credentials"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                      <el-checkbox-group v-model="personal.credentials">
                        <el-checkbox-button label="HOUSE_CERTIFICATE" name="credentials">房产证</el-checkbox-button>
                        <el-checkbox-button label="LAND_CERTIFICATE" name="credentials">国土证</el-checkbox-button>
                        <el-checkbox-button label="IMMOVABLE_CERTIFICATE" name="credentials">不动产权证</el-checkbox-button>
                        <el-checkbox-button label="LEASE_CONTRACT" name="credentials">租赁合同</el-checkbox-button>
                        <el-checkbox-button label="IDENTITY_CARD" name="credentials">身份证</el-checkbox-button>
                        <el-checkbox-button label="NONE" name="credentials">无资料</el-checkbox-button>
                      </el-checkbox-group>
                    </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="委托人1："
                      prop="bailorA"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-input v-model="personal.bailorA" 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="委托人1电话："
                      prop="bailorATel"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-input v-model="personal.bailorATel" 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="委托人2："
                      prop="bailorB"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-input v-model="personal.bailorB" 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="委托人2电话："
                      prop="bailorBTel"
                      label-width="120px"
                      class="postInfo-container-item"
                    >
                    <el-input v-model="personal.bailorBTel" 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"
                      label-width="140px"
                      class="postInfo-container-item"
                    >
                    <el-select v-model="personal.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="personal.terminalClienteleType==='企业'">
                    <el-form-item
                      label="终端客户名称："
                      prop="terminalClienteleId"
                      label-width="140px"
                      :rules="{required: true, message: '终端客户名称不能为空', trigger: 'blur'}"
                      class="postInfo-container-item"
                    >
                    <div v-if="couldEdit">
                          <el-select v-model="personal.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="personal.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="personal.terminalClienteleType==='个人'">
                    <el-form-item
                      label="终端联系人："
                      prop="terminalClienteleContactId"
                      label-width="120px"
                      :rules="{required: true, message: '终端联系人不能为空', trigger: 'blur'}"
                      class="postInfo-container-item"
                    >
                    <div v-if="couldEdit">
                          <el-select v-model="personal.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="personal.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="130px"
                      class="postInfo-container-item"
                    >
                    <el-input :value="personal.tmobile" class="filter-item"  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="personal.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="linkmanFrom" :model="linkmanFrom" :rules="rules">
        <el-row>
          <el-col :xs="24" :sm="12" :lg="6" :span="6">
            <el-form-item
              label="客户类型："
              prop="clienteleType"
              :rules="{required: true, message: '客户类型不能为空', trigger: 'blur'}"
              label-width="120px"
              class="postInfo-container-item"
            >
            <el-select v-model="linkmanFrom.clienteleType" disabled readonly>
                    <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="personal.clienteleType==='企业'">
            <el-form-item
              label="客户名称："
              prop="clienteleId"
              :rules="{required: true, message: '客户名称不能为空', trigger: 'blur'}"
              label-width="120px"
              class="postInfo-container-item"
            >
              <el-select v-model="linkmanFrom.clienteleId"  disabled readonly>
                <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="personal.clienteleType==='企业'">
            <el-form-item
              label="业务来源："
              prop="clienteleSubId"
              :rules="{required: true, message: '业务来源不能为空', trigger: 'blur'}"
              label-width="120px"
              class="postInfo-container-item"
            >
              <el-select v-model="linkmanFrom.clienteleSubId"  disabled readonly>
                <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="{required: true, message: '联系人姓名不能为空', trigger: 'blur'}"
              label-width="120px"
              class="postInfo-container-item"
            >
              <el-input v-model.trim="linkmanFrom.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="linkmanFrom.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=linkmanFrom.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="linkmanFrom.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="linkmanFrom.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="linkmanFrom.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="linkmanFrom.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="linkmanFrom.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="linkmanFrom.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="linkmanFrom.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="linkmanFrom.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="tLinkmanFrom" :model="tLinkmanFrom" :rules="rules" >
        <el-row>
          <el-col :xs="24" :sm="12" :lg="6" :span="6">
            <el-form-item
              label="联系人姓名："
              prop="name"
              :rules="{required: true, message: '联系人姓名不能为空', trigger: 'blur'}"
              label-width="120px"
              class="postInfo-container-item"
            >
              <el-input v-model.trim="tLinkmanFrom.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="tLinkmanFrom.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=tLinkmanFrom.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="tLinkmanFrom.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="tLinkmanFrom.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="tLinkmanFrom.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="tLinkmanFrom.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="tLinkmanFrom.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="tLinkmanFrom.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="tLinkmanFrom.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="tLinkmanFrom.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="terminalClientFrom" :model="terminalClientFrom" :rules="rules" >
        <el-row>
          <el-col :xs="24" :sm="12" :lg="8" :span="6">
            <el-form-item
              label="客户名称："
              prop="name"
              :rules="{required: true, message: '联系人姓名不能为空', trigger: 'blur'}"
              label-width="120px"
              class="postInfo-container-item"
            >
              <el-input v-model.trim="terminalClientFrom.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="{required: true, message: '联系电话不能为空', trigger: 'blur'}"
              label-width="120px"
              class="postInfo-container-item"
            >
              <el-input v-model.trim="terminalClientFrom.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="terminalClientFrom.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="terminalClientFrom.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>
</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: 'personalDoOrder',
      components: {
        Breadcrumb,
        YDetailPageLayout,
      },
      watch:{
      },
      computed: {
  
      },
      data() {
        return {
          rules:{
            loanLimit:[{required:true,message:"贷款额度不能为空",trigger:'blur'},{validator:isNumber,trigger:'blur'}],

          },
          personal:{
              id:null,
              clientManagerId:this.$store.getters.userInfo.id,
              clientManager:this.$store.getters.userInfo.name,
              evaluateAim:null,
              purpose:[],
              location:null,
              clienteleType:null,
              cclienteleName:null,
              cclienteleSubName:null,
              agent:null,
              cclienteleContactName:null,
              cmobile:null,
              cdepartment:null,
              cduty:null,
              loanNature:null,
              loanAim:null,
              loanLimit:null,
              loanPeriod:null,
              loanExpire:false,
              credentials:[],
              bailorA:null,
              bailorATel:null,
              bailorB:null,
              bailorBTel:null,
              terminalClienteleType:null,
              tterminalClienteleName:null,
              tterminalClienteleContactName:null,
              tmobile:null,
              remark:null
          },
          createLinkmanVisible:false,
          linkmanFrom:{
            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
          },
          createTerminalClientVisible:false,
          terminalClientFrom:{
            name:null,
            companyType:null,
            address:null,
            phone:null,
            terminal:true
          },
          createTlinkmanVisible:false,
          tLinkmanFrom:{
            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
          },
          customerCompany:[],
          subCustomerCompany:[],
          customerContract:[],
          tCustomerCompany:[],
          tSubCustomerCompany:[],
          tCustomerContract:[],
        }
      },
      created() {
        this.personal.id = this.$route.query.id
        this.couldEdit = this.$route.query.couldEdit ==='true';
        this.couldBack = this.$route.query.couldBack ==='true';
        this.getPersonal();
        this.getCustomerCompany(0);
        this.getCustomerCompany(1);
      },
      methods: {
        handleCreate(){
          this.$refs.personalForm.validate(valid => {
          if (valid) {
            this.personal.purpose = JSON.stringify(this.personal.purpose);
            this.personal.credentials = JSON.stringify(this.personal.credentials);
            if (this.personal.id) {
              this.$api.personal.edit(this.personal).then(res => {
                if (res.code === 200) {
                  this.$notify({
                    title: '成功',
                    message: '保存成功',
                    type: 'success',
                    duration: 2000
                  });
                  const back = this.$route.query.back;
                  if (back) {
                    this.$router.push(back)
                  }
                  this.initData();
                }
              })
            } else {
              this.$api.personal.add(this.personal).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)
                  }
                  this.initData();
                }else{
                  this.$notify({
                            title: '失败',
                            message: '下单失败，请稍后再试。',
                            type: 'error',
                            duration: 2000
                          });
                }
              })
            }
          }
        })
        },
        changeCustomerType(val){
        if (val ===0){
            if (this.personal.clienteleId){
            this.personal.clienteleId = null;
            this.customerCompany=[]
          }
          if (this.personal.clienteleSubId){
            this.personal.clienteleSubId = null;
            this.subCustomerCompany=[]
          }
          if (this.personal.clienteleContactId){
            this.personal.clienteleContactId = null;
            this.customerContract =[]
          }
          if (this.personal.clienteleType==='个人'){
            let simpleAll = new Object();
            simpleAll.ccId = 1;
            simpleAll.terminal = 0;
            this.$api.customerLinkman.simpleAll(simpleAll).then(res=>{
              if (res.code === 200){
                  this.customerContract = res.data;
                  if (this.personal.clienteleContactId){
                    this.personal.clienteleContactId = null
                  }
              }
            })
          }
          if (this.personal.clienteleType==='企业'){
              this.getCustomerCompany(0)
              this.personal.clienteleContactId = null
              this.customerContract =[];
          }
        }else {
          if (this.personal.terminalClienteleType==='个人'){
            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;
                  if (this.personal.terminalClienteleId){
                    this.personal.terminalClienteleId = null
                  }
              }
            })
          }
          if (this.personal.terminalClienteleType==='企业'){
              this.getCustomerCompany(1)
              if (this.personal.terminalClienteleContactId){
                this.personal.terminalClienteleContactId = null
                this.tCustomerContract =[];
              }
          }
        }
        },
        findSubClientele(val){
        if (val===0){
          if (this.personal.clienteleId){
            let simpleAll = new Object();
              simpleAll.terminal=val;
              simpleAll.parentId= this.personal.clienteleId;
              this.$api.customerCompany.simpleAll(simpleAll).then(res=>{
              if (res.code === 200){
                  this.subCustomerCompany = res.data;
                  if (this.personal.clienteleSubId){
                    this.personal.clienteleSubId = null
                  }
                  if (this.personal.clienteleContactId){
                    this.personal.clienteleContactId = null
                    this.customerContract =[];
                  }
              }
            })
          }
        }else {
          if (this.personal.terminalClienteleId){
            let simpleAll = new Object();
              simpleAll.terminal=val;
              simpleAll.ccId = this.personal.terminalClienteleId;
              this.$api.customerCompany.detail(this.personal.terminalClienteleId).then(res=>{
              if (res.code === 200){
                this.personal.tmobile = res.data.phone;
              }
            })
          }
        }
        },
        createTerminalClient(){
          this.createTerminalClientVisible = true;
        },
        getCustomerContract(){
          if (this.personal.clienteleSubId){
              let simpleAll = new Object();
              simpleAll.ccId = this.personal.clienteleSubId
              this.$api.customerLinkman.simpleAll(simpleAll).then(res=>{
              if (res.code === 200){
                  this.customerContract = res.data;
                  if (this.personal.clienteleContactId){
                    this.personal.clienteleContactId = null
                  }
              }
            })
          }
        },
        getContactInfo(){
          if (this.personal.clienteleContactId){
              this.$api.customerLinkman.detail(this.personal.clienteleContactId).then(res=>{
                if (res.code === 200){
                  this.personal.cmobile = res.data.mobile;
                  this.personal.cDepartment = res.data.department
                  this.personal.cDuty = res.data.duty
                }
                  
              })
          }
        },
        getTcontactInfo(){
          if (this.personal.terminalClienteleContactId){
              this.$api.customerLinkman.detail(this.personal.terminalClienteleContactId).then(res=>{
                  if (res.code === 200){
                    this.personal.tmobile = res.data.mobile;
                  }
              })
          }
        },
        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;
              }
          })
        }
        },
        createLinkman(val){
          this.createLinkmanVisible = true;
          this.linkmanFrom.terminal = val;
          this.linkmanFrom.clienteleType = this.major.clienteleType;
          this.linkmanFrom.clienteleId = this.major.clienteleId;
          this.linkmanFrom.clienteleSubId = this.major.clienteleSubId;
          if (this.major.clienteleType==='企业'){
            this.linkmanFrom.ccId = this.major.clienteleSubId
          }else{
            this.major.clienteleSubId = 1;
            this.linkmanFrom.ccId = this.major.clienteleSubId;
          }
          
        },
        createTlinkman(){
            this.createTlinkmanVisible = true;
            this.tLinkmanFrom.terminal = 1;
            this.major.clienteleSubId = 1;
            this.tLinkmanFrom.ccId = this.major.clienteleSubId;
        },
        saveLinkman(){
            this.$refs.linkmanFrom.validate(valid =>{
              if (valid){
                  this.$api.customerLinkman.add(this.linkmanFrom).then(res=>{
                    if (res.code ===200){
                        this.$notify({
                          title: '成功',
                          message: '新增客户联系人成功',
                          type: 'success',
                          duration: 2000
                        });
                    }
                    this.getCustomerContract();
                    setTimeout(()=>{
                      this.major.clienteleContactId = this.customerContract[0].id;
                      this.getContactInfo();
                    },2000)
                    this.createLinkmanVisible=false;
                  })
              }
            })
        },
        saveTlinkman(){
          this.$refs.tLinkmanFrom.validate(valid =>{
              if (valid){
                  this.$api.customerLinkman.add(this.tLinkmanFrom).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.major.terminalClienteleContactId = this.tCustomerContract[0].id;
                      this.getTcontactInfo();
                    },2000)
                    this.createTlinkmanVisible=false;
                  })
              }
            })
        },
        saveClient(){
            this.$refs.terminalClientFrom.validate(valid =>{
              if (valid){
                  this.$api.customerCompany.add(this.terminalClientFrom).then(res=>{
                    if (res.code ===200){
                        this.$notify({
                          title: '成功',
                          message: '新增客户成功',
                          type: 'success',
                          duration: 2000
                        });
                    }
                    this.getCustomerCompany(1);
                    setTimeout(()=>{
                      this.major.terminalClienteleId  = this.tCustomerCompany[0].id;
                      this.findSubClientele(1);
                    },2000)
                    this.createTerminalClientVisible=false;
                  })
              }
            })
        },
        getPersonal(){
            if (this.personal.id){
                this.$api.personal.detail(this.personal.id).then(res=>{
                    if (res.code ===200 ){
                        res.data.credentials = JSON.parse(res.data.credentials);
                        res.data.purpose = JSON.parse(res.data.purpose);
                        this.personal = res.data;
                    }
                })
            }
        },
        doRecall(){
        this.$confirm('请确认是否撤回此个贷订单的业务流程?','提示',{
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(()=>{
            if (this.personal.id){
              this.$api.personal.doRecall(this.personal.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
                  });
                }
              })
            }
        })
      }
      },
    }
  </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>
  