<template>
	<view class="content">
		<view class="inner">
			<view class="form-box">
				<view class="form-item">
					<text class="label"><text class="color-price">*</text> 姓名</text>
					<input  class="input-width" type="text" v-model="form.productName" placeholder="请输入姓名"
						placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label"><text class="color-price">*</text> 医院</text>
					<input  class="input-width" type="text" v-model="form.productName" placeholder="请输入医院"
						placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label"><text class="color-price">*</text> 科室</text>
					<input  class="input-width" type="text" v-model="form.productName" placeholder="请输入科室"
						placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label"><text class="color-price">*</text> 职称</text>
					<input  class="input-width" type="text" v-model="form.productName" placeholder="请输入职称"
						placeholder-class="form-input" />
				</view>
			</view>
		</view>
		<view class="btn-box">
			<view class="sub-btn" @click="submit()">
				<!-- <image src="/static/images/health/nav_add_icon24.png" class="w48 h48"></image> -->
				<text>确认并进入直播间</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getServiceById,updateService,saveService
	} from '@/api/companyUser.js'
	export default {
		data() {
			return {
				startDate:this.utils.timeFormat(new Date()),
				type: null,
				patientId: null,
				famaleurl:"/static/images/health/female_profile.png",
				maleurl:"/static/images/health/my_heads.png",
				checked:1,
				array:['是','否'],
				tags: [{
					name: '心脏病',
					checked:true,
					id: 1
				},
				{
					name: '脑梗死',
						checked:false,
					id: 2
				},{
					name: '肾病',
						checked:false,
					id: 3
				},{
					name: '脂肪肝',
						checked:false,
					id: 4
				}],
				form: {
						"amount": null,
						"memberStatus": null,
						"plannedCompletionDate": null,
						"productName":null,
						"purchaseQuantity":1,
						"purchaseTimes":null,
						"remark": null,
						"surplusTimes":null,
				},
				id:null
			};
		},
		onLoad(options) {
			this.type = options.type;
			this.form.userId=options.userId
			this.form.companyUserId=options.companyUserId;
			console.log(this.type)
			if (this.type == 'edit') {
				this.id=options.id;
				this.getServiceInfo();
			}
		},
		methods: {
			sexChange(type) {
				this.form.sex = type
			},
			radioClick(item) {
			        this.checked=item.id
			      },
			getServiceInfo() {
				var data = {
					id: this.id
				};
				getServiceById(data).then(
					res => {
						if (res.code == 200) {
							this.form = res.data;
                            this.form.plannedCompletionDate=this.utils.timeFormat(res.data.plannedCompletionDate,'yyyy-mm-dd')
							this.startDate=this.form.plannedCompletionDate
						} else {
							uni.showToast({
								title: res.msg,
							});
						}
					},
					rej => {}
				);
			},
			submit() {
				uni.navigateTo({
					url: '/pages_live/card'
				})
				// if (this.form.productName == null || this.form.productName == '') {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "名称不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.purchaseQuantity == null|| this.form.purchaseQuantity == 0) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "数量不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.amount == null|| this.form.amount == '') {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "金额不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.plannedCompletionDate == null|| this.form.plannedCompletionDate == '') {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "时间不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.purchaseTimes == null|| this.form.purchaseTimes == '') {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "购买次数不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.surplusTimes == null|| this.form.surplusTimes == '') {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "剩余次数不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.memberStatus == null|| this.form.memberStatus == '') {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "会员情况不能为空",
				// 	});
				// 	return;
				// }
				// if (this.type == "add") {
				// 	this.saveService()
				// } else if (this.type == "edit") {
				// 	this.updateService()
				// }
               
			},
			updateService() {
				updateService(this.form).then(
					res => {
						if (res.code == 200) {
							uni.showToast({
								icon: 'success',
								title: "操作成功",
							});
							setTimeout(function() {
								uni.$emit('refreshBuyOrder');
								uni.navigateBack({
									delta: 1
								})
							}, 500);
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg,
							});
						}
					},
					rej => {}
				);
			},
			saveService() {
				saveService(this.form).then(
					res => {
						if (res.code == 200) {
							uni.showToast({
								icon: 'success',
								title: "操作成功",
							});
							setTimeout(function() {
								uni.$emit('refreshBuyOrder');
								uni.navigateBack({
									delta: 1
								})
							}, 500);
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg,
							});
						}
					},
					rej => {}
				);
			},
			// 出生日期选择
			bindDateChange: function(e) {
				this.form.plannedCompletionDate = e.target.value
			},
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.content {
		height: 100%;
		display: flex;
		flex-direction: column;
		//  justify-content: space-between;
        background: #FFFFFF;
		.inner {
			// height: calc(100% - 120upx);
			// padding: 20upx;

			.form-box {
				padding: 0 32upx;
				
				border-radius: 16upx;
				margin-bottom: 20upx;

				.form-title {
					font-family: PingFang SC;
					font-weight: 600;
					font-size: 40rpx;
					color: #222426;
					text-align: left;
					padding: 30rpx 0;
					display: block;
				}

				.form-item {
					padding: 30upx 0;
					display: flex;
					align-items: center;
					justify-content: space-between;
					border-bottom: 1px solid #EBEDF0;

					// &:last-child {
					// 	border-bottom: none;
					// }
        
					.label {
						width: 200upx;
						text-align: left;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
						flex-shrink: 0;
					}
                   
					input {
						flex:1;
						text-align: right;
					}
               .num-box{
               	input{
               		text-align: center !important;
               	}
               }
					.form-input {
						
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #C8C9CC;
						text-align: right;
					}

					.form-item-tag{
						margin-right: 16rpx;
						.tag{
							border-radius: 8rpx 8rpx 8rpx 8rpx;
							border: 2rpx solid #ECECEC;
							display: flex;
							align-items: center;
							padding: 24rpx;
							font-family: PingFang SC;
							font-weight: 400;
							font-size: 24rpx;
							&.active{
								background: #F0FAFF;
								border: 2rpx solid #008FD3;
								color: #008FD3;
							}
						}
						
						
						
					}
					.right{
						display: flex;
						align-items: center;
					}
					.sex-box{
						flex:1;
						display: flex;
						align-items: center;
						justify-content: flex-end;
						.sex-item{
							width: 146rpx;
							height: 64rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							background: #F5F7FA;
							border-radius: 32rpx 32rpx 32rpx 32rpx;
							margin-left: 16rpx;
							.u-icon__icon{
								margin: 0;
							}
							text{
								// font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 28rpx;
								color: #898E91;
								margin-left: 12rpx;
							}
							&.active{
								background: #FCF0E7;
								text{
									color:#FF5030
								}
							}
						}
					}
					.form-textarea{
						font-size: 30upx;
						color: #999999;
						height: 100upx;
						padding: 4upx 0;
					}
					 
					.birth-picker {
						flex: 1;
						display: flex;
						align-items: center;
						
						.right-box{
							width: 100%;
							display: flex;
							align-items: center;
							.input-box{
								// width: 470upx;
							}
							.arrow{
								width: 13upx;
								height: 23upx;
								margin-left: 20upx;
							}
						}
					}
				}
			}
		}

		.btn-box {
			height: 120upx;
			padding: 0 30upx;
			display: flex;
			align-items: center;
			justify-content: center;
            margin-top: 86rpx;
			// position: fixed;
			// width: 90%;
			// bottom: 0;
			// left: 50%;
			// transform: translate(-50%,-50%);
			// background: #FFFFFF;
			.sub-btn {
				width: 100%;
				height: 88upx;
				line-height: 88upx;
				text-align: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 32rpx;
				color: #FFFFFF;
				background: #388BFF ;
				border-radius: 44upx;
				margin-bottom: 40upx;
				display: flex;
				align-items: center;
				justify-content: center;
				image{
					margin-right: 16rpx;
				}
			}
		}
	}
</style>