<!--
 * @Title: 
 * @Description: 任务转派
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
	<view class="wrap">
		<uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
			@clickLeft="toBack">
			<view class="nav-title">
				<text>{{title}}</text>
			</view>
		</uni-nav-bar>
		<view class="container">
			<uni-section title="当前负责人" type="circle">
				<uni-group>
					<view>{{contactUserName}}</view>
				</uni-group>
			</uni-section>
			<uni-section title="指派给" type="circle">
				<uni-group>
					<uni-data-select v-model="selectedPersonId" :localdata="servicePersonList" @change="selectChange"
						placeholder="请选择运维人员">
					</uni-data-select>
				</uni-group>
			</uni-section>
			<view style="margin-top: 10px;margin-bottom: 10px;padding-left: 10px;padding-right: 10px;">
				<button style="background-color: lightcoral;" type="default" @click="toOrderChange()">确认转派</button>
			</view>
		</view>
	</view>
</template>

<script>
	import http from '@/http/api.js';
	export default {
		components: {

		},
		onLoad(option) {
			this.orderId = option.orderId;
			this.contactUserName = option.contactUserName;
			this.getServicePersonList();
		},
		data() {
			return {
				orderId: '',
				contactUserName: '',
				selectedPersonId: '',
				servicePersonList: [],
				title: '维修任务转派',
				desc: '',
			}
		},
		computed: {},
		onShow() {},
		created() {},
		methods: {
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			selectChange(e) {},
			getServicePersonList() {
				let that = this;
				http.request({
					url: '/galaxy-business/serviceperson/yw/list',
					method: 'GET',
				}).then(res => {
					if (res.success) {
						let persons = res.data.map(function(item) {
							let person = {};
							person['value'] = item.id;
							person['text'] = item.realName;
							return person;
						})
						that.servicePersonList = persons;
					}
				}).catch(err => {
					console.log(err)
				})
			},
			toOrderChange() {
				let that = this;
				var postData = {};
				postData['id'] = '' + this.orderId;
				postData['servicePersonId'] =  this.selectedPersonId;
				
				http.request({
					url: '/galaxy-business/rtu/check/order/change',
					method: 'POST',
					data: postData
				}).then(res => {
					if (res.success) {
						uni.showModal({
							content: '任务指派操作已成功!',
							showCancel: true,
							success(res) {
								if (res.confirm) {
									that.toBack();
								}
							}
						});
					} else {
						uni.showModal({
							content: '任务指派操作失败!',
							showCancel: true,
							success(res) {

							}
						});
					}
				}).catch(err => {
					console.log(err)
				})
			},
		}
	}
</script>

<style>
	/* page {
		background-color: rgb(240, 242, 244);
	} */
</style>

<style lang="scss" scoped>

</style>