<template>
	<view class="flex-col">
		<view class="p-col-4">
			<d-text text="请选择退诊原因" className="m-l-32 tips-c"></d-text>
		</view>
		<u-checkbox-group shape="circle" icon-size="35" size="44" active-color="#6ACDBB">
			<view v-for="(item, index) in list" :key="item.key" class="flex-row flex-jus-sp white"
				style="width: 100vw; padding: 32rpx 0 32rpx 32rpx;">
				<d-text :text="item.value" className="content-c fs-32"></d-text>
				<u-checkbox @change="changeCheck(item)" :value="reason_id === item.key" :name="item.value"></u-checkbox>
			</view>
		</u-checkbox-group>
		<view class="m-t-8">
			<u-button :throttle-time="0" shape="circle" @click="sub"
				:custom-style="{width: '646rpx',height: '86rpx',backgroundColor:'#6ACDBB',color:'#fff'}">提交</u-button>
		</view>
	</view>
</template>

<script>
	import {
		RefuseReason,
		storePatientRefuse
	} from "@/api/consult.js";
	export default {
		data() {
			return {
				list: [],
				patient_id: "",
				reason_id: "",
				reason: []
			}
		},
		onLoad(options) {
			this.getReason();
			this.patient_id = options.id;
		},
		methods: {
			changeCheck(item) {
				this.reason_id = item.key;
				this.reason.push(item.value)
			},
			getReason() {
				RefuseReason({
					store_id: uni.getStorageSync('store_id') || '11001'
				}).then((res) => {
					this.list = res.data.map((row) => ({
						...row,
						checked: false,
					}));

				});
			},
			async sub() {
				try {
					if (this.reason_id===' ') {
						this.$toast("请选择退诊原因");
						return;
					}
					const res = await storePatientRefuse({
						register_id: this.patient_id,
						refuse_reason: this.reason,
						status: 2,
						store_id: uni.getStorageSync('store_id') || '11001'
					});

					if (res.errcode == 0) {
						this.$toast("提交成功,已拒诊");
						setTimeout(() => {
							uni.navigateBack({
								delta: 2
							})
						}, 700)
					}else{
						this.$toast(res.msg);
					}
				} catch (error) {}
			},

		}
	}
</script>
<style>
	page {
		background-color: #F9FAFB;
	}
</style>