<template>
	<view class="page">
		<navBar title="定制我家的无主灯" :back="true" color="black" background="white" />

		<image :src="picBase+topPic" 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;">定制我家的无主灯</text>
					</view>
				</view>
				<view class="rDes" @click="goRule">
					<view class="con">
						详情
					</view>
					<image :src="picUrl+'/static/other/halfRight_b.png'" mode="" style="width: 25rpx;height: 15rpx;">
					</image>
				</view>

			</view>

			<view class="label" @click="handleOpenOrClose(1)"
				:style="{'margin-bottom':addOrLessIcon1=='/static/index/shortLine.png'?'32rpx':'0'}">
				<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('hx',item,index)" class="item " :class="[currHouseIndex==index?'act':'']"
					v-for="(item,index) in houseTypeList">
					{{item.value}}
				</view>
			</view>


			<view class="label" @click="handleOpenOrClose(2)"
				:style="{'margin-bottom':addOrLessIcon2=='/static/index/shortLine.png'?'32rpx':'0'}">
				<view class="txt">
					空间
				</view>
				<image :src="addOrLessIcon2" mode="" class="" :style="{height:addOrLessIcon2=='/static/index/shortLine.png'
					?'2rpx':'22rpx'}" style="width: 22rpx;margin-right: 56rpx;">
				</image>
			</view>

			<view class="parms">
				<view v-if="show2" @click="sel('kj',item,index)" class="item "
					:class="[currHouseIndex1==index?'act':'']" v-for="(item,index) in lockTypeList">
					{{item.value}}
				</view>
			</view>

			<view class="label" @click="handleOpenOrClose(3)"
				:style="{'margin-bottom':addOrLessIcon3=='/static/index/shortLine.png'?'32rpx':'0'}">
				<view class="txt">
					品牌
				</view>
				<image :src="addOrLessIcon3" mode="" class="" :style="{height:addOrLessIcon3=='/static/index/shortLine.png'
					?'2rpx':'22rpx'}" style="width: 22rpx;margin-right: 56rpx;">
				</image>
			</view>

			<view class="parms">
				<view v-if="show3" @click="sel('pp',item,index)" class="item "
					:class="[currHouseIndex2==index?'act':'']" v-for="(item,index) in brandTypeList">
					{{item.value}}
				</view>
			</view>

			<view class="label" @click="handleOpenOrClose(4)"
				:style="{'margin-bottom':addOrLessIcon4=='/static/index/shortLine.png'?'32rpx':'0'}">
				<view class="txt">
					系列
				</view>
				<image :src="addOrLessIcon4" mode="" class="" :style="{height:addOrLessIcon4=='/static/index/shortLine.png'
					?'2rpx':'22rpx'}" style="width: 22rpx;margin-right: 56rpx;">
				</image>
			</view>

			<view class="parms">
				<view v-if="show4" @click="sel('xl',item,index)" class="item "
					:class="[currHouseIndex3==index?'act':'']" v-for="(item,index) in serTypeList">
					{{item.value}}
				</view>
			</view>


			<view class="label" @click="handleOpenOrClose(5)"
				:style="{'margin-bottom':addOrLessIcon5=='/static/index/shortLine.png'?'32rpx':'0'}">
				<view class="txt">
					版本
				</view>
				<image :src="addOrLessIcon5" mode="" class="" :style="{height:addOrLessIcon5=='/static/index/shortLine.png'
					?'2rpx':'22rpx'}" style="width: 22rpx;margin-right: 56rpx;">
				</image>
			</view>

			<view class="parms">
				<view v-if="show5" @click="sel('bb',item,index)" class="item "
					:class="[currHouseIndex4==index?'act':'']" v-for="(item,index) in chuanglianTypeList">
					{{item.value}}
				</view>
			</view>


			<view class="label" style="margin-bottom: 32rpx;">
				包含灯型
			</view>

			<view class="parms2">
				<view @click="goPreview(item.id)" class="itemLast " :class="[currHouseIndex4==index?'act':'']"
					v-for="(item,index) in ktTypeList">
					{{item.name}}
				</view>
			</view>

		</view>

		<view class="bot">
			<view class="left" @click="showConfig=true">
				<view class="price" style="min-width: 0rpx;">
					￥{{totalPrice.toFixed(0)}}
				</view>
				<image v-if="!showConfig" src="/static/index/arrDown.png" mode="" @click="showConfig=true"></image>
				<image v-else src="/static/index/arrUp.png" mode="" @click="showConfig=false"></image>

			</view>
			<view class="right" @click="preConfig">
				预览配置
			</view>
		</view>
		<u-popup :show="showConfig" @close="close" @open="open" round='10'>
			<view class="topBar" style="">
				<view class="left">

				</view>
				<view class="cen">
					清单
				</view>
				<view class="close" @click="showConfig=false">
					<u-icon name="close"></u-icon>
				</view>
			</view>
			<view class="pupopCon">
				<view class="item" v-if='selHx'>
					<view class="top">
						<view class="name">
							户型
						</view>
						<view class="info">
							{{selHx.value}}
						</view>
					</view>
				</view>
				<view class="item" v-if='selKj'>
					<view class="top">
						<view class="name">
							空间
						</view>
						<view class="info">
							{{selKj.value}}
						</view>
					</view>
				</view>
				<view class="item" v-if='selPp'>
					<view class="top">
						<view class="name">
							品牌
						</view>
						<view class="info">
							{{selPp.value}}
						</view>
					</view>
				</view>
				<view class="item" v-if='selXl'>
					<view class="top">
						<view class="name">
							系列
						</view>
						<view class="info">
							{{selXl.value}}
						</view>
					</view>
				</view>
				<view class="item" v-if='selBb'>
					<view class="top">
						<view class="name">
							版本
						</view>
						<view class="info">
							{{selBb.value}}
						</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getIndexConfigReq,
		getHomeDataNextReq,

	} from '@/api/test/index.js'
	import {
		getDataMoneyReq,
	} from '@/api/index/index.js'
	export default {
		components: {

		},
		data() {
			return {
				picUrl: this.$picUrl,
				picBase: this.$picBase,
				addOrLessIcon1: '/static/index/shortLine.png',
				addOrLessIcon2: '/static/index/shortLine.png',
				addOrLessIcon3: '/static/index/shortLine.png',
				addOrLessIcon4: '/static/index/shortLine.png',
				addOrLessIcon5: '/static/index/shortLine.png',

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

				showConfig: false,

				currHouseIndex: -1,
				currHouseIndex1: -1,
				currHouseIndex2: -1,
				currHouseIndex3: -1,
				currHouseIndex4: -1,
				houseTypeList: [

				],
				brandTypeList: [

				],
				lockTypeList: [

				],
				chuanglianTypeList: [

				],
				ktTypeList: [{
						id: 1,
						name: '筒灯'
					},
					{
						id: 2,
						name: '射灯'
					},
					{
						id: 3,
						name: '线性灯'
					},
					{
						id: 4,
						name: '磁吸轨道灯'
					}
				],
				serTypeList: [],

				selHx: null,
				selKj: null,
				selPp: null,
				selXl: null,
				selBb: null,

				rule: '',

				totalPrice: 0,

				pConfig: -1,
				cutdownRatio: 1,

				topPic: ''
			}
		},
		async onLoad(o) {
			this.topPic = getApp().noMainImg.head_image
			console.log('1this.topPic', this.topPic);

			let res = await getIndexConfigReq({
				type: 1
			})
			if (res.code == 0) {
				console.log('获取首页配置返回值-无主灯: ', res);
				this.houseTypeList = res.data.house_type
				this.brandTypeList = res.data.brand
				this.lockTypeList = res.data.space
				this.serTypeList = res.data.series
				this.chuanglianTypeList = res.data.version

				this.rule = res.data.rule.content

			} else {
				uni.showToast({
					title: res.message,
					icon: 'none'
				})
			}

		},
		onShow() {
			this.cutdownRatio = this.$getCutDown()
		},
		computed: {},
		methods: {
			async getPrice(pramas) {
				let res = await getDataMoneyReq(pramas)
				if (res.code == 0) {
					console.log('配置价格-无主灯: ', res)
					this.totalPrice = res.data.money * this.cutdownRatio
					this.pConfig = res.data.id
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				}
			},

			async sel(type, item, index) {
				if (type == 'hx') {
					this.currHouseIndex = -1
					this.currHouseIndex1 = -1
					this.currHouseIndex2 = -1
					this.currHouseIndex3 = -1
					this.currHouseIndex4 = -1

					this.selHx = null
					this.selKj = null
					this.selPp = null
					this.selXl = null
					this.selBb = null


					this.currHouseIndex = index
					this.selHx = item

					let p = {
						type: 1,
						house_type: this.selHx.id
					}

					if (this.selHx && this.selKj && this.selPp && this.selXl && this.selBb) {
						this.getPrice(p)
					} else {
						this.totalPrice = 0
					}


					let res = await getHomeDataNextReq(p)
					if (res.code == 0) {
						this.brandTypeList = res.data.brand
						this.lockTypeList = res.data.space
						this.serTypeList = res.data.series
						this.chuanglianTypeList = res.data.version
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				} else if (type == 'kj') {
					if (!this.selHx) {
						return this.$toast('请先选择户型')
					}
					this.currHouseIndex1 = -1
					this.currHouseIndex2 = -1
					this.currHouseIndex3 = -1
					this.currHouseIndex4 = -1

					this.selKj = null
					this.selPp = null
					this.selXl = null
					this.selBb = null


					this.currHouseIndex1 = index
					this.selKj = item

					let p = {
						type: 1,
						house_type: this.selHx.id,
						space: this.selKj.id
					}

					if (this.selHx && this.selKj && this.selPp && this.selXl && this.selBb) {
						this.getPrice(p)
					} else {
						this.totalPrice = 0
					}

					let res = await getHomeDataNextReq(p)
					if (res.code == 0) {
						this.brandTypeList = res.data.brand
						// this.lockTypeList = res.data.space
						this.serTypeList = res.data.series
						this.chuanglianTypeList = res.data.version
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				} else if (type == 'pp') {
					if (!this.selHx) {
						return this.$toast('请先选择户型')
					} else if (!this.selKj) {
						return this.$toast('请先选择空间')
					}
					this.currHouseIndex2 = -1
					this.currHouseIndex3 = -1
					this.currHouseIndex4 = -1

					this.selPp = null
					this.selXl = null
					this.selBb = null


					this.currHouseIndex2 = index
					this.selPp = item

					let p = {
						type: 1,
						house_type: this.selHx.id,
						space: this.selKj.id,
						brand: this.selPp.id
					}

					if (this.selHx && this.selKj && this.selPp && this.selXl && this.selBb) {
						this.getPrice(p)
					} else {
						this.totalPrice = 0
					}

					let res = await getHomeDataNextReq(p)
					if (res.code == 0) {

						console.log('系列返回值：', res);
						this.serTypeList = res.data.series
						this.chuanglianTypeList = res.data.version
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				} else if (type == 'xl') {
					if (!this.selHx) {
						return this.$toast('请先选择户型')
					} else if (!this.selKj) {
						return this.$toast('请先选择空间')
					} else if (!this.selPp) {
						return this.$toast('请先选择品牌')
					}
					this.currHouseIndex3 = -1
					this.currHouseIndex4 = -1

					this.selXl = null
					this.selBb = null


					this.currHouseIndex3 = index
					this.selXl = item
					let p = {
						type: 1,
						house_type: this.selHx.id,
						space: this.selKj.id,
						brand: this.selPp.id,
						series: this.selXl.id
					}

					if (this.selHx && this.selKj && this.selPp && this.selXl && this.selBb) {
						this.getPrice(p)
					} else {
						this.totalPrice = 0
					}

					let res = await getHomeDataNextReq(p)
					if (res.code == 0) {
						this.chuanglianTypeList = res.data.version
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				} else if (type == 'bb') {
					if (!this.selHx) {
						return this.$toast('请先选择户型')
					} else if (!this.selKj) {
						return this.$toast('请先选择空间')
					} else if (!this.selPp) {
						return this.$toast('请先选择品牌')
					} else if (!this.selXl) {
						return this.$toast('请先选择系列')
					}
					this.currHouseIndex4 = -1

					this.selBb = null


					this.currHouseIndex4 = index
					this.selBb = item

					let p = {
						type: 1,
						house_type: this.selHx.id,
						space: this.selKj.id,
						brand: this.selPp.id,
						series: this.selXl.id,
						version: this.selBb.id
					}

					if (this.selHx && this.selKj && this.selPp && this.selXl && this.selBb) {
						this.getPrice(p)
					} else {
						this.totalPrice = 0
					}

					let res = await getHomeDataNextReq(p)
					if (res.code == 0) {
						// this.chuanglianTypeList = res.data.version
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				}

			},

			preConfig() {
				if (this.houseTypeList.length == 0 || this.brandTypeList.length == 0 || this.lockTypeList.length == 0 ||
					this.serTypeList.length == 0 || this.chuanglianTypeList.length == 0) {
					return this.$toast('抱歉！参数配置缺失，暂无法预览配置')
				}

				if (!this.selHx) {
					return this.$toast('请选择户型')
				}
				if (!this.selKj) {
					return this.$toast('请选择空间')
				}
				if (!this.selPp) {
					return this.$toast('请选择品牌')
				}
				if (!this.selXl) {
					return this.$toast('请选择系列')
				}
				if (!this.selBb) {
					return this.$toast('请选择版本')
				}


				getApp().selHx = this.selHx
				getApp().selKj = this.selKj
				getApp().selPp = this.selPp
				getApp().selXl = this.selXl
				getApp().selBb = this.selBb

				getApp().pConfig = this.pConfig

				getApp().totalPrice = this.totalPrice
				uni.navigateTo({
					url: '/pages/index/customNoMian_step2/index'
				})
			},
			goPreview(id) {
				uni.navigateTo({
					url: '/pages/index/customNoMain/index?id=' + id
				})
			},
			handleOpenOrClose(i) {
				if (this['addOrLessIcon' + i] == '/static/index/shortLine.png') {
					this['addOrLessIcon' + i] = '/static/index/add.png'
					this['show' + i] = false
				} else {
					this['addOrLessIcon' + i] = '/static/index/shortLine.png'
					this['show' + i] = true
				}
			},
			goRule() {
				getApp().content = this.rule
				console.log('this.rule', this.rule);
				uni.navigateTo({
					url: '/pages/index/rule/index?type=noMain'
				})
			},
			cheSel() {
				if (!this.selHx) {
					return this.$toast('请先选择户型')
				} else if (!this.selKj) {
					return this.$toast('请先选择空间')
				} else if (!this.selPp) {
					return this.$toast('请先选择品牌')
				} else if (!this.selXl) {
					return this.$toast('请先选择系列')
				} else if (!this.selBb) {
					return this.$toast('请先选择版本')
				}
			}
		}
	}
</script>

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