<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<!--<link rel="stylesheet" type="text/css" href="../../../css/bootstrap.min.css" />-->
		<link rel="stylesheet" type="text/css" href="../../../css/cross.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/cross.ui.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/style.min.css" />
		<link href="../../../plugins/toastr/toastr.min.css" rel="stylesheet">
		<link rel="stylesheet" type="text/css" href="../css/article.css"/>
	</head>
	<body>
		<div id="app">
			<div class="sel-tap sel-article">
	           	<div class="p10 pt60 c-h80">
			        <ul class="select-tit c-border-b clearfix h34 lh34">
			            <li v-for="(tit, index) in selectArr" :key="index" class="fl mr10 c-border-r c-border-l c-border-t b-r-5500 bgc-f5f5fa c-666 cur-pit" :class="{'active': index == judgeIndex}" @click="selectTit(index)">{{tit}}</li>
			        </ul>
			        <div class="set-article-content plr10" id="setCon">
			            <div class="set-search ptb20 lh30 clearfix">
			            	<div class="c-position-r fl mb0">
			                    一级分类：<span class="list-tit set-bg cur-pit c-999" @click="judgeLevel(1)">{{levelTit1}}</span>
			                    <ul class="pull-list c-border-l c-border-r c-border-b" v-if="isShowLevel1">
			                        <li class="cur-pit c-999" v-for="(level1, index) in levelArr1" :key="index" @click="selectLi(1, level1)">{{level1.categoryname}}</li>
			                    </ul>
			                </div>
			                <div class="c-position-r fl mb0">
			                   	 二级分类：<span class="list-tit set-bg cur-pit c-999" @click="judgeLevel(2)">{{levelTit2}}</span>
			                    <ul class="pull-list c-border-l c-border-r c-border-b" v-if="isShowLevel2">
			                        <li class="cur-pit c-999" v-for="(level2, index) in levelArr2" :key="index" @click="selectLi(2, level2)">{{level2.categoryname}}</li>
			                    </ul>
			                </div>
			                <div class="fl mb0">
			                    <input class="list-tit w150" type="text" placeholder="输入文字标题" v-model="articleTitle">
			                </div>
			                <div class="fl mb0">
			                    <span class="list-tit w80 b-r-3 c-t-center c-fff bgc-12b7f5 cur-pit btn" @click="search()">搜索</span>
			                </div>
			            </div>
			            <!--<ul class="article-list c-border">
			                <li class="bgc-f5f5fa c-f999 clearfix">
			                    <span class="fl c-w35 c-border-r c-t-center">文章标题</span>
			                    <span class="fl c-w22 c-border-r c-t-center">分类</span>
			                    <span class="fl c-w30 c-border-r c-t-center">来源</span>
			                    <span class="fl c-w13 c-t-center">操作</span>
			                </li>
			                <li class="c-border-t c-f666 clearfix" v-for="(list, index) in articleList" :key="index">
			                    <p class="fl c-w35 plr5 c-border-r text-ellipsis">{{list.articletitle || list.attachedTitle}}</p>
			                    <p class="fl c-w22 c-border-r text-ellipsis">{{list.firstlevelcategoryname || list.level1TypeName ? list.firstlevelcategoryname || list.level1TypeName : ''}}<span v-if="(list.firstlevelcategoryname || list.level1TypeName) && (list.secondlevelcategoryname || list.level1TypeName)">、</span>{{list.secondlevelcategoryname || list.level2TypeName ? list.secondlevelcategoryname || list.level2TypeName : ''}}</p>
			                    <span class="fl c-w30 c-border-r text-ellipsis">{{list.articlesource || list.articleSource}}</span>
			                    <p class="fl c-w13 c-t-center c-12b7f5">
			                        <span class="cur-pit operate" v-if="judgeIndex == 2 || list.isauthentication == 1" @click="send(list)">发送</span>
			                        <span class="c-999" v-if="judgeIndex != 2 && list.isauthentication == 0">未认证</span>
			                        <span class="c-999" v-if="judgeIndex != 2 && list.isauthentication == 2">认证未通过</span>
			                    </p>
			                </li>
			            </ul>-->
			            <table class="article-table" width="100%">
			                <thead>
			                    <tr>
			                        <th class="c-w35">文章标题</th>
			                        <th class="c-w22">分类</th>
			                        <th>来源</th>
			                        <th>操作</th>
			                    </tr>
			                </thead>
			                <tbody>
			                    <tr v-for="(list, index) in articleList" :key="index">
			                        <td class="text-ellipsis">{{list.articletitle || list.attachedTitle}}</td>
			                        <td class="text-ellipsis">{{list.firstlevelcategoryname || list.level1TypeName ? list.firstlevelcategoryname || list.level1TypeName : ''}}<span v-if="(list.firstlevelcategoryname || list.level1TypeName) && (list.secondlevelcategoryname || list.level1TypeName)">、</span>{{list.secondlevelcategoryname || list.level2TypeName ? list.secondlevelcategoryname || list.level2TypeName : ''}}</td>
			                        <td>{{list.articlesource || list.articleSource}}</td>
			                        <td>
			                            <a class="operate" v-if="judgeIndex == 2 || list.isauthentication == 1" @click="send(list)">发送</a>
                                        <span class="c-999 ml10" v-if="judgeIndex != 2 && list.isauthentication == 0">未认证</span>
                                        <span class="c-999 ml10" v-if="judgeIndex != 2 && list.isauthentication == 2">认证未通过</span>
			                        </td>
			                    </tr>
			                </tbody>
			            </table>
			            <div class="mt20 lh24 pr30 txt-center clearfix" v-show="articleList.length">
			                <div class="fr ml10 clearfix">
			                    <span class="fl c-border w40 m0">
			                        <input class="fl w40 c-f999" v-model="editPage" />
			                    </span>
			                    <span class="fr bgc-12b7f5 c-fff c-f12 btn sure-btn" @click="setPage(editPage)">跳转</span>
			                </div>
			                <span class="fr btn page-btn ml10" @click="setPage(page + 2)" v-if="page == 1 && (page + 2) <= allPage">{{page + 2}}</span>
			                <span class="fr btn page-btn ml10" @click="setPage(page + 1)" v-if="(page + 1) <= allPage">{{page + 1}}</span>
			                <span class="fr btn page-btn ml10 btn-active">{{page}}</span>
			                <span class="fr btn page-btn ml10"  @click="setPage(page - 1)" v-if="page != 1">{{page - 1}}</span>
			                <span class="fr btn page-btn ml10"  @click="setPage(page - 2)" v-if="page > 2 && page == allPage">{{page - 2}}</span>
			                <span class="fr">当前第{{page}}页，共{{allPage}}页，{{allRecords}}条数据</span>
			            </div>
			            <p class="pt60 c-t-center c-999 c-f24" v-show="!articleList.length">无数据</p>
			        </div>
			    </div>
	        </div>
		</div>
        <script src="../../../js/vue.js" type="text/javascript" charset="utf-8"></script>
	    <script src="../../../js/jquery-2.2.4.js"></script>
	     <script src="../../../js/es6-promise.js" type="text/javascript" charset="utf-8"></script>
	    <script src="../../../js/util.js" type="text/javascript" charset="utf-8"></script>
	    <script src="../../../api/http-request.js" type="text/javascript" charset="utf-8"></script>
	    <script type="text/javascript" src="../../../api/jbsc-api.js" ></script>
	    <script type="application/javascript" src="../../../api/rehabilitation-api.js"></script>
		<script src="../../../js/underscore.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../plugins/toastr/toastr.min.js"></script>
		<!--<script src="../../../plugins/layer/layer.min.js"></script>-->
        <script type="text/javascript">
	    	var httpData=GetRequest();
        	var loginDoctor = JSON.parse(window.localStorage.getItem('wlyyAgent') || window.localStorage.getItem('userRole') || window.localStorage.getItem('severDocInfo') || window.localStorage.getItem('docInfo'));
