<template>
	<view class="new_fllow">
		<view class="fllow_form">
			<view><text>*</text>回款编号</view>
			<view class="form_input" >
				<input type="text" v-model="number" placeholder-style="font-size:30rpx;color: #999;" placeholder="请输入回款编号" class="">
			</view>
		</view>
		<view class="fllow_form">
			<view><text>*</text>客户名称</view>
			<view class="form_right">
				<view>{{info.customer.name}}</view>
				<view class="iconfont icon-arrows_right"></view>
			</view>
		</view>
		<view class="fllow_form">
			<view><text>*</text>合同编号</view>
			<view class="form_right">
				<view>{{info.contract.num}}</view>
				<view class="iconfont icon-arrows_right"></view>
			</view>
		</view>
		<view class="fllow_form">
			<view><text>*</text>回款期数</view>
			<picker :range="numList" disabled :value="index" @change="changeNum" :range-key="'num'">
				<view class="form_right">
					<view>{{plannum ? plannum : '点击选择'}}</view>
					<view class="iconfont icon-arrows_right"></view>
				</view>
			</picker>
		</view>
		<view class="fllow_form">
			<view><text>*</text>回款日期</view>
			<picker mode="date" @change="changeTime">
				<view class="form_right">
					<view>{{return_time ? return_time : '点击选择'}}</view>
					<view class="iconfont icon-arrows_right"></view>
				</view>
			</picker>
		</view>
		<view class="fllow_form">
			<view><text>*</text>回款金额</view>
			<view class="form_input" >
				<input type="text" v-model="money" placeholder-style="font-size:30rpx;color: #999;" placeholder="请输入计划回款金额" class="">
			</view>
		</view>
		<view class="fllow_form">
			<view><text>*</text>计划回款方式</view>
			<picker :value="index" @change="changeType" :range="type">
				<view class="form_right">
					<view>{{return_type ? return_type : '点击选择'}}</view>
					<view class="iconfont icon-arrows_right"></view>
				</view>
			</picker>
		</view>
		<view class="fllow_area">
			<view class="area_head">备注</view>
			<textarea v-model="remarks"  placeholder="请输入备注" placeholder-style="color:#999" />
		</view>
		<!-- 审核信息 -->
		<examine-template :remindPeople="remindPeople" @delExamine="delRemind"></examine-template>
		<view id="btn" class="btn_g bg-blue button-hover round" @click="saveFollow">
			保存
		</view>
	</view>
</template>

<script>
	import { netSelect, netContractDetail, netPaymentDetail, netPaymentNum, netEditPaymentInfo } from '@/api/kehu.js'
	import { BASE_IMG_URL } from '@/util/api.js'
	export default {
		data() {
			return {
				type:[],   //回款方式 
				numList:[],   //回款  期数
				info:null,   //回款 合同 信息
				id:'',    //回款 id
				contractid:'', //合同id
				plannum:'',
				plan_id:'',   //回款  期数id
				number:'',   //回款  编号 
				money:'',   //回款  金额
				return_time:'',   //  回款  日期
				return_type:'',   //回款  方式
				remarks:'',   //备注
				flow_staff_id:'',   //流程 审批人id
				BASE_IMG_URL:BASE_IMG_URL,
				remindPeople:[], //提醒谁看
				remindType:'contract',
			}
		},
		onLoad(options) {
			this.id = options.id
			this.contractid = options.contractid
			
			//获取 回款方式
			this.getType()
			//获取 回款  期数
			this.getNum()
			//获取 回款 详情
			this.getPaymentInfo()
		},
		methods: {	
			//获取 回款  详情
			getPaymentInfo() {
				netPaymentDetail({id:this.id}).then(res=>{
					res = res.data
					this.info = res
					this.number = res.number
					this.plannum = res.plan.num
					this.return_time = res.return_time
					this.money = res.money
					this.return_type = res.return_type
					this.remarks = res.remarks
				})
			},
			getType() {
				netSelect().then(res=>{
					this.type = res.data['回款方式']
				})
			},
			//获取  回款  期数
			getNum() {
				netPaymentNum({contract_id:this.contractid}).then(res=>{
					this.numList = res.data
				})
			},
			//改变  回款  期数
			changeNum(e) {
				this.plan_id = this.numList[e.detail.value].id
				this.plannum = this.numList[e.detail.value].num
			},
			//改变 回款  方式
			changeType(e) {
				this.return_type = this.type[e.detail.value]
			},
			//计划 回款  日期
			changeTime(e) {
				this.return_time = e.detail.value
			},
			//更多
			moreClick() {
				uni.navigateTo({
					url: '/pagesA/crm/selectMember/selectMember'
				})
			},
			saveFollow() {
				let {
					id,
					number,   //回款  编号 
					money,   // 回款  金额
					return_time,   //  回款  日期
					return_type,   // 回款  方式
					remarks,   //备注
					info,
					remindPeople
				} = this
				if(!number) {
					uni.showToast({
						title:'请输入回款编号',
						icon:'none'
					})
					return
				}
				if(!money) {
					uni.showToast({
						title:'请输入回款金额',
						icon:'none'
					})
					return
				}
				if(!return_time) {
					uni.showToast({
						title:'请选择回款日期',
						icon:'none'
					})
					return
				}
				if(!return_type) {
					uni.showToast({
						title:'请选择回款方式',
						icon:'none'
					})
					return
				}
				if(!remindPeople || remindPeople.length == 0) {
					uni.showToast({
						title:'请选择回款审批人',
						icon:'none'
					})
					return
				}
				let arr = []
				remindPeople.forEach(ele=>{
					arr.push(ele.id)
				})
				let flow_staff_id = arr.join(',')
				let params = {
					id,
					number,  //回款  编号 
					money,   // 回款  金额
					return_time,   // 回款  日期
					return_type,   // 回款  方式
					remarks,
					flow_staff_ids:flow_staff_id,
					customer_id: this.info.customer.id,
					contract_id: this.info.contract.id
				}
				netEditPaymentInfo(params).then(res=>{
					uni.showToast({
						title: res.msg,
						icon:'none'
					})
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},2000)
				})
			}
		}
	}
