<template>
<div>
	<div class="query-box appProval">
		<ul>
			<li><span><em>{{$t('system.query_company')}}</em>
					<el-select :disabled="IsParentCompany!=1" v-model="QueryMsg.BranchId" @change="getList()"  >
			            <el-option
			                v-for="item in companyList"
			                :label='item.BName'
			                :value='item.Id'
			                :key='item.Id'>
			            </el-option>
			        </el-select>					
				</span></li>
				<li>
					<!-- <input type="button" class="hollowFixedBtn" :value="$t('pub.searchBtn')" @click="getList()"/> -->
				</li>
		</ul>
	</div>
	<div class="flexOne">
		<div class="approval_title">{{$t('objFill.v101.administrative.chuqinxj')}}(4)</div>
		<div class="approval_list" v-loading='loading'>
			<div class="approval_item" v-for="(item,index) in dataList">
				<img :src="item.Icon" width="86" style="float: left;margin: 17px 20px 0 0;" />
				<div class="approval_desDiv">
					<p class="tit">{{item.Name}}</p>
					<p class="des" v-html="item.describe"></p>
					<p class="tim">{{item.UpdateTime}}</p>
				</div>
				<div class="approval_fwDiv">
					<p>{{$t('objFill.v101.administrative.kejianfanw')}}</p>
					<p class="updateP">{{$t('objFill.v101.administrative.quanbukejian')}}</p>
				</div>
				<div class="approval_doDiv">
					<p>
						<button v-if='item.Status==1'  class="normalBtn" @click="goUrl('ApprovalProcess',item.Id)">{{$t('fnc.spliucheng')}}</button> &nbsp;&nbsp;
						<button v-if='item.Status==1' @click="updateTempStatus(item.Id,item.TemplateType,item.Status)" class="hollowFixedBtn">{{$t('fnc.tingyong')}}</button>
						<button v-if='item.Status==2' @click="updateTempStatus(item.Id,item.TemplateType,item.Status)" class="hollowFixedBtn">{{$t('fnc.qiyong')}}</button>
					</p>
				</div>
			</div>
		</div>

	</div>
</div>
</template>

