<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>
				<el-button class="btn-check" size="medium" 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="contractName" label="合同名称">
					</el-table-column>
					<el-table-column prop="treatyNo" label="协议编号">
					</el-table-column>
					<el-table-column prop="factoryName" label="厂家名称">
					</el-table-column>
					<el-table-column prop="frameMoney" label="框架金额">
					</el-table-column>
					<el-table-column prop="purchasePeriod" label="采购时段">
					</el-table-column>
					<el-table-column prop="unitPrice" label="人天单价">
					</el-table-column>
					<el-table-column prop="treaTime" label="协议时间">
					</el-table-column>
					<el-table-column label="操作" width="160px" align="center">
						<template slot-scope="scope">
							<el-button size="mini" type="primary" @click="dialogCheck(1,scope.row)">查看</el-button>
							<el-button size="mini" type="primary" @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">
			<div v-loading="loadinged">
				<el-form :model="infolist" ref="infolist" :rules="rules">
					<div class="info-line">
						<el-form-item prop="contractName">
							<span>合同名称</span>
							<el-input v-model="infolist.contractName" placeholder="合同名称" :disabled="disableStatus">
							</el-input>
						</el-form-item>
						<el-form-item prop="treatyNo">
							<span>协议编号</span>
							<el-input v-model="infolist.treatyNo" placeholder="协议编号" :disabled="disableStatus">
							</el-input>
						</el-form-item>
						<el-form-item prop="factoryName">
							<span>厂家名称</span>
							<el-input v-model="infolist.factoryName" placeholder="厂家名称" :disabled="disableStatus">
							</el-input>
						</el-form-item>
						<el-form-item prop="purchasePeriod">
							<span>采购时段</span>
							<el-date-picker v-model="infolist.purchasePeriod" type="daterange" placeholder="协议时间"
								:disabled="disableStatus" style="display: inline-flex;width: calc(100% - 100px);">
							</el-date-picker>
						</el-form-item>
						<el-form-item prop="frameMoney">
							<span>框架金额</span>
							<el-input v-model="infolist.frameMoney" placeholder="框架金额" :disabled="disableStatus">
							</el-input>
						</el-form-item>
						<el-form-item prop="treaTime">
							<span>协议时间</span>
							<el-date-picker v-model="infolist.treaTime" type="daterange" placeholder="协议时间"
								:disabled="disableStatus" style="display: inline-flex;width: calc(100% - 100px);">
							</el-date-picker>
						</el-form-item>
						<el-form-item prop="unitPrice">
							<span>人天单价</span>
							<el-input v-model="infolist.unitPrice" placeholder="采购时段" :disabled="disableStatus">
							</el-input>
						</el-form-item>
					</div>
				</el-form>

				<div slot="footer" class="dialog-footer myfooter">
					<el-button type="primary" @click="dialogCli(2)" v-if="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'

	export default {
		components: {
			mySearch,
			myMessage,
			toolList
		},
		data() {

			return {
				rules: {

				},
				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,

			}
		},
		methods: {
			closedia() {
				this.infolist = {};
				this.dialogStatus = false;
			},
			//搜索数据
			searchInfo(v) {
				this.params = {};
				v[0] ? this.params.name = v[0] : '';
				v[1] ? this.params.buyTypeCode = v[1] : '';
				this.getList(this.params, this.pageSize);
			},
			//获取列表
			getList(v, n) {
				this.pageSize = n;
				let _this = this;
				this.loading = true;
				this.tableData = [];
				this.$http({
					url: "/market/cChannelContract/queryList",
					method: "post",
					headers: {
						"Content-Type": "application/json",
						"page": '{"pageNo":"' + n + '","pageSize":"10"}'
					},
					data: v,
				}).then((res) => {
					this.tableData = res.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;
					return
				}
				let t1 = this.infolist.treaTime.split('~')[0];
				let t2 = this.infolist.treaTime.split('~')[1];
				let t3 = this.infolist.purchasePeriod.split('~')[0];
				let t4 = this.infolist.purchasePeriod.split('~')[1];
				this.infolist.treaTime = [t1,t2];
				this.infolist.purchasePeriod = [t3,t4];
				this.infolist.opNo = this.userInfo.loginNo;
				this.infolist.opName = this.userInfo.loginName;
			},
			//添加
			dialogCli(v) {
				if (v === 1) {
					this.infolist = {};
					this.dialogStatus = false;
					return
				} else {
					if(this.infolist.purchasePeriod){
						let t1 = this.$formatDate(this.infolist.purchasePeriod[0], "YYYY-MM-DD");
						let t2 = this.$formatDate(this.infolist.purchasePeriod[1], "YYYY-MM-DD");
						this.infolist.purchasePeriod = t1 + '~' + t2;
					}
					if(this.infolist.treaTime){
						let t3 = this.$formatDate(this.infolist.treaTime[0], "YYYY-MM-DD");
						let t4 = this.$formatDate(this.infolist.treaTime[1], "YYYY-MM-DD");
						this.infolist.treaTime = t3+ '~' +t4;
					}
					if (this.titname === '添加') {
						this.submitInfo("/market/cChannelContract/add");
					} else if (this.titname === '修改') {
						this.submitInfo("/market/cChannelContract/update", v);
					}
				}
			},
			submitInfo(u) {
				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: this.infolist,
						}).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/cChannelContract/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;
			},
			//文件返回值
			uploadBack(v) {
				console.log(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);
		}
	}
</style>
