<template>
	<view>
		<view class="head">

			<view class="nameImage">
				<image class="image1" src="../../../static/项目管理/图像@2x.png"></image>
				<text class="name">{{formData.name}}</text>

				<view class="tianchong"></view>


				<view class="bottom">
					<view class="contact">
						<view class="con">

							<image class="image2" src="../../../static/项目管理/联系人@2x.png"></image>
							<text class="con1">联系人</text>
						</view>

						<text class="contact1">{{formData.customer}} {{formData.customerTel}}</text>
					</view>
					<view class="address">
						<view class="add">
							<image class="image3" src="../../../static/项目管理/地址@2x.png"></image>
							<text class="add1">地 址</text>
						</view>
						<text class="address1">{{formData.province}}{{formData.city}}{{formData.address}}</text>
					</view>
				</view>
			</view>
		</view>

		<view class="xiaban"></view>
		<view class="mid">
			<text class="gateway" style="font-size: 40rpx;font-weight: 550;">网关列表</text>
			<view class="tiao"></view>
		</view>

		<view class="gatewayList" v-for="item in gateways" :key="item.code">

			<view class="col">
				<view class="switch">
					<switch :checked="gatewayData.useStatus" color="#007AFE" @change="switchChange" />
				</view>
				<view class="list" @tap="showDevice" :data-code="item.code">设备列表 ></view>
			</view>


			<text class="title">{{item.number}}</text>

			<view class="content">
				<text>网关IP：{{item.ip}}</text>
				<text>点位名称：{{item.location}}</text>
			</view>
		</view>

		<view class="uni-btn-v">
			<button form-type="submit" class="button1" @tap="del">删除项目</button>
			<button form-type="submit" class="button2" @tap="showEdit" :data-code="formData.code">修改项目信息</button>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				gateways: [],

				formData: {
					code: '',
					name: '',
					number: '',
					description: '',
					customer: '',
					customerTel: '',
					address: '',
					province: '',
					city: '',
					operatorCode: '',
					operatorNumber: ''
				},

				gatewayData: {
					code: '',
					ip: '',
					location: '',
					useStatus: '1',
					number: '',
					operatorCode: '',
					operatorNumber: '',
					projectCode: '',
					projectNumber: '',
				}
			}
		},
		onLoad(e) {
			console.log(e);

			uni.request({
				url: 'http://127.0.0.1:9999/project/detail?code=' + e.code,
				method: 'GET',
				data: {},
				success: res => {
					this.formData = res.data.data.project;
					console.log(this.formData);
				},

			});

			uni.request({
				url: 'http://127.0.0.1:9999/gateway/list?projectCode=' + e.code,
				method: 'GET',
				data: {},
				success: res => {
					this.gateways = res.data.data.gateways;
					console.log(this.gateways);
				},

			});

			uni.$on('flush', () => {
				uni.request({
					url: 'http://127.0.0.1:9999/project/detail?code=' + e.code,
					method: 'GET',
					data: {},
					success: res => {
						this.formData = res.data.data.project;
						console.log(this.formData);
					},

				});

				uni.request({
					url: 'http://127.0.0.1:9999/gateway/list?projectCode=' + e.code,
					method: 'GET',
					data: {},
					success: res => {
						this.gateways = res.data.data.gateways;
						console.log(this.gateways);
					},

				});
			})
		},
		methods: {
			switchChange(e) {
				console.log(e.detail.value);

				if (e.detail.value == true) {
				} else {
				}
			},

			showEdit(e) {
				console.log(e);
				var code = e.currentTarget.dataset.code;

				uni.navigateTo({
					url: '/pages/project/projectEdit/projectEdit?code=' + code,
				});
			},

			async del(e) {
				let vm = this;
				let url = uni.$api.project.delete;
				let data = {
					code: this.formData.code,
				}

				uni.showModal({
					title: '提示',
					content: '确认删除此信息？',
					async success(e) {
						console.log(e);
						if (e.confirm) {
							// 执行确认后的操作
							let res = await uni.$http.get(url, data)

							//让返回的页面刷新
							uni.$emit('flush');

							uni.switchTab({
								url: '/pages/project/project'
							})

						} else {

						}
					},
				})
			},

			showDevice(e) {
				console.log(e);
				var code = e.currentTarget.dataset.code;

				uni.navigateTo({
					url: '/pages/device/device?code=' + code,
				});

			}
		}
	}
