<template>
	<view>
		<uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="转派保养订单" @clickLeft="back"></uni-nav-bar>
		<view class="page-bottom-padding">
			<template>
				<CellTip title="转派信息"> </CellTip>
				<TurnSendList :executorInfo="executorInfo" :code="code" @change="getRedeployCause"></TurnSendList>
			</template>
			<template v-if="worksheetInfo">
				<CellTip title="基本信息"> </CellTip>
				<DetailMain :detailsInfo="maintainDetailFn(worksheetInfo)"></DetailMain>
			</template>
		</view>
		<view class="btn-submit" @click="bindSubmit">
			提交
		</view>
	</view>
</template>

<script>
	import {
		get,
		postJ
	} from "@/utils/api.js"
	import {
		maintainDetailFn
	} from '@/utils/common.js'
	import DetailMain from '@/components/DetailMain.vue'
	import TurnSendList from '@/components/TurnSendList.vue'
	import CellTip from '@/components/CellTip.vue'
	import CellInfo from '@/components/CellInfo.vue'

	export default {
		components: {
			DetailMain,
			TurnSendList,
			CellTip,
			CellInfo
		},
		data() {
			return {
				pageId: '',
				worksheetInfo: null,
				maintainDetailFn,
				executorInfo: null,
				redeployCause: '',
				code:""
			}
		},
		onLoad(options) {
			this.pageId = options.id;
			this.getInfo();
		},
		onShow() {
			//转派人员信息
			this.executorInfo = this.$store.state.maintenance.executorInfo;
		},
		methods: {
			getInfo() {
				get(this.apiUrl + "/maintain/order/getDetail/" + this.pageId).then(res => {
					// console.log(res)
					this.worksheetInfo = res.data;
					this.code = this.worksheetInfo.plan.executeDeptCode
				})
			},
			getRedeployCause(e) {
				this.redeployCause = e.detail.value;
			},
			bindSubmit() {
				if (!this.executorInfo || !this.executorInfo.executorId) {
					uni.showToast({
						title: '请选择转派人员',
						icon: 'none'
					})
					return
				}
				if (!this.redeployCause) {
					uni.showToast({
						title: '请输入转派原因',
						icon: 'none'
					})
					return
				}
				let data = {
					userId: this.executorInfo.executorId,
					userName: this.executorInfo.executorName,
					woId: this.pageId,
				}
				postJ(this.apiUrl + "/maintain/order/transfer", data).then(res => {
					uni.showToast({
						title: '转派成功',
					})
					setTimeout(() => {
						this.back(2)

					}, 1000)

				}).catch(err => {
					uni.showToast({
						title: err.message || '转派失败',
						icon: 'none'
					})
				})
			},



		}
	}
</script>
