<template>
	<view>
		<view
			style="box-shadow: 0px 0px 8px 0px rgba(165, 189, 251, 0.4);width: 96%;border-top-right-radius: 10rpx;margin: 10rpx auto;padding-top: 10rpx;">
			<span
				style="width: 10rpx;height: 40rpx;background-color: #2979ff;display: block;float: left;margin-top: 20rpx;"></span>
			<view style="width: 92%;margin: 0 auto;margin: 0 auto;">
				<view
					style="display: flex;justify-content: space-between;height: 80rpx;line-height: 80rpx;border-bottom: 1rpx solid #eff4ff;">
					<h3>基本信息</h3>
				</view>
				<view>
					<u-form :model="form" ref="uForm" label-width="200">
						<view style="width: 100%;">
							<u-form-item label="仓库名称:" prop="fWarehouseFid">
								<u-input v-model="form.fWarehouseName" type="select"
									@click="openWarehouse('fWarehouseFid')" />
							</u-form-item>
						</view>
						<!-- <view style="width: 100%;">
							<u-form-item label="巡检日期起:" prop="fInspectorBeginDatetime">
								<u-input type="select" v-model="form.fInspectorBeginDatetime"
									@click="openCalendar('fInspectorBeginDatetime')" />
							</u-form-item>
						</view> -->
						<!-- <view style="width: 100%;">
							<u-form-item label="巡检日期止:" prop="fInspectorEndDatetime">
								<u-input v-model="form.fInspectorEndDatetime" type="select"
									@click="openCalendar('fInspectorEndDatetime')" />
							</u-form-item>
						</view> -->
						<!-- <view style="width: 100%;">
							<u-form-item label="巡检人:" prop="fInspectorId">
								<u-input v-model="fInspectorName" type="select"
									@click="openInspector('fInspectorId')" />
							</u-form-item>
						</view> -->
						<view style="width: 100%;">
							<u-form-item label="备注:" prop="remark">
								<u-input type="textarea" height="70" v-model="form.fRemark" />
							</u-form-item>
						</view>
					</u-form>
				</view>
			</view>
		</view>
		<view
			style="box-shadow: 0px 0px 8px 0px rgba(165, 189, 251, 0.4);width: 96%;border-top-right-radius: 10rpx;margin: 10rpx auto;padding-top: 10rpx;">
			<span
				style="width: 10rpx;height: 40rpx;background-color: #2979ff;display: block;float: left;margin-top: 20rpx;"></span>
			<view style="width: 92%;margin: 0 auto;margin: 0 auto;">
				<view
					style="display: flex;justify-content: space-between;height: 80rpx;line-height: 80rpx;border-bottom: 1rpx solid #eff4ff;">
					<h3>巡检明细</h3>
					<!-- <view class="various"><u-icon name="trash" color="#2979ff" size="44" @click="detailRemoval(index)"></u-icon></view> -->
				</view>
				<view>
					<view>
						<u-upload @on-remove="onRemove" @on-success="success" :action="action" deletable
							:header="headers" :file-list="fileList"></u-upload>
					</view>
				</view>
			</view>
		</view>
		<view
			style="z-index: 100;width: 100%;position:fixed; bottom:44rpx;background-color: #FFFFFF;padding-left: 20px;padding-right: 20px;">
			<u-button type="primary" @click="appCheckCode">确认添加</u-button>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
		<u-toast ref="uToast" />
		<u-calendar v-model="calendar" mode="date" @change="changeData"></u-calendar>
		<u-select v-model="warehouse" value-name="fId" label-name="fName" :list="warehouseList"
			@confirm="warehouseConfirm"></u-select>
		<u-select v-model="inspector" value-name="userId" label-name="userName" :list="inspectorList"
			@confirm="inspectorConfirm"></u-select>
		<u-picker mode="time" v-model="detailedTime" :params="params" @confirm="confirm"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					fWarehouseFid: '',
					fWarehouseName: '',
					fRemark: '',
					fPhotoUrl: []
				},
				fName: '',
				headers: {
					Authorization: 'Bearer ' + uni.getStorageSync('lifeData').vuex_token
				},
				action: this.$u.http.config.baseUrl + '/common/upload',
				fileList: [],
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				fInspectorName: '',
				list: [],
				rules: {},
				calendar: false,
				detailedTime: false,
				type: '',
				index: null,
				warehouse: false,
				inspector: false,
				warehouseList: [],
				inspectorList: [],
				pictureEist: []
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		created() {
			this.$u.get('/basicdata/warehouse/lists?fStatus=0&delFlag=0').then(res => {
				this.warehouseList = res.rows
			})
			this.$u.get('/system/user/selectUserByRole', {
				roleName: "巡检员"
			}).then(res => {
				this.inspectorList = res.rows
			})
		},
		methods: {
			newDetails() {
				this.list.push({
					fWarehouseFid: '',
					fWarehouseName: '',
					fRemark: '',
					fPhotoUrl: []
				})
			},
			//上传成功触发
			success(data, index, lists, name) {
				this.pictureEist = lists
			},
			onRemove(index, lists, name) {
				this.pictureEist = lists
			},
			appCheckCode() {
				if(this.form.fPhotoUrl){
					this.$refs.uToast.show({
						title: '请上传附件',
						position:'bottom'
					})
				}
				if(this.form.fWarehouseFid){
					this.$refs.uToast.show({
						title: '请选择仓库名称',
						position:'bottom'
					})
				}
				this.pictureEist.forEach(item=>this.form.fPhotoUrl.push({url:item.response.url}))
				this.form.fPhotoUrl = JSON.stringify(this.form.fPhotoUrl)
				this.$u.post('/warehouse/check/saveCheckItemsDetails', {
					...this.form
				}).then(res => {
					this.$refs.uToast.show({
						title: '创建成功',
						type: 'success',
						callback() {
							uni.navigateBack()
						}
					})
				})
			},
			//日历确定触发
			changeData(e) {
				if (this.type == 'fInspectorBeginDatetime') this.form.fInspectorBeginDatetime = e.result + ' 00:00:00'
				if (this.type == 'fInspectorEndDatetime') this.form.fInspectorEndDatetime = e.result + ' 23:59:59'
			},
			// 计划日期选择
			confirm(e) {
				console.log(e)
				if (this.type == 'fInspectionDatetime') this.list[this.index].fInspectionDatetime = e.year + "-" + e
					.month + "-" + e.day + ' ' + e.hour + ":" + e.minute + ":" + e.second
			},
			//打开日历
			openCalendar(type, index) {
				if (type == 'fInspectorBeginDatetime' && index == undefined) {
					this.type = type
					this.calendar = !this.calendar
				}
				if (type == 'fInspectorEndDatetime' && index == undefined) {
					this.type = type
					this.calendar = !this.calendar
				}
				if (type == 'fInspectionDatetime' && (index == 0 || index > 0)) {
					this.type = type
					this.index = index
					this.detailedTime = !this.detailedTime
				}
			},
			//打开仓库
			openWarehouse(store, index) {
				if (store == 'fWarehouseFid' && index == undefined) {
					this.store = store
					this.warehouse = !this.warehouse
				}
				if (store == 'fWarehouseFidName' && (index == 0 || index > 0)) {
					this.store = store
					this.index = index
					this.warehouse = !this.warehouse
				}
			},
			//仓库选择
			warehouseConfirm(e) {
				if (this.store == 'fWarehouseFid') {
					this.form.fWarehouseFid = e[0].value
					this.form.fWarehouseName = e[0].label
				}
				if (this.store == 'fWarehouseFidName') {
					this.list[this.index].fWarehouseFid = e[0].value
					this.list[this.index].fWarehouseFidName = e[0].label
				}
			},
			openInspector(people, index) {
				if (people == 'fInspectorId' && index == undefined) {
					this.people = people
					this.inspector = !this.inspector
				}
				if (people == 'fInspectorName' && (index == 0 || index > 0)) {
					this.people = people
					this.index = index
					this.inspector = !this.inspector
				}
			},
			//明细移除
			detailRemoval(index) {
				this.list.splice(index, 1);
			},
			//选择巡检员
			inspectorConfirm(e) {
				if (this.people == 'fInspectorId') {
					this.form.fInspectorId = e[0].value
					this.fInspectorName = e[0].label
				}
				if (this.people == 'fInspectorName') {
					this.list[this.index].fInspectorId = e[0].value
					this.list[this.index].fInspectorName = e[0].label
				}
			},
			tips(content) {
				this.$refs.uTips.show({
					title: content,
					type: 'error',
					duration: '2300'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
</style>
