<template>
	<view class="container">
		<view class="title">
		   <view>
				<text class="line"></text>个人声明
			</view>
		   <text class="page_mark">6/8</text>
		 </view>
		 <view class="content">
			<view class="ulBox">
			   <view class="liBox" v-for="personalStatements in dropOptionsInfoList" @click="selectStatements(personalStatements)"
			    >
				  <text class="iconfont icon-yuanxingweixuanzhong" v-if="!personalStatements.status"></text>
				  <text class="iconfont icon-selected-copy" v-if="personalStatements.status"></text>
			      <text class="itemName"> {{personalStatements.dropOptionName}}</text> 
			      <text class="iconfont icon-gougou" v-if="personalStatements.status"></text>
			    </view>
			</view>
		 </view>
		 <view class="fixed" @click="saveInfo()">
		   保存并下一步
		 </view>
	</view>
</template>

<script>
	import api from '../../api/api';
	export default{
		data(){
			return {
				dropOptionsInfoList:[],
				applyParam:{
					personalStatement:''
				},
				personalStatementList:[]
			}
		},
		components:{},
		onLoad(){
			this.dropOptionsQuery();
			if(uni.getStorageSync('applyId')){
				setTimeout(()=>{
					this.queryById(uni.getStorageSync('applyId'))
				},500)
			}
		},
		methods:{
			dropOptionsQuery(){
				api.dropOptionsQuery({code:'CFFP_Partner_Statements'}).then((res)=>{
					this.dropOptionsInfoList = res["data"]["dropMasterInfoList"][0]["dropOptionsInfoList"];
				})
			},
			selectStatements(personalStatements) {
			      if (personalStatements.status == 1) {
			        personalStatements.status = 0;
			      } else {
			        personalStatements.status = 1;
			      }
				console.log(this.dropOptionsInfoList)
			},
			queryById(id){
				api.queryById(id).then((res)=>{
					if(res['success']){
						this.applyParam = res['data']['data'];
						if(this.applyParam.personalStatement){
							this.personalStatementList = this.applyParam.personalStatement.split(',');
							for(let i=0;i<this.dropOptionsInfoList.length;i++){
								for(let j=0;j<this.personalStatementList.length;j++){
									if(this.dropOptionsInfoList[i]['dropOptionName'] == this.personalStatementList[j]){
										this.dropOptionsInfoList[i].status = 1;
									}
								}
							}
						}
					}
				})
			},
			saveInfo(){
				const selectedPersonalStatement = this.dropOptionsInfoList.filter((item) => {
				    return item.status == 1;
				});
				if (!selectedPersonalStatement.length) {
					uni.showToast({
						title: '请选择至少一项个人声明！',
						duration: 2000,
						icon: 'none'
					})
				return;
				}
				this.personalStatementList = [];
				for(let i=0;i<selectedPersonalStatement.length;i++){
					this.personalStatementList.push(selectedPersonalStatement[i]['dropOptionName']);
				}
				this.applyParam.personalStatement = this.personalStatementList .join(',');
				this.applyParam.operatStep = 6;
				api.saveApplyInfo(this.applyParam).then((res)=>{
					if(res['success']){
						uni.navigateTo({
							// url:`contract?id=${res['data']['id']}`
							url:`contract`
						});
					}else{
						uni.showToast({
							title: res['message'],
							duration: 2000,
							icon: 'none'
						})
						return;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import 'applyCommon.scss';
	.container {
		background-color: #FBFBFB;
	}
</style>