</script>

<style>
	.list {
		font-size: 28rpx;
		color: #007AFF;
		margin-right: 20rpx;
		margin-top: 85rpx;
	}

	.switch {
		transform: scale(0.6);
		margin-left: 30rpx;
	}

	.col {
		float: right;
	}

	.uni-btn-v {
		display: flex;
		flex-direction: row;
		margin-top: 100rpx;
	}

	.button1 {
		width: 315rpx;
		height: 76rpx;
		margin-top: 30rpx;
		background-color: #E02021;
		color: white;
		font-size: unset;
	}

	.button2 {
		width: 315rpx;
		height: 76rpx;
		margin-top: 30rpx;
		background-color: #007AFF;
		color: white;
		font-size: unset;
	}

	.gatewayList {
		width: 702rpx;
		height: 230rpx;
		background-color: white;
		margin-top: 30rpx;
		margin-left: 24rpx;
		border-radius: 10rpx;
		padding-top: 30rpx;
	}

	.content {
		display: flex;
		flex-direction: column;
		margin-top: 30rpx;
		margin-left: 30rpx;
		line-height: 60rpx;
		color: #444546;
	}

	.title {
		font-size: 36rpx;
		margin-left: 30rpx;
		color: #282828;
		font-weight: 600;
	}

	.mid {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 36rpx;
	}

	.tiao {
		width: 60px;
		height: 3px;
		margin-top: 20rpx;
		background: #007AFF;
	}

	.address1 {
		float: right;
		margin-right: 40rpx;
		margin-top: 40rpx;
	}

	.add1 {
		color: #848586;
		margin-left: 20rpx;
	}

	.add {
		float: left;
		margin-left: 60rpx;
		margin-top: 40rpx;
		display: flex;
		flex-direction: row;
	}

	.contact1 {
		float: right;
		margin-right: 40rpx;
		margin-top: 40rpx;
	}

	.con1 {
		color: #848586;
		margin-left: 20rpx;
		padding-top: 20rpx;
	}

	.con {
		float: left;
		margin-left: 60rpx;
		margin-top: 40rpx;
	}

	.image2 {
		float: left;
		width: 36rpx;
		height: 36rpx;
	}

	.image3 {
		width: 36rpx;
		height: 36rpx;
	}

	.xiaban {
		height: 50rpx;
		width: 702rpx;
		background-color: white;
		margin-left: 24rpx;
		border-bottom-left-radius: 10rpx;
		border-bottom-right-radius: 10rpx;
	}

	.head {
		height: 420rpx;
		background: linear-gradient(180deg, #2A8FFB 0%, #0467FB 100%);
		display: flex;
		justify-content: center;
	}

	.image1 {
		margin-left: 280rpx;
		height: 200rpx;
		width: 140rpx;
		margin-top: 41rpx;
	}

	.name {
		font-size: 36rpx;
		color: white;
		margin-top: 20rpx;
		margin-bottom: ;
	}

	.nameImage {
		display: flex;
		flex-direction: column;
		text-align: center;
	}

	.tianchong {
		width: 702rpx;
		height: 65rpx;
	}

	.bottom {
		width: 702rpx;
		height: 145rpx;
		background-color: white;
		border-top-left-radius: 10rpx;
		border-top-right-radius: 10rpx;
		display: flex;
		flex-direction: column;
		font-size: 26rpx;
	}
</style>
