var template = ''
$.ajax('../html/mzfWatches.html',{
	data: {},
	dataType: 'html',
	cache: false,
	timeout: 60000, 
	async: false,
	error: function(res) {
	},
	success: function(res) {
		template = res
	}
})
Vue.component('mzf-watches', {
	props: [],
	template: template,
	data: function() {
		return {
			tableData:[],
			testArr1: [],
			testArr2: [],
			testPosition1: 0,
			testPosition2: 0,
			list:[],
			startTime:new Date('2023','05','26'),
			endTime:new Date(),
			regionData:[
				{label:'全部',value:'8'},
				{label:'未管理',value:'0'},
				{label:'在管',value:'1'},
				{label:'失访',value:'2'},
				{label:'出组',value:'3'},
				{label:'不纳入管理 ',value:'4'},
				{label:'入组 ',value:'5'},
				{label:'死亡 ',value:'6'},
				{label:'已管理 ',value:'7'},
			],
			// region: '8', //管理状态
			tertiaryHospitalsData:[],
			tertiary: [], //地区
			communityHospitalsData:[],
			communityHospitals: [], // 三级医院
			groupingData:[],
			group: [], // 社区
			queryLevel: 1, // :1.全部 2.区  3.等级医院 4.社区医院
			patient: '', // 患者姓名
			administrationStatusList:[],
			administrationStatusData:[
				{label:'全部',id:'1',type:'5'}
			],
			show:false,
			showTwo:false,
			showThree:false,
			currentPage:1,
			currentSize:10, 
			datatotal:0, //总数
			datatotalTwo:0,
			currentPageTwo:1,
			currentSizeTwo:10, 
			loadingTwo:false,
			setDisabled:{
				disabledDate:function(time) {
					return time.getTime() < new Date('2023','05','26') || time.getTime() > Date.now();
				}
			},
			s:'',
			e:'',
			dialogVisible: false,
			dataInfo: [],
			url: '',
			showPdf: false,
			
			watchPageCode:'',
			copdListTbas:[
				{id:'1',name:'运动'},
				{id:'2',name:'睡眠'},
				{id:'3',name:'心率'},
				{id:'4',name:'PAI'},
				{id:'5',name:'血氧'},
				{id:'6',name:'健康分'},
			],
			copdListIndex:'1',
			copdListData:[],
		}
	},
	created: function(){
		
		this.findCopdHealthInfoList()
	},
	watch:{
		
	},
	methods: {
		tabClick:function(index) {
			this.copdListIndex = index
			this.currentPageTwo = 1
			this.copdList()
		},
		findCopdHealthInfoList:function () {
			var vm = this
			vm.loadingTwo = true
			statisticAPI.watchStatisticsList({
				startDate:this.startTime.format('yyyy-MM-dd'),
				endDate:this.endTime.format('yyyy-MM-dd'),
			}).then(function(res){
				if(res.status == 200) {
					// console.log(res,'hxsj');
					vm.loadingTwo = false
					vm.tableData = res.data
					// vm.datatotal = res.data.length
				}
			}).catch(function(err){
				vm.loadingTwo = false
			})
		},
		watchPage:function() {
			var vm = this
			vm.loadingTwo = true
			statisticAPI.watchPage({
				startDate:this.startTime.format('yyyy-MM-dd'),
				endDate:this.endTime.format('yyyy-MM-dd'),
				page:vm.currentPage,
				size:vm.currentSize,
				area:vm.watchPageCode,
			}).then(function(res){
				if(res.status == 200) {
					console.log(res,'hxsj');
					vm.loadingTwo = false
					vm.dataInfo = res.detailModelList
					vm.datatotal = res.totalCount
				}
			}).catch(function(err){
				vm.loadingTwo = false
			})
		},
		copdList:function() {
			var vm = this
			vm.loadingTwo = true
			statisticAPI.copdList({
				patient:vm.patient,
				type:vm.copdListIndex,
				begin:this.startTime.format('yyyy-MM-dd'),
				end:this.endTime.format('yyyy-MM-dd'),
				page:vm.currentPageTwo,
				size:vm.currentSizeTwo,
			}).then(function(res){
				if(res.status == 200) {
					console.log(res,'shahshas');
					vm.loadingTwo = false
					vm.copdListData = res.detailModelList
					vm.datatotalTwo = res.totalCount
				}
			}).catch(function(err){
				vm.loadingTwo = false
			})
		},
		startTimeChange:function(o) {
			if(!this.list[0] || this.list[0].type!=0) {
			 this.list.unshift({type:'0',id:'time',label:o.format('yyyy-MM-dd') +"~"+ this.endTime.format('yyyy-MM-dd')})
			}else{
				this.list[0].label = o.format('yyyy-MM-dd') +"~"+ this.endTime.format('yyyy-MM-dd')
			}
		},
		endTimeChange:function(o) {
			if(!this.list[0] || this.list[0].type!=0) {
				this.list.unshift({type:'0',id:'time',label:this.startTime.format('yyyy-MM-dd') +"~"+ o.format('yyyy-MM-dd')})
			}else{
				this.list[0].label = this.startTime.format('yyyy-MM-dd') +"~"+ o.format('yyyy-MM-dd')
			}
		},
		 
		// 下一页  上一页
		handleCurrentChange:function(val) {
			var vm = this
			vm.currentPage = val
			this.watchPage()
		},
		handleCurrentChangeTwo:function() {
			var vm = this
			vm.currentPageTwo = val
			this.copdList()
		},
		// change:function(val) {
		// 	this.list = this.list.concat(val)
		// },
		// 查询
		confirm:function() {
			this.findCopdHealthInfoList()
		},
		// 恢复默认
		// cancel:function() {
		// 	this.startTime = new Date('2023','05','26')
		// 	this.endTime = new Date()
		// 	this.tertiary = []
		// 	this.communityHospitals = []
		// 	this.group = []
		// 	this.region = '8'
		// 	this.queryLevel = 1
		// },
		// 查看
		showInfo: function(item) {
			this.dialogVisible = true
			this.watchPageCode = item.code=='合计'?'':item.code
			this.watchPage()
			
		},
		// 弹框再次查看
		btn: function(item) {
			this.showPdf = true
			this.patient = item.patient
			this.copdListIndex = '1'
			this.copdList()
		},
		// 导出
		exportHandle:function() {
			var vm = this
			vm.loadingTwo = true
			statisticAPI.exportWatchStatisticsList({
				startDate:this.startTime.format('yyyy-MM-dd'),
				endDate:this.endTime.format('yyyy-MM-dd'),
			},'手表亚组数据.xls').then(function(res){
				vm.loadingTwo = false
			})
		},
		// 居民列表导出
		exportHandleList:function() {
			var vm = this
			vm.loadingTwo = true
			statisticAPI.exportWatchPage({
				startDate:this.startTime.format('yyyy-MM-dd'),
				endDate:this.endTime.format('yyyy-MM-dd'),
				area:vm.watchPageCode,
			},'手表亚组居民数据.xls').then(function(res){
				vm.loadingTwo = false
			})
		},
		// 居民体征导出
		exportcopdListData:function() {
			var vm = this
			vm.loadingTwo = true
			var name = vm.copdListIndex==1?'运动数据':vm.copdListIndex==2?'睡眠数据':vm.copdListIndex==3?'心率数据':vm.copdListIndex==4?'PAI数据':vm.copdListIndex==5?'血氧数据':'健康分数据'
			statisticAPI.exportWatchPage({
				patient:vm.patient,
				type:vm.copdListIndex,
				begin:this.startTime.format('yyyy-MM-dd'),
				end:this.endTime.format('yyyy-MM-dd'),
			},name+'.xls').then(function(res){
				vm.loadingTwo = false
			})
		},
		
		
		
	}
})