<template>
	<view>
		<uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="巡点检工单详情" @clickLeft="back">
			<!--  -->
			<template slot="float" v-if="status!==2">
				<view class="nav-icon-caozuo iconfont icon-caozuo" @click="setOptionShow"></view>
			</template>
		</uni-nav-bar>
		<!-- 进度组件 根据状态显示不同列表  -->
		<popupOper :optionShow="optionShow" @operate="operate" :operationList="operationList"></popupOper>
		<view class="page-bottom-padding" v-if="worksheetInfo">
			<uni-collapse ref="collapse">
				<!-- <uni-collapse-item :open="(worksheetInfo && worksheetInfo.status.id == '99') ? false : true" -->
				<uni-collapse-item :typeOpen="1" title="基本信息" open>
					<view class="bg">
						<DetailMain :detailsInfo="tourTallyDetailFn(worksheetInfo)"></DetailMain>
					</view>
				</uni-collapse-item>
			</uni-collapse>
			<!-- 巡检点设备 -->
			<template>
				<CellTip title="巡检点设备"> </CellTip>
				<OrderDetail v-for="(item,idx) in worksheetInfo.equiList" :key="idx" :border="true"
					:value1="'设备编码:'+item.equiCode" :value2="'设备型号:' + item.equiModel" :value3="'设备名称:'+item.equiName">
					<template slot="custSlot">
						<view class="" v-for="(el,idx) in item.ruleItems">
							<view class="list-cell">
								<text class="font-text">检测事项：{{el.itemName}}</text>

							</view>
							<view class="list-cell font-sm">
								<text>检测标准：{{el.itemStandard}}</text>
								<text>检测内容：{{el.itemContent}}</text>
							</view>
							<view class="list-cell font-sm">
								<text>状态：{{el.status === null?'未处理':el.status===1?"正常":"缺陷"}}</text>
							</view>
						</view>
					</template>
				</OrderDetail>
			</template>
			<!-- 执行信息 -->
			<!-- <template v-if="worksheetInfo && worksheetInfo.status.id == '99'"> -->
			<template>
				<CellTip title="执行信息"> </CellTip>
				<CellInfo label="报工结果" :value="statusList[worksheetInfo.workOrder.status]"></CellInfo>
				<CellInfo label="实际开始时间" :value="worksheetInfo.workOrder.startTime"></CellInfo>
				<CellInfo label="实际结束时间" :value="worksheetInfo.workOrder.endTime"></CellInfo>
			</template>
			<!-- 执行处理结果 -->
			<!--<template v-if="worksheetInfo && worksheetInfo.status.id == '99'">
				<CellTip title="执行处理结果"> </CellTip>
				<uni-collapse ref="collapse" v-for="item in worksheetInfo.details" :key="'zxcl'+item.id">
					<uni-collapse-item :open="false" :typeOpen="false" titleStyle="background-color: #ffffff">
						<OrderDetail slot="typeOpenShow" :value1="item.name" :value2="item.spec"
							:value3="'通用设备-' + item.name" :value4="item.code" :value5="item.address"
							:value6="'x' + (item.num || 1)">
						</OrderDetail>
						<view class="content-status" @click.stop>
							<view class="cell-box border-bottom" v-for="(items,indexs) in item.contentDetails"
								:key="indexs" @click="goDetail(items.id, items.status)">
								<view class="cell">
									{{items.content}}
								</view>
								<view class="cell">
									检测内容：{{items.kpi}}
								</view>
								<view class="cell">
									检测标准：{{items.paramRange}}
								</view>
								<view class="btn  cell-box-right"
									:class="items.status.id == '1' ? 'btn-primary' : 'btn-warning'">
									{{items.status.name}}
								</view>
							</view>
						</view>
					</uni-collapse-item>
				</uni-collapse>
			</template> -->

		</view>
	</view>
</template>

<script>
	import {
		get,
		postJ
	} from "@/utils/api.js"
	import {
		tourTallyDetailFn
	} from '@/utils/common.js'
	import DetailMain from '@/components/DetailMain.vue'
	import CellTip from '@/components/CellTip.vue'
	import CellInfo from '@/components/CellInfo.vue'
	import OrderDetail from '../components/OrderDetail.vue'
	import popupOper from '@/components/PopupOper.vue'
	export default {
		components: {
			DetailMain,
			popupOper,
			OrderDetail,
			CellTip,
			CellInfo
		},
		data() {
			return {
				statusList: {
					0: "待接收",
					1: "执行中",
					3: "已完成",
				},
				pageId: "",
				worksheetInfo: {
					equiList:[],
					workOrder:{}
				},
				tourTallyDetailFn,
				optionShow: false,
				status: "",
				operationList: [{
					title: '执行',
					class: 'iconfont icon-zhuanpai',
					type: 1
				}],
			}
		},
		onLoad(options) {
			this.pageId = options.id;
			this.getInfo();
		},
		onShow() {
			this.optionShow = false;
			if (this.worksheetInfo) {
				this.getInfo();
			}
		},
		methods: {

			getInfo() {
				get(this.apiUrl + "/patrol/order/getDetail/" + this.pageId).then(res => {
					if(res?.success){
						this.worksheetInfo = res.data;
						let status = res.data.workOrder.status;
						this.status = status
						//只有已指派和暂停可以转派
						if (status === 0) {
							this.operationList = [{
								title: '受理',
								class: 'iconfont icon-zhuanpai',
								type: 3
							}, {
								title: '转派',
								class: 'iconfont icon-zhuanpai',
								type: 2
							}]
						} else if (status == 2) {
							this.operationList = []
						}
					}
				});
			},
			//选择对应的操作
			operate(type) {
				if (type === 2) { //转派
					uni.navigateTo({
						url: "../turn_send/turn_send?id=" + this.pageId
					})
				} else if (type === 1) { //报工
					uni.navigateTo({
						url: "../submitted_ministry/submitted_ministry?id=" + this.pageId
					})

				} else if (type === 3) {

					uni.navigateTo({
						url: "../accept/index?id=" + this.pageId
					})
				}
			},
			//点击显示弹窗
			setOptionShow() {
				this.optionShow = !this.optionShow;
			},
			goDetail(id, status) {
				//已报修
				// if (status.id == '2') {
				// 	uni.navigateTo({
				// 		url: '../defects/defects?id=' + id + "&type=details" + "&parentsId=" + this.pageId
				// 	})
				// }
			}

		}
	}
</script>

<style lang="scss" scoped>
	@import "@/components/submitted.scss";

	.list-cell {
		display: flex;
		align-items: center;
		justify-content: space-between;
		color: $uni-text-color-grey;
		padding: 5rpx 20rpx;
	}

	.font-sm {
		font-size: $uni-font-size-sm;
	}

	.font-text {
		color: $uni-text-color;
	}
</style>
