<template>
	<fullscreen :fullscreen.sync="fullscreen" class="container">
		<div class="container-box">
			<div class="dc">
				<el-button type="primary" style="margin-right: 20px;" @click="outexl">导出</el-button>
				<span style="margin-right: 20px;">共 {{fillCnt}} 条数据</span>
				<span>更新日期:{{lastUpdateTime}}</span>
			</div>
			<div class="tabbox">
				<el-table height="calc(100% - 40px)" class="com-table" ref="multipleTable" :data="tableData"
					tooltip-effect="dark" size="small" border style="width: 100%" v-loading="loading">
					<!-- @selection-change="handleSelectionChange"> -->
					<!-- <el-table-column type="selection" width="55">
					</el-table-column> -->
					<el-table-column prop="regionName" label="区域名称">
                        <template slot-scope="scope">
                            {{scope.row.regionName}}{{scope.row.areaName}}
                        </template>
					</el-table-column>
					<el-table-column prop="regionDutyName" label="负责人">
                        <template slot-scope="scope">
                            {{scope.row.regionDutyName}}{{scope.row.areaDutyName}}
                        </template>
					</el-table-column>
					<el-table-column prop="cnt" label="员工总数">
					</el-table-column>
					<el-table-column label="操作" width="160px" align="center">
						<template slot-scope="scope">
							<el-button size="mini" type="primary" @click="choseperson(scope.row)">查看</el-button>
						</template>
					</el-table-column>
				</el-table>
				<el-pagination class="pageBox" @current-change="currchange" layout="prev, pager, next" background
                    :total="total">
                </el-pagination>
			</div>
		</div>
	</fullscreen>

