<template>
	<view class="page">
		<navBar :backType="navBarTitle" :title="navBarTitle?navBarTitle:'智能控制系统'" :back="true" color="black"
			background="white" />
		<image class="topImg" :src="picUrl + '/static/other/c2.png'" mode=""></image>

		<view class="cen">
			<image class="water" src="/static/index/water.png" mode=""></image>
			<image class="halfC" src="/static/index/halfCircle_275.png" mode=""></image>
			定制我家的智能控制系统
		</view>

		<view class="parmasBox">
			<view class="con">
				<view class="top">
					<view class="item">
						<view class="name">
							户型
						</view>
						<view class="des">
							{{selHx.value}}
						</view>
					</view>
					<view class="item">
						<view class="name">
							品牌
						</view>
						<view class="des">
							{{selPp.value}}
						</view>
					</view>

					<view class="item">
						<view class="name">
							智能锁
						</view>
						<view class="des">
							{{selSuo.value}}
						</view>
					</view>
					<view class="item">
						<view class="name">
							智能开关
						</view>
						<view class="des">
							{{selMb.value}}
						</view>
					</view>
					<view class="item">
						<view class="name">
							智能窗帘
						</view>
						<view class="des">
							{{selCl.value}}
						</view>
					</view>

					<view class="item">
						<view class="name">
							智能空调
						</view>
						<view class="des">
							{{selKt.value}}
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="parmasBox" v-if="navBarTitle">
			<view class="con">
				<view class="top">
					<view class="item">
						<view class="name">
							收货人
						</view>
						<view class="des">
							{{shareCon.name}}
						</view>
					</view>
					<view class="item">
						<view class="name">
							电话
						</view>
						<view class="des">
							{{shareCon.phone}}
						</view>
					</view>
					<view class="item">
						<view class="name">
							收货地址
						</view>
						<view class="des">
							{{shareCon.address}}
						</view>
					</view>
					<view class="item">
						<view class="name">
							备注
						</view>
						<view class="des">
							{{shareCon.remark}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<image v-if="!navBarTitle" @click="back" src="/static/index/backBtnImg.png" mode="" class="rule_img"></image>
		<view class="bot" v-if="!navBarTitle">
			<!-- <view class="left" @click="showPreviewConfig=true"> -->
			<view class="left" @click="">
				<view class="price">
					￥{{totalPrice.toFixed(2)}}
				</view>
				<image v-if="!showPreviewConfig" src="/static/index/arrDown.png" mode=""
					@click="showPreviewConfig=true"></image>
				<image v-else src="/static/index/arrUp.png" mode="" @click="showPreviewConfig=false"></image>
			</view>
			<button open-type="share" v-if="orderSuc" class="right">
				分享
			</button>

			<view class="right" v-else @click="showFixInfo=true">
				确认配置
			</view>
		</view>


		<u-popup :show="showFixInfo" @close="close" @open="open" round='10'>
			<view class="topBar" style="">
				<view class="left">

				</view>
				<view class="cen">
					信息填写
				</view>
				<view class="close" @click="showFixInfo=false">
					<u-icon name="close"></u-icon>
				</view>
			</view>
			<view class="pupopCon">
				<view class="item">
					<view class="label">
						收货人
					</view>
					<u--input clearable placeholder="请输入收货人" border="surround" v-model="name"
						@change="change"></u--input>
				</view>
				<view class="item">
					<view class="label">
						电话
					</view>
					<u--input clearable placeholder="请输入电话" border="surround" v-model="phone"
						@change="change"></u--input>
				</view>
				<view class="item" style="margin-bottom: 24rpx;height: auto;">
					<view class="label">
						收货地址
					</view>
					<u--textarea v-model="addr" placeholder="请输入收货地址"></u--textarea>
				</view>

				<view class="item" style="margin-bottom: 24rpx;">
					<view class="label">
						备注
					</view>
					<u--input clearable placeholder="请输入备注" border="surround" v-model="remark"
						@change="change"></u--input>
				</view>
				<u-button text="确认下单" color="#333" @click="postOrder"></u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		postOrderReq,

		getOrderDetailReq
	} from '@/api/test/index.js'
	export default {
		components: {

		},
		data() {
			return {
				picUrl: this.$picUrl,

				showFixInfo: false,

				showPreviewConfig: false,

				selHx: null,
				selPp: null,
				selSuo: null,
				selMb: null,
				selCl: null,
				selKt: null,
				totalPrice: null,

				name: '',
				phone: '',
				addr: '',
				remark: '',

				orderId: '',

				pConfig: -1,
				shareCon: null,

				navBarTitle: '',
				orderSuc: false,
			}
		},
		async onLoad(o) {
			// o.orderId = '43c43ced14b312fb69d80cedbd7b23f4'
			if (o.orderId) {
				this.orderId = o.orderId
				this.navBarTitle = '首页'
				console.log('o.orderId', o.orderId);

				let res = await getOrderDetailReq({
					orderId: o.orderId
				})
				if (res.code == 0) {
					console.log('邀请订单详情返回值-智能控制系统: ', res);

					this.shareCon = res.data

					this.selHx = res.data.config.house_type_data
					this.selPp = res.data.config.brand
					this.selSuo = res.data.config.mind_lock
					this.selMb = res.data.config.mind_switch
					this.selCl = res.data.config.mind_curtain
					this.selKt = res.data.config.mind_air_conditioner
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				}
			} else {
				this.selHx = getApp().selHx
				this.selPp = getApp().selPp
				this.selSuo = getApp().selSuo
				this.selMb = getApp().selMb
				this.selCl = getApp().selCl
				this.selKt = getApp().selKt
				this.totalPrice = getApp().totalPrice

				this.pConfig = getApp().pConfig
			}
		},
		onShareAppMessage(params) {
			if (params.from === 'button' || params.from === 'menu') {
				return {
					title: '定制我家的智能控制系统',
					imageUrl: this.picUrl + '/static/other/c2.png',
					path: '/pages/index/aiControlSys_step2/index?orderId=' + this.orderId,
					mpId: this.$appId,
					type: this.$shareType,
				}
			}
		},
		methods: {
			async postOrder() {
				console.log('智控下单参数', {
					address: this.addr,
					phone: this.phone,
					name: this.name,
					remark: this.remark,
					config_id: this.selHx.id + ',' + this.selPp.id + ',' + this.selSuo.id + ',' + this.selMb
						.id + ',' + this.selCl.id + ',' + this.selKt.id,
					type: 3
				});
				let res = await postOrderReq({
					address: this.addr,
					phone: this.phone,
					name: this.name,
					remark: this.remark,
					// config_id: this.selHx.id + ',' + this.selPp.id + ',' + this.selSuo.id + ',' + this.selMb
					// 	.id + ',' + this.selCl.id + ',' + this.selKt.id,
					config_id: this.pConfig,

					type: 3
				})
				if (res.code == 0) {
					console.log('提交订单返回值: ', res);
					this.$toast('提交成功')

					this.orderId = res.data.orderId
					this.showFixInfo = false
					this.orderSuc = true
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				}
			},
			back() {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "./index.scss";
</style>