<!-- 订单管理 -->
<template>
	<view class="content">
		<view style="width: 100%; height: 55px;"></view>
		<view class="top-heder">
			<view class="t-input">
				<!--        <uni-icons type="search" color="#BCBCBC" size="22"></uni-icons>-->
				<u-search v-model="carNum" @custom="search()" @search="search()" clearabled
					placeholder="搜索车牌号....."></u-search>
			</view>
			<view class="icon1" @click="goNotice()">
				<image src="/static/imgs/staffxiaoxi.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<view class="msg-num" v-show="noReadNum>0">{{ noReadNum }}</view>
			</view>
		</view>
		<view class="tap">
			<scroll-view scroll-x="true" style="width: 100%;">
				<view style="display: flex; align-items: center; white-space: nowrap;">
					<view class="tap-box" v-for="(item, index) in newTapList" :key="index" @click="tapqh(index,item)">
						<view>
							<view class="xhuihui" :class="{'xzhei': tapindex == index}"
								style="white-space: nowrap;margin-right: 0.5rem">
								{{ item.text }}{{ countMap.length !== 0 ? ('(' + countMap.get(getValueByText(item.text)) + ')') : '' }}
							</view>
							<view class="gang" v-if="tapindex == index"></view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>

		<view class="mub">
			<view class="top-ail">
				<scroll-view class="school-scroll-view" scroll-y @scrolltolower="onReachBottomCus"
					:style="{ height: scrollHeight + 'px' }" refresher-enabled @refresherrefresh="onRefresherrefresh"
					:refresher-triggered="isTriggered">
					<view class="jsy" v-if="infoDatas.length == 0">
						<u-empty mode="list">
						</u-empty>
					</view>
					<view class="m-box" v-for="(item,index) in infoDatas" :key="index" v-else>
						<view class="sshi" v-if="item.isPass == '0'">
							<image v-if="item.status == 1" :src="imgurl + '/noPass.png'" mode=""></image>
							<view v-else class="">
								<text v-if="tapValue == '3'">重检中</text>
								<text v-if="tapValue == '4'">复检中</text>
							</view>
						</view>
						<view class="sshi" v-if="item.isPass == '1'">
							<image :src="imgurl + '/pass.png'" mode=""></image>
						</view>

						<view class="m-top">
							<view class="top-left" v-if="tapValue != '6' && tapValue != '8'">
								<view class="dhei" v-if="item.goodsName">{{ item.goodsName }}</view>
								<text class="xhui" v-if="item.goodsTitle">车型：{{ item.goodsTitle }}</text>
								<text class="xhui" style="margin-left: 50rpx;" v-if="item.skuName">
									检测类型：{{ item.skuName }}
								</text>
							</view>
							<view class="top-left" v-else-if="tapValue == '8'">
								<view class="dhei">待转订单</view>
							</view>
							<view class="top-left" v-else>
								<view class="dhei" v-if="!item.meetAddress">待接车</view>
								<view class="dhei" v-else>上门取车</view>
							</view>
							<view class="top-right" v-if="isShowClient">
								<image src="../../static/detection/teel.png" mode="" style="position: relative;"
									@click="callUser(item.buyPhone)">
								</image>
								<image src="../../static/detection/daohang.png" mode="" v-if="item.meetAddress"
									style="position: absolute;right: 120rpx;height: 60rpx;width: 60rpx;"
									@click="handleNavigation(item)">
								</image>
							</view>
						</view>
						<view class="">
							<view v-if="isShowClient || isExamine">
								<view class="on-input">
									<uni-icons type="person" color="#999999" size="16"></uni-icons>
									<text>客户：</text>
									<text>{{ item.buyName ? item.buyName : "" }}</text>
								</view>
								<view class="on-input">
									<uni-icons type="phone" color="#999999" size="16"></uni-icons>
									<text>电话：</text>
									<text>{{ item.buyPhone || '暂无电话' }}</text>
								</view>
								<view class="on-input" v-if="item.appointmentDay">
									<uni-icons type="phone" color="#999999" size="16"></uni-icons>
									<text>预约时间：</text>
									<text>{{ item.appointmentDay }}</text>
									<text v-if="item.appointmentTime"> - {{ item.appointmentTime }}</text>
								</view>
								<view class="on-input" v-if="item.meetAddress && tapValue == '6'"
									@click="handleNavigation(item)">
									<uni-icons type="map" color="#999999" size="16"></uni-icons>
									<text style="width: 170rpx;">接车地址：</text>
									<text>{{ item.meetAddress }}</text>
								</view>
								<view class="on-input" v-if="item.otherPhone">
									<uni-icons type="map" color="#999999" size="16"></uni-icons>
									<text>代办人电话：</text>
									<text>{{ item.otherPhone }}</text>
								</view>
							</view>
							<view class="on-input">
								<uni-icons type="car" color="#999999" size="16"></uni-icons>
								<text>车牌号：</text>
								<text>{{ item.carNum || '暂无车牌号'}}</text>
							</view>
							<view class="on-input" v-if="item.nodeNames">
								<uni-icons type="more" color="#999999" size="16"></uni-icons>
								<text class="single-line" v-if="!belowStandardShow.includes(tapValue)">检测内容：</text>
								<text class="single-line" style="color: red;" v-else>需复检项目：</text>
								<text class="multi-line"
									:style="belowStandardShow.includes(tapValue) ? 'color:red' : ''">{{ item.nodeNames }}</text>
							</view>
							<view class="bottom-di">
								<view class="button-container">
									<u-button class="button" v-if="beginButtonShow.includes(tapValue)"
										@click="orderTakingBefore(item)" size="10">
										开始检测
									</u-button>
									<u-button class="button" v-if="cancelButtonShow.includes(tapValue)"
										@click="cancelAnOrder(item)" size="10">
										取消接单
									</u-button>
									<u-button class="button" v-if="meetCarButtonShow.includes(tapValue)"
										@click="meetCarPhoto(item);openMeetCar = true" size="10">
										接车拍照
									</u-button>
									<u-button class="button" v-if="meetCarButtonShow.includes(tapValue)"
										@click="getMeetMan();meetCarPhoto(item);showMeetMan = true" size="10">
										更换人员
									</u-button>
									<u-button class="button" v-if="tapValue == '9'" @click="leadCar(item)" size="10">
										引车
									</u-button>
									<u-button class="button" @click="hge=true;getProject(item)"
										v-if="isExamine && tapValue == '7'" size="10">重审项目</u-button>
									<u-button class="button" v-if="!detailButtonNoShow.includes(tapValue)"
										@click="godetails(item)" size="10">查看详情</u-button>
									<u-button class="button" v-if="tapValue == '8'" @click="goMeetOrderCreate(item)"
										size="10">创建订单</u-button>
									<u-button class="button" v-if="tapValue == '8'" @click="cancelMeetCar(item)"
										size="10">删除接车</u-button>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<u-popup :show="openMeetCar" @close="openMeetCar = false" :round="10">
			<view class="popup-box">
				<u--textarea v-model="remark" placeholder="请输入内容" border="bottom"></u--textarea>
				<view class="on-inputx">
					<text>施工图片：</text>
				</view>
				<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
					:maxCount="10"></u-upload>
				<view class="bottomx" @click="submit()">
					<uni-icons type="compose" color="#0174F6" size="20"></uni-icons>
					<text>提交</text>
				</view>
			</view>
		</u-popup>
		<u-picker :show="showMeetMan" keyName="nickname" title="更换接车人" :columns="[columnsMeetMan]"
			@confirm="confirmsMeetMan" @cancel="cancelsMeetMan"></u-picker>

		<view class="lanniu-container2">
			<u-picker :show="show" :columns="chooseWorkNodes" @confirm="confirms" @cancel="cancels"
				keyName="label"></u-picker>
		</view>

		<view class="lanniu-container">
			<!-- <view class="lanniu" v-if="isExamine" @click="gogogo">
				<text>添加线下订单</text>
			</view> -->
			<view class="lanniu" v-if="isExamine" @click="gogogoOldOrder">
				<text>补录</text>
			</view>
			<view class="lanniu" @click="gogogoMeetCarOrder">
				<text>接车</text>
			</view>
		</view>

		<view style="width: 100%; height: 50px;"></view>
		<tabBar :msg="msg"></tabBar>
		<u-popup :show="hge" @close="closehge" :round="10">
			<view class="popup-box">
				<view v-if="isExamine">
					<view class="t-title">重审/退办</view>
					<view class="on-inputx">
						<view class="anniu" :class="{'an':isRetrial == item.value}" v-for="(item,index) in cstb"
							:key="index" @click="shenmowanyi(item.value,index)">
							<text>{{ item.text }}</text>
						</view>
					</view>
					<view class="t-title" v-if="tbindex == 1 && isRetrial == 1">选择复检的项目</view>
					<view class="box_ on-inputx" v-if="tbindex == 1 && isRetrial == 1">
						<view class="box_button " :class="{ 'box_button_x' :csId.includes(item.id)  }"
							v-for="item in selectProject" @click="clickProject(item)">{{ item.projectName }}
						</view>
					</view>
				</view>
				<view class="bottomx" @click="submitRecheck()">
					<uni-icons type="compose" color="#0174F6" size="20"></uni-icons>
					<text>提交</text>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import config from '@/config'
	import request from '../../utils/request';
	import tabBar from '../../components/staffTabBer/tabBar.vue'
	import {
		type
	} from "../../uni_modules/uni-forms/components/uni-forms/utils";
	import upload from "@/utils/upload";
	import USearch from "@/uni_modules/uview-ui/components/u-search/u-search.vue";
	import {
		setStorageWithExpiry
	} from '../../utils/auth';

	export default {
		data() {
			return {
				isShowClient: false,
				msgSocket: this.$msgSocket,
				imgurl: this.$imgeUrl,
				baseUrl: this.$baseUrl,
				infoDatas: {},
				openMeetCar: false,
				isTriggered: false,
				selectedInfo: undefined,
				partnerId: uni.getStorageSync("partnerId"),
				goodsTitle: '',
				tapindex: 0,
				fileList1: [],
				fileList2: [],
				newTapList: [],
				inspectionInfoId: undefined,
				isExamine: false,
				isLeadMead: false,
				hge: false,
				msg: '1',
				carNum: '',
				pageNum: 1, //第几页
				noReadNum: 0,
				pageSize: 20, //一页多少张
				totalPages: 0, //总数
				remark: '',
				scrollHeight: 0,
				selectProject: [],
				// tapList: [
				//   {
				//     text: "待接受",
				//     value: "1"
				//   },
				//   {
				//     text: "进行中",
				//     value: "2"
				//   },
				//
				//   {
				//     text: "已完成",
				//     value: "3",
				//   }
				// ],
				tapList: [
					// {
					//   text: "待支付",
					//   value: "1"
					// },

					{
						text: "接车转订单",
						value: "8",
					},
					{
						text: "待审核重检",
						value: "7",
					},
					{
						text: "待引车",
						value: "9",
					},
					{
						text: "待检测",
						value: "1"
					},
					{
						text: "待接车",
						value: "6",
					},
					{
						text: "检测中",
						value: "2",
					},
					{
						text: "待重检",
						value: "3",
					},
					{
						text: "待复检",
						value: "4",
					},
					{
						text: "已完成",
						value: "5",
					},
				],
				tapValue: 1,
				chooseWorkNodes: [],
				columnsMeetMan: [],
				tbindex: 1,
				isRetrial: 1,
				show: false,
				showMeetMan: false,
				takingData: {
					workNodeId: null,
					id: null
				},
				beginButtonShow: ['1', '3', '4'],
				cancelButtonShow: ['2'],
				meetCarButtonShow: ['6'],
				adminCanShow: ['7', '8'],
				leadMeadShow: ['7', '8'],
				detailButtonNoShow: ['6', '8'],
				belowStandardShow: ['7', '4'],
				countMap: [],
				csId: [],
				cstb: [{
						text: '重检',
						value: "2"
					}, {
						text: '复检',
						value: "1"
					},
					{
						text: '退办理',
						value: "0"
					},
				],
				// 我自己的位置经纬度（百度地图需要传入自己的经纬度进行导航）
				selfLocation: {
					latitude: '',
					longitude: ''
				},
				timer: null //定时器名称
			}
		},
		async onLoad() {
			this.$startSocketConnect(uni.getStorageSync('userId'))
			this.newTapList = [{
					text: "待检测",
					value: "1"
				},
				{
					text: "待接车",
					value: "6",
				},
				{
					text: "检测中",
					value: "2",
				},
				{
					text: "待重检",
					value: "3",
				},
				{
					text: "待复检",
					value: "4",
				},
				{
					text: "已完成",
					value: "5",
				}
			]
			await this.isExamines()
			await this.isLeadMeads()
			this.msgInfo()
			this.tapValue = this.newTapList[0].value
			this.tapindex = 0
			this.getList()
			uni.$on('refresh', () => {
				this.getList()
			})
		},
		onShow() {
			this.getLocation()
			const this_ = this
			this_.getWarnCount()
			this.timer = setInterval(function() {
				this_.getWarnCount()
			}, 10000);
			// this.getList()
		},
		onReady() {
			// 动态计算滚动区域高度
			this.calculateScrollHeight();
		},
		watch: {
			msgSocket(newVal, oldVal) {
				console.log('msgSocket值发生变化', newVal, oldVal)
				this.msgInfo()
			},
			deep: true,
		},
		onReachBottom() {
			if (this.pageNum >= this.totalPages) {
				uni.showToast({
					title: '没有下一页数据',
					icon: 'none'
				})

			} else {
				this.pageNum++
				this.getList()
			}
		},
		components: {
			USearch,
			tabBar,
		},
		//uniapp中onHide()能监听到页面离开
		onHide() { //离开页面前清除计时器
			// console.log('onHide');
			clearInterval(this.timer);
			this.timer = null;
		},
		onUnload() {
			clearInterval(this.timer);
			this.timer = null;
		},
		methods: {
			getLocation() {
				uni.getLocation({
					type: 'wgs84', // 默认为 'wgs84'，表示获取经纬度，支持转换为百度、腾讯等地图坐标系
					success: (res) => {
						this.selfLocation.latitude = res.latitude
						this.selfLocation.longitude = res.longitude
					},
					fail: (err) => {
						console.log('获取位置失败:', err);
					}
				});

			},
			calculateScrollHeight() {
				// 获取屏幕高度
				const screenHeight = uni.getSystemInfoSync().windowHeight;
				// 获取顶部区域高度
				const topHeight = 270;
				// 计算滚动区域高度
				this.scrollHeight = screenHeight - topHeight;
			},
			// 取消接车
			cancelMeetCar(data) {
				uni.showModal({
					title: '提示',
					content: '确定将此接车订单取消吗？',
					success: async (res) => {
						if (res.confirm) {
							try {
								request({
									url: `/inspection-meet-car-order/delete`,
									method: 'DELETE',
									params: {
										id: data.id
									}
								}).then(res => {
									this.onRefresherrefresh()
								})
							} catch (error) {
								console.error('取消预约:', error);
								uni.showToast({
									title: '取消',
									icon: 'none'
								});
							}
						}
					}
				});
			},
			//查询重审可以选择的项目
			getProject(data) {
				this.inspectionInfoId = data.id
				request({
					url: '/system/info/getWeorkNodesById',
					method: 'get',
					params: {
						inspectionId: data.id
					}
				}).then(res => {
					this.selectProject = res.data
					// 默认勾选上不合格的项目
					this.csId = data.nodeIds
					console.log('this.csId', this.csId);
				})
			},
			closehge() {
				this.hge = false
				this.csId = []
			},
			goMeetOrderCreate(data) {
				//将data设置缓存
				setStorageWithExpiry('meetCarOrderData', data, 120)
				uni.navigateTo({
					url: `/pages/index/Neworder?meetCarId=${data.id}`
				})
			},
			Nnimamadewen(value, index) {
				this.geindex = index
				this.type = value
			},
			shenmowanyi(value, index) {
				this.tbindex = value
				this.isRetrial = value
			},
			clickProject(data) {
				//判断当前id是否存在csId数组里面
				let index = this.csId.indexOf(data.id)
				if (index !== -1) {
					// 如果存在，则从数组中删除
					this.csId.splice(index, 1);
				} else {
					// 如果不存在，则添加到数组中
					this.csId.push(data.id);
				}
				console.log('this.csId', this.csId);
			},
			/**
			 * 上滑加载数据
			 */
			onReachBottomCus() {
				//判断 如果页码*页容量大于等于总条数，提示该页数据加载完毕
				if (this.pageNum >= this.totalPages) {
					uni.$u.toast('没有更多数据了')
					return
				}
				//页码+1,调用获取数据的方法获取第二页数据
				this.pageNum++
				//此处调用自己获取数据列表的方法
				this.getList()
			},
			/**
			 * 下拉刷新数据
			 */
			onRefresherrefresh() {
				this.isTriggered = true
				this.pageNum = 1
				this.total = 0
				this.infoDatas = []
				this.getList()
			},
			async getCount() {
				await request({
					url: '/system/info/getCountByType?partnerId=' + this.partnerId,
					method: 'get'
				}).then(res => {
					this.countMap = new Map(Object.entries(res.data))
				})
			},
			getWarnCount() {
				request({
					url: '/system/notify-message/get-unread-count',
					method: 'get',
					params: {
						systemCode: "jiance"
					}
				}).then(res => {
					this.noReadNum = res.data
					this.$forceUpdate()
				}).catch(e => {
					console.log('查询消息报错', e);
				})
			},
			async submitRecheck(id) {
				console.log(this.isRetrial);
				let inspectionInfo = {
					inspectionInfoId: this.inspectionInfoId,
					id: this.workNodeId,
					type: this.isRetrial,
				}
				let status = 0
				if (this.isExamine && this.tbindex == 1 && this.isRetrial == 1) {
					if (this.csId == '' || this.csId == undefined) {
						uni.showToast({
							title: '请选择要复检的项目',
							icon: 'none'
						})
						return
					}
					const workNodes = []
					this.csId.forEach(item => {
						let a = {
							id: item,
							status: 2
						}
						workNodes.push(a)
					})
					inspectionInfo.workNodes = workNodes
					status = 2
					// await request({
					// 	url: '/system/info/recheck',
					// 	method: 'post',
					// 	data: inspectionInfo
					// })
					// this.onRefresherrefresh()
					// this.closehge()
					// return
				} else if (this.isExamine && this.tbindex == 2 && this.isRetrial == 2) {
					//跳转到修改工单页面
					//跳转到修改工单页面
					uni.navigateTo({
						url: '/pages/index/Neworder?inspectionInfoId=' + this.inspectionInfoId
					})
					return
				} else if (this.tbindex == 0 && this.isRetrial == 0) {
					status = 1
				}
				inspectionInfo.selectType = status

				let res = await request({
					// url: '/partnerOwn/partner/stopInspection',
					url: '/system/info/controls',
					method: 'post',
					data: inspectionInfo
				})
				if (res.code == 200) {
					uni.showToast({
						title: "成功",
					})

				}
				this.onRefresherrefresh()
				this.closehge()
				console.log(data);


			},
			/** 接车拍照提交*/
			submit(item) {
				console.log('文件', this.fileList1)
				console.log('infoid', this.selectedInfo)
				if (this.fileList1.length == 0) {
					uni.showToast({
						title: '请拍摄现场图片',
						icon: 'none'
					})
					return
				}
				request({
					url: '/system/info/meetCarPhoto',
					data: {
						meetCarId: this.selectedInfo.id,
						remark: this.remark,
						sourceType: this.selectedInfo.sourceType,
						dealImages: this.fileList1.map(item => item.url).join(',')
					},
					method: 'post'
				}).then(res => {
					if (res.code === 200) {
						uni.showToast({
							title: '提交成功',
							icon: 'none',
							duration: 2000
						});
						this.openMeetCar = false
						this.remark = ''
						this.fileList1 = []
						this.onRefresherrefresh()
					}
				})
			},
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,

					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					console.log(result)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			async uploadFilePromise(url) {
				let res = await upload({
					url: '/common/upload',
					filePath: url,
				})
				return res.data.url

			},
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			search() {
				this.pageNum = 1;
				this.getList();
			},
			goNotice() {
				uni.navigateTo({
					url: '/pages/xiaoxi/notice?type=staff'
				})
			},
			confirms(e) {
				this.takingData.workNodeId = e.value[0].value
				this.show = false
				this.orderTaking(this.takingData)
			},
			cancels() {
				this.show = false
			},
			confirmsMeetMan(e) {
				const selectedUserId = e.value[0].id
				console.log('选择的工单id', this.selectedInfo)
				console.log('selectedUserId', e)
				//修改接车人
				request({
					url: '/system/info/updateLeadMan',
					method: 'post',
					data: {
						id: this.selectedInfo.id,
						meetManId: selectedUserId,
						sourceType: this.selectedInfo.sourceType
					}
				}).then(res => {
					if (res.code === 200) {
						uni.showToast({
							title: '更换成功',
							icon: 'none',
							duration: 2000
						});
						this.getList()
					}
				})
				this.showMeetMan = false
			},
			cancelsMeetMan() {
				this.showMeetMan = false
			},
			leadCar(data) {
				let this_ = this
				uni.showModal({
					title: '提示',
					content: '是否确定引车',
					success: async function(res) {
						if (res.confirm) {
							const res = await request({
								url: "/system/info/leadCar",
								data: data,
								method: 'post'
							})
							this_.onRefresherrefresh()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					},

				});

			},
			/*获取接车员信息*/
			getMeetMan() {
				console.log('执行了吗')
				request({
					url: '/system/role/selectListByRoleId',
					method: 'get',
					params: {
						pageNo: 1,
						pageSize: 10000
					}
				}).then(res => {
					this.columnsMeetMan = res.data.records
				})
			},
			// 让操作人选择要开始的项目
			async orderTakingBefore(item) {
				this.takingData = {
					workNodeId: null,
					id: item.id
				}
				let res = await request({
					url: `/system/info/getWorkNodeByIdAndNow?id=${item.id}&status=${(this.tapValue === '4' ? "3" : "0")}${(this.tapValue === '3' ? "&flag=false" : "")}`,
					method: 'get',
				})
				if (res.data) {
					this.chooseWorkNodes = [Object.keys(res.data).map(key => ({
						value: key,
						label: res.data[key]
					}))]
				}
				// this.chooseWorkNodes = [res.data.map(i => {
				//   return {
				//     label: i.projectName,
				//     value: i.id
				//   }
				// })]
				this.show = true
			},
			msgInfo() {
				console.log(this.msgSocket, 'msgSocket')
				if (this.msgSocket) {
					console.log('消息回调启动成功')
					this.msgSocket.onMessage(res => {
						this.pageNum = 1
						this.totalPages = 0
						this.getList()
					})
				}

			},
			/**
			 * 根据 text 查找对应的 value
			 * @param {string} text - 要查找的文本
			 * @param {Array} list - 数据列表（默认使用 tapList）
			 * @returns {string|null} 返回对应的 value，找不到则返回 null
			 */
			getValueByText(text, list = this.tapList) {
				const item = list.find(item => item.text === text);
				return item ? item.value : null;
			},
			/*判断是否是收费登陆人*/
			async isExamines() {
				const res = await request({
					url: '/system/info/isExamine',
					method: 'get'
				})
				this.isExamine = res.data
				if (this.isExamine) {
					this.newTapList.unshift({
						text: "接车转订单",
						value: "8",
					}, {
						text: "待审核重检",
						value: "7",
					})
				}
			},
			async isLeadMeads() {
				const res = await request({
					url: `/system/user/ifLoginUserHasRoleByCode?roleCode=jcycy`,
					method: 'get',
				})
				this.isLeadMead = res.data
				if (this.isLeadMead) {
					this.newTapList.unshift({
						text: "待引车",
						value: "9",
					}, )
				}
			},
			callUser(phone) {
				uni.makePhoneCall({
					phoneNumber: phone //仅为示例
				});
			},
			async getList() {
				let res = await request({
					url: '/system/info/geStelectInspection',
					method: 'get',
					params: {
						partnerId: this.partnerId,
						status: this.tapValue,
						carNum: this.carNum,
						pageSize: this.pageSize,
						pageNum: this.pageNum,
					}
				})
				if (res.code == 200) {
					if (this.pageNum != 1) {
						this.infoDatas = this.infoDatas.concat(res.rows)
					} else {
						this.infoDatas = res.rows
					}
					console.log('此时的tapindex', this.tapindex);
					const ids = this.infoDatas.filter(item => !item.nodeNames).map(item => item.id)
					if (this.tapValue != '6') {
						if (!this.belowStandardShow.includes(this.tapValue)) {
							if (ids && ids.length > 0) {
								const response = await request({
									url: "/partnerOwn/partner/getProjectByIds?ids=" + ids,
									method: 'get'
								})
								if (response.data) {
									const data = response.data
									this.infoDatas.forEach(item => {
										this.$set(item, 'nodeNames', data[item.id])
									})
								}
							}
						} else {
							// 查询不合格的项目
							if (ids && ids.length > 0) {
								const response = await request({
									url: `/partnerOwn/partner/getProjectBelowStandardByIds`,
									method: 'get',
									params: {
										ids: ids.join(','),
										status: this.tapValue == '4' ? '3' : '',
										type: this.tapValue == '7' ? '0' : ''
									}
								})
								if (response.data) {
									const data = response.data
									this.infoDatas.forEach(item => {
										let nodeNamesArr = []
										let nodeIds = []
										if (data[item.id]) {
											data[item.id].forEach(data => {
												nodeNamesArr.push(data.name)
												nodeIds.push(data.id)
											})
											const nodeNames = nodeNamesArr.join('、')
											this.$set(item, 'nodeNames', nodeNames)
											this.$set(item, 'nodeIds', nodeIds)
											console.log('数据', item);
										}
									})

								}
							}
						}
					}

					let total = res.total
					this.totalPages = Math.ceil(total / this.pageSize);
				}

				await this.getCount()
				this.isTriggered = false
			},
			getfan() {
				uni.navigateBack()
			},
			godetails(item) {
				uni.navigateTo({
					url: `/pages/index/orderdetails?inspectionInfoId=${item.id}&workNodeId=${item.workNodeId}&workNodeStatus=${item.workNodeStatus}&type=staff`
				})
			},
			orderTaking(data) {
				request({
					url: '/system/info/orderTaking',
					method: 'post',
					params: {
						inspectionId: data.id,
						workNodeId: data.workNodeId
					}
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '接单成功',
							icon: 'none'
						})
						// this.tapindex = 1
						this.godetails({
							id: data.id,
							workNodeId: data.workNodeId,
							workNodeStatus: 1
						})
					}
				})
			},
			cancelAnOrder(data) {
				request({
					url: '/system/info/cancelAnOrder',
					method: 'post',
					params: {
						inspectionId: data.id,
						workNodeId: data.workNodeId
					}
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '取消接单成功',
							icon: 'none'
						})
						this.getList()
					}
				})
			},
			/**接车拍照 */
			meetCarPhoto(data) {
				this.selectedInfo = data
			},
			gogogo() {
				uni.navigateTo({
					url: '/pages/index/Neworder'
				})
			},
			gogogoOldOrder() {
				uni.navigateTo({
					url: '/pages/index/oldOrder'
				})
			},
			gogogoMeetCarOrder() {
				uni.navigateTo({
					url: '/pages/index/meetCarOrder'
				})
			},
			tapqh(index, data) {
				//如果是待接车
				if (data.value == '6') {
					this.isShowClient = true
				} else {
					this.isShowClient = false
				}
				this.tapValue = data.value
				console.log('当前tap的value', this.tapValue);
				this.tapindex = index
				this.infoDatas = []
				this.pageNum = 1
				this.getList()
			},
			handleNavigation(data) {
				console.log('执行了 地图 ');
				const _this = this;
				// if (!this.latitude || !this.longitude || !this.name) return;

				// 判断系统安装的地图应用有哪些, 并生成菜单按钮
				let _mapName = [{
						title: '高德地图',
						name: 'amap',
						androidName: 'com.autonavi.minimap',
						iosName: 'iosamap://'
					},
					{
						title: '百度地图',
						name: 'baidumap',
						androidName: 'com.baidu.BaiduMap',
						iosName: 'baidumap://'
					},
					{
						title: '腾讯地图',
						name: 'qqmap',
						androidName: 'com.tencent.map',
						iosName: 'qqmap://'
					},
				];

				// 根据真机有的地图软件 生成的 操作菜单
				let buttons = [];
				let platform = uni.getSystemInfoSync().platform;
				console.log('获取platform', platform);
				platform === 'android' && _mapName.forEach(item => {
					if (plus.runtime.isApplicationExist({
							pname: item.androidName
						})) {
						buttons.push(item);
					}
				});
				platform === 'ios' && _mapName.forEach(item => {
					if (plus.runtime.isApplicationExist({
							action: item.iosName
						})) {
						buttons.push(item);
					}
				});

				if (buttons.length) {
					plus.nativeUI.actionSheet({ //选择菜单
						title: "选择地图应用",
						cancel: "取消",
						buttons: buttons
					}, function(e) {
						let _map = buttons[e.index - 1];
						_this.openURL(_map, platform, data);
					});
				} else {
					uni.showToast({
						title: '请安装地图软件',
						icon: 'none'
					});
					return;
				}
			},

			// 打开第三方程序实际应用
			openURL(map, platform, data) {
				console.log('执行打开地图');
				console.log('data', data);

				let _defaultUrl = {
					'android': {
						"amap": `amapuri://route/plan/?sid=&did=&dlat=${data.latitude}&dlon=${data.longitude}&dname=${data.meetAddress}&dev=0&t=0`,
						'qqmap': `qqmap://map/routeplan?type=drive&to=${data.meetAddress}&tocoord=${data.latitude},${data.longitude}&referer=fuxishan_uni_client`,
						'baidumap': `baidumap://map/direction?origin=${this.selfLocation.latitude},${this.selfLocation.longitude}&destination=name:${data.meetAddress}|latlng:${data.latitude},${data.longitude}&coord_type=wgs84&mode=driving&src=andr.baidu.openAPIdemo`
					},
					'ios': {
						"amap": `iosamap://path?sourceApplication=fuxishan_uni_client&dlat=${data.latitude}&dlon=${data.longitude}&dname=${data.meetAddress}&dev=0&t=0`,
						'qqmap': `qqmap://map/routeplan?type=drive&to=${data.name}&tocoord=${data.latitude},${data.longitude}&referer=fuxishan_uni_client`,
						// 'baidumap': `baidumap://map/direction?origin=${data.selfLocation.latitude},${data.selfLocation.longitude}&destination=name:${data.name}|latlng:${data.latitude},${data.longitude}&mode=driving&src=ios.baidu.openAPIdemo`
					}
				};
				// 构建 URL
				let newurl = encodeURI(_defaultUrl[platform][map.name]);

				// 打开 URL
				plus.runtime.openURL(newurl, function(res) {
					uni.showModal({
						content: '打开地图成功'
					});
				}, function(err) {
					console.log('打开地图失败: ', err);
					uni.showModal({
						content: '打开地图失败: ' + err.message
					});
				});
			}



		}
	}
