<template>
	<view class="page">
		<navBar title="网络规划-全屋WiFi" :back="true" color="black" background="white" />

		<image :src="picUrl + '/static/other/c1.png'" mode="" class="topBg"></image>

		<view class="content">
			<view class="topBox">
				<view class="lTxt">
					<image src="/static/index/water.png" mode="" class="water1"></image>
					<view class="main">
						<image src="/static/index/halfCircle_275.png" mode="" style="width: 56rpx;height: 56rpx;">
						</image>
						<text style="z-index: 3;position: relative;">定制我家的全屋WiFi</text>
					</view>
				</view>
				<view class="rDes" @click="toRule">
					<view class="con">
						详情
					</view>
					<image :src="picUrl+'/static/other/r_whitebg.png'" mode="" style="width: 24rpx;height: 8rpx;">
					</image>
				</view>
			</view>

			<view class="label" @click="handleOpenOrClose(1)">
				<view class="txt">
					户型
				</view>
				<image :src="addOrLessIcon1" mode="" class="" :style="{height:addOrLessIcon1=='/static/index/shortLine.png'
					?'2rpx':'22rpx'}" style="width: 22rpx;margin-right: 56rpx;">
				</image>
			</view>

			<view class="parms">
				<view v-if="show1" @click="sel(item, index)" class="item " :class="[currHouseIndex==index?'act':'']"
					v-for="(item,index) in houseTypeList" :style="{'margin-right': index==1?'0':''}">
					{{item.value}}
				</view>
			</view>
		</view>
		<!-- 	<view class="rule">
			<image src="/static/index/ruleImg.png" mode=""></image>
			<view class="txt">
				挑选规则
			</view>
		</view> -->
		<view class="bot">
			<view class="left">
				<view class="price">
					￥{{totalPrice.toFixed(2)}}
				</view>
				<image src="/static/index/arrDown.png" mode=""></image>
			</view>
			<button open-type="share" v-if="orderSuc" class="right">
				分享
			</button>

			<view class="right" v-else @click="confirmConfig">
				确认配置
			</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 {
		getIndexConfigReq,
		postOrderReq,
	} from '@/api/test/index.js'
	import {
		getDataMoneyReq
	} from '@/api/index/index.js'
	export default {
		components: {

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

				showFixInfo: false,

				addOrLessIcon1: '/static/index/shortLine.png',
				addOrLessIcon2: '/static/index/add.png',
				addOrLessIcon3: '/static/index/add.png',
				addOrLessIcon4: '/static/index/add.png',
				addOrLessIcon5: '/static/index/add.png',
				// lessIcon: require('/static/index/shortLine.png'),

				show1: true,
				show2: false,
				show3: false,
				show4: false,
				show5: false,

				currHouseIndex: -1,
				houseTypeList: [],

				selHx: null,

				totalPrice: 0,

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

				orderId: '',
				pConfig: -1,

				orderSuc: false,
				cutdownRatio: 1,
				rule: ''
			}
		},
		async onLoad(options) {
			let res = await getIndexConfigReq({
				type: 4
			})
			if (res.code == 0) {
				console.log('获取首页配置返回值-全屋WiFi: ', res);
				this.houseTypeList = res.data.house_type

				// this.selHx = res.data.house_type[0]
				this.rule = res.data.rule.content

				// this.getPrice(4, this.selHx.id)
			}
		},
		onShow() {
			this.cutdownRatio = this.$getCutDown()
		},
		onShareAppMessage(params) {
			if (params.from === 'button' || params.from === 'menu') {
				return {
					title: '定制我家的全屋WiFi',
					imageUrl: this.picUrl + '/static/other/c1.png',
					path: '/pages/index/fullHouseWifi_step2/index?orderId=' + this.orderId,
					mpId: this.$appId,
					type: this.$shareType,
				}
			}
		},
		methods: {
			confirmConfig() {
				if (!this.selHx) {
					return this.$toast('请选择户型')
				}
				this.showFixInfo = true
			},
			toRule() {
				getApp().content = this.rule
				uni.navigateTo({
					url: '/pages/index/rule/index?type=wifi'
				})
			},
			async postOrder() {
				console.log('wifi下单参数', {
					address: this.addr,
					phone: this.phone,
					name: this.name,
					remark: this.remark,
					config_id: this.selHx.id,
					type: 4
				});
				let res = await postOrderReq({
					address: this.addr,
					phone: this.phone,
					name: this.name,
					remark: this.remark,
					// config_id: String(this.selHx.id),
					config_id: this.pConfig,
					type: 4
				})
				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'
					})
				}
			},
			sel(item, index) {
				this.currHouseIndex = index
				this.selHx = item
				this.getPrice(4, this.selHx.id)
			},

			async getPrice(type = 4, house_type) {
				let res = await getDataMoneyReq({
					type,
					house_type,
				})
				if (res.code == 0) {
					console.log('配置价格-wifi: ', res)
					this.totalPrice = res.data.money * this.cutdownRatio

					this.pConfig = res.data.id
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				}
			},
			handleOpenOrClose(i) {
				if (this['addOrLessIcon' + i] == '/static/index/shortLine.png') {
					this['addOrLessIcon' + i] = '/static/index/add.png'
					this['show' + i] = false
				} else if (this['addOrLessIcon' + i] == '/static/index/add.png') {
					this['addOrLessIcon' + i] = '/static/index/shortLine.png'
					this['show' + i] = true
				}
			},
		}
	}
</script>

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