<script>
	export default {
		data() {
			return {
				loading:true,
				//请求数据
				QueryMsg: {
					BranchId: '-1'
				},
				//返回数据
				dataList: [],
				companyList: [],
				IsParentCompany:2
			}
		},
		methods: {
			getList() {
				let describe = [
          this.$t('objFill.v101.administrative.shiyqjsq')+'<br/>'+this.$t('objFill.v101.administrative.shiyqjsqnr'),
          this.$t('objFill.v101.administrative.shiyyccsq')+'<br/>'+this.$t('objFill.v101.administrative.shiyyccsqnr'),
          this.$t('objFill.v101.administrative.shiywcsq')+'<br/>'+this.$t('objFill.v101.administrative.shiywcsqnr'), 
          this.$t('objFill.v101.administrative.dangygkqqkkbk')+'<br/>'+this.$t('objFill.v101.administrative.dangygkqqkkbknr')]
				this.apipost('WorkFlow_get_GetTemplateList', {BranchId:this.QueryMsg.BranchId}, res => {
					if(res.data.resultCode == 1) {
						this.loading=false;
						this.dataList = res.data.data[0].List;
						this.dataList.forEach((item, index) => {
							item.describe = describe[index]
						})

					}
				}, err => {})
			},
			getCompanyList() {
				let userInfo = this.getLocalStorage();
				let RB_Group_id = userInfo.RB_Group_id;
				let msg = {
					Status: 0,
					is_show: 0,
					RB_Group_Id: RB_Group_id
				}
				this.apipost('admin_get_BranchGetList', msg, res => {
					if(res.data.resultCode == 1) {
						res.data.data.forEach(x => {
							var obj = {
								Id: '',
								BName: ''
							}
							obj.Id = x.Id.toString();
							obj.BName = x.BName;
							this.companyList.push(obj);
						})
					}
				}, err => {})
			},
			updateTempStatus(id, type, status) {
				if(status == 1) {
					this.$confirm(this.$t('objFill.v101.administrative.shifouty')+'?', this.$t('tips.tips'), {
						confirmButtonText: this.$t('pub.sureBtn'),
						cancelButtonText: this.$t('pub.cancelBtn'),
						type: 'warning'
					}).then(() => {
						this.apipost('WorkFlow_post_SetTemplate', {
							Id: id,
							TemplateType: type,
							Status: 2,
							BranchId:this.QueryMsg.BranchId
						}, res => {
							if(res.data.resultCode == 1) {
								this.$message.success(this.$t('objFill.v101.administrative.yijjianty'))
								this.getList()
							} else {
								this.$message.error(this.$t('objFill.chaozuosib'))
							}
						}, err => {})
					}).catch(() => {
						this.$message.info(this.$t('objFill.v101.administrative.yiquxiaoty'))
					});
				}
				if(status == 2) {
					this.$confirm(this.$t('visa.v_shifouqiyong')+'?' , this.$t('tips.tips'), {
						confirmButtonText: this.$t('pub.sureBtn'),
						cancelButtonText: this.$t('pub.cancelBtn'),
						type: 'warning'
					}).then(() => {
						this.apipost('WorkFlow_post_SetTemplate', {
							Id: id,
							TemplateType: type,
							Status: 1,
							BranchId:this.QueryMsg.BranchId
						}, res => {
							if(res.data.resultCode == 1) {
								this.$message.success(this.$t('objFill.v101.administrative.qiyongchengg'))
								this.getList()
							} else {
								this.$message.error(this.$t('objFill.chaozuosib'))
							}
						}, err => {})
					}).catch(() => {
						this.$message.info(this.$t('objFill.v101.administrative.yiquxiaoqy'))

					});
				}
			},
			goUrl (path,id) {
	            this.$router.push({ name: path,query:{"id":id,"Bid":this.QueryMsg.BranchId} }) 
			}
		},
		mounted() {
			let userInfo = this.getLocalStorage();
			this.QueryMsg.BranchId=userInfo.RB_Branch_id.toString();
			this.IsParentCompany=userInfo.IsParentCompany;
			let RefBranchId=this.$route.query.Bid;
			if(RefBranchId!=null&&this.IsParentCompany==1){
				this.QueryMsg.BranchId=RefBranchId.toString();
			}
			this.getCompanyList();
			this.getList()
		}
	}
</script>

<style>

	.approval_title {
		height: 14px;
		line-height: 14px;
		padding-left: 15px;
		border-left: 3px solid #E95252;
		margin: 30px 0;
	}
	
	.appProval .el-input__inner{
		height: 34px!important;
	}
	
	.approval_desDiv {
		float: left;
		width: 450px;
		height: 120px;
		padding: 15px 0;
		border-right: 1px dotted #DCDFE6;
	}
	
	.approval_item {
		height: 160px;
		padding: 20px;
		background: #fff;
		overflow: auto;
		border-radius: 8px;
		margin-bottom: 10px;
	}
	
	.approval_item p.tit {
		font-size: 18px;
		color: #333;
	}
	
	.approval_item p.des {
		font-size: 14px;
		color: #666;
		line-height: 22px;
	}
	
	.approval_item p.tim {
		font-size: 14px;
		color: #999;
		line-height: 22px;
	}
	
	.approval_fwDiv {
		float: left;
		width: 520px;
		height: 120px;
		padding: 50px 0;
		border-right: 1px dotted #DCDFE6;
	}
	
	.approval_fwDiv>p {
		text-align: center;
		font-size: 16px;
		color: #333;
	}
	
	.approval_fwDiv>p.updateP {
		font-size: 14px;
		color: #666;
		line-height: 24px;
	}
	
	.approval_doDiv {
		float: left;
		width: 500px;
	}
	
	.approval_doDiv>p {
		text-align: center;
		line-height: 120px;
	}
</style>