<!-- 										服务设置页												 -->
<template style="background-color: #f6f6f6;">
	<view style="width: 100%;height: 100%;">
		<!-- 弹窗 -->
		<u-modal v-model="tcShow" :content="content" width="50%" :show-cancel-button='true' :show-title="false" @confirm="qrsq"></u-modal>
		
		<!-- 开关选择器 -->
		<view v-for="(item,index) in serbicelist" class="list" :key='index':data-index="index">
			<!-- 左边文字 -->
			<view style="width: 20%;">{{item.zhonglei}}</view>
			<!-- 开通状态 -->
			<view style="width: 40%;">
				<text v-if="item.Opening == 3||item.Opening == false" style="text-decoration: underline; color: #888888;" @click="this.tcShow=true,num=index" >未开通</text>
				<text v-if="item.Opening == 1" style="color: #888888;">待审核</text>
		
			</view>
			<!-- 服务状态 -->
			<view style="width: 20%;color: #999999;">
				<text v-if="item.state">服务开启</text>
				<text v-else>服务关闭</text>
			</view>
			<!-- 控制器 -->
			<view style="width: 15%;">
			<u-switch v-model="item.state" :data-index="item.state" active-color="#84bb43" inactive-color="#eee" @change="openSave" :disabled="item.disp"></u-switch>
			</view>
		</view>
		<!-- 更多设置 -->
		<view class="list">
			<view style="height: 80rpx;width: 100%;display: flex;justify-content: space-between;align-items: center;padding: 0 20rpx;" @click="next">
				<text style="color: #757575;margin-right: 20rpx;">更多设置</text>
				<u-icon name="arrow-right" color="#c9c9c9"></u-icon>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {

		},
		onLoad() {
			this.getStatus();

		},
		mounted() {

		},
		data() {
			return {
				//弹窗
				tcShow:false,//控制弹窗
				content:'申请开通此服务？',
				num:'',//点击的下标
				//zhonglei咨询种类
				//state服务开启状态 true为开 false为关
				//Opening开通状态 0为开通 1为申请中 2为未开通  修改为2=已通过，3=已经拒绝
				serbicelist: [{
					zhonglei: '电话咨询',
					state: false,
					Opening: 0,
					disp:true,
				}, {
					zhonglei: '图文咨询',
					state: false,
					Opening: 0,
					disp:true,
				}, {
					zhonglei: '门诊预约',
					state: false,
					Opening: 0,
					disp:true,
				}]
			}
		},
		methods: {
			/**
			 * @author Liu Yuanhang
			 * 查询开启状态（未完成暂时没有审核表）
			 */
			getStatus:async function(){
				let res = await this.$request.post('doctor/getSettingBase',{'type':1});
				console.log('我是res',res);
				if(res.status==0){
					this.serbicelist[0].state = res.data.is_phone;
					this.serbicelist[1].state = res.data.is_chat;
					this.serbicelist[2].state = res.data.is_appoint
					if(res.data.is_appoint_status){
						this.serbicelist[2].Opening=res.data.is_appoint_status.status
						if(res.data.is_appoint_status.status==2){
							this.serbicelist[2].disp=false;
						}
					}else{
						this.serbicelist[2].Opening=0
					}
				
					if(res.data.is_chat_status){
						this.serbicelist[1].Opening=res.data.is_chat_status.status
						if(res.data.is_chat_status.status==2){
							this.serbicelist[1].disp=false;
						}
					}else{
						this.serbicelist[1].Opening=0
					}
					
					if(res.data.is_phone_status){
						this.serbicelist[0].Opening=res.data.is_phone_status.status
						if(res.data.is_phone_status.status==2){
							this.serbicelist[0].disp=false;
						}
					}else{
						this.serbicelist[0].Opening=0
					}
				}
			},
			
			/**
			 * @author Liu Yuanhang
			 * 修改状态
			 * @param {Object} e
			 */
			openSave:async function(e){
				let list = this.serbicelist;
			
				let data =  {"is_chat":list[1]['state'],"is_phone":list[0]['state'],"is_appoint":list[2]['state']}
				if(typeof data != 'string'){
					data = JSON.stringify(data);
				}
				let res = await this.$request.post('doctor/saveSettingBase',{'type':1,'data':data});
				console.log("修改操作设置",res);
				if(res.status==0){
					uni.showToast({
						title:'操作成功',
						duration:2000,
						icon:'none'
					})
				}
			},
			// 下一页
			next(){
				console.log(this.serbicelist[0].Opening,this.serbicelist[1].Opening,this.serbicelist[2].Opening)
				if(!((this.serbicelist[0].Opening==2)||(this.serbicelist[1].Opening==2)||(this.serbicelist[2].Opening==2))){
					uni.showToast({
						title:'未开通任何服务',
						icon:'none'
					}) 
				}else{
					uni.navigateTo({
					url:'/pages/service/more'
					})
				}
				
			},
			// 确认申请
			qrsq:async function(){
				let types = 0;
				if(this.num==0){
					types = 2;
				}else if(this.num==1){
					types = 1;
				}else{
					types = 3;
				}
				let res = await this.$request.post("ServiceApply/serviceExamine",{"service_type":types});
				console.log("开通服务",res);
				if(res.status==0){
					uni.showToast({
						'title':'请求成功',
						duration:3000
					})
					this.serbicelist[this.num].Opening = 1;
				}
			},

		}
	}
</script>

<style>
	.list {
		height: 120rpx;
		width: 100%;
		padding: 0 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #FFFFFF;
		border-bottom:1rpx solid #f6f6f6;
	}
</style>