<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="请输入申请人调解请求" />
				</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="请输入事实和理由" />
				</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>
				<uni-forms-item label="选择机构或自然人" label-width="120px" name="objectiJuris">
					<uni-data-checkbox class='checkbox' :disabled="ids?true:false" :localdata="objectiJurisArr"
						v-model="formData.organizeFlag" @change='clearValidate'></uni-data-checkbox>
				</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">
							 <uni-data-checkbox
									v-model="formData.affiliate.applicant[index].applicant.operatorFlag"
							        :localdata="isOperate"
							      ></uni-data-checkbox>
						</uni-forms-item>
						<uni-forms-item :label="formData.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.organizeFlag==0 ? '请输入申请人姓名':'请输入申请机构名称'" />
						</uni-forms-item>
						<uni-forms-item label="证件类型" label-width="120px" v-if="formData.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.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.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"  type="text"
										placeholder="请输入证件号码" />
								</uni-forms-item>
						
						<uni-forms-item label="申请人邮箱:" key="email" v-if="formData.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.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.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">
							<uni-easyinput v-model="formData.affiliate.applicant[index].applicantAgent.phone"  type="text"
								placeholder="请输入代理人联系电话" />
						</uni-forms-item>
						<uni-forms-item label="代理人姓名:" label-width="120px">
							<uni-easyinput v-model="formData.affiliate.applicant[index].applicantAgent.name"  type="text"
								placeholder="请输入委托代理人姓名" />
						</uni-forms-item>
						<uni-forms-item label="代理人邮箱:" label-width="120px">
							<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">
						 <uni-data-checkbox
								v-model="formData.affiliate.res[index].res.operatorFlag"
						        :localdata="isRespondent"
						      ></uni-data-checkbox>
					</uni-forms-item>
					<uni-forms-item label="被申请人姓名:" :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="被申请人联系电话:" :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="被申请人身份证号:" :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 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">
						<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','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">
						<uni-easyinput v-model="formData.affiliate.res[index].resAgent.phone"  type="text"
							placeholder="请输入代理人联系电话" />
					</uni-forms-item>
					<uni-forms-item label="代理人姓名:" label-width="120px">
						<uni-easyinput v-model="formData.affiliate.res[index].resAgent.name"  type="text"
							placeholder="请输入委托代理人姓名" />
					</uni-forms-item>
					<uni-forms-item label="代理人邮箱:" label-width="120px">
						<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",
					// affiliate: {
					// 	roleType:1,	
					// 	respondentSex: 0,
					// },
					affiliate:{
							applicant:[{
								applicant:{
									roleType: 1,
									name: "",
									idCard: "",
									code: "",
									phone: "",
									compLegalPerson: "",
									email: "",
									home: "",
									address: "",
									idType: 0,
									nationality: 0,
									birth: "",
									sex: "",
									group_order: 1,
									operatorFlag:1
								},
								applicantAgent:{
									roleType:2,
									name:"",
									idCard:"",
									code:"",
									phone:"",
									compLegalPerson:"",
									email:"",
									home:"",
									address:"",
									idType:0,
									nationality:1,
									birth:"",
									sex:"",
									operatorFlag:1
								}	
							}],
							res:[{
								res:{
									roleType: 3,
									name: "",
									idCard: "",
									code: "",
									phone: "",
									compLegalPerson: "",
									email: "",
									home: "",
									address: "",
									idType: 0,
									nationality: 0,
									birth: "",
									sex: "",
									group_order: 1,
									operatorFlag:1
								},
								resAgent:{
									roleType: 4,
									name: "",
									idCard: "",
									code: "",
									phone: "",
									compLegalPerson: "",
									email: "",
									home: "",
									address: "",
									idType: 0,
									nationality: 0,
									birth: "",
									sex: "",
									group_order: 1,
									operatorFlag:1
								}
							}]
					},
					columnValueList: [],
					caseAttachList: [],
				},
				testVerify:true,
				getUserInfoList: {},
				ids: null,
				tempFilePaths: null,
				tempFilePathsZip: 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:'被申请人联系电话格式不正确'}
				],
				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.$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
					if (this.formData.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)
						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.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) {
				let indexs = ""
				this.formData.affiliate.applicant.forEach((item,index)=>{
					indexs = index
				})
				if (this.formData.organizeFlag == 0) {
					this.$set(this.formData.affiliate.applicant[indexs].applicant, 'name', this.getUserInfoList.nickName)
					this.$set(this.formData.affiliate.applicant[indexs].applicant, 'idCard', this.getUserInfoList.idCard)
					this.$set(this.formData.affiliate.applicant[indexs].applicant, 'email', this.getUserInfoList.email)
					this.$set(this.formData.affiliate.applicant[indexs].applicant, '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, '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].res, 'name', this.formZipData.affiliate.applicant[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 {
						this.$set(this.formData.affiliate.applicant[indexs].applicantAgent, 'name', null)
						this.$set(this.formData.affiliate.applicant[indexs].applicantAgent, 'email', null)
						this.$set(this.formData.affiliate.applicant[indexs].applicantAgent, 'phone', null)
					}
				} else if (this.formData.organizeFlag == 1) {
					this.$set(this.formData.affiliate.applicant[indexs].applicantAgent, 'name', this.getUserInfoList.nickName)
					this.$set(this.formData.affiliate.applicant[indexs].applicantAgent, 'email', this.getUserInfoList.email)
					this.$set(this.formData.affiliate.applicant[indexs].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[0]
							.applicant.name);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'code', this.formZipData.affiliate[0].applicant.code);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'home', this.formZipData.affiliate[0]
							.applicant.home);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'address', this.formZipData.affiliate[0]
							.applicant.address);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'compLegalPerson', this.formZipData.affiliate[0]
							.applicant.compLegalPerson);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'email', this.formZipData.affiliate[0]
							.applicant.email);
						this.$set(this.formData.affiliate.applicant[0].applicant, 'phone', this.formZipData.affiliate[0]
							.applicant.phone);
						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 {
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'name', null)
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'idCard', null)
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'email', null)
						this.$set(this.formData.affiliate.applicant[indexs].applicant, 'phone', null)
					}
				}
				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 = ""
					data.affiliate.applicant.forEach((item,index) =>{
						if(!item.applicant){
							item.applicant = {}
						}
						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
					
				})
			},
			// 被申请人获取性别出生年月
			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;
						if (this.formData.organizeFlag == 0) {
							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.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);
							// this.$set(this.formData.affiliate[0].resAgent, 'phone', this.formZipData
							// 	.affiliate[0].resAgent.phone);
							// this.$set(this.formData.affiliate[0].resAgent, 'name', this.formZipData.affiliate[0]
							// 	.resAgent.name);
							// this.$set(this.formData.affiliate[0].resAgent, 'email', this.formZipData.affiliate[0]
							// 	.resAgent.email);
						} else if (this.formData.organizeFlag == 1) {
							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);
							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);
						}
						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})
					})
				})
			},
			// 新增多个申请代理人
			addMultiple(){
				this.delShow =true
				let idnexVal = ""
				this.formData.affiliate.forEach((item,index)=>{
					idnexVal = index
				})
				getUserInfo().then(res => {
					this.getUserInfoList = res.data
					if (this.formData.organizeFlag == 0) {
						this.$set(this.formData.affiliate[idnexVal].applicant, 'name', res.data.nickName)
						this.$set(this.formData.affiliate[idnexVal].applicant, 'idCard', res.data.idCard)
						this.$set(this.formData.affiliate[idnexVal].applicant, 'email', res.data.email)
						this.$set(this.formData.affiliate[idnexVal].applicant, 'phone', res.data.phonenumber)
						this.$set(this.formData.affiliate[idnexVal].applicant, 'idType', res.data.idType)
						this.$set(this.formData.affiliate[idnexVal].applicant, 'nationality', res.data.nationality)
					} else if (this.formData.organizeFlag == 1) {
						this.$set(this.formData.affiliate[idnexVal].applicantAgent, 'name', res.data.nickName)
						this.$set(this.formData.affiliate[idnexVal].applicantAgent, 'email', res.data.email)
						this.$set(this.formData.affiliate[idnexVal].applicantAgent, 'phone', res.data.phonenumber)
						this.$set(this.formData.affiliate[idnexVal].applicantAgent, 'nationality', res.data.nationality)
					}
				
				})
			},
			// 新增多个申请人和申请代理人
			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
					},
					applicantAgent:{
						roleType:2,
						name:"",
						idCard:"",
						code:"",
						phone:"",
						compLegalPerson:"",
						email:"",
						home:"",
						address:"",
						idType:0,
						nationality:1,
						birth:"",
						sex:"",
						operatorFlag:1
					}
				})
				let idnexVal = ""
				this.formData.affiliate.applicant.forEach((item,index)=>{
					idnexVal = index
				})
				getUserInfo().then(res => {
					this.getUserInfoList = res.data
					if (this.formData.organizeFlag == 0) {
						this.$set(this.formData.affiliate.applicant[idnexVal].applicant, 'name', res.data.nickName)
						this.$set(this.formData.affiliate.applicant[idnexVal].applicant, 'idCard', res.data.idCard)
						this.$set(this.formData.affiliate.applicant[idnexVal].applicant, 'email', res.data.email)
						this.$set(this.formData.affiliate.applicant[idnexVal].applicant, 'phone', res.data.phonenumber)
						this.$set(this.formData.affiliate.applicant[idnexVal].applicant, 'idType', res.data.idType)
						this.$set(this.formData.affiliate.applicant[idnexVal].applicant, 'nationality', res.data.nationality)
					} else if (this.formData.organizeFlag == 1) {
						this.$set(this.formData.affiliate.applicant[idnexVal].applicantAgent, 'name', res.data.nickName)
						this.$set(this.formData.affiliate.applicant[idnexVal].applicantAgent, 'email', res.data.email)
						this.$set(this.formData.affiliate.applicant[idnexVal].applicantAgent, 'phone', res.data.phonenumber)
						this.$set(this.formData.affiliate.applicant[idnexVal].applicantAgent, 'nationality', res.data.nationality)
					}
				
				})
			},
			// 新增多个被申请人和代理人
			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
					},
					resAgent:{
						roleType: 4,
						name: "",
						idCard: "",
						code: "",
						phone: "",
						compLegalPerson: "",
						email: "",
						home: "",
						address: "",
						idType: 0,
						nationality: 0,
						birth: "",
						sex: "",
						group_order: 1,
						operatorFlag:1
					}
				})
			},
			//删除新增的多个申请代理人
			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>