<template>
	<view class="hzIndex">
		<hzHeader title="服务报修"></hzHeader>
		<view class="container hzContent">
			<l-file ref="lFile" @up-success="onSuccess"></l-file>
			<view class="main">
				<view class="tab-box">
					<view class="tab-item" :class="currentTabIndex == 0 ? 'active_tab' : ''"
						@click="currentTabIndex = 0">
						维保填报
						<view class="tabBottom" v-if="currentTabIndex == 0"></view>
					</view>
					<view class="tab-item" :class="currentTabIndex == 1 ? 'active_tab' : ''"
						@click="currentTabIndex = 1">
						维保记录
						<view class="tabBottom" v-if="currentTabIndex == 1"></view>
					</view>
				</view>
			</view>
			<view class="content" v-if="currentTabIndex == 0">
				<view class="interviewee">
					<!-- <view class="radio">
						<view>
							<view class="barber">
								<view class="barber-item" @click="changeItemTabIndex(0)">
									<text class="round" :class="itemTabIndex == 0 ? 'barberactive' : ''"></text>
									<text class="input_left">维保服务</text>
								</view>
								<view class="barber-item" @click="changeItemTabIndex(1)">
									<text class="round" :class="itemTabIndex == 1 ? 'barberactive' : ''"></text>
									<text class="input_left">专项服务</text>
								</view>
							</view>
						</view>

						<view class="radiolist" style="border-top:0.5px solid #eeeeee">
							<view style="border-top: none;border-bottom: 0.5px solid #eeeeee;" class=""
								@click="showradio(index)" v-for="(item, index) in firstRepairItems" :key="index"
								:class="[firstIndex == index ? 'showcolor' : '']">
								<p class="item_title">{{ item.name }}</p>
								<span class="item_more">{{ item.sub_name }}</span>
								<image src="/static/imgs/handel.png" v-if="firstIndex == index" />
							</view>
						</view>
					</view> -->
					<view class="form-box card-box">
						<view class="dateTit">
							<view class="leftIcon">

							</view>
							<text style="font-size:32upx;color:#333;font-weight: 600;">服务类型</text>
						</view>
						<view class="barber">
							<view class="barber-box">
								<view class="barber-item" :class="itemTabIndex == 0 ? 'barberactive' : ''"
									@click="changeItemTabIndex(0)">
									维保服务
								</view>
								<view class="barber-item" :class="itemTabIndex == 1 ? 'barberactive' : ''"
									@click="changeItemTabIndex(1)">
									专项服务
								</view>
							</view>
						</view>
						<view class="form-item">
							<text class="label">服务项目<text class="required">*</text></text>
							<view class="ipt-box select">
								<image class="arrow" src="/static/icons/right-arrow.png" mode=""></image>
								<picker class="picker" v-if="firstRepairItems.length > 0" :range="firstRepairItems"
									@change="showradio" range-key="name">
									<view>{{ firstRepairItems[firstIndex].name }}</view>
								</picker>
							</view>
						</view>
					</view>
					<view class="form-box card-box">
						<view class="form-item">
							<text class="label" v-if="itemTabIndex==0">维保区域<text class="required">*</text></text>
							<text class="label" v-if="itemTabIndex==1">服务区域<text class="required">*</text></text>
							<view class="ipt-box select">
								<image class="arrow" src="/static/icons/right-arrow.png" mode=""></image>
								<picker class="picker" v-if="places.length > 0" :range="places" @change="changePlace"
									range-key="name">
									<view>{{ places[placeIndex].name }}</view>
								</picker>
							</view>
						</view>
						<view class="form-item">
							<text class="label" v-if="itemTabIndex==0">维保小项<text class="required">*</text></text>
							<text class="label" v-if="itemTabIndex==1">服务小项<text class="required">*</text></text>
							<view class="ipt-box select">
								<image class="arrow" src="/static/icons/right-arrow.png" mode=""></image>
								<picker class="picker" v-if="secondRepairItems.length > 0" :range="secondRepairItems"
									@change="changeSecondRepairItems" range-key="name">
									<view>{{ secondRepairItems[secondIndex].name }}</view>
								</picker>
							</view>
						</view>
						<view class="form-item" v-if="deviceList.length>0">
							<text class="label">设备编号<text class="required">*</text></text>
							<view class="ipt-box select">
								<image class="arrow" src="/static/icons/right-arrow.png" mode=""></image>
								<jPicker class="cont" @sure="pickerChange($event,'device_no')" :options="deviceList"
									showKey="device_no" :val="deviceListIndex" placeholderText="-请选择设备编号-" />
								<!-- <picker class="picker"  :range="deviceList" @change="changedeviceList" range-key="device_no">
								<view>{{ deviceList[deviceListIndex].device_no }}</view>
							</picker> -->
							</view>
						</view>
						<view class="form-item" v-if="deviceList.length>0&&deviceListIndex!=-1">
							<text class="label">设备位置</text>
							<view class="ipt-box">
								<input class="top-t" v-model="deviceList[deviceListIndex].device_addr" disabled
									maxlength="50" />
							</view>
						</view>
						<view class="form-item" v-if="deviceList.length>0&&deviceListIndex!=-1">
							<text class="label">设备名称</text>
							<view class="ipt-box">
								<input class="top-t" v-model="deviceList[deviceListIndex].device_name" disabled
									maxlength="50" />
							</view>
						</view>
						<view class="form-item">
							<text class="label" v-if="itemTabIndex==0">维保类型<text class="required">*</text></text>
							<text class="label" v-if="itemTabIndex==1">服务类型<text class="required">*</text></text>
							<view class="ipt-box select">
								<image class="arrow" src="/static/icons/right-arrow.png" mode=""></image>
								<picker class="picker" :range="wbTypes" @change="changeWbTypes" range-key="name">
									<view>{{ wbTypes[wbTypesIndex] }}</view>
								</picker>
							</view>
						</view>
						<view class="form-item" v-if="wbTypesIndex==1">
							<text class="label">到场时间:</text>
							<view class="ipt-box select">
								<image class="arrow" src="/static/icons/right-arrow.png" mode=""></image>
								<picker class="picker" mode="time" :value="arrival_time" @change="arrivalTimeChange">
									<view>{{arrival_time}}</view>
								</picker>
							</view>
						</view>
						<view class="form-item flex-colum">
							<text class="label" v-if="itemTabIndex==0">维保内容<text class="required">*</text></text>
							<text class="label" v-if="itemTabIndex==1">服务内容<text class="required">*</text></text>
							<view class="ipt-box"><input class="top-t" v-model="formDesc" placeholder="请输入维保内容"
									type="text" maxlength="200" /></view>
						</view>
						<view class="form-item flex-colum">
							<text class="label">更换配件<text class="required">*</text></text>
							<!-- <view class="ipt-box select">
								<radio-group @change="radioChange">
									<label v-for="(item, index) in replacePartsItem" :key="item.value">
										<view style="display: inline-block;margin-right: 20upx;">
											<radio :value="item.value" :checked="item.value ==replacePartsItemIndex"
												color="#00c277" />
											{{item.name}}
										</view>
									</label>
								</radio-group>
							</view> -->
							<view class="box box-row-reverse box-around">
								<view class="check-box box box-row-reverse box-align-center" @click="radioChange(index)"
									v-for="(item, index) in replacePartsItem" :key="index">
									<image class="check-img"
										:src="replacePartsItemIndex == index?eckList.eck:eckList.nEck" mode=""></image>
									<view class="check-name">{{item.name}}</view>
								</view>
							</view>
						</view>
						<view class="form-item" v-if="replacePartsItemIndex==1">
							<text class="label">配件信息:</text>
							<view class="ipt-box">
								<input class="top-t" v-model="faultProposal" placeholder="请输入更换的配件信息" type="text"
									maxlength="50" />
							</view>
						</view>
						<view class="form-item" v-show="false">
							<text class="label">附件上传:</text>
							<view class="ipt-box box box-between">
								<view class="box  box-column" style="color: #aaaaaa;font-size: 26upx;flex-grow:1">
									<view class="box box-between" v-if="uploadFileNames.length>0"
										v-for="(item, i) in uploadFileNames" :key="i"
										style="margin: 8upx 0upx;font-size: 28upx;color: #00C277;padding-right: 20upx;">
										<view>{{item}}</view>
										<view style="height: 42upx;width: 42upx;text-align: center;"
											@click="removeUploadFile(i)">
											<image style="height: 42upx;width: 42upx;"
												src="../../static/icons/jian.png"></image>
										</view>
									</view>
									<view v-if="uploadFileNames.length==0" style="padding: 10upx;">
										未上传附件(仅支持doc、docx、xls、xlsx、pdf文件)</view>
								</view>
								<view @tap="onUpload"
									style="min-width: 90upx;border: 1px solid #00C277; border-radius: 10upx;font-size: 24upx;color: #00C277;height: 44upx;line-height: 44upx;text-align: center;">
									上传
								</view>
							</view>
						</view>
					</view>
					<!-- <view style="margin: 20upx;">
						<text class="input_left" v-if="itemTabIndex==0">维保图片（最多上传6张）</text>
						<text class="input_left" v-if="itemTabIndex==1">服务图片（最多上传6张）</text>
					</view>
					<view class="pic">
						<view class="img-box">
							<view class="img-item" v-for="(item, index) in imgs" :key="index">
								<image class="remove-btn" @click="removeImg(index)" src="/static/icons/delete-icon.png"
									mode=""></image>
								<image class="img" :src="item.replace(/[\r\n]/g,'')" mode=""></image>
							</view>
							<view class="img-item upload-btn" @click="chooseImg()" v-if="imgs.length < 6">
								<image class="img" src="/static/imgs/tianjia-img.png" mode=""></image>
							</view>
						</view>
					</view> -->
					<view class="form-box card-box">
						<view class="form-item flex-colum">
							<text class="label" v-if="itemTabIndex==0" style="width: 100%;">维保图片<text
									style="color: #CACACA;">（最多上传6张）</text></text>
							<text class="label" v-if="itemTabIndex==1" style="width: 100%;">服务图片<text
									style="color: #CACACA;">（最多上传6张）</text></text>
							<view class="pic" style="padding-left: 0;">
								<view class="img-box">
									<view class="img-item" v-for="(item, index) in imgs" :key="index">
										<image class="remove-btn" @click="removeImg(index)"
											src="/static/icons/delete-icon.png" mode=""></image>
										<image class="img" :src="item.replace(/[\r\n]/g,'')" mode=""></image>
									</view>
									<view class="img-item upload-btn" @click="chooseImg()" v-if="imgs.length < 3">
										<image class="img" src="/static/imgs/tianjia-img.png" mode=""></image>
									</view>
								</view>
							</view>
							<view style="font-size: 28rpx;font-weight: 600;color: red;border-bottom: 1px solid #eee;">互联网信息系统严禁存储、传输、处理涉及国家秘密企业秘密以及敏感信息，违者将严肃问责追责!</view>
						</view>
					</view>

				</view>
				<view class="occupied"></view>
				<view class="footer-btn" @click="submit">
					<view class="btn">提交</view>
				</view>
			</view>
			<!-- 检查列表 -->
			<view v-else style="margin-top: 24upx;">
				<view class="card-box" style="margin: 24upx;">
					<view>
						<lb-picker ref="picker1" v-model="repairCheckValue" mode="multiSelector" :props="myProps"
							:list="repairItems" :level="2" :dataset="{ name: 'repairCheckName' }"
							@confirm="handleConfirm">
						</lb-picker>
					</view>
					<view class="form-item searchv">
						<picker class="time-data" mode="date" @change="startDateChange">
							<view class="">{{ startDate }}</view>
						</picker>
						<text class="timecenter">至</text>
						<picker class="time-data" mode="date" @change="endDateChange">
							<view class="">{{ endDate }}</view>
						</picker>
						<!-- <view class="search" style="height: 60upx;font-size: 26upx;margin-top: 7upx;" @click="searchYjList">搜索</view> -->
						<!-- <image style="width: 5vh;height: 5vh;margin-left: 1vh;" @click="search" src="/static/icons/seach.png" mode=""></image>
						 -->
					</view>
				</view>
				<view class="list-box" v-if="repair.length > 0">
					<view class="detail-box" v-for="(item, i) in repair" :key="i">
						<view class="detail_header" @click="details(item)">
							<image class="blueSign" src="@/static/haircut/bx.png" mode=""></image>
							<text class="font-tilte" v-if="item.is_inspection==2">维保服务</text>
							<text class="font-tilte" v-if="item.is_inspection==3">专项服务</text>
							<text v-if="item.reply_flag =='0'" class="font-result">未审核</text>
							<text v-if="item.reply_flag =='1'" class="font-result" style="color: #ff9000;">已拒绝</text>
							<text v-if="item.reply_flag =='2'" class="font-result" style="color: green;">已通过</text>
							<text v-if="item.reply_flag =='3'" class="font-result" style="color: #666666;">已取消</text>
						</view>

						<view class="detail_msg">
							<!-- <view class="info-item">
							<text>维保人：</text>
							<text class="infoSpan">{{ item.userName }}</text>
						</view> -->
							<view class="info-item" @click="details(item)">
								<text v-if="item.is_inspection==2">维保选项：</text>
								<text v-if="item.is_inspection==3">服务选项：</text>
								<text class="infoSpan">{{ item.repair_option_name }}</text>
							</view>
							<view class="info-item" @click="details(item)">
								<text v-if="item.is_inspection==2">维保区域：</text>
								<text v-if="item.is_inspection==3">服务区域：</text>
								<text class="infoSpan">{{ item.repair_place}}</text>
							</view>
							<view v-if="item.repair_option_sub_name" class="info-item" @click="details(item)">
								<text v-if="item.is_inspection==2">维保小项：</text>
								<text v-if="item.is_inspection==3">服务小项：</text>
								<text class="infoSpan">{{ item.repair_option_sub_name}}</text>
							</view>
							<view v-if="item.repair_option_sub_name=='电梯维保'" class="info-item" @click="details(item)">
								<text>设备编号：</text>
								<text class="infoSpan">{{ item.elevator_no}}</text>
							</view>
							<view v-if="item.repair_option_sub_name=='电梯维保'" class="info-item" @click="details(item)">
								<text>设备位置：</text>
								<text class="infoSpan">{{item.repair_floor}}</text>
							</view>
							<view class="info-item" @click="details(item)">
								<text v-if="item.is_inspection==2">维保类型：</text>
								<text v-if="item.is_inspection==3">服务类型：</text>
								<text class="infoSpan">{{ item.wb_types}}</text>
							</view>
							<view class="info-item" @click="details(item)">
								<text v-if="item.is_inspection==2">维保内容：</text>
								<text v-if="item.is_inspection==3">服务内容：</text>
								<text class="infoSpan">{{ item.fault_detail}}</text>
							</view>
							<view v-if="item.fault_proposal" class="info-item" @click="details(item)">
								<text>更换配件：</text>
								<text class="infoSpan">{{ item.fault_proposal}}</text>
							</view>
							<view class="info-item" @click="details(item)">
								<text v-if="item.is_inspection==2">维保时间：</text>
								<text v-if="item.is_inspection==3">服务时间：</text>
								<text class="infoSpan">{{ item.repair_time}}</text>
							</view>
							<view class="info-item" @click="details(item)">
								<text v-if="item.is_inspection==2">维保人员：</text>
								<text v-if="item.is_inspection==3">服务人员：</text>
								<text class="infoSpan">{{ item.repair_person_name}}</text>
							</view>
							<view class="comment-btn" v-if="item.reply_flag==0" @click="cancleRepair(item)">取消</view>
							<!-- <view class="comment-btn" v-if="item.conmentStatus == 0" @click="goEvaluatePage(item.detailId)">评价</view> -->
							<!-- <view class="comment-btn bg-ccc" v-if="item.conmentStatus == 1">已评价</view> -->
						</view>
					</view>
				</view>
				<content-none v-else :padTop="20"></content-none>
			</view>
			<load-more v-if="currentTabIndex == 1" :loadingType="loadingType" :contentText="contentText"></load-more>
			<!-- <view class="common-shade box box-center box-align-center" v-if="showAlert" @click="showAlert=false" >
			<view  style="background: white;height: 160upx;width: 100%;border-radius: 10upx 10upx 0upx 0upx;position: absolute;bottom: 0upx;">
				<view @click="photo" style="border-bottom: 1px solid #000000; border-radius: 10upx 10upx 0upx 0upx; height: 80upx;line-height: 80upx;text-align: center;">
					拍摄
				</view>
				<view @click="getImage" style="height: 80upx;line-height: 80upx;text-align: center;">
					从相册选择
				</view>
			
			</view>
		</view> -->
		</view>
	</view>
