<template>
	<view>
		<topnav :title='pageTitle' @tohome="tohome"></topnav>
		<view class="content">
			<view class="orderBox">
				<orderinfo :info="order"></orderinfo>

			</view>
			<view class="pageTitle">
				添加护工
			</view>
			<view class="listBox" style="margin-top: 30rpx;">
				<view class="listBoxItem">
					<view class="listBoxItemLeft">
						选择护工
					</view>
					<view class="listBoxItemRight" @click="bindSelectCarer">
						<text>{{selectCarer==""?"请选择":selectCarer}}</text>
						<text class="iconfont icon-Icons_ToolBar_ArrowRight"></text>
					</view>
				</view>
			</view>
		</view>

		<view class="bottom">
			<view class="bottomLeft">
			</view>
			<view class="bottomRight">
				<view class="btnCancel btn" @click="bindCancel">取消</view>
				<view class="btnSubmit btn" @click="bindsubmitFun">提交</view>
			</view>
		</view>
	</view>
</template>

<script>
	var util = require("../../../../utils/util.js");
	export default {
		data() {
			return {
				pageTitle: "派单",
				order: {
					"id": 731,
					"serial": "",
					"customer_id": 16,
					"manager_id": null,
					"bed_id": 778,
					"patient_id": 793,
					"project_id": 1,
					"product_id": 1,
					"product_item_id": 1,
					"product_paramedic_level_id": 1,
					"from_date": "",
					"to_date": "",
					"status": 0,
					"total": 150,
					"paid_total": 0,
					"contact": null,
					"mobile": "13912797667",
					"paramedic_id": 31,
					"price": "150.00",
					"patient_quantity": null,
					"created_at": "",
					"updated_at": "",
					"balance": "0.00",
					"status_name": "",
					"days": 0,
					"product_item": {
						"id": 1,
						"name": "一对一"
					},
					"paramedic_level": {
						"id": 8,
						"name": "",
						"laravel_through_key": 1
					},
					"project": {
						"id": 1,
						"name": "",
						"logo_url": null,
						"banners_url": null
					},
					"bed": {
						"id": 778,
						"name": "1",
						"room_name": "101",
						"area_name": "",
						"building_name": "内科楼"
					},
					"customer": {
						"id": 16,
						"name": null,
						"balance": "0.00"
					},
					"patient": {
						"id": 793,
						"name": "刘瑜",
						"sex": null,
						"age": null,
						"mobile": null
					},
					"paramedic": {
						"id": 31,
						"name": "刘忠兰",
						"mobile": "15850579275",
						"paramedic_level_name": "普通护工",
						"avatar_url": null,
						"age": "",
						"status_name": null
					},
					"factorjson": [{
						"fee": "0.00",
						"price": "0.00",
						"factor_id": 1,
						"factor_name": "所在科室",
						"fee_percent": "25.00",
						"used_for_fee": 1,
						"factor_item_id": 2,
						"factor_item_name": "骨科"
					}]
				},
				selectCarer: "",
				selectCarerID: "",
				id: "",

			}
		},
		onLoad: function(option) {
			var that = this;
			that.id = option.id;
			util.getOrderInfo(option.id, function(r) {
				that.order = r.data;
			}, function(r) {

			});
		},

		onShow: function() {
			var carer = uni.getStorageSync("selectCarer");
			if (carer != null && !util.isNull(carer)) {
				this.selectCarer = carer.name;
				this.selectCarerID = carer.id;
			}
		},
		onUnload: function() {
			uni.removeStorageSync('selectCarer');

		},
		onHide: function() {
			uni.removeStorageSync('selectCarer');
		},
		methods: {
			tohome:function(){
				uni.navigateTo({
					url:"../../../../pages/index/index"
				})
			},
			bindCancel: function(e) {
				uni.navigateBack({

				})
			},
			bindsubmitFun: function(e) {
				var that = this;
				if (util.isNull(that.selectCarerID)) {
					util.alert("请选择护工")
					return false;
				}
				uni.showModal({
					title: '提示',
					content: "确认派单？",
					confirmText: "确认",
					confirmColor: "#000",
					cancelColor: "#eee",
					success(res) {
						if (res.confirm) {
							that.doAssgin();
						}
					}
				});
			},
			doAssgin: function() {
				var that = this;
				util.request({
					bindThis: that,
					method: 'POST',
					customLoading: false,
					api: 'manager/assign-order/' + that.id,
					data: {
						paramedic_id: that.selectCarerID
					},
					utilSuccess: function(res) {
						console.log('3：提交成功返回' + res);
						uni.showModal({
							title: "派单成功",
							success: function() {
								uni.navigateTo({
									url: "../orderinfo/orderinfo?id=" + that.id
								})
							}
						})
						that.processAfterPay(res);
					},
					utilFail: function(res) {
						console.log('4：提交失败' + res);
						util.alert(res);
					}
				});

			},
			bindSelectCarer: function(e) {
				uni.navigateTo({
					url: "../../../packagecarer/pages/selectcarer/selectcarer"
				})
			}
		}
	}
</script>

<style>
	.bottom {
		background: #FFFFFF;
		box-shadow: 0 -2rpx 12rpx 0 rgba(0, 0, 0, 0.16), inset 0 1rpx 0 0 #E4E4E4;
		width: 100%;
		height: 100rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		display: flex;
		justify-content: space-between;
	}

	.bottom .bottomLeft {
		display: flex;
		align-items: center;
	}

	.bottom .bottomRight {
		display: flex;
		flex: 1;
	}

	.btn {
		width: 50%;
		line-height: 100rpx;
		text-align: center;
		line-height: 100rpx;
		font-family: SourceHanSansCN-Medium;
		font-size: 32rpx;
		letter-spacing: 0;
	}

	.btnCancel {

		color: #666666;
		background: #F0F0F0;
	}

	.btnSubmit {

		color: #FFFFFF;
		background: #0DC99E;
	}
</style>
