<template>
	<fullscreen :fullscreen.sync="fullscreen" class="container">
		<div class="container-box">
			<toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
			<div class="search">
				<mySearch :searchList="searchList" @searchInfo="searchInfo"></mySearch>
				<div>
					<el-button class="btn-check" size="medium" type="primary" @click="dialogCheck(5)">合同信息管理
					</el-button>
					<el-button class="btn-check" size="medium" type="primary" @click="dialogCheck(6)">添加
					</el-button>
				</div>
			</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="ledgerName" label="工单名称">
					</el-table-column>
					<el-table-column prop="opTime" label="创建时间">
					</el-table-column>
					<el-table-column prop="stsDesc" label="状态">
					</el-table-column>
					<el-table-column label="操作" width="160px" align="center">
						<template slot-scope="scope">
							<span style="margin:0 5px;">
								<el-button size="mini" type="primary" @click="dialogCheck(1,scope.row)">查看</el-button>
							</span>
							<span style="margin:0 5px;" v-if="scope.row.opNo == userInfo.loginNo">
								<el-button v-if="scope.row.sts == 3" size="mini" type="primary" @click="dialogCli(6,scope.row)">归档</el-button>
								<el-button v-if="scope.row.sts == 0 || scope.row.sts == 2" size="mini" type="primary" @click="dialogCheck(4,scope.row)">修改</el-button>
								<el-button v-if="scope.row.sts == 0 || scope.row.sts == 2" size="mini" type="danger" @click="delLine(scope.row)">删除</el-button>
							</span>
							<span style="margin:0 5px;" v-if="scope.row.secNo == userInfo.loginNo">
								<el-button v-if="scope.row.sts == 1" size="mini" type="danger" @click="dialogCheck(2,scope.row)">审核</el-button>
							</span>
						</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;">
					<el-form-item class="info-line online">
						<span>台账名称</span>
						<el-input v-model="infolist.ledgerName" :disabled="disableStatus"></el-input>
					</el-form-item>
					<div class="tit">基本信息</div>
					<div class="info-line">
						<el-form-item>
							<span>支撑方名称</span>
							<el-input v-model="infolist.factoryName" :disabled="disableStatus" placeholder="支撑方名称">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>采购时段</span>
							<el-date-picker v-model="infolist.purchasePeriod" type="daterange" placeholder="采购时段"
								:disabled="disableStatus" style="display: inline-flex;width: calc(100% - 120px);">
							</el-date-picker>
						</el-form-item>
						<el-form-item>
							<span>协议编号</span>
							<el-input v-model="infolist.treatyNo" :disabled="disableStatus" placeholder="协议编号">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>协议名称</span>
							<el-select :popper-append-to-body="false" clearable v-model="infolist.contractName" placeholder="协议名称" @change="choContra">
							    <el-option v-for="items in suppOpt" :key="items.id" :label="items.contractName"
							        :value="items.id">
							    </el-option>
							</el-select>
						</el-form-item>
						<el-form-item>
							<span>协议时段</span>
							<el-date-picker v-model="infolist.treaTime" type="daterange" placeholder="协议时段"
								:disabled="disableStatus" style="display: inline-flex;width: calc(100% - 120px);">
							</el-date-picker>
						</el-form-item>
						<el-form-item>
							<span>框架金额</span>
							<el-input v-model="infolist.frameMoney" :disabled="disableStatus" placeholder="框架金额">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>人天单价</span>
							<el-input v-model="infolist.unitPrice" :disabled="disableStatus" placeholder="人天单价">
							</el-input>
						</el-form-item>
					</div>
					<div style="padding-left: 100px">
						<myUpload @uploadBack="uploadBack1" :fileInfo="fileInfo1" :fileList="fileInfo1.fileList">
						</myUpload>
					</div>
					<div style="padding: 0 20px 0 100px;margin-bottom: 20px;">
						<uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown>
					</div>

					<div class="tit" style="margin-top: 20px;">工作量核定信息</div>
					<div class="info-line">
						<el-form-item>
							<span>评审工单名称</span>
							<el-input v-model="infolist.workName" :disabled="disableStatus" placeholder="评审工单名称">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>评审工单编号</span>
							<el-input v-model="infolist.workNo" :disabled="disableStatus" placeholder="评审工单编号">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>评审提交时间</span>
							<el-date-picker v-model="infolist.workSubTime" type="date" placeholder="评审提交时间"
								:disabled="disableStatus">
							</el-date-picker>
						</el-form-item>
						<el-form-item>
							<span>结果反馈时间</span>
							<el-date-picker v-model="infolist.workFeedTime" type="date" placeholder="结果反馈时间"
								:disabled="disableStatus">
							</el-date-picker>
						</el-form-item>
						<el-form-item>
							<span>报审量(人/天)</span>
							<el-input v-model="infolist.workAmount" :disabled="disableStatus" placeholder="报审量(人/天)">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>核减(人/天)</span>
							<el-input v-model="infolist.workCheck" :disabled="disableStatus" placeholder="核减(人/天)">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>有效(人/天)</span>
							<el-input v-model="infolist.workValid" :disabled="disableStatus" placeholder="有效(人/天)">
							</el-input>
						</el-form-item>
					</div>
					<div style="padding-left: 100px">
						<myUpload @uploadBack="uploadBack2" :fileInfo="fileInfo2" :fileList="fileInfo2.fileList">
						</myUpload>
					</div>
					<!-- <div style="padding: 0 20px 0 100px;margin-bottom: 20px;">
						<uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown>
					</div> -->

					<div class="tit" style="margin-top: 20px;">服务考核信息</div>
					<div class="info-line">
						<el-form-item>
							<span>会议纪要名称</span>
							<el-input v-model="infolist.serveName" :disabled="disableStatus" placeholder="会议纪要名称">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>会议纪要编号</span>
							<el-input v-model="infolist.serveNo" :disabled="disableStatus" placeholder="会议纪要编号">
							</el-input>
						</el-form-item>
					</div>
					<el-form-item class="info-line mouth">
						<span>服务评分</span>
						<el-input v-model="serveScore[0]" :disabled="disableStatus" placeholder="月份">
						</el-input>
						月
						<el-input v-model="serveScore[1]" :disabled="disableStatus"  style="margin-right:30px">
						</el-input>
						<el-input v-model="serveScore[2]" :disabled="disableStatus" placeholder="月份">
						</el-input>
						月
						<el-input v-model="serveScore[3]" :disabled="disableStatus"  style="margin-right:30px">
						</el-input>
						<el-input v-model="serveScore[4]" :disabled="disableStatus" placeholder="月份">
						</el-input>
						月
						<el-input v-model="serveScore[5]" :disabled="disableStatus"  style="margin-right:30px">
						</el-input>
					</el-form-item>
					<div class="info-line">
						<el-form-item>
							<span>平均得分</span>
							<el-input v-model="infolist.serveAveScore" :disabled="disableStatus" placeholder="平均得分">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>审批人员</span>
							<el-input v-model="infolist.serveAuditName" :disabled="disableStatus" placeholder="审批人员">
							</el-input>
						</el-form-item>
					</div>
					<div style="padding-left: 100px">
						<myUpload @uploadBack="uploadBack3" :fileInfo="fileInfo3" :fileList="fileInfo3.fileList">
						</myUpload>
					</div>
					<!-- <div style="padding: 0 20px 0 100px;margin-bottom: 20px;">
						<uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown>
					</div> -->

					<div class="tit" style="margin-top: 20px;">补充协议信息</div>
					<div class="info-line">
						<el-form-item>
							<span>协议名称</span>
							<el-input v-model="infolist.dealName" :disabled="disableStatus" placeholder="协议名称">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>签署时间</span>
							<el-date-picker v-model="infolist.dealTime" type="date" placeholder="签署时间"
								:disabled="disableStatus">
							</el-date-picker>
						</el-form-item>
						<el-form-item>
							<span>协议编号</span>
							<el-input v-model="infolist.dealNo" :disabled="disableStatus" placeholder="协议编号">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>支付金额</span>
							<el-input v-model="infolist.dealPay" :disabled="disableStatus" placeholder="支付金额">
							</el-input>
						</el-form-item>
						<el-form-item>
							<span>剩余预算</span>
							<el-input v-model="infolist.dealSurplus" :disabled="disableStatus" placeholder="剩余预算">
							</el-input>
						</el-form-item>
					</div>
					<div style="padding-left: 100px">
						<myUpload @uploadBack="uploadBack4" :fileInfo="fileInfo4" :fileList="fileInfo4.fileList">
						</myUpload>
					</div>
					<!-- <div style="padding: 0 20px 0 100px;margin-bottom: 20px;">
						<uploadDown :datalist="datalist" :dialogStatus="uploadstatus"></uploadDown>
					</div> -->

				</el-form>

				<div slot="footer" class="dialog-footer myfooter">
					<el-button type="primary" @click="dialogCli(2)" v-if="titname === '审核'">通 过
					</el-button>
					<el-button type="primary" @click="dialogCli(3)" v-if="titname === '审核'">打 回
					</el-button>
					<el-button type="primary" @click="dialogCli(4)" v-if="titname === '修改'||titname === '添加'">发 布
					</el-button>
					<el-button type="primary" @click="dialogCli(5)" v-if="titname === '修改'||titname === '添加'">草 稿
					</el-button>
					<el-button @click="dialogCli(1)" v-if="titname === '查看'">确 定</el-button>
					<el-button @click="dialogCli(1)">取 消</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.vue";
	import uploadDown from "../../../components/uploadDown.vue";
	import deptTreeOnly from "../../../components/deptTreeOnly.vue"

	export default {
		components: {
			mySearch,
			myMessage,
			toolList,
			myUpload,
			uploadDown,
			deptTreeOnly
		},
		data() {
			return {
				searchList: [{
					type: 'input',
					tit: '合同名称',
					value: '',
					width: '24%',
				}, {
					type: 'input',
					tit: '台账名称',
					value: '',
					width: '24%',
				}, {
					type: 'date',
					tit: '开始时间',
					value: '',
					width: '24%',
				}, {
					type: 'date',
					tit: '结束时间',
					value: '',
					width: '24%',
				}, ],
				tooltit: '服务质量考核及结算审批',
				fullscreen: false,
				total: 0,
				pageSize: 1,
				tableData: [],
				dialogStatus: false,
				disableStatus: false,
				titname: '',
				infolist: {},
				userInfo: {},
				params: {},
				centerDialogVisible: false,
				messTit: '',
				delid: '',
				loading: false,
				loadinged: false,
				attList1: [],
				attList2: [],
				attList3: [],
				attList4: [],
				fileInfo1: {
					url: '/market/cmkAttachInfo/upload?uploadType=area1',
					fileList: []
				},
				fileInfo2: {
					url: '/market/cmkAttachInfo/upload?uploadType=area2',
					fileList: []
				},
				fileInfo3: {
					url: '/market/cmkAttachInfo/upload?uploadType=area3',
					fileList: []
				},
				fileInfo4: {
					url: '/market/cmkAttachInfo/upload?uploadType=area4',
					fileList: []
				},
				datalist: {
					url: '/market/compatt/downfile',
					type: 1
				},
				uploadstatus: false,//文件状态
				suppOpt: [],
				serveScore: [],
			}
		},
		methods: {
			//选择合同
			choContra(v){
				for (let i = 0; i < this.suppOpt.length; i++) {
					if(this.suppOpt[i].id == v){
						this.infolist.contractName = this.suppOpt[i].contractName;
						this.infolist.treatyNo = this.suppOpt[i].treatyNo;
						this.infolist.factoryName = this.suppOpt[i].factoryName;
						this.infolist.frameMoney = this.suppOpt[i].frameMoney;
						this.infolist.unitPrice = this.suppOpt[i].unitPrice;
						this.infolist.treaTime = [this.suppOpt[i].treaTime.split('~')[0], this.suppOpt[i].treaTime.split('~')[1]];
						this.infolist.purchasePeriod = [this.suppOpt[i].purchasePeriod.split('~')[0], this.suppOpt[i].purchasePeriod.split('~')[1]];
					}
				}
			},
			closedia() {
				this.infolist = {};
				this.dialogStatus = false;
			},
			//搜索数据
			searchInfo(v) {
				this.params = {};
				v[0] ? this.params.contractName = v[0] : '';
				v[1] ? this.params.ledgerName = v[1] : '';
				v[2] ? this.params.startTime = v[2] : '';
				v[3] ? this.params.endTime = v[3] : '';
				this.getList(this.params, this.pageSize);
			},
			//获取列表
			getList(v, n) {
				this.pageSize = n;
				let _this = this;
				this.loading = true;
				this.tableData = [];
				this.$http({
					url: "/market/cChannelBusi/queryPage",
					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) {
				let _this = this;
				this.dialogStatus = true;
				this.infolist = Object.assign({}, n);
				this.disableStatus = false;
				if (v === 1) {
					this.titname = '查看';
					this.disableStatus = true;
				} else if (v === 2) { //审核
					this.titname = '审核';
				} else if (v === 3) { //归档
					this.titname = '归档';
				} else if (v === 4) { //修改
					this.titname = '修改';
				} else if (v === 6) { //添加
					this.titname = '添加';
				} else if (v == 5) {
					_this.$router.push({
						path: '/contractInfo',
					});
					_this.setabList('合同信息管理', '/contractInfo');
				}
				this.infolist.treaTime = [this.infolist.treaTime.split('~')[0], this.infolist.treaTime.split('~')[1]];
				this.infolist.purchasePeriod = [this.infolist.purchasePeriod.split('~')[0], this.infolist.purchasePeriod.split('~')[1]];
				let serveScore1 = this.infolist.serveScore.split(';')[0];
				let serveScore2 = this.infolist.serveScore.split(';')[1];
				let serveScore3 = this.infolist.serveScore.split(';')[2];
				this.serveScore = [serveScore1.split(',')[0],serveScore1.split(',')[1],serveScore2.split(',')[0],serveScore2.split(',')[1],serveScore3.split(',')[0],serveScore3.split(',')[1]];
				this.infolist.opNo = this.userInfo.loginNo;
				this.infolist.opName = this.userInfo.loginName;
				this.infolist.opTime =  this.$formatDate(new Date(), 'YYYY-MM-DD HH:mm:ss')
			},
			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));
			},
			//添加
			dialogCli(v,n) {
				if (v == 1) {
					this.infolist = {};
					this.dialogStatus = false;
					return
				}
				// 0 草稿;1审核中;2未通过;3通过;4办结
				let info = this.infolist;
				info.attList1 = this.attList1;
				info.attList2 = this.attList2;
				info.attList3 = this.attList3;
				info.attList4 = this.attList4;
				info.workSubTime =  this.$formatDate(info.workSubTime, 'YYYY-MM-DD HH:mm:ss')
				info.dealTime =  this.$formatDate(info.dealTime, 'YYYY-MM-DD HH:mm:ss')
				info.workFeedTime =  this.$formatDate(info.workFeedTime, 'YYYY-MM-DD HH:mm:ss')
				let t1 = this.$formatDate(info.purchasePeriod[0], "YYYY-MM-DD");
				let t2 = this.$formatDate(info.purchasePeriod[1], "YYYY-MM-DD");
				info.purchasePeriod = t1 + '~' + t2;
				let t3 = this.$formatDate(info.treaTime[0], "YYYY-MM-DD");
				let t4 = this.$formatDate(info.treaTime[1], "YYYY-MM-DD");
				info.treaTime = t3+ '~' +t4;
				info.serveScore = this.serveScore[0]+','+this.serveScore[1]+';'+this.serveScore[2]+','+this.serveScore[3]+';'+this.serveScore[4]+','+this.serveScore[5]+';';
				if (v == 2) { //通过
					info.sts = "3";
					info.stsDesc = "通过";
					this.submitInfo("/market/cChannelBusi/update", info);
				}
				if (v == 3) { //打回
					info.sts = "2";
					info.stsDesc = "打回";
					this.submitInfo("/market/cChannelBusi/update", info);
				}
				if (v == 4) { //发布
					info.sts = "1";
					info.stsDesc = "待审核";
					this.$http({
						url: "/sysmgr/csysuserinfo/queryUserListByLoginNoAndDuty",
						method: "post",
						headers: {
							"Content-Type": "application/json",
							"page": '{"pageNo":"' + 1 + '","pageSize":"100"}'
						},
						data: {"duty":"7,12"},
					}).then((res) => {
						if(res.data.length == 0){
							this.$message({
								message: '暂无领导审批，发起失败！',
								type: 'error'
							});
							return
						}
						info.secNo = res.data[0].loginNoStr;
						info.secName = res.data[0].loginNameStr;
						if(info.id){
							this.submitInfo("/market/cChannelBusi/update", info);
						}else{
							this.submitInfo("/market/cChannelBusi/add", info);
						}
					});
				}
				if (v == 5) { //草稿
					info.sts = "0";
					info.stsDesc = "草稿";
					if(info.id){
						this.submitInfo("/market/cChannelBusi/update", info);
					}else{
						this.submitInfo("/market/cChannelBusi/add", info);
					}
				}
				if (v == 6) { //归档
					info.sts = "4";
					info.stsDesc = "归档";
					this.submitInfo("/market/cChannelBusi/update", n);
				}
			},
			submitInfo(u, v) {
				let _this = this;
				this.$refs.infolist.validate(valid => {
					if (valid) {
						this.loadinged = true;
						this.$http({
							url: u,
							method: "post",
							headers: {
								"Content-Type": "application/json",
							},
							data: v,
						}).then((res) => {
							this.loadinged = false;
							if (res.data.result === 1) {
								_this.$message({
									message: res.data.desc,
									type: 'error'
								});
							} else {
								_this.$message({
									message: '成功',
									type: 'success'
								});
								_this.infolist = {};
								_this.dialogStatus = false;
								_this.getList({}, _this.pageSize);
							}

						});
					}
				})
			},
			closeMessage(v) {
				this.centerDialogVisible = false;
				let _this = this;
				if (v === 1) {
					_this.$http({
						url: "/market/cChannelBusi/del",
						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;
			},
			//文件返回值
			uploadBack1(v) {
				this.attList1 = v;
			},
			uploadBack2(v) {
				this.attList2 = v;
			},
			uploadBack3(v) {
				this.attList3 = v;
			},
			uploadBack4(v) {
				this.attList4 = 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);

				this.$http({
					url: "/market/cChannelContract/queryList",
					method: "post",
					headers: {
						"Content-Type": "application/json",
						"page": '{"pageNo":"' + 1 + '","pageSize":"1000"}'
					},
					data: {},
				}).then((res) => {
					this.suppOpt = res.data;
				});

			}
		},
		mounted() {
			this.getList({}, 1);
			this.getUser();
		},
		created() {

		}
	}
</script>
<style scoped lang="scss">
	.tit {
		font-size: 20px;
		margin-bottom: 20px;
	}

	.compListree {
		width: 100% !important;

		span {
			width: 100% !important;
			display: inline-block;
			padding: 10px 0;

			em {
				width: 120px;
				display: inline-block;
				font-style: normal;
			}

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

	.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: 100px;
			display: inline-block;
			text-align: left;

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

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

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

		span {
			vertical-align: top;
		}

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

		.tree {
			width: calc(50% - 60px);
			display: inline-block;
			margin-right: 20px;
			height: 300px;
			overflow-y: scroll;

			.el-icon-error {
				float: right;
				font-size: 20px;
				margin-top: 9px;
				cursor: pointer;
			}
		}

		.treeUser {
			margin: 0;
			border: 1px solid #ddd;

			p {
				background: #f4f4f4;
				padding: 0 20px;
				margin-bottom: 5px;
			}
		}
	}
</style>