</template>

<script>
	import {
		saveFaultRepairInfo,
		getMyFaultRepairList,
		getFaultRepairByParentCode,
		getFaultRepairAll,
		getDeviceList,
		cancleRepair
	} from '@/common/api.js';
	import {
		callbackRequest,
		getStorage,
		alertTip,
		convertImgToBase64,
		formatDate,
		wxSdk,
		uploadImg
	} from '@/common/util.js';
	import loadMore from '@/components/loadMore.vue';
	import contentNone from '@/components/contentNone.vue';
	import uniNumberBox from '@/components/uni-number-box/uni-number-box.vue';
	import LbPicker from '@/components/lb-picker';
	import lFile from '@/components/l-file/l-file.vue';
	import jPicker from '../../components/J-Picker/jPicker.vue';
	import {
		pathToBase64
	} from '@/js_sdk/mmmm-image-tools/index.js';
	export default {
		components: {
			loadMore,
			contentNone,
			uniNumberBox,
			LbPicker,
			lFile,
			jPicker
		},
		data() {
			return {
				itemTabIndex: 0,
				formatDate: formatDate,
				//分页
				page: 1,
				pageSize: 10,
				loadingType: 0, //0-loading前；1-loading中；2-没有更多了
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				places: [{
					id: '0',
					name: '-请选择维保区域-'
				}, {
					id: '1',
					name: '科技楼'
				}, {
					id: '2',
					name: '调度楼'
				}, {
					id: '3',
					name: '后勤楼'
				}, {
					id: '4',
					name: '会议中心'
				}], //, { id: '5', name: '其它' }
				placeIndex: 0,
				userInfo: getStorage('userInfo'),
				entryOrderPic: [],
				showIndex: 0,
				currentTabIndex: 0,
				repair: [],
				formBxwz: '',
				formDesc: '',
				formName: getStorage('userInfo').userName,
				formTelp: getStorage('userInfo').telnumber,
				faultProposal: "",
				faultEvaluate: "",
				imgs: [],
				imgsId: [],
				index: 0,
				firstRepairItems: [],
				firstIndex: 0,
				secondRepairItems: [],
				secondIndex: 0,
				repairFloor: '',
				repairRoomNo: '',
				urgents: ['不紧急', '紧急'],
				urgentIndex: 0,
				checkFraction: '0',
				wbTypes: ['-请选择维保类型-', '维修', '保养'],
				wbTypesIndex: 0,
				myProps: {
					label: 'name',
					value: 'code',
					children: 'child'
				},
				repairItems: [],
				repairCheckValue: [],
				repairCheckName: '',
				startDate: this.getDay(-7),
				endDate: this.getDay(0),
				uploadFileNames: [],
				uploadFileIds: [],
				deviceList: [],
				deviceListIndex: -1,
				replacePartsItem: [{
						value: '0',
						name: '否'
					},
					{
						value: '1',
						name: '是'
					}
				],
				replacePartsItemIndex: 0,
				arrival_time: '00:00',
				showAlert: false,
				eckList: {
					eck: require('@/static/haircut/eck.png'),
					nEck: require('@/static/haircut/nEck.png')
				}
			};
		},
		watch: {
			currentTabIndex: function(newVal, oldVal) {
				if (newVal == 1) {
					this.page = 1;
					this.loadingType = 0;
					this.dataList();
				} else {}
			},
			checkFraction: function(newVal, oldVal) {
				var l = newVal.length;
				if (l == 1) {
					var oneReg = new RegExp("^[0-9\-]");
					if (!oneReg.test(newVal)) {
						newVal = newVal.slice(0, -1);
						setTimeout(() => {
							this.checkFraction = newVal
						}, 100);
					}
				} else {
					let num = newVal.charAt(newVal.length - 1)
					var reg = new RegExp("[0-9]")
					if (!reg.test(num)) {
						newVal = newVal.slice(0, -1);
						setTimeout(() => {
							this.checkFraction = newVal
						}, 100);
					}
				}
			},
			itemTabIndex: function(newVal, oldVal) {
				this.getFirstRepairItems();
			}
		},
		onLoad(option) {
			this.currentTabIndex = option.currentTabIndex || 0;
			// 部门
			this.getFaultRepairAll();
			if (this.currentTabIndex == 1) {

				this.page = 1;
				this.loadingType = 0;
				this.dataList();
			} else {
				this.getFirstRepairItems();
			}

		},
		onReachBottom() {
			if (this.loadingType !== 0 || this.currentTabIndex == 0) {
				return;
			}
			this.loadingType = 1;
			this.page = this.page + 1;
			this.dataList();
		},
		methods: {
			arrivalTimeChange(e) {
				this.arrival_time = e.target.value;
			},
			pickerChange(e, key) {
				this.deviceListIndex = e.pickerIndex
				//this.nData[key]=e.pickerVal;
			},
			cancleRepair(item) {
				let params = {
					method: cancleRepair,
					data: {
						id: item.id,
						reply_flag: '3'
					}
				};
				callbackRequest(params).then(res => {
					if (res.data.returnCode == 1) {
						alertTip("已成功取消！");
						this.page = 1;
						this.loadingType = 0;
						this.dataList();
					} else {
						alertTip(res.data.returnMsg);
					}
				});
			},
			changeItemTabIndex(e) {
				this.itemTabIndex = e;
				this.places = e == 0 ? [{
					id: '0',
					name: '-请选择维保区域-'
				}, {
					id: '1',
					name: '科技楼'
				}, {
					id: '2',
					name: '调度楼'
				}, {
					id: '3',
					name: '后勤楼'
				}, {
					id: '4',
					name: '会议中心'
				}] : [{
					id: '0',
					name: '-请选择服务区域-'
				}, {
					id: '1',
					name: '科技楼'
				}, {
					id: '2',
					name: '调度楼'
				}, {
					id: '3',
					name: '后勤楼'
				}, {
					id: '4',
					name: '会议中心'
				}];
				this.placeIndex = 0;
				this.firstIndex = 0;
				this.wbTypes = e == 0 ? ['-请选择维保类型-', '维修', '保养'] : ['-请选择服务类型-', '维修', '保养'];
				this.wbTypesIndex = 0;
			},
			getFirstRepairItems() {
				let params = {
					method: getFaultRepairByParentCode,
					data: {
						parentCode: '0',
						itemType: this.itemTabIndex == 0 ? 3 : 4
					}
				};
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						this.firstRepairItems = res.returnData;
						this.getSecondRepairItems();
					} else {
						alertTip(res.returnMsg);
					}
				});
			},
			getSecondRepairItems() {
				this.secondIndex = 0;
				var parentCode = this.firstRepairItems[this.firstIndex].code;
				let params = {
					method: getFaultRepairByParentCode,
					data: {
						parentCode: parentCode,
						itemType: this.itemTabIndex == 0 ? 3 : 4
					}
				};
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						if (res.returnData.length > 0) {
							this.secondRepairItems = [{
								id: '',
								name: '-请选择' + (this.itemTabIndex == 0 ? '维保' : '服务') + '小项-'
							}];
							this.secondRepairItems = this.secondRepairItems.concat(res.returnData);
						} else {
							this.secondRepairItems = [{
								id: '',
								name: '暂无'
							}]
						}
						this.getDeviceList();
					} else {
						alertTip(res.returnMsg);
					}
				});
			},
			getDeviceList() {
				var id = this.secondRepairItems[this.secondIndex].id;
				if (id == '') {
					this.deviceList = [];
					return;
				}
				this.deviceListIndex = -1;
				let params = {
					method: getDeviceList,
					data: {
						repairItemsId: id,
						deviceRegion: this.placeIndex == 0 ? "" : this.places[this.placeIndex].name
					}
				};
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						this.deviceList = res.returnData || [];
						// if(this.deviceList.length>0){
						// 	var arr = [{device_addr:'',device_name:'',device_no:'-请选择设备编号-'}];
						// 	this.deviceList = arr.concat(this.deviceList);
						// }
					} else {
						this.deviceList = [];
					}
				});
			},
			getFaultRepairAll() {
				let params = {
					method: getFaultRepairAll,
					data: {
						itemType: 3
					}
				};
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						this.repairItems = res.returnData;
					} else {
						alertTip(res.returnMsg);
					}
				});
			},
			changePlace(e) {
				this.placeIndex = e.detail.value;
				this.getDeviceList();
			},
			changeWbTypes(e) {
				this.wbTypesIndex = e.detail.value;
			},
			changedeviceList(e) {
				this.deviceListIndex = e.detail.value;
			},
			details: function(item) {
				uni.navigateTo({
					url: '/pages/malfunc-check/check-details-wb?id=' + item.id
				});
			},
			cleanRepair() {
				this.page = 1;
				this.loadingType = 0;
				this.repair = [];
				this.repairCheckValue = [];
				this.repairCheckName = '';
				this.dataList();
			},
			startDateChange: function(e) {
				this.page = 1;
				this.loadingType = 0;
				this.repair = [];
				this.startDate = e.target.value;
				this.dataList();
			},
			endDateChange: function(e) {
				this.page = 1;
				this.loadingType = 0;
				this.repair = [];
				this.endDate = e.target.value;
				this.dataList();
			},
			radioChange(index) {
				this.replacePartsItemIndex = index;
			},
			handleTap(picker) {
				this.$refs[picker].show()
			},
			handleConfirm(e) {
				if (e) {
					const name = e.dataset.name
					const label = e.item.map(m => m.name).join('-')
					if (name && label) {
						this[name] = label
					}
					this.repairCheckValue = e.value;
					this.page = 1;
					this.loadingType = 0;
					this.repair = [];
					this.dataList();
				}
			},
			changeSecondRepairItems(e) {
				this.secondIndex = e.detail.value;
				this.getDeviceList();
			},
			unbChange(value, index) {
				this.checkFraction = value;
			},
			getDay(i) {
				var date1 = new Date(new Date().getTime() + i * 24 * 60 * 60 * 1000);

				var year = date1.getFullYear();
				var month = date1.getMonth() + 1;
				if (month < 10) {
					month = "0" + month;
				}
				var day = date1.getDate();
				if (day < 10) {
					day = "0" + day;
				}
				return year + '-' + month + '-' + day;
			},
			dataList() {
				let params = {
					method: getMyFaultRepairList,
					data: {
						userId: this.userInfo.id,
						pageNum: this.page,
						pageSize: this.pageSize,
						repairOption: (this.repairCheckValue[0] || '') + "",
						repairOptionSub: (this.repairCheckValue[1] || '') + "",
						startDate: this.startDate,
						endDate: this.endDate,
						isInspection: 2
					}
				};
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						if (this.page == 1) {
							this.repair = res.returnData || [];
						} else {
							if (res.returnData.length > 0) {
								this.repair = this.repair.concat(res.returnData);
								this.loadingType = 0;
							} else {
								this.loadingType = 2;
							}
						}
					} else {
						alertTip(res.returnMsg);
					}
				});
			},
			submit() {
				console.log(this.deviceListIndex, "asddddddd");
				if (this.placeIndex == 0) {
					alertTip('请选择' + (this.itemTabIndex == 0 ? '维保' : '服务') + '区域');
					return false;
				}
				if (this.secondRepairItems.length > 1 && this.secondIndex == 0) {
					alertTip('请选择' + (this.itemTabIndex == 0 ? '维保' : '服务') + '小项');
					return false;
				}
				if (this.deviceList.length > 0 && this.deviceListIndex == -1) {
					alertTip('请选择设备编号');
					return false;
				}
				if (this.wbTypesIndex == 0) {
					alertTip('请选择' + (this.itemTabIndex == 0 ? '维保' : '服务') + '类型');
					return false;
				}
				if (this.wbTypesIndex == 1 && this.arrival_time == '00:00') {
					alertTip('请选择到场时间');
					return false;
				}
				var regPhone = /^1[3|4|5|6|7|8|9]\d{9}$/;
				if (!this.formDesc) {
					alertTip('请输入' + (this.itemTabIndex == 0 ? '维保' : '服务') + '内容');
					return false;
				}
				let params = {
					method: saveFaultRepairInfo,
					data: {
						userId: this.userInfo.id,
						// repairDeptId:this.userInfo.deptId,//this.deptList[this.departmentIndex].id,
						// repairDeptName:this.userInfo.deptName,//this.deptList[this.departmentIndex].name,
						repairPersonId: this.userInfo.id,
						repairPersonName: this.formName,
						repairOption: this.firstRepairItems[this.firstIndex].code,
						repairOptionSub: this.secondRepairItems[this.secondIndex].code,
						repairAddr: this.formBxwz, //详细地址
						faultDetail: this.formDesc,
						faultPic1: this.imgsId[0],
						faultPic2: this.imgsId[1],
						faultPic3: this.imgsId[2],
						faultPic4: this.imgsId[3],
						faultPic5: this.imgsId[4],
						faultPic6: this.imgsId[5],
						repairPlace: this.places[this.placeIndex].name,
						repairPersonPhone: this.formTelp,
						isInspection: this.itemTabIndex == 0 ? 2 : 3,
						urgent: this.urgentIndex,
						repairFloor: this.deviceListIndex == -1 ? "" : this.deviceList[this.deviceListIndex]
							.device_addr,
						repairRoomNo: this.repairRoomNo,
						checkFraction: this.checkFraction,
						faultProposal: this.faultProposal,
						faultEvaluate: this.faultEvaluate,
						wbTypes: this.wbTypes[this.wbTypesIndex],
						elevatorNo: this.deviceListIndex == -1 ? "" : this.deviceList[this.deviceListIndex].device_no,
						uploadFileIds: this.uploadFileIds.join(','),
						replaceParts: this.replacePartsItemIndex,
						deviceName: this.deviceListIndex == -1 ? "" : this.deviceList[this.deviceListIndex]
							.device_name,
						arrivalTime: this.wbTypesIndex == 1 ? this.arrival_time : ''
					}
				};
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						alertTip(res.returnMsg);
						setTimeout(_ => {
							this.repair = [];
							this.imgs = [];
							this.imgsId = []
							this.showIndex = 0;
							this.currentTabIndex = 1;
							this.formBxwz = '';
							this.formDesc = '';
						}, 2000);
					} else {
						alertTip(res.returnMsg);
					}
				});
			},
			navTo(url) {
				uni.navigateTo({
					url
				});
			},
			showradio(e) {
				var self = this;
				self.firstIndex = e.detail.value;
				this.getSecondRepairItems();
			},
			async chooseImg() {
				let chec = 0;
				let sty = [];
				let _this = this;
				uni.showActionSheet({
					itemList: ['拍照', '相册'],
					success: function(resp) {
						chec = resp.tapIndex;
						if (chec == 0) {
							sty = ['camera']; //从相册相机选择 
						} else {
							sty = ['album']; //从相册相机选择
						}
						uni.chooseImage({
							count: 6,
							sizeType: ['compressed'],
							sourceType: sty,
							quality: 1,
							success: async function(res) {
								let resData = res.tempFilePaths;
								for (let i = 0; i < resData.length; i++) {
									if (_this.imgs.length > 6) {
										break;
									}
									uni.getImageInfo({
										src: resData[i],
										success: async (path) => {
											convertImgToBase64(path.path,
												async function(base64) {
													if (_this.imgs.length <
														6) {
														// _this.imgs.push(base64);
														uni.showLoading({
															title: '图片上传中'
														})
														let blength =
															base64.length;
														let glength = 7500;
														if (blength <=
															glength) {
															let uploadParam = {
																base64: base64,
																userId: getStorage(
																		'userInfo'
																	)
																	.userId +
																	i,
																groupEnd: '1'
															}
															await uploadImg
																(
																	uploadParam
																)
																.then(
																	resu => {
																		resu =
																			resu
																			.data;
																		uni
																			.hideLoading();
																		if (resu
																			.returnCode !=
																			1
																		) {
																			alertTip
																				(resu
																					.returnMsg
																				);
																		} else {
																			_this
																				.imgs
																				.push(
																					base64
																				);
																			_this
																				.imgsId
																				.push(
																					resu
																					.returnData +
																					".jpg"
																				);
																		}
																	});
														} else {
															let fnum =
																parseInt(
																	blength /
																	glength
																);
															for (let j =
																	1; j <
																fnum +
																1; j++) {
																if (j ==
																	fnum) {
																	let groupBase =
																		base64
																		.slice(
																			(j -
																				1
																			) *
																			glength
																		);
																	console
																		.log(
																			groupBase
																			.length,
																			"groupBaselength"
																		);
																	let uploadParam = {
																		base64: groupBase,
																		userId: getStorage(
																				'userInfo'
																			)
																			.userId +
																			i,
																		groupEnd: '1'
																	}
																	await uploadImg
																		(
																			uploadParam
																		)
																		.then(
																			resu => {
																				resu =
																					resu
																					.data;
																				if (resu
																					.returnCode ==
																					1
																				) {
																					_this
																						.imgs
																						.push(
																							base64
																						);
																					_this
																						.imgsId
																						.push(
																							resu
																							.returnData +
																							".jpg"
																						);
																				} else {
																					uni
																						.hideLoading();
																					alertTip
																						(resu
																							.returnMsg
																						);
																					return;
																				}
																			}
																		);
																} else {
																	let groupBase =
																		base64
																		.slice(
																			(j -
																				1
																			) *
																			glength,
																			glength *
																			j
																		);
																	let uploadParam = {
																		base64: groupBase,
																		userId: getStorage(
																				'userInfo'
																			)
																			.userId +
																			i,
																		groupEnd: '0'
																	}
																	await uploadImg
																		(
																			uploadParam
																		)
																		.then(
																			resu => {
																				resu =
																					resu
																					.data;
																				if (resu
																					.returnCode ==
																					1
																				) {} else {
																					uni
																						.hideLoading();
																					alertTip
																						(resu
																							.returnMsg
																						);
																					return;
																				}
																			}
																		);
																}

															}
															uni
																.hideLoading();
														}


													}

												});
										},
									});
								}

							}
						});
					},
					fail: function(resp) {
						console.log(resp.errMsg);
					}
				});
			},
			//删除图片
			removeImg(index) {
				this.imgs.splice(index, 1);
				this.imgsId.splice(index, 1);
			},
			onDown() {
				let url =
					'https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2534506313,1688529724&fm=26&gp=0.jpg';
				this.$refs.lFile.download(url, 'local')
					.then(path => {
						this.localPath = path;
					});
			},
			removeUploadFile(i) {
				this.uploadFileNames.splice(i, 1);
				this.uploadFileIds.splice(i, 1);
			},

			/* 上传 */
			onUpload() {
				this.$refs.lFile.upload({
					// #ifdef APP-PLUS
					// nvue页面使用时请查阅nvue获取当前webview的api，当前示例为vue窗口
					currentWebview: this.$mp.page.$getAppWebview(),
					// #endif
					//非真实地址，记得更换,调试时ios有跨域，需要后端开启跨域并且接口地址不要使用http://localhost/
					url: 'http://hz.witrear.logplat.top:27001/greenH5/greenH5modul/rest/uploadFile/upload',
					//默认file,上传文件的key
					name: 'myFile',
					userId: this.userInfo.id,

					// header: {'Authorization':'token'},
					//...其他参数
				});
			},
			onSuccess(res) {
				var returnCode = JSON.parse(res.data.id).returnCode;
				if (returnCode == 1) {
					this.uploadFileNames.push(res.fileName);
					this.uploadFileIds.push(JSON.parse(res.data.id).id);
					console.log(this.uploadFileNames, 'uploadFileNames');
					console.log(this.uploadFileIds, 'uploadFileIds');
				} else {
					alertTip(JSON.parse(res.data.id).returnMsg);
				}

			}
		}
	};
