<template>
	<view class="conent">
		<view class="assignrbitrators">
			<uni-forms ref="form" :modelValue="formData" :rules="rules">
				<uni-section title="案件信息" type="line" padding></uni-section>
				<uni-forms-item label="案件压缩包:" name="headZip" label-width="120px">
					<uni-file-picker ref="files" file-mediatype="all" return-type='object' v-model="fileListZip"
						:auto-upload="false" @select="selectZip" :limit='1' />
				</uni-forms-item>
				<uni-forms-item label="申请人调解请求:" name="arbitratClaims" label-width="120px" required
					:rules="[{required: true,errorMessage: '申请人调解请求不能为空'}]">
					<uni-easyinput v-model="formData.arbitratClaims" type="textarea" placeholder="请输入申请人调解请求" :maxlength='3000' />
				</uni-forms-item>
				<uni-forms-item label="事实和理由:" name="facts" label-width="120px" required
					:rules="[{required: true,errorMessage: '事实和理由不能为空'}]">
					<uni-easyinput v-model="formData.facts" type="textarea" placeholder="请输入事实和理由" :maxlength='3000'/>
				</uni-forms-item>
				<uni-forms-item label="申请人案件证据资料上传:" name="headImage" label-width="120px">
					<uni-file-picker ref="files" file-mediatype="all" return-type='object' v-model="fileList"
						:auto-upload="false" @select="select" :limit='1' />
				</uni-forms-item>
				<uni-forms-item label="证据:" label-width="120px" v-if="ids">
					<view class="" v-for="item in formData.caseAttachList">
						<uni-link v-if="item.annexType==2" :href="baseUrl+item.annexPath" color="#007BFF"
							:text="item.annexName"></uni-link>
					</view>
				</uni-forms-item>
				<uni-forms-item label="调解申请书:" label-width="120px" v-if="ids">
					<view class="" v-for="item in formData.caseAttachList">
						<uni-link v-if="item.annexType==3" :href="baseUrl+item.annexPath" color="#007BFF"
							:text="item.annexName"></uni-link>
					</view>
				</uni-forms-item>
				<button type="primary" @click="addMultipleApplicants" size="mini"
					style="margin-bottom: 20px;">新增多个申请人</button>
				<view class="" v-for="(item,index) in formData.affiliate.applicant">
					<button class="mini-btn" type="primary" size="mini" @tap="delValue(index)"
						v-if="index>=1?true:false">删除</button>
					<uni-section :title="'申请人信息' + (index + 1)" type="line" padding></uni-section>
					<uni-forms-item label="选择机构或自然人" label-width="120px" name="objectiJuris">
						<uni-data-checkbox class='checkbox' :disabled="ids?true:false" :localdata="objectiJurisArr"
							v-model="formData.affiliate.applicant[index].applicant.organizeFlag"
							@change='clearValidate($event,index)'></uni-data-checkbox>
					</uni-forms-item>
					<uni-forms-item label="是否操作人" label-width="120px"
						v-if="formData.affiliate.applicant[index].applicant.organizeFlag==0" key="operatorFlag">
						<uni-data-checkbox v-model="formData.affiliate.applicant[index].applicant.operatorFlag"
							:localdata="isOperate"></uni-data-checkbox>
					</uni-forms-item>
					<uni-forms-item
						:label="formData.affiliate.applicant[index].applicant.organizeFlag==0 ? '申请人':'申请机构'"
						:rules="rulesPersonName" :name="['affiliate','applicant',index,'applicant','name']"
						label-width="120px" required>
						<uni-easyinput v-model="formData.affiliate.applicant[index].applicant.name" type="text"
							:placeholder="formData.affiliate.applicant[index].applicant.organizeFlag==0 ? '请输入申请人姓名':'请输入申请机构名称'" />
					</uni-forms-item>
					<uni-forms-item label="证件类型" label-width="120px"
						v-if="formData.affiliate.applicant[index].applicant.organizeFlag==0">
						<uni-data-select v-model="formData.affiliate.applicant[index].applicant.idType"
							:localdata="certificate" @change="changeDocment"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="地区" label-width="120px">
						<uni-data-select v-model="formData.affiliate.applicant[index].applicant.nationality"
							:localdata="nationality" @change="changeArea"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item key='code' v-if="formData.affiliate.applicant[index].applicant.organizeFlag==1"
						label="机构代码" required label-width="120px"
						:name="['affiliate','applicant',index,'applicant','code']"
						:rules="[{required: true,errorMessage: '机构代码不能为空'}]">
						<uni-easyinput v-model="formData.affiliate.applicant[index].applicant.code" type="text"
							placeholder="请输入统一社会代码" />
					</uni-forms-item>
					<uni-forms-item label="证件号码" key='idCard'
						v-if="formData.affiliate.applicant[index].applicant.organizeFlag==0"
						:name="['affiliate','applicant',index,'applicant','idCard']" label-width="120px" required
						:rules="[
							{required: true,errorMessage: '申请人身份证号不能为空'},
							{pattern:'^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$',errorMessage:'申请人身份证格式错误'}]">
						<uni-easyinput v-model="formData.affiliate.applicant[index].applicant.idCard"
							@blur="handleBlurApplicant(index)" type="text" placeholder="请输入证件号码" />
					</uni-forms-item>
					<uni-forms-item v-if="formData.affiliate.applicant[index].applicant.organizeFlag==0" key="sex"
						label="性别" label-width="120px" required>
						<uni-data-checkbox class='checkbox' :disabled='true'
							v-model="formData.affiliate.applicant[index].applicant.sex"
							:localdata="respondentSexy"></uni-data-checkbox>
					</uni-forms-item>
					<uni-forms-item label="出生年月日" label-width="120px"
						v-if="formData.affiliate.applicant[index].applicant.organizeFlag==0" key="birth">
						<uni-datetime-picker v-model="formData.affiliate.applicant[index].applicant.birth"
							:disabled='true' type="date" :clear-icon="false" />
					</uni-forms-item>
					<uni-forms-item label="邮箱:" key="email"
						v-if="formData.affiliate.applicant[index].applicant.organizeFlag==0"
						:name="['affiliate','applicant',index,'applicant','email']" label-width="120px" required :rules="[
							{required: true,errorMessage: '被申请人邮箱不能为空'},
							{pattern:'^\\S+?@\\S+?\\.\\S+?$',errorMessage:'邮箱格式不正确'}
							]">
						<uni-easyinput v-model="formData.affiliate.applicant[index].applicant.email" type="text"
							placeholder="请输入申请人邮箱" />
					</uni-forms-item>
					<uni-forms-item label="电话:" key="phone"
						v-if="formData.affiliate.applicant[index].applicant.organizeFlag==0"
						:name="['affiliate','applicant',index,'applicant','phone']" label-width="120px"
						:required="testVerify" :rules="rulesRespondentPhone">
						<uni-easyinput v-model="formData.affiliate.applicant[index].applicant.phone" type="text"
							placeholder="请输入申请人电话" />
					</uni-forms-item>
					<uni-forms-item label="法定代表人:" v-if="formData.affiliate.applicant[index].applicant.organizeFlag==1"
						:name="['affiliate','applicant',index,'applicant','compLegalPerson']" key="compLegalPerson"
						label-width="120px" required :rules="[{required: true,errorMessage: '法定代表人不能为空'}]">
						<uni-easyinput v-model="formData.affiliate.applicant[index].applicant.compLegalPerson"
							type="text" placeholder="请输入法定代表人" />
					</uni-forms-item>
					<uni-forms-item label="住所:" :name="['affiliate','applicant',index,'applicant','home']"
						label-width="120px" required :rules="[{required: true,errorMessage: '申请人住所不能为空'}]">
						<uni-easyinput v-model="formData.affiliate.applicant[index].applicant.home" type="text"
							placeholder="请输入申请人住所" />
					</uni-forms-item>
					<uni-forms-item label="联系地址:" :name="['affiliate','applicant',index,'applicant','address']"
						label-width="120px" required :rules="[{required: true,errorMessage: '申请人联系地址不能为空'}]">
						<uni-easyinput v-model="formData.affiliate.applicant[index].applicant.address" type="text"
							placeholder="请输入申请人联系地址" />
					</uni-forms-item>
					<uni-section title="申请代理人" type="line" padding></uni-section>
					<uni-forms-item label="是否操作人" label-width="120px">
						<uni-data-checkbox v-model="formData.affiliate.applicant[index].applicantAgent.operatorFlag"
							:localdata="isProxyApplicant"></uni-data-checkbox>
					</uni-forms-item>
					<uni-forms-item label="联系电话:" label-width="120px" :name="['affiliate','applicant',index,'applicantAgent','phone']" :required="formData.affiliate.applicant[index].applicant.organizeFlag==0 ? false:true"  :rules="formData.affiliate.applicant[index].applicant.organizeFlag==1 ?rulesAgentPhone:[]">
						<uni-easyinput v-model="formData.affiliate.applicant[index].applicantAgent.phone" type="text"
							placeholder="请输入代理人联系电话" />
					</uni-forms-item> 
					<uni-forms-item label="姓名:" label-width="120px" :name="['affiliate','applicant',index,'applicantAgent','name']" :required="formData.affiliate.applicant[index].applicant.organizeFlag==0 ? false:true" :rules="formData.affiliate.applicant[index].applicant.organizeFlag==1 ?rulesAgentName:[]">
						<uni-easyinput v-model="formData.affiliate.applicant[index].applicantAgent.name" type="text"
							placeholder="请输入委托代理人姓名" />
					</uni-forms-item>
					<uni-forms-item label="邮箱:" label-width="120px" :name="['affiliate','applicant',index,'applicantAgent','email']" :required="formData.affiliate.applicant[index].applicant.organizeFlag==0 ? false :true" :rules="formData.affiliate.applicant[index].applicant.organizeFlag==1 ? rulesAgentEmail:[]">
						<uni-easyinput v-model="formData.affiliate.applicant[index].applicantAgent.email" type="text"
							placeholder="请输入代理人邮箱" />
					</uni-forms-item>
				</view>
				<!-- 新增多个被申请人 -->
				<button type="primary" @click="addRespondent" size="mini" style="margin-bottom: 20px;">新增多个被申请人</button>
				<view class="" v-for="(item,index) in formData.affiliate.res">
					<button class="mini-btn" type="primary" size="mini" @tap="delRespondent(index)"
						v-if="index>=1?true:false">删除</button>
					<uni-section :title="'被申请人信息'+(index+1)" type="line" padding></uni-section>
					<uni-forms-item label="选择机构或自然人" label-width="120px" name="objectiJuris">
						<uni-data-checkbox class='checkbox' :disabled="ids?true:false" :localdata="objectiJurisArr"
							v-model="formData.affiliate.res[index].res.organizeFlag"
							@change='clearValidateRes($event,index)'></uni-data-checkbox>
					</uni-forms-item>
					<uni-forms-item label="是否操作人" label-width="120px"
						v-if="formData.affiliate.res[index].res.organizeFlag==0" key="operatorFlag">
						<uni-data-checkbox v-model="formData.affiliate.res[index].res.operatorFlag"
							:localdata="isRespondent"></uni-data-checkbox>
					</uni-forms-item>
					<uni-forms-item label="被申请人:" v-if="formData.affiliate.res[index].res.organizeFlag==0" key="name"
						:name="['affiliate','res',index,'res','name']" label-width="120px" required
						:rules="[{required: true,errorMessage: '不能为空'}]">
						<uni-easyinput v-model="formData.affiliate.res[index].res.name" type="text"
							placeholder="请输入被申请人姓名" />
					</uni-forms-item>
					<uni-forms-item label="机构名称:" v-if="formData.affiliate.res[index].res.organizeFlag==1" key="name"
						:name="['affiliate','res',index,'res','name']" label-width="120px" required
						:rules="[{required: true,errorMessage: '不能为空'}]">
						<uni-easyinput v-model="formData.affiliate.res[index].res.name" type="text"
							placeholder="请输入被申请机构名称" />
					</uni-forms-item>
					<uni-forms-item label="统一社会信用代码:" v-if="formData.affiliate.res[index].res.organizeFlag==1"
						key="code" :name="['affiliate','res',index,'res','code']" label-width="120px" required
						:rules="[{required: true,errorMessage: '统一社会信用代码不能为空'}]">
						<uni-easyinput v-model="formData.affiliate.res[index].res.code" type="text"
							placeholder="请输入统一社会信用代码" />
					</uni-forms-item>
					<uni-forms-item label="证件类型" label-width="120px"
						v-if="formData.affiliate.res[index].res.organizeFlag==0">
						<uni-data-select v-model="formData.affiliate.res[index].res.idType" :localdata="certificate"
							@change="changeDocment"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="国籍" label-width="120px">
						<uni-data-select v-model="formData.affiliate.res[index].res.nationality"
							:localdata="nationality" @change="changeArea"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="法定代表人:" v-if="formData.affiliate.res[index].res.organizeFlag==1"
						:name="['affiliate','res',index,'res','compLegalPerson']" key="compLegalPerson"
						label-width="120px" required :rules="[{required: true,errorMessage: '法定代表人不能为空'}]">
						<uni-easyinput v-model="formData.affiliate.res[index].res.compLegalPerson" type="text"
							placeholder="请输入法定代表人" />
					</uni-forms-item>
					<uni-forms-item label="联系电话:" v-if="formData.affiliate.res[index].res.organizeFlag==0" key="phone"
						:name="['affiliate','res',index,'res','phone']" label-width="120px" :required="testVerify"
						:rules="rulesRespondentPhone">
						<uni-easyinput v-model="formData.affiliate.res[index].res.phone" type="text"
							placeholder="请输入被申请人联系电话" />
					</uni-forms-item>
					<uni-forms-item label="身份证号:" v-if="formData.affiliate.res[index].res.organizeFlag==0" key="idCard"
						:name="['affiliate','res',index,'res','idCard']" label-width="120px" required :rules="[
						{required: true,errorMessage: '被申请人身份证号不能为空'},
						{pattern:'^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$',errorMessage:'被申请人身份证格式错误'}
						
						]">
						<uni-easyinput v-model="formData.affiliate.res[index].res.idCard" @blur="handleBlur(index)"
							type="text" placeholder="请输入被申请人身份证号" />
					</uni-forms-item>
					<uni-forms-item v-if="formData.affiliate.res[index].res.organizeFlag==0" key="sex" label="被申请人性别"
						label-width="120px" required>
						<uni-data-checkbox class='checkbox' :disabled='true'
							v-model="formData.affiliate.res[index].res.sex"
							:localdata="respondentSexy"></uni-data-checkbox>
					</uni-forms-item>
					<uni-forms-item label="出生年月日" label-width="120px"
						v-if="formData.affiliate.res[index].res.organizeFlag==0" key="birth">
						<uni-datetime-picker v-model="formData.affiliate.res[index].res.birth" :disabled='true'
							type="date" :clear-icon="false" />
					</uni-forms-item>
					<uni-forms-item label="住所:" :name="['affiliate','res',index,'res','home']" label-width="120px"
						required :rules="[{required: true,errorMessage: '被申请人住所不能为空'}]">
						<uni-easyinput v-model="formData.affiliate.res[index].res.home" type="text"
							placeholder="请输入被申请人住所" />
					</uni-forms-item>
					<uni-forms-item label="联系地址:" :name="['affiliate','res',index,'res','address']" label-width="120px"
						required :rules="[{required: true,errorMessage: '被申请人联系地址不能为空'}]">
						<uni-easyinput v-model="formData.affiliate.res[index].res.address" type="text"
							placeholder="请输入被申请人联系地址" />
					</uni-forms-item>
					<uni-forms-item v-if="formData.affiliate.res[index].res.organizeFlag==0" key="email" label="邮箱:"
						:name="['affiliate','res',index,'res','email']" label-width="120px" required :rules="[
						{required: true,errorMessage: '被申请人邮箱不能为空'},
						{pattern:'^\\S+?@\\S+?\\.\\S+?$',errorMessage:'邮箱格式不正确'}
						
						]">
						<uni-easyinput v-model="formData.affiliate.res[index].res.email" type="text"
							placeholder="请输入被申请人邮箱" />
					</uni-forms-item>
					<uni-section title="被申请代理人" type="line" padding></uni-section>
					<uni-forms-item label="是否操作人" label-width="120px">
						<uni-data-checkbox v-model="formData.affiliate.res[index].resAgent.operatorFlag"
							:localdata="isResApplicant"></uni-data-checkbox>
					</uni-forms-item>
					<uni-forms-item label="联系电话:" label-width="120px" :name="['affiliate','res',index,'resAgent','phone']" :required="formData.affiliate.res[index].res.organizeFlag==0 ? false :true" :rules="formData.affiliate.res[index].res.organizeFlag==1?rulesResPhone:[]">
						<uni-easyinput v-model="formData.affiliate.res[index].resAgent.phone" type="text"
							placeholder="请输入代理人联系电话" />
					</uni-forms-item>
					<uni-forms-item label="姓名:" label-width="120px" :name="['affiliate','res',index,'resAgent','name']" :required="formData.affiliate.res[index].res.organizeFlag==0 ?false:true" :rules="formData.affiliate.res[index].res.organizeFlag==1?rulesResName:[]">
						<uni-easyinput v-model="formData.affiliate.res[index].resAgent.name" type="text"
							placeholder="请输入委托代理人姓名" />
					</uni-forms-item>
					<uni-forms-item label="邮箱:" label-width="120px" :name="['affiliate','res',index,'resAgent','email']" :required="formData.affiliate.res[index].res.organizeFlag==0 ?false:true" :rules="formData.affiliate.res[index].res.organizeFlag==1?rulesResEmail:[]">
						<uni-easyinput v-model="formData.affiliate.res[index].resAgent.email" type="text"
							placeholder="请输入代理人邮箱" />
					</uni-forms-item>
				</view>
			</uni-forms>
			<view class="determine" style="text-align: center;">
				<button class="mini-btn" type="primary" size="mini" @tap="submitReasont">确定</button>
				<button style="margin-left:30rpx;" class="mini-btn" type="default" size="mini"
					@tap="cencalBut">取消</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getTemplate,
		getInfoByIdCard,
		caseApplicationInsert,
		updateComfire,
		caseApplicationSelectById,
		getUserInfo,
		idType
	} from '../../../api/handlecase/index.js'
	import {
		getToken
	} from '@/utils/auth'
	import config from '@/config'
	import constant from '../../../utils/constant.js'
	export default {
		data() {
			return {
				baseUrl: config.baseUrlTJ,
				certificate: [],
				dynamicLists: [],
				nationality: [{
						value: 0,
						text: "境内"
					},
					{
						value: 1,
						text: "境外"
					},
				],
				isOperate: [{
						value: 1,
						text: "是"
					},
					{
						value: 0,
						text: "否"
					},
				],
				isProxyApplicant: [{
						value: 1,
						text: "是"
					},
					{
						value: 0,
						text: "否"
					},
				],
				isRespondent: [{
						value: 1,
						text: "是"
					},
					{
						value: 0,
						text: "否"
					},
				],
				isResApplicant: [{
						value: 1,
						text: "是"
					},
					{
						value: 0,
						text: "否"
					},
				],
				delShow: false,
				formZipData: {},
				formData: {
					organizeFlag: 0,
					caseSource: "YC",
					facts:"",
					affiliate: {
						applicant: [{
							applicant: {
								roleType: 1,
								name: "",
								idCard: "",
								code: "",
								phone: "",
								compLegalPerson: "",
								email: "",
								home: "",
								address: "",
								idType: 0,
								nationality: 0,
								birth: "",
								sex: "",
								group_order: 1,
								operatorFlag: 1,
								organizeFlag: 0,
							},
							applicantAgent: {
								roleType: 2,
								name: "",
								idCard: "",
								code: "",
								phone: "",
								compLegalPerson: "",
								email: "",
								home: "",
								address: "",
								idType: 0,
								nationality: 1,
								birth: "",
								sex: "",
								operatorFlag: 1,
								organizeFlag: 0,
							}
						}],
						res: [{
							res: {
								roleType: 3,
								name: "",
								idCard: "",
								code: "",
								phone: "",
								compLegalPerson: "",
								email: "",
								home: "",
								address: "",
								idType: 0,
								nationality: 0,
								birth: "",
								sex: "",
								group_order: 1,
								operatorFlag: 1,
								organizeFlag: 0,
							},
							resAgent: {
								roleType: 4,
								name: "",
								idCard: "",
								code: "",
								phone: "",
								compLegalPerson: "",
								email: "",
								home: "",
								address: "",
								idType: 0,
								nationality: 0,
								birth: "",
								sex: "",
								group_order: 1,
								operatorFlag: 1,
								organizeFlag: 0,
							}
						}]
					},
					columnValueList: [],
					caseAttachList: [],
				},
				testVerify: true,
				agentRequired:false,
				agentName:false,
				agentEmail:false,
				agentResPhone:false,
				agentResName:false,
				agentResEmail:false,
				getUserInfoList: {},
				ids: null,
				tempFilePaths: null,
				tempFilePathsZip: null,
				lengths:null,
				templateList: [],
				objectiJurisArr: [{
					text: '自然人',
					value: 0
				}, {
					text: '机构',
					value: 1
				}],
				respondentSexy: [{
					text: '女',
					value: 1
				}, {
					text: '男',
					value: 0
				}],
				fileList: {},
				fileListZip: {},
				rules: {},
				rulesRespondentPhone: [{
						required: true,
						errorMessage: '被申请人联系电话不能为空'
					},
					{
						pattern: '^[1][3,4,5,6,7,8,9][0-9]{9}$',
						errorMessage: '被申请人联系电话格式不正确'
					}
				],
				// 申请代验证
				rulesAgentPhone:[
					{
						required: true,
						errorMessage: '联系电话不能为空'
					},
					{
						pattern: '^[1][3,4,5,6,7,8,9][0-9]{9}$',
						errorMessage: '联系电话格式不正确'
					}
				],
				rulesAgentName:[
					{
						required: true,
						errorMessage: '姓名不能空',
					}
				],
				rulesAgentEmail:[
					{
						required: true,
						errorMessage: '邮箱不能为空'
					},
					{
						pattern: '^\\S+?@\\S+?\\.\\S+?$',
						errorMessage: '邮箱格式不正确'
					}
				],
				// 被申请代理验证
				rulesResPhone:[
					{
						required: true,
						errorMessage: '联系电话不能为空'
					},
					{
						pattern: '^[1][3,4,5,6,7,8,9][0-9]{9}$',
						errorMessage: '联系电话格式不正确'
					}
				],
				rulesResName:[
					{
						required: true,
						errorMessage: '姓名不能空',
					}
				],
				rulesResEmail:[
					{
						required: true,
						errorMessage: '邮箱不能为空'
					},
					{
						pattern: '^\\S+?@\\S+?\\.\\S+?$',
						errorMessage: '邮箱格式不正确'
					}
				],
				rulesPersonName: [{
					'required': true,
					errorMessage: '不能为空'
				}],
				rulesappNo: [{
					required: true,
					errorMessage: '输入信息不能为空',
				}, {

					validateFunction: (rule, value, data, callback) => {
						//判断手机号格
						if (this.formData.organizeFlag == 0) {
							let pNoReg =
								/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
							if (!pNoReg.test(value)) {
								callback('请输入正确的身份证号码')
							}
						} else {
							if (!value) {
								callback('请输入正确的机构信息')
							}
						}
						return true
					}

				}]
			}


		},
		methods: {
			submitReasont() {
				this.$nextTick(()=>{
					this.$refs.form.validate().then(res => {
						console.log("pppppppppppp")
						if (this.ids) {
							this.modifyData(this.formData)
						} else {
							this.insertFn(this.formData)
						}
					
					}).catch(err => {
						console.log(err)
					})
				})
			},
			// 获取新增默认值
			getUserInfoNumber() {
				let indexs = ""
				this.formData.affiliate.applicant.forEach((item, index) => {
					indexs = index
				})
				getUserInfo().then(res => {
					this.getUserInfoList = res.data
					console.log(res.data)
					if (this.formData.affiliate.applicant[indexs].applicant.organizeFlag == 0) {
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'name', res.data.nickName)
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'idCard', res.data.idCard)
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'email', res.data.email)
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'phone', res.data
							.phonenumber)
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'idType', res.data.idType)
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'nationality', res.data
							.nationality)
						this.$set(this.formData.affiliate.applicant[indexs].applicant, "sex", Number(this
							.getUserInfoList.sex));
						this.$set(this.formData.affiliate.applicant[indexs].applicant, "birth", this
							.getUserInfoList
							.birth);
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'address', res.data.address)
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'home', res.data.home)
						if (res.data.nationality == 0) {
							this.testVerify = true
							this.rulesRespondentPhone[0].required = true;
						} else if (res.data.nationality == 1) {
							this.testVerify = false
							this.rulesRespondentPhone[0].required = false;
						}
					} else if (this.formData.affiliate.applicant[indexs].applicant.organizeFlag == 1) {
						console.log(this.formData.organizeFlag)
						this.$set(this.formData.affiliate.applicant[indexs].applicantAgent, 'name', res.data
							.nickName)
						this.$set(this.formData.affiliate.applicant[indexs].applicantAgent, 'email', res.data
							.email)
						this.$set(this.formData.affiliate.applicant[indexs].applicantAgent, 'phone', res.data
							.phonenumber)
						this.$set(this.formData.affiliate.applicant[indexs].applicantAgent, 'nationality', res.data
							.nationality)
					}

				})
			},
			clearValidate(val,index) {
				let indexs = ""
				this.formData.affiliate.applicant.forEach((item, index) => {
					indexs = index
				})
				if (val.detail.value == 0 && index == 0) {
					this.$set(this.formData.affiliate.applicant[0].applicant, 'name', this.getUserInfoList.nickName)
					this.$set(this.formData.affiliate.applicant[0].applicant, 'idCard', this.getUserInfoList.idCard)
					this.$set(this.formData.affiliate.applicant[0].applicant, 'email', this.getUserInfoList.email)
					this.$set(this.formData.affiliate.applicant[0].applicant, 'phone', this.getUserInfoList
						.phonenumber)
					this.$set(this.formData.affiliate.applicant[0].applicant, "sex", Number(this
						.getUserInfoList.sex));
					this.$set(this.formData.affiliate.applicant[0].applicant, "birth", this.getUserInfoList
						.birth);
					this.$set(this.formData.affiliate.applicant[0].applicant, 'address', this.getUserInfoList.address)
					this.$set(this.formData.affiliate.applicant[0].applicant, 'home', this.getUserInfoList.home)
					if (this.formZipData.affiliate) {
						this.$set(this.formData, 'arbitratClaims', this.formZipData.arbitratClaims);
						this.$set(this.formData, 'facts', this.formZipData.facts);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'home', this.formZipData.affiliate
							.applicant[0]
							.applicant.home);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'address', this.formZipData.affiliate
							.applicant[0]
							.applicant.address);
						this.$set(this.formData.affiliate.applicant[0].applicantAgent, 'phone', this.formZipData
							.affiliate.applicant[0].applicantAgent.phone);
						this.$set(this.formData.affiliate.applicant[0].applicantAgent, 'name', this.formZipData.affiliate
							.applicant[0]
							.applicantAgent.name);
						this.$set(this.formData.affiliate.applicant[0].applicantAgent, 'email', this.formZipData.affiliate
							.applicant[0]
							.applicantAgent.email);
						this.$set(this.formData.affiliate.applicant[0].applicant, "sex", Number(this
							.getUserInfoList.sex));
						this.$set(this.formData.affiliate.applicant[0].applicant, "birth", this.getUserInfoList
							.birth);
					} 
					
				} else if (val.detail.value == 1 && index == 0) {
					this.$set(this.formData.affiliate.applicant[0].applicantAgent, 'name', this.getUserInfoList
						.nickName)
					this.$set(this.formData.affiliate.applicant[0].applicantAgent, 'email', this.getUserInfoList
						.email)
					this.$set(this.formData.affiliate.applicant[0].applicantAgent, 'phone', this.getUserInfoList
						.phonenumber)
					if (this.formZipData.affiliate) {
						this.$set(this.formData, 'arbitratClaims', this.formZipData.arbitratClaims);
						this.$set(this.formData, 'facts', this.formZipData.facts);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'name', this.formZipData.affiliate
							.applicant[0]
							.applicant.name);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'code', this.formZipData.affiliate
							.applicant[0].applicant.code);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'home', this.formZipData.affiliate
							.applicant[0]
							.applicant.home);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'address', this.formZipData.affiliate
							.applicant[0]
							.applicant.address);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'compLegalPerson', this.formZipData
							.affiliate.applicant[0]
							.applicant.compLegalPerson);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'email', this.formZipData.affiliate
							.applicant[0]
							.applicant.email);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'phone', this.formZipData.affiliate
							.applicant[0]
							.applicant.phone);
					} 
				}
				if(val.detail.value == 0){
					this.$set(this.formData.affiliate.applicant[index].applicantAgent, 'name', null)
					this.$set(this.formData.affiliate.applicant[index].applicantAgent, 'email', null)
					this.$set(this.formData.affiliate.applicant[index].applicantAgent, 'phone', null)
					/* this.rulesAgentPhone[0].required = false;
					this.agentRequired = false;
					this.agentName = false;
					this.rulesAgentName[0].required = false;
					this.rulesAgentEmail[0].required = false;
					this.agentEmail = false; */
				}else if(val.detail.value == 1){
					this.$set(this.formData.affiliate.applicant[index].applicant, 'name', null)
					this.$set(this.formData.affiliate.applicant[index].applicant, 'idCard', null)
					this.$set(this.formData.affiliate.applicant[index].applicant, 'email', null)
					this.$set(this.formData.affiliate.applicant[index].applicant, 'phone', null)
					this.$set(this.formData.affiliate.applicant[index].applicant, 'address', null)
					this.$set(this.formData.affiliate.applicant[index].applicant, 'home', null)
					/* this.rulesAgentPhone[0].required = true;
					this.agentRequired = true;
					this.agentName = true;
					this.rulesAgentName[0].required = true;
					this.rulesAgentEmail[0].required = true;
					this.agentEmail = true; */
				}
				this.$refs.form.setRules()
				this.$refs["form"].clearValidate()
			},
			// 被申请人机构和自然人
			clearValidateRes(val,index) {
				console.log(this.formData.affiliate.res[0].res)
				if (val.detail.value == 0 && index==0) {
					if (this.formZipData.affiliate) {
						this.$set(this.formData.affiliate.res[0].res, 'name', this.formZipData.affiliate
							.res[0]
							.res.name);
						this.$set(this.formData.affiliate.res[0].res, 'phone', this.formZipData.affiliate.res[0]
							.res.phone);
						this.$set(this.formData.affiliate.res[0].res, 'idCard', this.formZipData
							.affiliate.res[0].res.idCard);
						this.$set(this.formData.affiliate.res[0].res, 'sex', Number(this.formZipData
							.affiliate.res[0].res.sex));
						this.$set(this.formData.affiliate.res[0].res, 'birth', this.formZipData.affiliate.res[0]
							.res.birth);
						this.$set(this.formData.affiliate.res[0].res, 'home', this.formZipData.affiliate.res[0]
							.res.home);
						this.$set(this.formData.affiliate.res[0].res, 'email', this.formZipData.affiliate.res[0]
							.res.email);
					}
					
					
				} else if (val.detail.value == 1 && index == 0) {
					if (this.formZipData.affiliate) {
						this.$set(this.formData.affiliate.res[0].res, 'name', this.formZipData.affiliate
							.res[0]
							.res.name);
						this.$set(this.formData.affiliate.res[0].res, 'home', this.formZipData.affiliate
							.res[0]
							.res.home);
						this.$set(this.formData.affiliate.res[0].res, 'code', this.formZipData.affiliate
							.res[0]
							.res.code);
					}
					
				}
				if(val.detail.value == 0){

				}else if(val.detail.value == 1){
					this.$set(this.formData.affiliate.res[index].res, 'name', null)
					this.$set(this.formData.affiliate.res[index].res, 'home', null)
				}
				this.$refs.form.setRules()
				this.$refs["form"].clearValidate()
			},
			/** 获取裁决书模板 */
			getTemplateFn(data) {
				getTemplate(data).then((res) => {
					//this.templateList = res.rows;
					res.rows.forEach(item => {
						this.templateList.push({
							value: item.id,
							text: item.temName
						})
					})
				});
			},
			/** 根据案件id获取对应信息 */
			caseApplicationSelectByIdFn(data) {
				caseApplicationSelectById(data).then(res => {
					let data = res.data
					console.log(res.data)
					let indexs = ""
					if (data.affiliate.applicant.length == 0) {
						data.affiliate.applicant.push({
							applicant: {},
							applicantAgent: {}
						})
					} else {
						data.affiliate.applicant.forEach((item, index) => {
							if (!item.applicant) {
								item.applicant = {}
							} else {
								data.affiliate.applicant[index].applicant.sex = Number(data.affiliate.applicant[index].applicant
									.sex)
							}
							if (!item.applicantAgent) {
								item.applicantAgent = {}
							}
						})
					}
					if (data.affiliate.res.length == 0) {
						data.affiliate.res.push({
							res: {},
							resAgent: {}
						})
					} else {
						data.affiliate.res.forEach((item, index) => {
							indexs = index
							if (!item.res) {
								item.res = {}
							} else {
								data.affiliate.res[indexs].res.sex = Number(data.affiliate.res[indexs].res
									.sex)
							}
							if (!item.resAgent) {
								item.resAgent = {}
							}
						})
					}
					this.formData = data

				})
			},
			// 申请人获取性别出生年月日
			handleBlurApplicant(index) {
				console.log(index)
				let idCards = {
					idCard: this.formData.affiliate.applicant[index].applicant.idCard,
				};

				getInfoByIdCard(idCards).then(res => {
					this.formData.affiliate.applicant[index].applicant.sex = Number(res.respondentSex);
					this.formData.affiliate.applicant[index].applicant.birth = res.respondentBirth;
				})
			},
			// 被申请人获取性别出生年月
			handleBlur(index) {
				let idCards = {
					idCard: this.formData.affiliate.res[index].res.idCard,
				};

				getInfoByIdCard(idCards).then(res => {
					this.formData.affiliate.res[index].res.sex = Number(res.respondentSex);
					this.formData.affiliate.res[index].res.birth = res.respondentBirth;
				})
			},
			// 新增案件
			insertFn(data) {
				caseApplicationInsert(data).then((res) => {
					uni.showToast({
						title: '新增成功',
						icon: 'none',
						duration: 1000
					})
					uni.navigateTo({
						url: '../index'
					})
					// this.$router.go(-1)
				});
			},
			//修改案件
			modifyData(data) {
				updateComfire(data).then((res) => {
					uni.showToast({
						title: '修改成功',
						icon: 'none',
						duration: 1000
					})
					uni.navigateBack({
						delta: 1
					})
				});
			},
			// 压缩包上传
			selectZip(e) {
				if (e.tempFiles[0].extname != 'zip') {
					uni.showToast({
						title: '上传类型为zip',
						icon: 'none',
						duration: 1000
					})
					return
				}
				// loading
				this.tempFilePathsZip = e.tempFilePaths;
				uni.showLoading({
					title: '上传中'
				});
				uni.uploadFile({
					url: config.baseUrlTJ + "/caseApplication/userIdentify",
					filePath: this.tempFilePathsZip[0],
					header: {
						Authorization: getToken() || '',
					},
					name: 'file',
					success: (res) => {
						console.log(res)
						let result = JSON.parse(res.data)
						uni.showToast({
							title: '上传成功',
							icon: 'none',
							duration: 1000
						})
						this.formZipData = result.data;
						console.log(result.data)
						this.$set(this.formData, 'arbitratClaims', result.data.arbitratClaims);
						this.$set(this.formData, 'facts', result.data.facts);
						if (this.formData.affiliate.applicant[0].applicant.organizeFlag == 0) {
							this.$set(this.formData.affiliate.applicant[0].applicant, 'home', this.formZipData
								.affiliate.applicant[0]
								.applicant.home);
							this.$set(this.formData.affiliate.applicant[0].applicant, 'address', this
								.formZipData.affiliate.applicant[0]
								.applicant.address);
							this.$set(this.formData.affiliate.applicant[0].applicantAgent, 'phone', this
								.formZipData
								.affiliate.applicant[0].applicantAgent.phone);
							this.$set(this.formData.affiliate.applicant[0].applicantAgent, 'name', this
								.formZipData.affiliate.applicant[0]
								.applicantAgent.name);
							this.$set(this.formData.affiliate.applicant[0].applicantAgent, 'email', this
								.formZipData.affiliate.applicant[0]
								.applicantAgent.email);
						} else if (this.formData.affiliate.applicant[0].applicant.organizeFlag == 1) {
							this.$set(this.formData.affiliate.applicant[0].applicant, 'name', this.formZipData
								.affiliate.applicant[0]
								.applicant.name);
							this.$set(this.formData.affiliate.applicant[0].applicant, 'code', this.formZipData
								.affiliate.applicant[0].applicant.code);
							this.$set(this.formData.affiliate.applicant[0].applicant, 'home', this.formZipData
								.affiliate.applicant[0]
								.applicant.home);
							this.$set(this.formData.affiliate.applicant[0].applicant, 'address', this
								.formZipData.affiliate.applicant[0]
								.applicant.address);
							this.$set(this.formData.affiliate.applicant[0].applicant, 'compLegalPerson', this
								.formZipData.affiliate.applicant[0]
								.applicant.compLegalPerson);
							this.$set(this.formData.affiliate.applicant[0].applicant, 'email', this.formZipData
								.affiliate.applicant[0]
								.applicant.email);
							this.$set(this.formData.affiliate.applicant[0].applicant, 'phone', this.formZipData
								.affiliate.applicant[0]
								.applicant.phone);
						}

						if (this.formData.affiliate.res[0].res.organizeFlag == 0) {
							this.$set(this.formData.affiliate.res[0].res, 'name', this.formZipData.affiliate
								.res[0]
								.res.name);
							this.$set(this.formData.affiliate.res[0].res, 'phone', this.formZipData.affiliate
								.res[0]
								.res.phone);
							this.$set(this.formData.affiliate.res[0].res, 'idCard', this.formZipData
								.affiliate.res[0].res.idCard);
							this.$set(this.formData.affiliate.res[0].res, 'sex', Number(this.formZipData
								.affiliate.res[0].res.sex));
							this.$set(this.formData.affiliate.res[0].res, 'birth', this.formZipData.affiliate
								.res[0]
								.res.birth);
							this.$set(this.formData.affiliate.res[0].res, 'home', this.formZipData.affiliate
								.res[0]
								.res.home);
							this.$set(this.formData.affiliate.res[0].res, 'email', this.formZipData.affiliate
								.res[0]
								.res.email);
						} else if (this.formData.affiliate.res[0].res.organizeFlag == 1) {
							this.$set(this.formData.affiliate.res[0].res, 'name', this.formZipData.affiliate
								.res[0]
								.res.name);
							this.$set(this.formData.affiliate.res[0].res, 'home', this.formZipData.affiliate
								.res[0]
								.res.home);
							this.$set(this.formData.affiliate.res[0].res, 'code', this.formZipData.affiliate
								.res[0]
								.res.code);
						}
						uni.hideLoading();
					},
					fail: (err) => {
						uni.showToast({
							title: '上传失败',
							icon: 'none',
							duration: 1000
						})
						uni.hideLoading()
					}
				})
			},
			// 文件上传
			select(e) {
				this.tempFilePaths = e.tempFilePaths;
				// loading
				uni.showLoading({
					title: '上传中'
				});
				uni.uploadFile({
					url: config.baseUrlTJ + "/common/upload",
					filePath: this.tempFilePaths[0],
					header: {
						Authorization: getToken() || '',
					},
					formData: {
						annexType: 2,
						id: this.formData.id
					},
					name: 'file',
					success: (res) => {
						let result = JSON.parse(res.data)
						this.formData.caseAttachList.push({
							annexId: result.annexId,
							annexName: result.fileName
						});
						console.log(result.fileName)
						uni.showToast({
							title: '上传成功',
							icon: 'none',
							duration: 1000
						})
						uni.hideLoading();
					},
					fail: (err) => {
						uni.showToast({
							title: '上传失败',
							icon: 'none',
							duration: 1000
						})
						uni.hideLoading()
					}
				})
			},
			cencalBut() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 改变证件类型
			changeDocment(e) {
				console.log(e)
			},
			//改变地区类型
			changeArea(e) {
				if (e == 0) {
					this.testVerify = true
					this.rulesRespondentPhone[0].required = true;
				} else if (e == 1) {
					this.testVerify = false
					this.rulesRespondentPhone[0].required = false;
				}
			},
			// 获取证件类型
			getIdType() {
				idType().then(res => {
					console.log(res)
					res.data.forEach(item => {
						this.certificate.push({
							value: item.dictSort,
							text: item.dictLabel
						})
					})
				})
			},
			// 新增多个申请人和申请代理人
			addMultipleApplicants() {
				this.formData.affiliate.applicant.push({
					applicant: {
						roleType: 1,
						name: "",
						idCard: "",
						code: "",
						phone: "",
						compLegalPerson: "",
						email: "",
						home: "",
						address: "",
						idType: 0,
						nationality: 0,
						birth: "",
						sex: "",
						group_order: 1,
						operatorFlag: 1,
						organizeFlag: 0,
					},
					applicantAgent: {
						roleType: 2,
						name: "",
						idCard: "",
						code: "",
						phone: "",
						compLegalPerson: "",
						email: "",
						home: "",
						address: "",
						idType: 0,
						nationality: 1,
						birth: "",
						sex: "",
						operatorFlag: 1,
						organizeFlag: 0,
					}
				})
			},
			// 新增多个被申请人和代理人
			addRespondent() {
				this.formData.affiliate.res.push({
					res: {
						roleType: 3,
						name: "",
						idCard: "",
						code: "",
						phone: "",
						compLegalPerson: "",
						email: "",
						home: "",
						address: "",
						idType: 0,
						nationality: 0,
						birth: "",
						sex: "",
						group_order: 1,
						operatorFlag: 1,
						organizeFlag: 0,
					},
					resAgent: {
						roleType: 4,
						name: "",
						idCard: "",
						code: "",
						phone: "",
						compLegalPerson: "",
						email: "",
						home: "",
						address: "",
						idType: 0,
						nationality: 0,
						birth: "",
						sex: "",
						group_order: 1,
						operatorFlag: 1,
						organizeFlag: 0,
					}
				})
			},
			//删除新增的多个申请代理人
			delValue(id) {
				let index = this.formData.affiliate.applicant.findIndex(v => v.id === id)
				this.formData.affiliate.applicant.splice(index, 1)
			},
			//删除新增多个被申请代理人
			delRespondent(id) {
				let index = this.formData.affiliate.res.findIndex(v => v.id === id)
				this.formData.affiliate.res.splice(index, 1)
			}
		},
		onLoad(data) {
			this.ids = data.id
			if (this.ids) {
				this.caseApplicationSelectByIdFn({
					id: data.id
				})
				uni.setNavigationBarTitle({
					title: "案件修改"
				})
			} else {
				uni.setNavigationBarTitle({
					title: "案件新增"
				})
			}
			if (this.formData.affiliate.nationality == 0) {
				this.testVerify = true
				this.rulesRespondentPhone[0].required = true;
			} else if (this.formData.affiliate.idType == 1) {
				this.testVerify = false
				this.rulesRespondentPhone[0].required = false;
			}
			this.getTemplateFn()
			this.getUserInfoNumber()
			this.getIdType() //获取证件类型
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.assignrbitrators {
		margin: 30rpx;
	}

	::v-deep .uni-icons[data-v-a2e81f6e] {
		display: none;
	}
</style>