<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="tourTallyDetailFn(worksheetInfo)"></DetailMain>
			</template>
		</view>
		<button class="btn-submit" @click="bindSubmit" :loading="loading">
			提交
		</button>
	</view>
</template>

<script>
	import {
		get,postJ
	} from "@/utils/api.js"
	import {
		tourTallyDetailFn
	} 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:'',
				loading:false,
				worksheetInfo: null,
				tourTallyDetailFn,
				executorInfo: null,
				redeployCause:'',
				code:""
			}
		},
		onLoad(options) {
			this.pageId = options.id;
			this.getInfo();
		},
		onShow() {
			//转派人员信息
			this.executorInfo = this.$store.state.tour_tally.executorInfo;
		},
		methods: {
			getInfo(){
				get(this.apiUrl + "/patrol/order/getDetail/"+this.pageId).then(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,
				}
				this.loading=true
				postJ(this.apiUrl+ "/patrol/order/transfer",data).then(res=>{
					this.loading=false
					setTimeout(()=>{					
						this.back(2)
					},2000)
					uni.showToast({
						title:'转派成功',
					})
				}).catch(err=>{
					uni.showToast({
						title:err.message || '转派失败',
						icon:'none'
					})
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
input{
	text-align: right;
	color: $uni-text-color-grey;
	font-size: $uni-font-size-base;
}
</style>