</script>

<style lang="scss">
	@import url('../../static/css/repair/malfunction-repair.css');
	@import '@/static/css/common.scss';

	.cont {
		display: block;
		margin-left: 10upx;
		position: relative;
		cursor: pointer;
	}

	.statusred {
		float: right;
		margin-right: 30upx;
		color: red;
	}

	.barber {
		margin-top: 32upx;
		// margin-left: 24upx;
		// border-bottom: 1px solid #eee;
		padding: 0 40upx;

		.barber-box {
			display: flex;
			flex-direction: row;
			flex-wrap: wrap;
			align-items: center;
			justify-content: space-between;

			.barber-item {
				width: 128*2upx;
				height: 38*2upx;
				background: #F2F6FA;
				border-radius: 4*2upx;
				border: 1px solid #F2F6FA;
				line-height: 38*2upx;
				color: #555555;
				text-align: center;
				font-size: 28upx;
				// margin-left: 28upx;
				margin-top: 24upx;
			}

			.barber-item:nth-of-type(3n-2) {
				margin-left: 0;
			}

			.barberactive {
				background: #EDFCF7;
				border: 1px solid #00ADA6;
				color: #0DB0A7;
			}
		}
	}

	.box {
		display: flex;
		display: -webkit-flex;
	}

	.box-row-reverse {
		flex-direction: row;
	}

	/*水平排列*/
	.box-column {
		flex-direction: column;
	}

	/*上下排列*/
	.box-left {
		justify-content: flex-start;
	}

	/*居右*/
	.box-right {
		justify-content: flex-end;
	}

	/*居左*/
	.box-center {
		justify-content: center;
	}

	.box-between {
		justify-content: space-between;
	}

	.box-align-center {
		align-items: center;
	}

	.box-wrap {
		flex-wrap: wrap;
		margin-left: 28upx;
	}

	.box-around {
		justify-content: space-around;
	}

	.container {
		position: relative;
		overflow: hidden;

		.main {
			margin: 172upx 40upx 0;
			position: relative;
			z-index: 10;
		}

		.interviewee {
			padding: 24upx;
			padding-top: 0;
		}
	}

	.list-content {
		font-size: 28upx;
		margin: 0 40rpx;

		.details {
			background: white;
			padding: 0 15upx 15upx;
			// border-radius: 15upx;
			margin-bottom: 10rpx;

			.detail_header {
				border-bottom: #f8f8f8 5upx solid;
				height: 90upx;
				line-height: 90upx;
				// margin: 0;
				// border-radius: 10upx;

				.blueSign {
					height: 28upx;
					width: 5upx;
					background: #00c277;
					display: inline-block;
					margin-left: 20upx;
					vertical-align: middle;
				}

				.font-tilte {
					font-weight: bold;
					margin-left: 20upx;
					vertical-align: middle;
				}
			}

			.detail_msg {
				margin-left: 20upx;
				border-radius: 10upx;
				overflow: hidden;

				view {
					height: 50upx;
					line-height: 50upx;
				}

				.status {
					position: absolute;
					color: red;
					margin-left: 580upx;
					margin-top: -15upx;
				}
			}
		}
	}

	.img-box {
		overflow: hidden;
		padding-top: 20rpx;
		padding-bottom: 10rpx;

		.img-item {
			float: left;
			width: 67*2upx;
			height: 67*2upx;
			background: #E6E8EE;
			border-radius: 5*2upx;
			// margin: 0 20upx 20upx 0upx;
			position: relative;
			display: flex;
			align-items: center;
			justify-content: center;

			.img {
				display: block;
				width: 100%;
				height: 100%;
			}

			.remove-btn {
				position: absolute;
				top: -18upx;
				right: -18upx;
				width: 44upx;
				height: 44upx;
				z-index: 2;
			}
		}

		.upload-btn {
			.img {
				width: 60upx;
				height: 60upx;
			}
		}
	}

	.detail_msg .info-item {
		font-size: 28upx;
		margin-right: 30upx;

		text {
			display: inline-block;
			width: 140upx;
		}

		.infoSpan {
			width: 400upx;
			font-size: 28upx;
			color: #666;
			float: right;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			text-align: end;
		}
	}

	.form-box {
		margin-top: 24upx;
		padding: 0 24upx;
		overflow: hidden;

		.dateTit {
			margin-top: 24upx;
		}

		.form-item {
			overflow: hidden;
			border-bottom: 1px solid #EBEFF7;
			padding: 26upx 0;

			.label {
				float: left;
				width: 150upx;
				font-size: 28upx;
				color: #555555;
				font-weight: 400;
				line-height: 50upx;
			}

			.ipt-box {
				margin-left: 150upx;

				input {
					width: 100%;
					height: 50upx;
					line-height: 50upx;
					font-size: 26upx;
					color: #999;
				}
			}

			.select {
				.arrow {
					float: right;
					width: 16upx;
					height: 29upx;
					margin-top: 10upx;
				}

				.picker {
					height: 50upx;
					line-height: 50upx;
					font-size: 26upx;
					color: #666;
					margin-left: 10upx;
				}
			}
		}

		.form-item:last-child {
			border-bottom: 1px solid rgba(0, 0, 0, 0);
		}

		.flex-colum {
			display: flex;
			flex-direction: column;

			.ipt-box {
				margin-left: unset;
				width: 100%;
				height: 110px;
				background: #F2F6FA;
				border-radius: 8px 8px 8px 8px;
				// margin-left: 24upx;
				margin-top: 24upx;
				padding-top: 12upx;
				padding-left: 12upx;
			}
		}
	}

	.check-box {
		.check-img {
			width: 40upx;
			height: 40upx;
		}

		.check-name {
			font-weight: 400;
			font-size: 14*2upx;
			color: #555555;
			margin-left: 16upx;
		}
	}


	.common-shade {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100vh;
		background: rgba(0, 0, 0, 0.7);
		z-index: 9999;
	}
</style>