//      	currentUserRole = window.localStorage.getItem('userRose'),
		    var userRole = (loginDoctor && loginDoctor.hospital) || (loginDoctor && loginDoctor.userRole && loginDoctor.userRole),
//			     currentUserRoleLevel = loginDoctor.currentUserRole.level,
		    // roleType = Number(loginDoctor.currentUserRole.isManage) ? 2 : 1
		    currentUserRoleLevel = 4,
		    roleType = 1;
		    var currentUserRole=userRole
		    if(typeof userRole === "object"){
		    	var currentDoc = _.find((userRole||[]),function(o) {
					return o.level =="4";
				}) || {};
				currentUserRole=currentDoc.code || currentDoc[0] && currentDoc[0].code
		    }
		    
	    	new Vue({
				el: "#app",
			    data:{
		            selectArr: ['文章库', '我的文章', '已推送文章'],
		            judgeIndex: 0,
		            levelArr1: [],
		            levelTit1: '请选择',
		            isShowLevel1: false,
		            levelArr2: [],
		            levelTit2: '请选择',
		            isShowLevel2: false,
		            resultCode:httpData['resultCode'],
		            isReha:httpData['isReha'],
		            planId:httpData['planId'],
		            selectObj: {
		                firstLevelCategoryId: null, // 文章一级分类
		                secondLevelCategoryId: null, // 文章二级分类
		                insertTimeStart: null, // 新增文章开始时间
		                insertTimeEnd: null, // 新增文章结束时间
		                articlelevel: null, // 文章级别
		                articleTitle: null, // 文章标题关键字
		                currentUserRole: currentUserRole, // 当前登录的角色
		                currentUserRoleLevel: currentUserRoleLevel, // 当前登录的角色级别
		                isAuthentication: 1, // 是否认证
		                isMyArticle: false, // 是否过滤我的文章(默认)
		                iDisplayStart: 0, // 当前页
		                iDisplayLength: 10, // pagesize
		                sEcho: 1, // 插件自带
		                roleType: roleType, // 1、普通医生，2、管理员
//		                patient: httpData['code'] // 居民CODE
		            },
		            pushObj: {
		                firstLevelCategoryId: null, // 文章一级分类
		                secondLevelCategoryId: null, // 文章二级分类
		                sendTimeStart: null, // 发送开始时间
		                sendTimeEnd: null, // 发送结束时间
		                articleTitle: null, // 文章标题关键字
		                currentRoleCode: currentUserRole, // 当前登录的角色
		                currentRoleLevel: currentUserRoleLevel, // 当前登录的角色级别
		                isMyArticle: null, // 是否过滤我的文章(默认)
		                iDisplayStart: 0, // 当前页
		                iDisplayLength: 10, // pagesize
		                sendType: roleType // 1、普通医生，2、管理员
		            },
		            firstLevelCategoryId: null, // 选择文章一级分类
		            secondLevelCategoryId: null, // 选择文章二级分类
		            articleTitle: null, // 输入文章标题关键字
		            articleList: [],
		            editPage: null,
		            page: 1,
		            allPage: null,
		            allRecords: null
			    },
				 mounted: function(){
			        this.getJkEduArticleLevel(1)
			        this.getJkEduArticleLevel(2)
			        this.queryArticlePcList(this.selectObj)
			    },
			    methods: {
			       	getJkEduArticleLevel:function(num, firstlevelId) {
			       		var vm=this;
			            var data={
			            	categoryLevel: num,
				            firstlevelId: firstlevelId || null,
				            secondLevelId: null
			            }
//			            vm.levelArr1=[];
			            var loadding = top.layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
			           	jbscAPI.getCategoryList(data).then(function(res){
			           		top.layer.close(loadding);
				            if (res.status == 200) {
				                if (num == 1) {
				                    vm.levelArr1 = res.data
				                    console.log(vm.levelArr1)
				                } else {
				                    vm.levelArr2 = res.data
				                }
				            }
			           	})
			             
			        },
			        queryArticlePcList:function(obj) {
			        	var vm=this;
			        	vm.articleList=[];
			        	var loadding = top.layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
			            jbscAPI.queryArticlePcList(obj).then(function(res){
			            	top.layer.close(loadding);
				            if (res.status === 200) {
				            	console.log(res)
				                vm.articleList = res.data.aaData
				                vm.allRecords = res.data.iTotalRecords
				                vm.allPage = Math.ceil(res.data.iTotalRecords / 10)
				            }
			            })
			               
			        },
			        pushArticleList:function(obj) {
			        	var vm=this;
			        	var loadding = top.layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
			            jbscAPI.pushArticleList(obj).then(function(res){
			            	top.layer.close(loadding);
				            if (res.status === 200) {
				                vm.articleList = res.data.aaData
				                vm.allRecords = res.data.iTotalRecords
				                vm.allPage = Math.ceil(res.data.iTotalRecords / 10)
				            }
			            })
			                
			        },
			        selectTit:function(index) {
			            this.judgeIndex = index
			            // 数据初始化
			            document.getElementById('setCon').scrollTop = 0
			            this.page = 1
			            this.selectObj.iDisplayStart = 0
			            this.firstLevelCategoryId = null
			            this.secondLevelCategoryId = null
			            this.articleTitle = null
			            this.levelTit1 = '请选择'
			            this.levelTit2 = '请选择'
			            if (index === 0) {
			                this.selectObj.isAuthentication = 1
			                this.selectObj.isMyArticle = false
			            } else if (index === 1) {
			                this.selectObj.isAuthentication = null
			                this.selectObj.isMyArticle = true
			            }
			            this.search()
			        },
			        judgeLevel:function(num) {
			            if (num === 1) {
			                this.isShowLevel1 = !this.isShowLevel1
			            } else {
			                this.isShowLevel2 = !this.isShowLevel2
			            }
			        },
			        selectLi:function(num, data) {
			            if (num === 1) {
			                this.isShowLevel1 = false
			                this.levelTit1 = data.categoryname
			                this.firstLevelCategoryId = data.categoryid
			                this.levelTit2 = '请选择'
			                this.secondLevelCategoryId = null
			                this.getJkEduArticleLevel(2, data.categoryid)
			            } else {
			                this.isShowLevel2 = false
			                this.levelTit2 = data.categoryname
			                this.secondLevelCategoryId = data.categoryid
			            }
			        },
			        search:function() {
			            var vm = this
			            if (this.judgeIndex === 2) {
			                this.pushObj.firstLevelCategoryId = this.firstLevelCategoryId
			                this.pushObj.secondLevelCategoryId = this.secondLevelCategoryId
			                this.pushObj.articleTitle = this.articleTitle
			                this.pushArticleList(vm.pushObj)
			            } else {
			                this.selectObj.firstLevelCategoryId = this.firstLevelCategoryId
			                this.selectObj.secondLevelCategoryId = this.secondLevelCategoryId
			                this.selectObj.articleTitle = this.articleTitle
			                this.queryArticlePcList(vm.selectObj)
			            }
			        },
			        setPage: function(key) {
			            var vm = this
			            if (+key && +key > 0 && +key <= this.allPage) {
			                this.page = +key
			                if (this.judgeIndex === 2) {
			                    this.pushObj.iDisplayStart = (this.page - 1) * 10
			                    this.pushArticleList(vm.pushObj)
			                } else {
			                    this.selectObj.iDisplayStart = (this.page - 1) * 10
			                    this.queryArticlePcList(vm.selectObj)
			                }
			            } else {
			               console.log('无效的页数跳转！')
			            }
			        },
			        send:function(data) {
			            var sendData = {
			                articleId: data.articleid || data.articleId,
			                patient: httpData['code'],
			                leaveWords: '',
			                currentUserRole: currentUserRole,
			                currentUserRoleLevel: currentUserRoleLevel,
			                sendType: roleType
			            }
			            this.doctorSendArticleToPatients(sendData)
			        },
			        doctorSendArticleToPatients:function(obj) {
			        	var vm=this
			        	var loadding = top.layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
			            jbscAPI.doctorSendArticleToPatients(obj).then(function(res){
			            	top.layer.close(loadding);
			            	if(res.status==10000){
			            		console.log(vm.isReha)
			            		if(vm.isReha){
			            			vm.saveRehabilitationOperateRecord(obj.articleId);
			            		}else{			            			
			            			vm.updataHeathStatus();
			            		}
			            	}else{			            		
			            		top.layer.msg(res.message, {icon: 1});
			            	}
			            })   
			        },
			        saveRehabilitationOperateRecord:function(id){
			        	var vm=this;
			        	var userInfo = JSON.parse(window.localStorage.getItem(httpRequest.agentName)); 
			        	var params={
			        		rehabilitationDetailId:vm.planId,
							node:null,
							patientCode:httpData['code'],
							doctorCode:userInfo.uid,
							relationRecordType:3,
							relationRecordCode:id,
							relationRecordImg:null,
							status:0
			        	}
			        	rehaAPI.saveRehabilitationOperateRecord({dataJson:JSON.stringify(params)}).then(function(res){
			        		var icon=5;
			        		if(res.status==200){//更新父窗体的状态
			        			icon=1;
		        				var index = parent.layer && parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
								parent.layer && parent.layer.close(index)
			        		}
			        		top.layer.msg(res.msg, {icon: icon});
			        	})
			        	
			        },
				    updataHeathStatus:function(){
				    	var obj={
				    		code:this.resultCode.toString()
				    	};
				    	jbscAPI.updateAfterEducate(obj).then(function(res){
				    		var icon=5;
				    		var msg=''
				    		if(res.status==200){
								msg='发送成功';				    			
				    			icon=1;
				    		}
				            top.layer.msg(msg || res.msg, {icon: icon});
			            })   
				    }
			    }
    })
        </script>
	</body>
</html>
