<template>
	<view class="content">
		<view class="inner">
			<view class="form-box">
				<view class="form-item">
					<text class="label">竞品公司</text>
					<input  class="input-width" type="text" v-model="form.competitorCompany" placeholder="请输入竞品公司"
						placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label">产品</text>
					<input class="input-width" type="text" v-model="form.product" placeholder="请输入产品"
						placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label">价格</text>
					<input  class="input-width" type="digit" v-model="form.price" placeholder="请输入价格"
						placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label">服务</text>
					<input class="input-width" type="text" v-model="form.service" placeholder="请输入竞品公司服务方式"
						placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label">免费服务次数</text>
					<input class="input-width" type="number" v-model="form.freeServiceTimes" 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 {
		getCompetitorById,saveCompetitor,updateCompetitor
	} from '@/api/companyUser.js'
	export default {
		data() {
			return {
				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: {
					"competitorCompany": null,
					"freeServiceTimes":null,
					"price":null,
					"product": null,
					"remark": null,
					"service": null,
				},
				id:null
			};
		},
		onLoad(options) {
			this.type = option.type;
			this.form.userId=options.userId
			this.form.companyUserId=options.companyUserId;
			console.log(this.type)
			if (this.type == 'edit') {
				this.id=option.id;
				this.getCompetitorInfo();
			}
		},
		methods: {
			getCompetitorInfo() {
				var data = {
					id: this.id
				};
				getCompetitorById(data).then(
					res => {
						if (res.code == 200) {
							this.form = res.data;

						} else {
							uni.showToast({
								title: res.msg,
							});
						}
					},
					rej => {}
				);
			},
			submit() {
				// if (this.form.userName == null) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "姓名不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.idCard == null) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "身份证号不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.sex == null) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "性别不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.birthday == null) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "出生年月不能为空",
				// 	});
				// 	return;
				// }
				if (this.type == "add") {
					this.saveCompetitor()
				} else if (this.type == "edit") {
					this.updateCompetitor()
				}
			},
			updateCompetitor() {
				updateCompetitor(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 => {}
				);
			},
			saveCompetitor() {
				saveCompetitor(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 => {}
				);
			},
		}
	}
</script>

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

	.content {
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.inner {
			// height: calc(100% - 120upx);
			padding: 20upx;

			.form-box {
				padding: 0 30upx;
				background: #FFFFFF;
				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: flex-start;
					border-bottom: 1px solid #F1F1F1;

					&:last-child {
						border-bottom: none;
					}
        
					.label {
						width: 300upx;
						text-align: left;
						font-size: 32upx;
						line-height: 44upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #222222;
						flex-shrink: 0;
					}

					input {
						text-align: right;
					}
               
					.form-input {
						font-size: 30upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
						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;

			// 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-size: 32upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				background: #008FD3 ;
				border-radius: 44upx;
				margin-bottom: 40upx;
				display: flex;
				align-items: center;
				justify-content: center;
				image{
					margin-right: 16rpx;
				}
			}
		}
	}
</style>