<template>
	<view class="wrap">
		<page-nav :desc="desc" :title="title"></page-nav>
		<view>
			<form @submit="formSubmit" @reset="formReset">
				<!-- 项目信息项 -->
				<view class="uni-form-item">
					<view class="view-flex-rs line-body">
						<view class="view-flex-cc">
							<text class="required-star">*</text>
						</view>
						<view style="width: 200rpx;" class="view-flex-cc item-title">
							<text>当前项目：</text>
						</view>
						<view style="flex-grow: 0.9;" class="view-flex-cc">
							<text>{{projectInfo.title}}</text>
						</view>
						<view style="width: 200rpx;" class="view-flex-cc">
							<button style="height: 80rpx;font-size: medium;" type="primary"
								@click="goto('/pages/checkReport/checkProjectSelect?model=1')">重新选择</button>
						</view>
					</view>
				</view>
				<!-- 检查区域信息项 -->
				<view class="uni-form-item" style="margin-top: 10px;">
					<view class="line-body view-flex-rs">
						<text class="required-star">*</text>
						<text class="item-title">检查区域</text>
					</view>
					<view>
						<uni-list-item @click="selectCheckArea()" :clickable="true" :ellipsis="1"
							:show-extra-icon="true" showArrow
							:extra-icon="{color: '#4cd964',size: '22',type: 'settings'}"
							v-bind:title="checkAreaDict.dictValue" />
					</view>
					<!-- 				<u-cell-item class="line-body" icon="setting-fill" v-bind:title="checkAreaDict.dictValue"
						hover-class="cell-hover-class" @click="selectCheckArea()"></u-cell-item> -->
				</view>
				<!-- 检查点位文本信息项 -->
				<view class="uni-form-item uni-column" style="margin-top: 10rpx;">
					<view class="line-body item-title">
						具体位置
					</view>
					<view class="line-body">
						<uni-easyinput errorMessage v-model="failureCheckPointDesc" placeholder="请输入内容"></uni-easyinput>
					</view>
				</view>
				<!-- 安全隐患问题类型信息项，字典 -->
				<view class="uni-form-item" style="margin-top: 10px;">
					<view class="line-body view-flex-rs">
						<text class="required-star">*</text>
						<text class="item-title">安全问题隐患类型</text>
					</view>
					<view>
						<uni-list-item @click="selectCheckItemType()" :clickable="true" :ellipsis="1"
							:show-extra-icon="true" showArrow
							:extra-icon="{color: '#4cd964',size: '22',type: 'settings'}"
							v-bind:title="checkItemTypeDict.dictValue" />
					</view>

					<!-- 	<u-cell-item class="line-body" icon="setting-fill" v-bind:title="checkItemTypeDict.dictValue"
						hover-class="cell-hover-class" @click="selectCheckItemType()"></u-cell-item> -->
				</view>
				<!-- 安全隐患问题标签信息项,字典 -->
				<view class="uni-form-item" style="margin-top: 10px;">
					<view class="line-body view-flex-rs">
						<text class="required-star">*</text>
						<text class="item-title">检查部位</text>
					</view>
					<view>
						<uni-list-item @click="selectCheckItemLabel()" :clickable="true" :ellipsis="1"
							:show-extra-icon="true" showArrow
							:extra-icon="{color: '#4cd964',size: '22',type: 'settings'}"
							v-bind:title="checkItemLabelDict.dictValue" />
					</view>
					<!-- <u-cell-item class="line-body" icon="setting-fill"  v-bind:title="checkItemLabelDict.dictValue"
						hover-class="cell-hover-class" @click="selectCheckItemLabel()"></u-cell-item> -->
				</view>


				<!-- 安全隐患问题排查标准信息项,字典 -->
				<view class="uni-form-item  uni-column" style="margin-top: 10px;">
					<view class="line-body view-flex-rs">
						<text class="required-star">*</text>
						<text class="item-title">问题隐患标签</text>
					</view>
					<view>
						<uni-list-item @click="selectCheckStandard()" :clickable="true" :ellipsis="1"
							:show-extra-icon="true" showArrow
							:extra-icon="{color: '#4cd964',size: '22',type: 'settings'}"
							v-bind:title="checkStandardDict.dictValue" />
					</view>


					<!-- <u-cell-item class="line-body" icon="setting-fill" v-bind:title="checkStandardDict.dictValue"
						hover-class="cell-hover-class" @click="selectCheckStandard()"></u-cell-item> -->
				</view>
				<view class="uni-form-item uni-column" style="margin-top: 10px;">
					<view class="line-body item-title">
						法律法规
					</view>
					<view class="line-body">
						<textarea disabled v-model="checkItemStandardBasisDict.dictValue" class="mline-text" />

						<!-- <uni-easyinput disabled v-model="checkItemStandardBasisDict.dictValue"></uni-easyinput> -->
					</view>
				</view>

				<!-- 	安全隐患问题描述信息项，文本 -->
				<view class="uni-form-item uni-column" style="margin-top: 10px;">
					<view class="line-body item-title">
						安全问题隐患描述
					</view>
					<view class="line-body">
						<textarea v-model="failureHiddenDangerDesc" name="failureCorrectiveSuggest"
							class="mline-text" />

					</view>
				</view>

				<!-- 隐患等级信息项,字典 -->
				<view class="uni-form-item" style="margin-top: 15px;">
					<view class="view-flex-rs">
						<view class="uni-title line-body"><text class="required-star">*</text><text
								class="item-title">隐患等级</text></view>
						<view class="line-body">
							<radio-group @change="hiddenDangerRadioChange"
								style="display: flex;flex-direction: row;justify-content: flex-start;">
								<label style="margin-top: 2px;margin-right: 5px;" class="view-flex-rs"
									v-for="(item, index) in hiddenDangerRadio.items" :key="item.id">
									<view>
										<radio :value="item.id" :checked="index === hiddenDangerRadio.current" />
									</view>
									<view style="font-size: 12px;">{{item.dictValue}}</view>
								</label>
							</radio-group>
						</view>
					</view>
				</view>
				<!-- 整改建议信息项，文本 -->
				<view class="uni-form-item uni-column" style="margin-top: 10px;">
					<view class="line-body item-title">
						整改建议
					</view>
					<view class="line-body">
						<textarea v-model="failureCorrectiveSuggest" name="failureCorrectiveSuggest"
							class="mline-text" />
					</view>
				</view>
				<!-- 整改期限信息项,字典 -->
				<view class="uni-form-item" style="margin-top: 15px;">
					<view class="view-flex-rs">
						<view class="uni-title line-body"><text class="required-star">*</text><text
								class="item-title">整改期限</text></view>
						<view class="line-body">
							<radio-group @change="planTimeRadioChange"
								style="display: flex;flex-direction: row;justify-content: flex-start;">
								<label style="margin-top: 2px; margin-right: 5px;" class="view-flex-rs"
									v-for="(item, index) in planTimeRadio.items" :key="item.id">
									<view>
										<radio :value="item.id" :checked="index === planTimeRadio.current" />
									</view>
									<view style="font-size: 12px;">{{item.dictValue}}</view>
								</label>
							</radio-group>
						</view>
					</view>
				</view>
				<!-- 图片信息项 -->
				<view class="uni-form-item" style="margin-top: 10px;">
					<view class="view-flex-rs line-body">
						<view class="view-flex-cc" style="height: 40px;">
							<text class="item-title">安全隐患问题图片</text>
						</view>
					</view>
				</view>
				<view class="uni-form-item" style="margin-top: 10px;">
					<view class="img-container">
						<view class="note-image-box">
							<view class="note-image-item" v-for="(item , index) in localImageList" :key="index">
								<view class="close-icon" @click="onDeleteClick(index)">
									<uni-icons type="closeempty" size="18" color="#fff"></uni-icons>
								</view>
								<view class="image-box">
									<image :src="item" mode="widthFix"></image>
								</view>
							</view>
							<view v-if="localImageList.length < 9" class="note-image-item" @click="getPhoto()">
								<view class="image-box">
									<uni-icons type="plusempty" size="50" color="#eee"></uni-icons>
								</view>
							</view>
						</view>
					</view>
				</view>
				<u-gap height="50"></u-gap>
				<view class="uni-form-item uni-column">
					<view class="line-body">
						<button type="primary" form-type="submit">提交</button>
					</view>
					<view class="line-body" style="margin-top: 10px;">
						<button type="default" @click="onSaveClick">保存</button>
					</view>
				</view>
				<u-gap height="50"></u-gap>
			</form>
		</view>
	</view>
