<template>
	<view class="main">
		<view class="desc">
			<view class="item">科室：{{ item.deptName }}</view>
			<view class="item">医生：{{ item.doctorName }}</view>
			<view class="item">日期：{{ item.createTime }}</view>
		</view>
		<u-divider text="随访内容"></u-divider>
		<view class="item" v-for="(item, index) in item.op" :key="item.name">
			<view class="mtt">
				<text class="ifnull" v-if="item.ifnull == '必填'">*</text>
				<text class="index">{{ index + 1 }}、</text>
				<text class="tm">{{ item.name }}</text>
				<text class="dx">（{{ item.input }}）</text>
			</view>
			<view class="mts">
				<input v-if="item.input == '填空'" v-model="item.s_value" placeholder="请输入" :disabled="look" />
				<images v-model="item.s_value" type="图片" v-if="item.input == '图片'" :read="look"></images>
				<images v-model="item.s_value" type="视频" v-if="item.input == '视频'" :read="look"></images>
				<images v-model="item.s_value" type="录音" v-if="item.input == '录音'" :read="look"></images>
				<input v-if="item.input == '数字'" type="number" v-model="item.s_value" placeholder="请输入" :disabled="look" />
				<textarea v-if="item.input == '多行文本'" v-model="item.s_value" placeholder="请输入" :disabled="look" />
				<view class="ops" v-if="item.input == '单选' || item.input == '多选' || item.input == '判断'">
					<view v-for="(op, i) in item.selects" :key="op.name">
						<view class="op" :class="{ active: op.check }" @click="check(item, op)">{{ op.name }}</view>
					</view>
				</view>
			</view>
		</view>
		<button class="btn" @click="add()" v-if="!look">立即提交</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			look: false,
			item: { op: { s_value: [] } }
		};
	},
	onLoad(e) {
		this.http.request({
			url: this.getUser().doctor ? '/work/record/detail/' + e.id : '/app/follow/detail/' + e.id,
			success: (res) => {
				this.item = res.data.data;
				if (this.getUser().doctor) {
					this.look = true;
					this.item.deptName = this.getUser().dept.deptName;
					this.item.doctorName = this.getUser().nickName;
				} else {
					this.item.deptName = e.deptName;
					this.item.doctorName = e.doctorName;
					this.look = this.item.state != 0 ? true : false;
				}
				this.item.op = JSON.parse(this.item.op);
				uni.setNavigationBarTitle({ title: this.item.templateName });
			}
		});
	},
	methods: {
		//单选或多选
		check(item, op) {
			if (this.look) {
				return;
			}
			if (item.input == '单选' || item.input == '判断') {
				item.selects.forEach((i) => (i.check = false));
				op.check = true;
			} else {
				op.check = !op.check;
			}
			item.s_value = op.check; //选中项
			this.$forceUpdate();
		},
		add() {
			let rule = [];
			let obj = {};
			this.item.op
				.filter((item) => item.ifnull == '必填')
				.forEach((item) => {
					rule.push({ name: item.name, checkType: 'notnull', errorMsg: '第' + (this.item.op.indexOf(item) + 1) + '项，' + item.name + '不能为空' });
					obj[item.name] = item.s_value;
				});
			if (!this.verify.check(obj, rule)) {
				uni.showModal({ content: this.verify.error, showCancel: false });
				return;
			}
			let data = JSON.parse(JSON.stringify(this.item));
			data.op = JSON.stringify(data.op);
			this.http.request({
				url: '/app/follow/push',
				data: data,
				method: 'POST',
				success: (res) => {
					uni.showModal({
						title: '提示',
						content: '感谢您的回访',
						showCancel: false,
						success: (res) => {
							uni.$emit('follow');
							uni.navigateBack();
						}
					});
				}
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: white;
}
.desc {
	background-color: $bg;
	padding: 10px;
	border-radius: 7px;
	.item {
		padding-top: 5px;
		font-size: 15px;
		color: $font-c;
	}
}
.item {
	.mtt {
		text-align: left;
		font-size: 16px;
		padding: 15px 0px 12px 0px;
		position: relative;
		color: $font-c;
		.ifnull {
			color: red;
			font-weight: bold;
		}
		.tm {
			padding-left: 0px;
		}
		.dx {
			font-size: 12px;
			color: #646464;
		}
	}
	input {
		background-color: $inp;
		border-radius: 5px;
		padding: 12px;
		font-size: 14px;
	}
	textarea {
		background-color: $inp;
		border-radius: 5px;
		width: 93%;
		padding: 12px;
		font-size: 14px;
		height: 70px;
	}
	.ops {
		margin-top: -5px;
		overflow: hidden;
		.op {
			padding: 9px;
			background-color: $inp;
			margin-top: 10px;
			font-size: 14px;
			border-radius: 3px;
			color: #656363;
			float: left;
			margin-right: 10px;
			&.active {
				background-color: $main-color;
				color: white;
			}
		}
	}
}
</style>