</script>

<style scoped lang="scss">
	.content {
		box-sizing: border-box;
		width: 100%;
		height: calc(100vh);
		background: white;
	}

	.sshi {
		position: absolute;
		bottom: 90rpx;
		right: 20px;
		width: 115px;
		height: 115px;
		box-sizing: border-box;
		padding: 10px;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.top-heder {
		width: 100%;
		height: 46px;
		background: white;
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;
		padding: 5px 15px;
	}

	.t-left {
		width: 10%;
	}

	.t-input {
		width: 85%;
		//height: 36px;
		//background: #F0F0F0;
		//border-radius: 50px;
		//box-sizing: border-box;
		padding: 0 15px;
		//display: flex;
		//align-items: center;

	}

	.top-ail {
		width: 100%;
		box-sizing: border-box;
		padding: 15px;
		background-color: #F4F4F4;

	}

	.mub {
		background-color: #F4F4F4;
		// height: calc(100vh);
	}

	.tap {
		width: 100%;
		height: 44px;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.tap-box {
		width: 50%;

	}

	.xhuihui {
		width: 100%;
		text-align: center;
		font-size: 16px;
		font-family: Source Han Sans CN-Regular, Source Han Sans CN;
		font-weight: 400;
		color: #666666;
		//margin-left: 0.5rem;
	}

	.gang {
		width: 32px;
		height: 4px;
		background: #0D2E8D;
		border-radius: 4px;
		margin: 2px auto;
		margin-left: 1rem;
	}

	.xzhei {

		font-weight: bold !important;
		color: #333333 !important;
	}

	.m-box {
		position: relative;
		background: #FFFFFF;
		border-radius: 8px;
		box-sizing: border-box;
		padding: 15px 10px;
		margin: 10px auto;

	}

	.m-top {
		width: 100%;
		box-sizing: border-box;
		padding-bottom: 15px;
		border-bottom: 1px solid #EEEEEE;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.top-left {}

	.top-right {
		z-index: 9999;
		width: 33px;
		height: 33px;
		border-radius: 50%;
		overflow: hidden;

		image {
			width: 100%;
			height: 100%;
		}

	}

	.dhei {
		font-size: 16px;
		font-weight: bold;
		color: #333333;
		margin-bottom: 5px;
	}

	.xhui {
		font-size: 15px;
		font-weight: 400;
		color: #999999;
	}

	.on-input {
		width: 100%;
		display: flex;
		align-items: center;
		font-size: 15px;
		font-family: Source Han Sans CN-Regular, Source Han Sans CN;
		font-weight: 400;
		color: #999999;
		margin-bottom: 10px;
		margin-top: 10px;
		// justify-content: space-between;
	}

	.bottom-di {
		display: flex;
		justify-content: center;
		align-items: center;

	}

	.button-container {
		display: flex;
		justify-content: space-between;
		width: 100%;
	}

	.button {
		width: 80%;
		height: 45px;
		background: linear-gradient(180deg, #3F61C0 0%, #0D2E8D 100%);
		border-radius: 50px;
		display: flex;
		align-items: center;
		justify-content: center;

		color: white;
	}


	.ju {
		font-size: 24px;

		font-weight: 600;
		color: #FF571A;
	}

	.lanniu-container {
		width: 90%;
		position: fixed;
		bottom: 60px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		/* 控制子元素之间的间距，可以改为 center/space-around */
		transform: translate(-50%);
		left: 50%;
		z-index: 10074;
	}

	.lanniu-container2 {
		position: fixed;
		display: flex;
		align-items: center;
		justify-content: space-between;
		/* 控制子元素之间的间距，可以改为 center/space-around */
		z-index: 999999;
	}

	.lanniu {
		display: flex;
		align-items: center;
		justify-content: center;
		background: #0D2E8D;
		color: white;
		height: 44px;
		border-radius: 8px;
		font-weight: bold;
		flex: 1;
		/* 子元素均分宽度 */
		margin: 0 5px;
		/* 控制子元素之间的间距 */
	}


	.csz {
		font-size: 20px;
		font-weight: bold;
		color: #FF571A;
	}

	/* 确保 "检测内容：" 始终在一行 */
	.single-line {
		white-space: nowrap;
		flex-shrink: 0;
	}

	/* 允许 item.nodeNames 多行显示 */
	.multi-line {
		white-space: pre-line;
		/* 保留换行符，但允许文本换行 */
		word-break: break-all;
		/* 长单词或 URL 会在必要时断开 */
	}

	.msg-num {
		position: absolute;
		right: -29rpx;
		top: -20rpx;
		color: white;
		background: #d74a43;
		padding: 5rpx 10rpx;
		/* 使用 padding 确保有足够的空间 */
		min-width: 35rpx;
		/* 最小宽度 */
		line-height: 1.2;
		/* 调整行高以适应不同内容 */
		text-align: center;
		font-weight: 800;
		font-size: 11px;
		border-radius: 20rpx;
		/* 椭圆效果 */
		white-space: nowrap;
		/* 确保文本不换行 */
	}

	.icon1 {
		position: relative;
		width: 56rpx;
		height: 56rpx;

		//margin-left: 30rpx;
		.msg-num {
			position: absolute;
			right: -15rpx;
			color: white;
			background: #d74a43;
			width: 35rpx;
			height: 35rpx;
			line-height: 35rpx;
			text-align: center;
			font-weight: 800;
			font-size: 11px;
			border-radius: 50%;
			top: -15rpx;
		}
	}

	.on-inputx {
		width: 100%;
		display: flex;

		align-items: center;
		margin: 15px auto;
	}

	.popup-box {
		overflow: hidden;
		border-radius: 8px;
		box-sizing: border-box;
		padding: 15px;
		width: 100%;
		background-color: white;
		margin-bottom: 80rpx;
	}

	.bottomx {
		margin: 0 auto;
		width: 425rpx;
		height: 76rpx;
		border-radius: 6px 6px 6px 6px;
		opacity: 1;
		border: 1px solid #0174F6;
		display: flex;
		align-items: center;
		justify-content: center;
		//color: #0174F6;
	}

	.popup-box {
		overflow: hidden;
		border-radius: 8px;
		box-sizing: border-box;
		padding: 15px;
		width: 100%;
		background-color: white;
	}

	.t-title {
		font-size: 17px;
		font-weight: bold;
		color: #333333;
	}

	.box_ {
		width: 100%;
		display: flex;
		flex-wrap: wrap;
	}

	.box_button {
		border-radius: 6px;
		border: 1px solid #999;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 14px;
		box-sizing: border-box;
		padding: 5px 10px;
		margin-right: 5px;
		margin-bottom: 5px;
	}

	.box_button_x {
		border-radius: 6px;
		border: 1px solid #0D2E8D;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 14px;
		box-sizing: border-box;
		padding: 5px 10px;
		margin-right: 5px;
		margin-bottom: 5px;
		background: #0D2E8D;
		color: #fff;
	}

	.on-inputx {
		width: 100%;
		display: flex;

		align-items: center;
		margin: 15px auto;
	}

	.anniu {
		box-sizing: border-box;
		padding: 2px 10px;
		margin: 0px 10px;
		// background: linear-gradient(180deg, #3F61C0 0%, #0D2E8D 100%);
		border: 1px solid #0D2E8D;
		border-radius: 23px;
		font-size: 15px;
		color: #0D2E8D;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.an {
		box-sizing: border-box;
		padding: 2px 10px;
		margin: 0px 10px;
		background: linear-gradient(180deg, #3F61C0 0%, #0D2E8D 100%) !important;

		border-radius: 23px;
		font-size: 15px;
		color: white !important;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>