</template>

<script>
	import pageNav from '@/components/page-nav/page-nav.vue';
	import http from '@/http/api.js';
	import {
		devUrl,
		prodUrl,
		oss
	} from '@/common/setting';
	export default {
		components: {
			pageNav
		},
		onLoad(option) {
			console.log(option.checkNo);
			this.baseURL = process.env.NODE_ENV === 'development' ? devUrl : prodUrl;
			this.checkNo = option.checkNo;
			//问题详情信息
			var data = uni.getStorageSync('check_report_storage_' + this.checkNo);
			if (data != null) {
				console.log("detail " + data)
				this.recordInfo = data;
				this.failureCheckPointDesc = data['failureCheckPointDesc']
				this.failureHiddenDangerDesc = data['failureHiddenDangerDesc']
				this.failureCorrectiveSuggest = data['failureCorrectiveSuggest']
				this.initProjectInfo(data['failureProjectId']);
				this.initCheckArea(data['failureCheckArea']);
				this.initCheckItemType(data['failureCheckHiddenDangerType']);
				this.initCheckItemLabel(data['failureCheckHiddenDanger']);
				this.initCheckStandard(data['failureCheckHiddenDangerItemPoint']);
				this.initCheckStandardBasis(data['failureCheckHiddenDangerStandard']);
				this.initHiddenDangerLevelRadio(data['failureHiddenDangerLevel']);
				this.initPlanTimeRadio(data['failureCorrectivePlanTime']);
				this.initPhoto()
			}

		},
		data() {
			return {
				baseURL: '',
				checkNo: '',
				recordInfo: {},
				savedImageList: [],
				planTimeRadio: {
					items: [],
					current: 0,
				},
				hiddenDangerRadio: {
					items: [],
					current: 0,
				},
				localImageList: [],
				uploadImageList: [],
				checkAreaDict: {
					id: '',
					dictKey: '',
					dictValue: '请点击选择'
				},
				checkItemTypeDict: {
					id: '',
					dictKey: '',
					dictValue: '请点击选择'
				},
				checkItemLabelDict: {
					id: '',
					dictKey: '',
					dictValue: '请点击选择'
				},
				checkStandardDict: {
					id: '',
					dictKey: '',
					dictValue: '请点击选择'
				},
				checkItemStandardBasisDict: {
					id: '',
					dictKey: '',
					dictValue: ''
				},
				title: '问题编辑',
				desc: '',
				projectInfo: {
					'projectId': '',
					'title': ''
				},
				failureHiddenDangerDesc: '',
				failureCheckPointDesc: '',
				failureCorrectiveSuggest: '',
			}
		},
		computed: {
			getIcon() {
				return path => {
					return 'https://cdn.uviewui.com/uview/example/' + path + '.png';
				}
			},
		},
		onShow() {
			uni.setNavigationBarTitle({
				title: "问题编辑"
			});

			//项目选择结果监听  
			uni.$on("handClickProjectSelect", res => {
				console.log(res);
				this.projectInfo = {
					projectId: res.projectId,
					title: '重新选择的项目名'
				}
				// 清除监听
				uni.$off('handClickProjectSelect');
			})

			//检查区域选择结果监听  
			uni.$on("handClickAreaSelect", res => {
				console.log(res);

				this.checkAreaDict = {
					dictValue: res.dictValue,
					dictKey: res.dictKey,
					id: res.id
				}

				// 清除监听
				uni.$off('handClickAreaSelect');
			})

			//安全隐患问题分类选择结果监听
			uni.$on("handClickItemSelect", res => {
				console.log("callback " + res);
				if (this.checkItemTypeDict.id == null || this.checkItemTypeDict.id.length == 0 || this
					.checkItemTypeDict.id !== res.id) {
					this.checkItemLabelDict = {
						id: '',
						dictKey: '',
						dictValue: '请点击选择'
					}
					this.checkStandardDict = {
						id: '',
						dictKey: '',
						dictValue: '请点击选择'
					}
					this.failureHiddenDangerDesc = "";
					this.checkItemStandardBasisDict = {
						id: '',
						dictKey: '',
						dictValue: ''
					}
				}
				this.checkItemTypeDict = {
					dictValue: res.dictValue,
					dictKey: res.dictKey,
					id: res.id
				}

				// 清除监听
				uni.$off('handClickItemSelect');
			})

			//安全隐患标签选择结果监听  
			uni.$on("handClickItemLabelSelect", res => {
				console.log("handClickItemLabelSelect" + res);
				if (this.checkItemLabelDict.id == null || this.checkItemLabelDict.id.length == 0 || this
					.checkItemLabelDict.id !== res.id) {

					this.checkStandardDict = {
						id: '',
						dictKey: '',
						dictValue: '请点击选择'
					}
					this.failureHiddenDangerDesc = "";
					this.checkItemStandardBasisDict = {
						id: '',
						dictKey: '',
						dictValue: ''
					}
				}
				this.checkItemLabelDict = {
					dictValue: res.dictValue,
					dictKey: res.dictKey,
					id: res.id
				}
				// 清除监听
				uni.$off('handClickItemLabelSelect');
			})

			//安全隐患排查标准选择结果监听
			uni.$on("handClickStandardSelect", res => {
				console.log(res);
				if (this.checkStandardDict.id == null || this.checkStandardDict.id.length == 0 || this
					.checkStandardDict.id !== res.id) {

					this.failureHiddenDangerDesc = "";

					this.checkItemStandardBasisDict = {
						id: '',
						dictKey: '',
						dictValue: ''
					}
				}
				this.checkStandardDict = {
					dictValue: res.dictValue,
					dictKey: res.dictKey,
					id: res.id
				}
				this.failureHiddenDangerDesc = res.dictValue;

				this.checkItemStandardBasisDict = {
					dictValue: res.subDict.dictValue,
					dictKey: res.subDict.dictKey,
					id: res.subDict.id
				}
				// 清除监听
				uni.$off('handClickStandardSelect');
			})
		},
		created() {

		},
		methods: {
			initProjectInfo(failureProjectId) {
				const that = this;
				const id = failureProjectId;
				http.request({
					url: '/blade-business/report/projectInfo/detail',
					method: 'GET',
					params: {
						id
					}
				}).then(res => {
					console.log(res.data)
					that.projectInfo = {
						projectId: res.data.id,
						title: res.data.projectName
					}
				}).catch(err => {
					console.log(err)
				})
			},
			initCheckArea(dictId) {
				const that = this;
				const id = dictId;
				http.request({
					url: '/galaxy-system/dict-biz/detail',
					method: 'GET',
					params: {
						id
					}
				}).then(res => {
					console.log(res.data)
					if (res.data != null) {
						that.checkAreaDict = {
							id: res.data['id'],
							dictKey: res.data['dictKey'],
							dictValue: res.data['dictValue'],
						};
					}

				}).catch(err => {
					console.log(err)
				})
			},
			initCheckItemType(dictId) {
				const that = this;
				const id = dictId;
				http.request({
					url: '/galaxy-system/dict-biz/detail',
					method: 'GET',
					params: {
						id
					}
				}).then(res => {
					console.log(res.data)
					if (res.data != null) {
						that.checkItemTypeDict = {
							id: res.data['id'],
							dictKey: res.data['dictKey'],
							dictValue: res.data['dictValue'],
						};
					}

				}).catch(err => {
					console.log(err)
				})

			},
			initCheckItemLabel(dictId) {
				const that = this;
				const id = dictId;
				http.request({
					url: '/galaxy-system/dict-biz/detail',
					method: 'GET',
					params: {
						id
					}
				}).then(res => {
					console.log(res.data)
					if (res.data != null) {
						that.checkItemLabelDict = {
							id: res.data['id'],
							dictKey: res.data['dictKey'],
							dictValue: res.data['dictValue'],
						};
					}

				}).catch(err => {
					console.log(err)
				})

			},
			initCheckStandard(dictId) {
				const that = this;
				const id = dictId;
				http.request({
					url: '/galaxy-system/dict-biz/detail',
					method: 'GET',
					params: {
						id
					}
				}).then(res => {
					console.log(res.data)
					if (res.data != null) {
						that.checkStandardDict = {
							id: res.data['id'],
							dictKey: res.data['dictKey'],
							dictValue: res.data['dictValue'],
						};
					}

				}).catch(err => {
					console.log(err)
				})

			},
			initCheckStandardBasis(dictId) {
				if (null != dictId && undefined != dictId && dictId.length > 0) {
					const that = this;
					const id = dictId;
					http.request({
						url: '/galaxy-system/dict-biz/detail',
						method: 'GET',
						params: {
							id
						}
					}).then(res => {
						console.log(res.data)
						if (res.data != null) {
							that.checkItemStandardBasisDict = {
								id: res.data['id'],
								dictKey: res.data['dictKey'],
								dictValue: res.data['dictValue'],
							};
						}

					}).catch(err => {
						console.log(err)
					})
				}
			},
			initHiddenDangerLevelRadio(dictId) {
				const that = this;
				//查询隐患等级
				http.request({
					url: '/galaxy-system/dict-biz/dictionary?code=danger_level',
					method: 'GET'
				}).then(res => {
					console.log(res.data)
					if (res.data != null) {
						var dangerLevelList = [];
						var index = 0;

						const dictLength = res.data['length'];
						for (var i = 0; i < dictLength; i++) {
							let dict = res.data['' + i];
							if (dict['id'] == dictId) {
								index = i;
							}
							dangerLevelList.push(dict);
						}

						that.hiddenDangerRadio = {
							current: index,
							items: dangerLevelList
						}

					}

				}).catch(err => {
					console.log(err)
				})

			},
			initHiddenDangerLevelRadio(dictId) {
				const that = this;
				//查询隐患等级
				http.request({
					url: '/galaxy-system/dict-biz/dictionary?code=danger_level',
					method: 'GET'
				}).then(res => {
					console.log(res.data)
					if (res.data != null) {
						var dangerLevelList = [];
						var index = 0;

						const dictLength = res.data['length'];
						for (var i = 0; i < dictLength; i++) {
							let dict = res.data['' + i];
							if (dict['id'] == dictId) {
								index = i;
							}
							dangerLevelList.push(dict);
						}

						that.hiddenDangerRadio = {
							current: index,
							items: dangerLevelList
						}

					}

				}).catch(err => {
					console.log(err)
				})

			},
			initPlanTimeRadio(dictId) {
				const that = this;
				//查询整改期限
				http.request({
					url: '/galaxy-system/dict-biz/dictionary?code=plan_time',
					method: 'GET'
				}).then(res => {
					console.log(res.data)
					if (res.data != null) {
						var planTimeList = [];
						var index = 0;
						const dictLength = res.data['length'];
						for (var i = 0; i < dictLength; i++) {
							let dict = res.data['' + i];
							if (dict['id'] == dictId) {
								index = i;
							}
							planTimeList.push(dict);
						}
						that.planTimeRadio = {
							current: index,
							items: planTimeList,
						}
					}
				}).catch(err => {
					console.log(err)
				})

			},
			getOssPath(imagePath) {
				if (null != imagePath && imagePath.indexOf("blob") == 0) {
					return imagePath;
				} else {
					return oss + imagePath;
				}
			},
			initPhoto() {
				var saveFilePaths = uni.getStorageSync('check_report_storage_image_' + this.checkNo);
				this.localImageList = this.localImageList.concat(saveFilePaths);
			},
			onDeleteClick(index) {
				this.localImageList.splice(index, 1);
			},
			removeRecord() {
				var tempIndexList = [];
				var list = uni.getStorageSync('check_report_storage_index');
				if (list != null && list.length > 0) {
					list.forEach(itemKey => {
						if (itemKey !== this.checkNo) {
							tempIndexList.push(itemKey);
						}
					});
				}
				uni.setStorageSync('check_report_storage_index', tempIndexList);
				uni.removeStorageSync('check_report_storage_' + this.checkNo);
			},
			planTimeRadioChange: function(evt) {
				for (let i = 0; i < this.planTimeRadio.items.length; i++) {
					if (this.planTimeRadio.items[i].id === evt.detail.value) {
						this.planTimeRadio.current = i;
						break;
					}
				}
			},
			hiddenDangerRadioChange: function(evt) {
				for (let i = 0; i < this.hiddenDangerRadio.items.length; i++) {
					if (this.hiddenDangerRadio.items[i].id === evt.detail.value) {
						this.hiddenDangerRadio.current = i;
						break;
					}
				}
			},
			getPhoto() {
				const that = this;
				uni.chooseImage({
					sourceType: ['album', 'camera'],
					success: (res) => {
						const len = res.tempFilePaths.length;
						if (len > 0) {
							if (len + that.localImageList.length > 9) {
								uni.showModal({
									content: '一次最多上传9张图片，请检查！',
									showCancel: false
								});
							} else {
								let pathList = [];
								res.tempFilePaths.forEach(path => {
									that.localImageList.push(path);
								})
							}
						}
					}
				})
			},
			saveLocalFile(paths) {
				var returnFileList = [];
				var count = 0;
				return new Promise((resolve, reject) => {
					paths.forEach(imagePath => {
						console.log("path " + imagePath);
						uni.saveFile({
							tempFilePath: imagePath,
							success: (res) => {
								var savedFilePath = res.savedFilePath;
								returnFileList.push(savedFilePath);
								count += 1;
								if (count == paths.length) {
									resolve(returnFileList);
								}
							},
							fail: (e) => {
								reject('err')
							}
						})
					});
				})
			},
			async saveLocalFiles(tempImageList) {
				if (tempImageList.length > 0) {
					await this.saveLocalFile(tempImageList).then(files => {
						files.forEach(f => {
							this.savedImageList.push(f);
						})
					});
				}
			},
			onSaveClick(e) {
				if ((this.projectInfo.projectId != null && this.projectInfo.projectId.length > 0) &&
					(this.checkAreaDict.id != null && this.checkAreaDict.id.length > 0) &&
					(this.checkItemTypeDict.id != null && this.checkItemTypeDict.id.length > 0) &&
					(this.checkItemLabelDict.id != null && this.checkItemLabelDict.id.length > 0) &&
					(this.checkStandardDict.id != null && this.checkStandardDict.id.length > 0)) {
					try {
						var data = {};
						data['failureHiddenDangerDesc'] = this.failureHiddenDangerDesc;
						data['failureCheckPointDesc'] = this.failureCheckPointDesc;
						data['failureCorrectiveSuggest'] = this.failureCorrectiveSuggest;
						data['failureCheckNo'] = this.checkNo;
						data['failureProjectId'] = this.projectInfo.projectId;
						data['failureCheckArea'] = this.checkAreaDict.id;

						data['failureCheckHiddenDangerType'] = this.checkItemTypeDict.id;
						data['failureCheckHiddenDanger'] = this.checkItemLabelDict.id;
						data['failureCheckHiddenDangerItemPoint'] = this.checkStandardDict.id;
						data['failureCheckHiddenDangerStandard'] = this.checkItemStandardBasisDict.id;


						data['failureHiddenDangerLevel'] = this.hiddenDangerRadio.items[this.hiddenDangerRadio.current]
							.id;
						data['failureCorrectivePlanTime'] = this.planTimeRadio.items[this.planTimeRadio.current]
							.id;

						var tempImageList = [];
						this.savedImageList = [];
						this.localImageList.forEach(path => {
							var text = String(path);
							if (text.indexOf("blob") == 0) {
								tempImageList.push(text);
							} else {
								this.savedImageList.push(text);
							}
						})

						this.saveLocalFiles(tempImageList);

						uni.setStorageSync('check_report_storage_image_' + this
							.checkNo, this.savedImageList);

						console.log("save " + data);


						uni.setStorageSync('check_report_storage_' + this.checkNo, data);
						uni.navigateBack();
					} catch (e) {
						console.log(e);
						uni.showModal({
							content: '保存失败！' + e.message,
							showCancel: false
						});
					}


				} else {
					uni.showModal({
						content: '请检查必填项',
						showCancel: false
					});
				}

			},
			uploadFile(imagePaths) {
				var returnImagePathList = [];
				var count = 0;
				console.log("accessToken:" + uni.getStorageSync('accessToken'));
				return new Promise((resolve, reject) => {
					imagePaths.forEach(imagePath => {
						console.log("path " + imagePath);
						uni.showLoading({
							title: '上传中'
						});
						uni.uploadFile({
							url: this.baseURL +
								'/galaxy-resource/oss/endpoint/put-file-attach?Blade-Auth=' +
								uni.getStorageSync('accessToken'),
							fileType: 'image',
							filePath: imagePath,
							name: 'file',
							success: (uploadFileRes) => {
								console.log(uploadFileRes);
								if (uploadFileRes.statusCode == 200) {
									let data = JSON.parse(uploadFileRes.data);
									if (data.success) {
										let name = data.data['name'];
										returnImagePathList.push(name);
									}
								}
								count += 1;
								if (count == imagePaths.length) {
									resolve(returnImagePathList);
								}

							},
							fail: (err) => {
								console.log(err);
								reject('err')
							},
							complete() {
								uni.hideLoading()
							}
						});
					});
				})
			},
			async upload(formdata) {
				const that = this;
				if (this.localImageList.length > 0) {

					await this.uploadFile(this.localImageList).then(names => {
						names.forEach(name => {
							console.log("image path " + name);
							this.uploadImageList.push(name);
						})
						var photoPaths = [];
						this.uploadImageList.forEach(name => {
							let p = {
								failureCheckNo: this.checkNo,
								photoPath: name
							}
							photoPaths.push(p);
						})
						formdata['photoPaths'] = photoPaths;

						http.request({
							url: '/blade-business/report/failure/save',
							method: 'POST',
							data: formdata
						}).then(res => {
							if (res.success) {
								that.removeRecord();
								uni.showModal({
									content: '上传成功',
									showCancel: false,
									success(res) {
										if (res.confirm) {
											uni.navigateBack();
										}
									}
								});
							} else {
								uni.showModal({
									content: '' + res.msg,
									showCancel: false
								});
							}
						}).catch(err => {
							console.log(err)
						})

					})
				} else {

					http.request({
						url: '/blade-business/report/failure/save',
						method: 'POST',
						data: formdata
					}).then(res => {
						if (res.success) {
							that.removeRecord();
							uni.showModal({
								content: '上传成功',
								showCancel: false,
								success(res) {
									if (res.confirm) {
										uni.navigateBack();
									}
								}
							});
						} else {
							uni.showModal({
								content: '' + res.msg,
								showCancel: false
							});
						}
					}).catch(err => {
						console.log(err)
					})
				}
			},
			formSubmit: function(e) {
				console.log('form发生了submit事件，携带数据为：' + JSON.stringify(e.detail.value))

				if ((this.projectInfo.projectId != null && this.projectInfo.projectId.length > 0) &&
					(this.checkAreaDict.id != null && this.checkAreaDict.id.length > 0) &&
					(this.checkItemTypeDict.id != null && this.checkItemTypeDict.id.length > 0) &&
					(this.checkItemLabelDict.id != null && this.checkItemLabelDict.id.length > 0) &&
					(this.checkStandardDict.id != null && this.checkStandardDict.id.length > 0)) {
					this.recordInfo['failureCheckPointDesc'] = this.failureCheckPointDesc;
					this.recordInfo['failureHiddenDangerDesc'] = this.failureHiddenDangerDesc;
					this.recordInfo['failureCorrectiveSuggest'] = this.failureCorrectiveSuggest;
					this.recordInfo['failureProjectId'] = this.projectInfo.projectId;
					this.recordInfo['failureCheckArea'] = this.checkAreaDict.id;
					this.recordInfo['failureCheckHiddenDangerType'] = this.checkItemTypeDict.id;
					this.recordInfo['failureCheckHiddenDanger'] = this.checkItemLabelDict.id;
					this.recordInfo['failureCheckHiddenDangerItemPoint'] = this.checkStandardDict.id;
					this.recordInfo['failureCheckHiddenDangerStandard'] = this.checkItemStandardBasisDict.id;
					this.recordInfo['failureHiddenDangerLevel'] = this.hiddenDangerRadio.items[this
							.hiddenDangerRadio.current]
						.id;
					this.recordInfo['failureCorrectivePlanTime'] = this.planTimeRadio.items[this.planTimeRadio
							.current]
						.id;
					this.upload(this.recordInfo);

				} else {
					uni.showModal({
						content: '请检查必填项',
						showCancel: false
					});
				}
			},
			formReset: function(e) {
				console.log('清空数据')
			},
			selectCheckArea() {
				this.$u.route({
					url: '/pages/checkReport/checkAreaSelect'
				})
			},
			selectCheckItemType() {
				uni.navigateTo({
					url: '/pages/checkReport/checkItemSelect'
				})
			},
			selectCheckItemLabel() {
				if (this.checkItemTypeDict.id.length > 0) {
					uni.navigateTo({
						url: '/pages/checkReport/checkItemLabelSelect?id=' + this.checkItemTypeDict.id
					})
				} else {
					uni.showModal({
						content: '请先选择安全隐患问题类型',
						showCancel: false
					});
				}
			},
			selectCheckStandard() {
				if (this.checkItemLabelDict.id.length > 0) {
					uni.navigateTo({
						url: '/pages/checkReport/checkStandardSelect?id=' + this.checkItemLabelDict.id
					})
				} else {
					uni.showModal({
						content: '请先选择安全隐患问题标签',
						showCancel: false
					});
				}
			},
			openPage(path) {
				this.$u.route({
					url: path
				})
			},
			getGroupTitle(item) {
				return item.groupName
			},
			getFieldTitle(item) {
				return item.title
			},
			goto(url) {
				console.log(url);

				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	/* page {
		background-color: rgb(240, 242, 244);
	} */

	.cell-hover-class {
		background-color: rgb(235, 237, 238);
	}

	.view-flex-rs {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
	}

	.view-flex-rc {
		display: flex;
		flex-direction: row;
		justify-content: center;
	}

	.view-flex-re {
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
	}

	.view-flex-cs {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
	}

	.view-flex-cc {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.view-flex-ce {
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
	}

	.line-body {
		padding-left: 10px;
		padding-right: 10px;
	}

	.required-star {
		color: #FF0000;
		font-size: 15px;
		width: 20px;
		text-align: center;
		padding-left: 0px;
		padding-right: 2px;
	}

	.item-title {
		color: #909399;
		font-size: 15px;
	}

	.mline-text {
		padding-left: 2px;
		width: 100%;
		/* background-color:#909399; */
		height: 100px;
		border: 1px solid #FF5A5F;
		border-radius: 5px;
	}
</style>

<style lang="scss" scoped>
	.u-cell-icon {
		width: 36rpx;
		height: 36rpx;
		margin-right: 8rpx;
	}

	.slot-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
	}

	.slot-image {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
		margin-right: 10px;
		width: 30px;
		height: 30px;
	}

	.slot-text {
		flex: 1;
		font-size: 14px;
		color: #4cd964;
		margin-right: 10px;
	}

	.img-container {
		margin-bottom: 20px;

		.note-image-box {
			margin-top: 5px;
			display: flex;
			flex-wrap: wrap;
			padding: 10px;

			.note-image-item {
				position: relative;
				width: 33.3%;
				height: 0;
				padding-top: 33.3%;
				box-sizing: border-box;
				// background-color: #18B566;


				.close-icon {
					display: flex;
					justify-content: center;
					align-items: center;
					position: absolute;
					right: 0px;
					top: 0px;
					width: 22px;
					height: 22px;
					border-radius: 50%;
					background-color: #d5d5d5;
					z-index: 2;
				}

				.image-box {
					display: flex;
					justify-content: center;

					align-items: center;
					position: absolute;
					top: 5px;
					right: 5px;
					border: 5px;
					left: 5px;
					border: 1px #eee solid;
					border-radius: 5px;
					overflow: hidden;
					width: 95%;
					height: 95%;

				}
			}
		}
	}
</style>