</template>
<script>
	import mySearch from "../../../components/search.vue";
	import myMessage from "../../../components/myMessage.vue"
	import toolList from '../../../components/toolList'

	export default {
		components: {
			mySearch,
			myMessage,
			toolList
		},
		data() {
			return {
				searchList: [{
					type: 'input',
					tit: '供应商名称',
					value: '',
					width: '98%',
				}],
				tooltit: '人员进度跟踪',
				fullscreen: false,
				total: 0,
				pageSize: 1,
				tableData: [{}],
				dialogStatus: false,
				disableStatus: false,
				titname: '',
				infolist: {},
				userInfo: {},
				params: {},
				centerDialogVisible: false,
				messTit: '',
				delid: '',
				loading: false,
				loadinged: false,
				time: '',
				num: '',
				fillCnt: '',
				lastUpdateTime: '',
                sts:1,
                companyFlag:'',
				// excelCityparam: ""
				memberFamilyBtnShow: "-1"
			}
		},
		methods: {
            outexl(){
                let url = '';
                let paramsf = {};
				if(window.sessionStorage.excelCityparam){
					paramsf.regionName = window.sessionStorage.excelCityparam
				}
                if(this.sts == 1){
                    url = '/market/cMemberWo/excelExportSummaryByProv';
                }else{
                    url = '/market/cMemberWo/excelExportSummaryByArea';
                }
                this.$http({
                    url: url,
                    method: "post",
                    responseType: 'blob',
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: paramsf,
                }).then((response) => {
                    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                        let blob = new Blob([response.data], {
                            type: response.data.type
                        });
                        window.navigator.msSaveOrOpenBlob(blob, 'adv.xlsx');
                    } else {
                        /* 火狐谷歌的文件下载方式 */
                        console.log(response.data.type)
                        var blob = new Blob([response.data])
                        var downloadElement = document.createElement('a')
                        var href = window.URL.createObjectURL(blob);
                        downloadElement.href = href;
                        downloadElement.download = 'adv.xlsx';
                        document.body.appendChild(downloadElement);
                        downloadElement.click();
                        document.body.removeChild(downloadElement);
                        window.URL.revokeObjectURL(href);
                    }
                });
            },
			choseperson(v){
				if(v.showButton){
					window.sessionStorage.memberFamilyBtnShow = v.showButton;
				}
                if(this.companyFlag == 0){
					if(v.regionName == "省公司"){
						 this.$router.push({
                        	path: "/employeeInfo",
                            query:{
                                regionName:v.regionName
                            }
                        });
                        this.setabList("员工信息", "/employeeInfo?regionName="+v.regionName);
						return
					}
					// if(v.areaName == "省公司"){
					// 	this.$router.push({
                    //     	path: "/employeeInfo",
                    //         query:{
                    //             regionName:v.areaName
                    //         }
                    //     });
                    //     this.setabList("员工信息", "/employeeInfo?regionName="+v.areaName);
					// 	return
					// }
                    if(this.sts == 2){
                        this.$router.push({
                        	path: "/employeeInfo",
                            query:{
                                regionName:v.areaName
                            }
                        });
                        this.setabList("员工信息", "/employeeInfo?regionName="+v.areaName);
                        return
                    }
					window.sessionStorage.excelCityparam = v.regionName;
                    this.$http({
                    	url: "/market/cMemberWo/querySummaryByAreaPage",
                    	method: "post",
                    	headers: {
                    		"Content-Type": "application/json",
                    		"page": '{"pageNo":"' + 1 + '","pageSize":"100"}'
                    	},
                    	data: {regionName:v.regionName},
                    }).then((res) => {
                    	this.tableData = res.data.data;
                    	this.total = res.data.totalRecord;
                    	this.loading = false;
                        this.sts = 2;
                    });
					
                }else{
                    this.$router.push({
                    	path: "/employeeInfo?regionName="+v.areaName,
                        query:{
                            regionName:v.areaName
                        }
                    });
					
                    this.setabList("员工信息", "/employeeInfo?regionName="+v.areaName);
                }
			},
			setabList(n, p) {
				let params = {
					children: "",
					name: n,
					rountPath: p,
					target: "_self",
				};
				for (let i = 0; i < this.$store.state.tabList.length; i++) {
					if (this.$store.state.tabList[i].name === params.name) {
						this.$store.state.tabList[i] = params;
					}
				}
				let set = new Set([...this.$store.state.tabList, params]);
				set.add(params);
				this.$store.commit("setDefaultActive", params.rountPath);
				this.$store.commit("setTabList", Array.from(set));
			},
			handleSelectionChange(val) {
				console.log(val) 
			},
			//搜索数据
			searchInfo(v) {
				this.params = {};
				v[0] ? this.params.supplierName = v[0] : '';
				this.getList(this.params, this.pageSize);
			},
			//获取列表
			getList(v, n) {
				this.pageSize = n;
				let _this = this;
				this.loading = true;
				this.tableData = [];
                let url = '';
                if(this.companyFlag == 0){
                    url="/market/cMemberWo/querySummaryByProvPage"
                }else if(this.companyFlag == 1){
                    url="/market/cMemberWo/querySummaryByAreaPage"
                    v.regionName = this.userInfo.cityName
					window.sessionStorage.excelCityparam = this.userInfo.cityName;
					this.sts = 2
                }
				this.$http({
					url: url,
					method: "post",
					headers: {
						"Content-Type": "application/json",
						"page": '{"pageNo":"' + n + '","pageSize":"10"}'
					},
					data: v,
				}).then((res) => {
					this.tableData = res.data.data;
					this.total = res.data.totalRecord;
					this.loading = false;
					
				});
			},
			// 分页
			currchange(v) {
				this.pageSize = v;
				this.getList(this.params, this.pageSize);
			},
			//申请
			dialogCheck(v, n) {
				this.dialogStatus = true;
				this.infolist = Object.assign({}, n);
				if (v === 1) {
					this.titname = '查看';
					this.disableStatus = true;
					return
				} else if (v === 2) {
					this.titname = '修改';
					this.disableStatus = false;
				} else if (v === 3) {
					this.titname = '添加';
					this.disableStatus = false;
				}
				this.infolist.opNo = this.userInfo.loginNo;
				this.infolist.opName = this.userInfo.loginName;
			},
			//功能栏
			iconCli(v) {
				if (v === 1) {
					this.getList(this.params, this.pageSize);
				}
				if (v === 2) {
					this.fullscreen = !this.fullscreen
				}
			},
			getUser() {
				this.userInfo = JSON.parse(window.sessionStorage.userInfo);
                this.$http({
                	url: "/market/cMemberFillDetail/querySummaryInfo",
                	method: "post",
                	headers: {
                		"Content-Type": "application/json",
                	},
                	data: {},
                }).then((res) => {
                    this.fillCnt = res.data.fillCnt;
                    this.lastUpdateTime = res.data.lastUpdateTime;
                });

                this.$http({
                    url: "/sysmgr/csysuserinfo/queryUserInfoByLoginNo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.companyFlag = res.data.companyFlag;
                     this.getList({}, 1);
                });
			}
		},
		mounted() {
			this.getUser();
			window.sessionStorage.memberFamilyBtnShow = this.memberFamilyBtnShow
		},
		created() {

		}
	}
</script>
<style scoped lang="scss">
	.onetab {
		margin-bottom: 20px;
		padding: 0 20px;
	}

	.titbox {
		div {
			float: right;

			i {
				font-size: 22px;
				margin-left: 20px;
				cursor: pointer;
			}
		}
	}

	.tabbox {
		margin-top: 15px;
	}

	.pageBox {
		text-align: right;
		margin-top: 10px;
	}

	.info-line {
		width: 100%;
		display: block;
		padding-left: 20px;

		div {
			width: 50%;
			display: inline-block;
		}

		span {
			width: 80px;
			display: inline-block;
			text-align: left;

			i {
				color: red;
				display: inline-block;
				padding-right: 5px;
			}
		}

		.el-select,
		.el-input {
			width: calc(100% - 100px);
		}
	}

	.online {
		width: 100%;

		.el-select {
			width: calc(100% - 100px);
		}

		span {
			vertical-align: top;
		}

		.el-textarea {
			width: calc(100% - 100px);
		}
	}
</style>
