	<template>
		<view>
			<view class="background">
				<view class="uni-list">
					<view class="container">
						<view>
							行政区
						</view>
						<view v-if="this.isEmpty(this.XZQValue.dictValue)" style="margin-top: 10;"
							@click="pickerShow('xzq')">
							<span style="color: darkgray;">请选择行政区</span>
						</view>
						<view v-else class="uni-list-cell-db" style="margin-top: 10;" @click="pickerShow('xzq')">
							<span style="color: black;">{{XZQValue.dictLabel}}</span>
						</view>

					</view>
				</view>
				<view class="uni-list">
					<view class="container">
						<view>
							小区
						</view>

						<view v-if="this.isEmpty(this.XQValue.id)" class="uni-list-cell-db" style="margin-top: 10;"
							@click="pickerShow('xq')">
							<span style="color: darkgray;">请选择小区</span>
						</view>
						<view v-else class="uni-list-cell-db" style="margin-top: 10;" @click="pickerShow('xq')">
							<span style="color: black;">{{XQValue.name}}</span>
						</view>
					</view>
				</view>
				<view class="uni-list">
					<view class="container">
						<view class="uni-list-cell-left">
							楼栋
						</view>
						<view v-if="this.isEmpty(this.LDValue.id)" class="uni-list-cell-db" style="margin-top: 10;"
							@click="pickerShow('ld')">
							<span style="color: darkgray;">请选择楼栋</span>
						</view>
						<view v-else class="uni-list-cell-db" style="margin-top: 10;" @click="pickerShow('ld')">
							<span style="color: black;">{{LDValue.name}}</span>
						</view>
					</view>
				</view>
				<view class="uni-list" style="margin-top: 10;">
					<view class="container">
						<view class="uni-list-cell-left">
							单元
						</view>
						<view v-if="this.isEmpty(this.DYValue.id)" class="uni-list-cell-db" style="margin-top: 10;"
							@click="pickerShow('dy')">
							<span style="color: darkgray;">请选择单元</span>
						</view>
						<view v-else class="uni-list-cell-db" style="margin-top: 10;" @click="pickerShow('dy')">
							<span style="color: black;">{{DYValue.name}}</span>
						</view>
					</view>
				</view>
				<view class="uni-list">
					<view class="container">
						<view class="uni-list-cell-left">
							房间
						</view>
						<view v-if="this.isEmpty(this.FJValue.id)" class="uni-list-cell-db" style="margin-top: 10;"
							@click="pickerShow('fj')">
							<span style="color: darkgray;">请选择房间</span>
						</view>
						<view v-else class="uni-list-cell-db" style="margin-top: 10;" @click="pickerShow('fj')">
							<span style="color: black;">{{FJValue.name}}</span>
						</view>
					</view>
				</view>
				<view class="container">

					<view class="title">是否按照施工图纸施工</view>
					<switch style="transform: scale(0.6,0.6);" @change="switch2Change" />

				</view>

				<SelectPicker :list="selectList" @change="changeSelect" v-if="open" @close="close" titleKey="name"
					subtitleKey="id" v-model="name"></SelectPicker>


				<SelectPicker :list="dictOptions" @change="changeSelectDict" v-if="openDict" @close="closeDict"
					titleKey="dictLabel" subtitleKey="dictValue" v-model="dictLabel"></SelectPicker>
			</view>


			<view class="background">
				<view class="uni-list">
					<view style="font-size: 16px;margin-left: 10px;margin-top: 10px;">
						立杠

						<span
							style="color: blue;font-size: 14px;  display: flex;justify-content:flex-end; margin-right: 15px;">历史</span>
					</view>

					<view class="container">

						<view>
							材 质
						</view>
						<view class="uni-list-cell-db" style="margin-top: 10;" @click="pickerShow('xzq')">
							<span>{{attributeXZQ}}</span>
						</view>
					</view>
					<view class="container">

						<view>
							规 格
						</view>
						<view class="uni-list-cell-db" style="margin-top: 10;" @click="pickerShow('xzq')">
							<span>{{attributeXZQ}}</span>
						</view>
					</view>
					<view class="number">
						<text>数 量</text> <!-- 左边文字 -->
						<input type="number" v-model="number"class="input" placeholder="请填写数量" style="margin-left: 10px;"></input>
						<!-- 右边输入框 -->
					</view>
				</view>

				<view class="align-items" style="margin-top: 20px;margin-bottom: 20px;">
					<view class="container" style="color: gainsboro;">*请上传照片</view>
					<view class="" style="display: flex; flex-wrap: wrap;margin-top: 10px;">
						<image src="/static/images/chooseimg.png" mode=""
							style="width: 190rpx; height: 190rpx; margin: 0 12rpx;; " @click="chooseimage()"></image>
						<view v-for="(item,index) in imgArr" :key="index" style="position: relative;">
							<view>
								<image :src="item" mode="" style="width: 190rpx; height: 190rpx; margin: 0 12rpx;"
									@click="showPhoto(index)">
								</image>
							</view>

							<view @click="remove(index)"
								style="position: absolute; top: 0; right: 14rpx; border-radius: 50%; background-color: #FF0000;">
								<u-icon name="close" color="#FFFFFF" size="35"></u-icon>
							</view>
						</view>
					</view>

				</view>
			</view>

			<view class="action-btn">
				<button @click="submit" class="btn cu-btn block bg-blue lg round">确认上传</button>
			</view>
		</view>
	</template>



	<script>
		import SelectPicker from '../../../components/selectPicker/select_picker.vue'
		import {
			getDicts
		} from "@/api/system/dict/data";
		import {
			getAreaList,
			getBuildingList,
			getUnitList,
			getHousesList
		} from '@/api/common'

		export default {
			components: {
				SelectPicker
			},
			data() {

				return {
					number: '',
					type: '',
					open: false,
					openDict: false,
					selectList: [],
					dictOptions: [],
					imgArr: [],
					XQValue: {},
					XZQValue: {},
					LDValue: {},
					DYValue: {},
					FJValue: {},
					FSValue: {},
					XQList: '',
					LDList: '',
					DYList: '',
					FJList: '',
					progress: 0, //上传图片进度百分比
					loading: false


				}
			},

			created() {
				getDicts("district").then(response => {
					this.dictOptions = response;
				});


			},
			onLoad() {
				uni.setNavigationBarTitle({
					title: '旧改工程-室内'
				})
			},
			methods: {
				//判断是否选择
				isEmpty(str) {

					return (!str || 0 === str.length);

				},
				showPhoto(index) {
					uni.previewImage({
						current: index,
						urls: this.imgArr,
					})
					console.log('sss')
				},
				remove(index) {
					uni.showModal({
						title: '提示',
						content: '是否删除该图片或视频？',
						success: (res) => {
							if (res.confirm) {
								this.imgArr.splice(index, 1)
								console.log('this.imgarr', this.imgArr)
								if (this.imgArr.length <= 0) {
									this.photo = true;
								}
							}
						}
					})
				},
				chooseimage() {
					console.log('图片')
					let _this = this;
					uni.chooseImage({
						sizeType: ['album', 'camera'],
						success(resp) {
							console.log('res--uni.chooseMedia', resp);
							resp.tempFiles.forEach((item, index) => {
								const task = uni.uploadFile({
									url: _this.$HTTP.webUrl + `/obs`,
									filePath: item.path,
									name: 'file',
									formData: {},
									header: _this.headers,
									success: res => {
										// 判断是否json字符串，将其转为json格式
										let data = _this.$u.test.jsonString(res
											.data) ? JSON.parse(res.data) : res.data;
										if (![200, 201, 204].includes(res.statusCode)) {
											// this.uploadError(index, data);
											_this.$modal.msg('上传失败！')
										} else {
											if (_this.progress === 100) {
												console.log('_this.progress', _this.progress)
												console.log('data----', data)
												console.log('res--', res)
												_this.imgArr.push(data.data.url)
												console.log('imgArr', _this.imgArr)
												_this.$modal.msg('上传成功！')
												_this.photo = false;
											}
										}
									},
									fail: e => {
										_this.$modal.msg('上传失败！')
										this.uploadError(index, e);
									},
									complete: res => {
										uni.hideLoading();
										_this.uploading = false;

									}
								});
								task.onProgressUpdate(res => {
									_this.progress = res.progress;
									console.log('onProgressUpdate', res)
									console.log('task.onProgressUpdate', _this.progress)
									uni.showLoading({
										title: '上传中'
									})
									if (_this.progress != 100) {
										_this.loading = false
										console.log('_this.loading false', _this.loading)
									} else {
										_this.loading = true
										console.log('_this.loading true', _this.loading)
									}
								});

							})

						},
					})
				},
				pickerShow(e) {


					this.type = e; //赋值类型
					if (e == 'xzq') { //行政区
						this.openDict = true;
						//this.selectList = this.dictOptions;

					} else if (e == 'xq') { //小区
						if (this.isEmpty(this.XZQValue.dictValue)) {
							this.$modal.msg('请选择行政区')

						} else {
							this.open = true;
							this.selectList = this.XQList;
						}
					} else if (e == 'ld') { //楼栋

						if (this.isEmpty(this.XQValue.id)) {
							this.$modal.msg('请选择小区')

						} else {
							this.open = true;
							this.selectList = this.LDList;
						}

					} else if (e == 'dy') { //单元
						if (this.isEmpty(this.LDValue.id)) {
							this.$modal.msg('请选择楼栋')

						} else {
							this.open = true;
							this.selectList = this.DYList;
						}
					} else if (e == 'fj') { //房间
						if (this.isEmpty(this.DYValue.id)) {
							this.$modal.msg('请选择单元')

						} else {
							this.open = true;
							this.selectList = this.FJList;
						}
					}

				},


				switch2Change(e) {
					console.log('switch2 发生 change 事件，携带值为', e.detail.value)
				},
				changeSelectDict(item, index) {
					this.openDict = false;
					this.XZQValue = item;

					//根据行政区id获取小区数据
					this.XQValue.name = ''; //重置楼栋数据
					this.LDValue.name = ''; //重置楼栋数据
					this.DYValue.name = ''; //重置单元数据
					this.FJValue.name = ''; //重置房间数据
					getAreaList(item.dictValue).then(res => {
						this.XQList = res;
					})

				},
				changeSelect(item, index) {
					// this.index = index;
					// this.address = item.communityName;
					this.open = false;

					if (this.type == 'xq') {
						this.XQValue = item;
						//根据小区id 获取楼栋数据
						this.LDValue.name = ''; //重置楼栋数据
						this.DYValue.name = ''; //重置单元数据
						this.FJValue.name = ''; //重置房间数据
						getBuildingList(item.id).then(res => {
							this.LDList = res
							// console.log("楼栋=", res)
						})
					} else if (this.type == 'ld') {
						this.LDValue = item;
						//根据楼栋ID 获取单元数据
						this.DYValue.name = ''; //重置单元数据
						this.FJValue.name = ''; //重置房间数据
						getUnitList(item.id).then(res => {
							this.DYList = res
							// console.log("单元=", res)
						})
					} else if (this.type == 'dy') {
						this.DYValue = item;
						//根据单元数据 获取房间数据 
						this.FJValue.name = ''; //重置房间数据
						getHousesList(item.id).then(res => {
							this.FJList = res
							// console.log("房间=", res)
						})
					} else if (this.type == 'fj') {
						this.FJValue = item;
					}

				},
				//关闭弹窗
				close(e) {
					this.open = false
				},
				//关闭弹窗
				closeDict(e) {
					this.openDict = false
				},
				//提交数据
				submit() {
					if (this.isEmpty(this.XZQValue.dictValue)) {
						this.$modal.msg("请选择行政区")
					} else if (this.isEmpty(this.XQValue.id)) {
						this.$modal.msg("请选择小区")
					} else if (this.isEmpty(this.LDValue.id)) {
						this.$modal.msg("请选择楼栋")
					} else if (this.isEmpty(this.DYValue.id)) {
						this.$modal.msg("请选择单元")
					} else if (this.isEmpty(this.FJValue.id)) {
						this.$modal.msg("请选择房间")
					} else if (this.imgArr.length <= 0) {
						this.$modal.msg('请上传照片')
					} else if (this.loading == false) {
						this.$modal.msg('照片未上传完毕，无法提交！')
					}
				}

			}
		}
	</script>

	<style>
		.container {
			display: flex;
			margin-left: 10px;
			margin-top: 10px;
			margin-right: 10px;
			align-items: flex-start;
			justify-content: space-between;
		}

		.number {
			display: flex;
			/* 水平居中显示子元素 */
			align-items: flex-start;
			/* 垂直居中显示子元素 */
			justify-content: space-between;
			/* 左右间距等于间距大小 */
			padding: 10px;
			/* 设置padding以提高视觉效果 */
		}

		.text {
			font-size: 16px;
			color: #333;
		}

		.background {
			border: 15px solid hsla(0, 0%, 100%, .5);
			background: white;
			background-clip: padding-box;
			/*从padding开始往外面裁剪背景*/

		}

		.btn {
			margin-top: 40px;
			margin-right: 20px;
			margin-bottom: 20px;
			margin-left: 20px;
			height: 45px;
		}
	</style>