</script>

<style lang="scss">
.new_fllow {
	margin-top: 40rpx;
	font-size: 28rpx;
	.fllow_form {
		display: flex;
		justify-content: space-between;
		height: 100rpx;
		line-height: 100rpx;
		background-color: #fff;
		border-bottom: 1rpx solid #EAEAEA;
		padding: 0 24rpx;
		.form_right {
			display: flex;
			color: #999;
			image {
				width: 40rpx;
				height: 40rpx;
				margin: 28rpx 5rpx 0 0;
			}
		}
		text {
			color: #f00;
			margin-left: 10rpx;
		}
		.form_input {
			input {
				height: 92%;
				// line-height: 100rpx;
				text-align: right;
				margin-right: 10rpx;
			}
		}
		.fllow_button {
			margin-top: 15rpx;
		}
	}
	.imglist{
		padding:24rpx 34rpx;
		background:#fff;
		border-bottom:1rpx solid #EAEAEA;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		flex-wrap: wrap;
		.imgbox{
			width:160rpx;
			height:160rpx;
			margin-right:14rpx;
			position: relative;
			margin-bottom:24rpx;
			border:1rpx solid #EAEAEA;
			.delimg{
				width:32rpx;
				height:32rpx;
				border-radius:50%;
				position: absolute;
				right:-16rpx;
				top:-16rpx;
				background:rgba(0,0,0,0.5);
				z-index: 2;
			}
			.selfimg{
				width:160rpx;
				height:160rpx;
			}
		}
	}
	.fllow_area {
			background-color: #fff;
			// padding: 0 70rpx;
			margin-bottom: 30rpx;
			padding-bottom: 30rpx;
			color: #999;
			.area_head {
				height: 100rpx;
				line-height: 100rpx;
				font-size: 32rpx;
				padding: 0 70rpx;
				text {
					color: #f00;
				}
			}
			textarea {
				width: 80%;
				height: 300rpx;
				padding: 30rpx;
				background: #f8f8f8;
				margin: 0 auto;
			}
		}
	.info_head{
		height: 80rpx;
		line-height: 80rpx;
		font-size: 24rpx;
		color: #999;
		padding-left: 24rpx;
	}
	.affiliation {
			background-color: #fff;
			margin-bottom: 20rpx;
			padding-bottom: 40rpx;
			.aff_head {
				height: 100rpx;
				line-height: 100rpx;
				padding-left: 30rpx;
				text {
					color: #f00;
					margin-left: 10rpx;
				}
			}
			.aff_con {
				display: flex;
				text-align: center;
				flex-wrap: wrap;
			
				.aff_item {
					width: 100rpx;
					margin-right: 15rpx;
					border-radius: 50%;
					margin-bottom:15rpx;
					image {
						margin-bottom: 15rpx;
						width: 60rpx;
						height: 60rpx;
						
					}
				}
			
				.affbox {
					position: relative;
			
					.delremind {
						width: 32rpx;
						height: 32rpx;
						border-radius: 50%;
						position: absolute;
						right: -16rpx;
						top: -16rpx;
						background: rgba(0, 0, 0, 0.5);
						z-index: 2;
					}
				}
			
				.aff_last {
					image {
						margin-bottom: 15rpx;
						width: 48rpx;
						height: 48rpx;
					}
				}
			}
		}
	.follow_task {
		height: 80rpx;
		line-height: 80rpx;
	}
}
#btn {
		font-size: 26rpx;
		color: #fff;
		text-align: center;
		line-height: 88rpx;
		width: 500rpx;
		height: 88rpx;
		background: $uni-text-color;
		border-radius: 29rpx;
		margin: 30rpx auto;
	}
</style>
