<template>
	<fullscreen :fullscreen.sync="fullscreen" class="container">
		<div class="container-box">
			<toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
			<div style="overflow: hidden;">
				<el-button style="float: right;margin-top: 10px;" type="primary" @click="dialogCheck(3)">添加</el-button>
			</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">
					<el-table-column prop="woTitle" label="业务名称">
					</el-table-column>
					<<!-- el-table-column prop="opNo" label="申请工号">
						</el-table-column> -->
						<el-table-column prop="opName" label="申请姓名">
						</el-table-column>
						<el-table-column prop="createTime" label="申请时间">
						</el-table-column>
						<el-table-column prop="stsDesc" label="状态">
						</el-table-column>
						<el-table-column label="操作" width="120px" align="center">
							<template slot-scope="scope">
								<el-button size="mini" type="primary" @click="dialogCheck(1,scope.row)">查看</el-button>
								<el-button size="mini" type="danger" v-if="scope.row.sts != 1"
									@click="dialogCheck(2,scope.row)">处理</el-button>
								<!-- <el-button size="mini" type="danger" @click="delLine(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>

		<el-dialog :title="titname" :visible.sync="dialogStatus" width="50%" :destroy-on-close="true"
			:modal-append-to-body="false" :close-on-click-modal="false" :before-close="closedia" :fullscreen="true">
			<div v-loading="loadinged">
				<el-form :model="infolist" ref="infolist" style="height: calc(100vh - 180px);overflow-y: scroll;">

					<div class="info-line">
						<el-form-item>
							<span>文件名称</span>
							<el-input v-model="infoApply.tit" placeholder="文件名称" :disabled="mydisable"></el-input>
						</el-form-item>
						<el-form-item>
							<span>信息类型</span>
							<el-input v-model="infoApply.xxlx" placeholder="信息类型" :disabled="mydisable"></el-input>
						</el-form-item>
						<el-form-item>
							<span>项目分类</span>
							<el-input v-model="infoApply.xmfl" placeholder="项目分类" :disabled="mydisable"></el-input>
						</el-form-item>
						<el-form-item>
							<span>发送时间</span>
							<el-date-picker style="display: inline-flex;width: calc(100% - 100px);" :disabled="mydisable"
								v-model="infoApply.fssj" type="daterange" placeholder="发送时间">
							</el-date-picker>
						</el-form-item>
						<el-form-item>
							<span>公务卡</span>
							<el-input v-model="infoApply.gwk" placeholder="是否已剔除公务卡" :disabled="mydisable">
							</el-input>
						</el-form-item>
					</div>
					<el-form-item class="info-line online">
						<span>背景说明</span>
						<el-input v-model="infoApply.bjsm" placeholder="背景说明" type="textarea" :rows="3" :disabled="mydisable">
						</el-input>
					</el-form-item>
					<el-form-item class="info-line online">
						<span>文件内容</span>
						<el-input v-model="infoApply.wjnr" placeholder="补充说明" type="textarea" :rows="3" :disabled="mydisable">
						</el-input>
					</el-form-item>
					<div style="padding:0 20px 0 100px;margin-bottom: 20px;" v-if="mydisable">
						<uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown>
					</div>
					<div style="padding-left: 80px" v-if="!mydisable">
						<myUpload @uploadBack="uploadBack" :fileInfo="fileInfo" :fileList="fileInfo.fileList">
						</myUpload>
					</div>
					<el-form-item class="info-line online" v-if="mydisable">
						<span>审批说明</span>
						<el-input v-model="infolist.remark" placeholder="审批说明" type="textarea" :rows="3"
							:disabled="disableStatus">
						</el-input>
					</el-form-item>
					<div style="margin-bottom: 20px;padding: 0 20px;">
						<el-table class="com-table" ref="multipleTable" :data="rovaList" tooltip-effect="dark" size="small"
							border style="width: 100%">
							<el-table-column prop="taskId" label="编号">
							</el-table-column>
							<el-table-column prop="taskName" label="环节">
							</el-table-column>
							<el-table-column prop="assigneeName" label="处理人">
							</el-table-column>
							<el-table-column prop="assigneeNo" label="处理人工号">
							</el-table-column>
							<el-table-column prop="opTime" label="处理时间">
							</el-table-column>
							<el-table-column prop="remark" label="备注">
							</el-table-column>
						</el-table>
					</div>
				</el-form>
				<div slot="footer" class="dialog-footer myfooter" v-if="mydisable">
					<el-button v-if="!disableStatus && vision != '在线公司操作'" type="primary" @click="dialogCli(2)">同 意
					</el-button>
					<el-button v-if="!disableStatus && vision != '在线公司操作'" type="primary" @click="dialogCli(1)">驳 回
					</el-button>
					<el-button v-if="disableStatus" @click="dialogCli(3)">确 定</el-button>
					<el-button @click="dialogCli(3)">取 消</el-button>
				</div>
				<div slot="footer" class="dialog-footer myfooter" v-if="!mydisable">
					<el-button v-if="!disableStatus && vision != '在线公司操作'" type="primary" @click="dialogCli(2)">发 起
					</el-button>
					<el-button @click="dialogCli(3)">取 消</el-button>
				</div>
			</div>
		</el-dialog>

		<myMessage :messTit='messTit' @closeMessage="closeMessage" :centerDialogVisible="centerDialogVisible"
			v-if="centerDialogVisible"></myMessage>
	</fullscreen>

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

	export default {
		components: {
			mySearch,
			myMessage,
			toolList,
			myUpload,
			uploadDown
		},
		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,
				fileInfo: {
				    limit: 5,
				    url: '/bpm/api/upload',
				    fileList: []
				},
				infoApply: {},
				rovaList: [],
				vision: '',
				datalist: {
					url: '/bpm/api/download',
					type: 1
				},
				uploadstatus: false,
				rovaList:[],
				mydisable:false,
				opname:'',
				opno:'',
				attList:[]
			}
		},
		methods: {
			closedia() {
				this.infolist = {};
				this.dialogStatus = false;
			},
			//搜索数据
			searchInfo(v) {
				this.params = {};
				v[0] ? this.params.tit = v[0] : '';
				this.getList(this.params, this.pageSize);
			},
			//获取列表
			getList(v, n) {
				this.pageSize = n;
				let _this = this;
				this.loading = true;
				v.procName = "营销类短信群发";
				this.$http({
					url: "/bpm/api/queryToDoAndFinishTaskList",
					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);
				this.mydisable = true;
				if (v === 1) {
					this.titname = '查看';
					this.disableStatus = true;
				} else if (v === 2) {
					this.titname = '修改';
					this.disableStatus = false;
					if(n.opName == this.userInfo.loginName){
						this.mydisable = false;
					}
				} else if (v === 3) {
					this.$router.push({
						path: '/groupAdd',
					});
					this.setabList('营销类短信群发申请', '/groupAdd');
					return
				}
				this.$http({
					url: '/bpm/api/taskInit',
					method: "post",
					headers: {
						"Content-Type": "application/json",
					},
					data: {
						woNo: n.woNo
					},
				}).then((res) => {
					// this.infolist = Object.assign({}, res.data);
					this.opname = res.data.opName;
					this.opno = res.data.opNo;
					this.infoApply = JSON.parse(res.data.params.terminalRes);
					if (res.data.taskList[res.data.taskList.length - 1].taskName == '需求审批') {
						this.vision = '需求审批';
					} else if (res.data.taskList[res.data.taskList.length - 1].taskName == '在线公司操作') {
						this.vision = '在线公司操作';
					} else {
						this.vision = '';
					}
					this.datalist.attList = JSON.parse(res.data.params.attList);
					this.attList = [];
					this.fileInfo.fileList = [];
					this.datalist.attList.forEach(item => {
						item.id = item.attchFileId;
					    this.fileInfo.fileList.push({
					        name: item.fileName,
					        url: '',
					        id: item.id,
							attchFileId:item.attchFileId,
					        fileName: item.fileName
					    });
					    this.attList.push({
					        name: item.fileName,
					        url: '',
					        id: item.id,
							attchFileId:item.attchFileId,
					        fileName: item.fileName
					    });
					})
					this.rovaList = res.data.taskList;
					this.uploadstatus = true;
				});
			},
			//添加
			dialogCli(v) {
				this.dialogStatus = false;
				if (v === 3) {
					return
				}
				let _this = this;
				this.infolist.opTime = _this.$formatDate(new Date(), "YYYY-MM-DD")
				this.infolist.opNo = this.userInfo.loginNo;
				this.infolist.opName = this.userInfo.loginName;
				if (v === 1) {
					let params = {
						dealType: '1',
						dealTypeDesc: '打回',
						procId: this.infolist.procId,
						procVersion: this.infolist.procVersion,
						remark: this.infolist.remark,
						stepId: this.infolist.stepId,
						taskId: this.infolist.taskId,
						taskName: this.infolist.taskName,
						opName: this.infolist.opName,
						opNo: this.infolist.opNo,
						opTime: this.infolist.opTime,
						params: {
							procExeCondiVal: '不同意',
							terminalRes: JSON.stringify(this.infoApply),
							assigneeNo:this.opno,
							assigneeName:this.opname,
						},
						woNo: this.infolist.woNo,
					}
					this.submitInfo("/bpm/api/submitTask", params);
				} else if (v === 2) {
					let param = {
						dealType: '0',
						dealTypeDesc: '提交',
						procId: this.infolist.procId,
						procVersion: this.infolist.procVersion,
						remark: this.infolist.remark,
						stepId: this.infolist.stepId,
						taskId: this.infolist.taskId,
						taskName: this.infolist.taskName,
						opName: this.infolist.opName,
						opNo: this.infolist.opNo,
						opTime: this.infolist.opTime,
						params: {
							terminalRes: JSON.stringify(this.infoApply)
						},
						woNo: this.infolist.woNo,
					}
					if (this.vision == '需求审批') {
						param.params.assigneeNo = this.infoApply.secNo;
						param.params.assigneeName = this.infoApply.secName;
					}
					if (!this.mydisable) {
						let attList = [];
						for (let i = 0; i < this.attList.length; i++) {
						    attList.push({
						        id: this.attList[i].id,
						        fileCode: this.attList[i].fileCode,
						        fileName: this.attList[i].fileName,
						        opName: this.attList[i].opName,
						        opNo: this.attList[i].opNo,
						        opTime: this.attList[i].opTime,
						        woNo: this.infolist.woNo,
						        attchFileId: this.attList[i].attchFileId,
						    });
						}
						param.params.attList = JSON.stringify(attList)
					}
					this.submitInfo("/bpm/api/submitTask", param);
				}
			},
			submitInfo(u, v) {
				let _this = this;
				this.$http({
					url: u,
					method: "post",
					headers: {
						"Content-Type": "application/json",
					},
					data: v,
				}).then((res) => {
					if (res.data.result === 1) {
						_this.$message({
							message: res.data.desc,
							type: 'error'
						});
					} else {
						_this.$message({
							message: '成功',
							type: 'success'
						});
						_this.getList(this.params, this.pageSize);
					}

				});
			},

			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));
			},
			closeMessage(v) {
				this.centerDialogVisible = false;
				let _this = this;
				if (v === 1) {
					_this.$http({
						url: "/bpm/api/deleteBpmPrePlugin",
						method: "post",
						headers: {
							"Content-Type": "application/json",
						},
						data: {
							id: this.delid
						},
					}).then((res) => {
						if (res.data.result === 1) {
							_this.$message({
								message: res.data.desc,
								type: 'error'
							});
						} else {
							_this.$message({
								message: '删除成功',
								type: 'success'
							});
							_this.getList(this.params, this.pageSize);
						}
					});
				}
			},
			//删除
			delLine(v) {
				this.centerDialogVisible = true;
				this.messTit = '即将删除此条数据, 是否删除?';
				this.delid = v.id;
			},
			//文件返回值
			uploadBack(v) {
				this.attList = v;
			},	
			//功能栏
			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);

			}
		},
		mounted() {
			this.getList({}, 1);
			this.getUser();
		},
		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);
		}
	}

	.adv-type {
		margin-top: 20px;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		// border: 1px solid #ddd;
		border-radius: 5px;
		padding: 20px;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);

		div {
			width: 33%;
			text-align: center;
			height: 80px;
			overflow: hidden;
			min-width: 100px;
			cursor: pointer;
			padding-top: 10px;
			margin: 10px 0;
		}

		div:hover {
			background: #CFE8FC;
			border-radius: 5px;
		}

		span {
			width: 100%;
			display: inline-block;
			height: 40px;

			// line-height: 40px;
			i {
				color: #0074D9;
				font-size: 36px;
			}
		}
	}
</style>
