<template>
	<view class="order-infos content">
		<u-sticky bgColor="#f5f7fa" class="sticky-main">
			<view class="order-card">
				<view class="order-card-title">
					<text class="info">{{shareInfo.share.tenantName || ''}}</text>
					<!-- <text class="no">No {{shareInfo.share.code || ''}}</text> -->
					<view class="orderStatus-info">
						<u--image width="100rpx" height="88rpx" v-if="shareInfo.share.orderStatus == 0"
							src="/subpages/static/img/no-take-order.png"></u--image>
						<u--image width="100rpx" height="88rpx" v-if="shareInfo.share.orderStatus == 1"
							src="/subpages/static/img/start-take-order.png"></u--image>
						<u--image width="100rpx" height="88rpx" v-if="shareInfo.share.orderStatus == 2"
							src="/subpages/static/img/completed.png"></u--image>
						<u--image width="100rpx" height="88rpx" v-if="shareInfo.share.orderStatus == 4"
							src="/subpages/static/img/cancellation.png"></u--image>
					</view>
				</view>
				<view class="order-card-info">
					<view class="row">
						<p class="cell">
							<text class="label">{{$t('order.orderDate')}}</text>
							<text class="info">{{shareInfo.share.setDate || ''}}</text>
						</p>
						<p class="cell">
							<text class="label">{{$t('order.vehicleType')}}</text>
							<text class="info"
								v-if="shareInfo.share.vehicleType == '101'">{{$t('order.saleOrder')}}【<text
									class="success">{{shareInfo.share.orderNumber}}{{$t('customer_meter.unitN')}}</text>】</text>
							<text class="info"
								v-if="shareInfo.share.vehicleType == '102'">{{$t('order.purchaseOrder')}}【<text
									class="success">{{shareInfo.share.orderNumber}}{{$t('customer_meter.unitN')}}</text>】</text>

						</p>
					</view>
					<view class="row">
						<p class="cell">
							<text class="label">{{$t('order.companyName')}}</text>
							<text class="info">{{shareInfo.share.companyName || ''}}</text>
						</p>
					</view>
					<view class="row">
						<p class="cell">
							<text class="label">{{$t('order.materialName')}}</text>
							<text class="info">{{shareInfo.share.materialName || ''}}</text>
						</p>
						<p class="cell">
							<text class="label">{{$t('order.haveOrderReceiving')}}</text>
							<text
								class="info warning">{{(shareInfo.share.tempOrderCount)}}{{$t('customer_meter.unitN')}}</text>
						</p>
					</view>
					<!-- 			<view class="row">
						<p class="cell">
							<text class="label">{{$t('order.orderDate')}}</text>
							<text class="info">{{shareInfo.share.createTime || ''}}</text>
						</p>
					</view> -->
					<button ref="sharebtn" class="share-button" data-name="shareBtn" open-type="share">
						分享订单
						<!-- <u--image width="100rpx" height="88rpx" src="/subpages/static/img/share.png"></u--image> -->
					</button>
				</view>
				<view class="code">
					<view class="label">{{$t('spare.orderCode')}}</view>
					<view class="info">{{ shareInfo.share.code || '' }}</view>
				</view>
			</view>
			<view class="tabs-box">
				<u-tabs lineWidth="40" :list="statusList" :current="statusActive" @change="onChangeStatus"
					lineColor="#3275F5" :itemStyle="{'height':'90rpx','padding':'0 32rpx'}">
				</u-tabs>
			</view>
		</u-sticky>

		<view class="swiper-box">
			<view class="order-card" v-if="shareInfo.orderInfo && shareInfo.orderInfo.length>0">

				<view v-for="(item,index) in shareInfo.orderInfo" :key="index" class="card-main">
					<view class="order-card-title">
						<view class="left-info">
							<u-checkbox-group v-if="statusActive=='2' && item.enabledMarkType==2">
								<u-checkbox shape="circle" v-model="item.isAudit" :checked="item.checked"
									@change="onAutoChange(item)"></u-checkbox>
							</u-checkbox-group>
							<text class="info">No {{item.code || ''}}</text>
						</view>
						<view class="orderStatus-info">
							<u-tag :text="$t('mine.reviewed')" plain shape="circle"
								v-if="item.enabledMarkType==0 && item.orderStatus == 0"></u-tag>
							<u-tag :text="$t('mine.unpaid')" plain type="warning" shape="circle"
								v-if="item.orderStatus == 1 && item.weighingStatus== 0" />
							<u-tag :text="$t('mine.ongoing')" plain type="success" shape="circle"
								v-if="item.enabledMarkType==0 && item.orderStatus == 2"></u-tag>
							<u-tag :text="$t('mine.weigh')" plain type="success" shape="circle"
								v-if="item.orderStatus==1 && item.weighingStatus !=0"></u-tag>
							<u-tag :text="$t('mine.invalid')" plain type="error" shape="circle"
								v-if="item.enabledMarkType==1 && item.orderStatus == 4"></u-tag>
							<u-tag :text="$t('mine.noneAudit')" plain type="warning" shape="circle"
								v-if="item.enabledMarkType==2" @click="onAudit(item)"></u-tag>
							<u-tag :text="$t('mine.nonePass')" plain type="error" shape="circle"
								v-if="item.enabledMarkType==1 && item.orderStatus == 5"></u-tag>
						</view>
					</view>
					<view class="order-card-info">
						<!-- 			<view class="order-type">
						<span class="tag tag-l" v-if="item.orderType == '1'">{{$t('order.temp')}}</span>
						<span class="tag tag-g" v-if="item.orderType == '2'">{{$t('order.fixed')}}</span>
						<span class="tag tag-s" v-if="item.orderType == '4'">{{$t('order.share')}}</span>
					</view> -->
						<view class="row">
							<p class="cell">
								<text class="label">{{$t('order.orderDate')}}</text>
								<text class="info">{{item.setDate}}</text>
							</p>
						</view>
						<view class="row" v-if="item.orderStatus == 1">
							<p class="cell">
								<text class="label">{{$t('order.inDoorTime')}}</text>
								<text class="info">{{item.enterTime}}</text>
							</p>
						</view>
						<view class="row">
							<p class="cell">
								<text class="label">{{$t('order.vehicle')}}</text>
								<text class="info">{{item.vehicle}}</text>
							</p>
							<p class="cell">
								<text class="label">{{$t('order.driver')}}</text>
								<text class="info">{{item.driver}}</text>
							</p>
						</view>
						<view class="row" v-if="item.orderStatus == 1 && item.weighingStatus!=0">
							<p class="cell">
								<text class="label">{{$t('order.tareWeight')}}</text>
								<text class="info">{{item.tareWeight}}</text>
							</p>
							<p class="cell">
								<text class="label">{{$t('order.grossWeight')}}</text>
								<text class="info">{{item.grossWeight}}</text>
							</p>
						</view>
						<view class="row">
							<p class="cell" v-if="item.orderStatus == 1 && item.weighingStatus!=0">
								<text class="label">{{$t('order.netWeight')}}</text>
								<text class="info">{{item.netWeight}}</text>
							</p>
							<p class="cell">
								<text class="label">{{$t('order.orderNumber')}}</text>
								<text class="info">{{item.orderNumber}} T</text>
							</p>
						</view>
						<view class="row" v-if="item.orderStatus == 1 && item.weighingStatus!=0">
							<p class="cell">
								<text class="label">{{$t('order.inTime')}}</text>
								<text class="info">{{item.inTime || ''}}</text>
							</p>
						</view>
						<view class="row" v-if="item.weighingStatus == 2">
							<p class="cell">
								<text class="label">{{$t('order.outTime')}}</text>
								<text class="info">{{item.outTime || ''}}</text>
							</p>
						</view>
						<view class="row" v-if="item.orderStatus == 2">
							<p class="cell">
								<text class="label">{{$t('order.outDate')}}</text>
								<text class="info">{{item.outDoorTime || ''}}</text>
							</p>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="bottom-btn" v-if="enabledMarkType=='2' && shareInfo.orderInfo && shareInfo.orderInfo.length>0">
			<view class="left">
				<view class="all">
					<u-checkbox-group>
						<u-checkbox @change="onAutoAllChange" shape="circle" label="全选"></u-checkbox>
					</u-checkbox-group>
				</view>
				<view class="title">
					<text class="label">已选择:{{shareInfo.orderInfo.filter((a,i)=>{return a.isAudit==1}).length }}车</text>
				</view>
			</view>
			<view class="right">
				<view class="btn">
					<u-button type="success" size="small" text="通过" class="ok" @click="onAuditBatch(1)"></u-button>
					<u-button type="error" size="small" text="不通过" class="no" @click="onAuditBatch(0)"></u-button>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		getShareOrderInfo,
		receiveOrderAudit
	} from "../../api/order"
	export default {
		data() {
			return {
				loading: false,
				statusActive: 0,
				enabledMarkType: "3",
				shareInfo: {
					orderInfo: {
						isAudit: 1,
						checked: true,
					},
					share: {}
				},
				statusList: [{
						name: this.$t("customer_meter.all"),
						enabledMarkType: '3'
					},
					{
						name: this.$t("mine.alreadyAudit"),
						enabledMarkType: '0'
					},
					{
						name: this.$t("mine.noneAudit"),
						enabledMarkType: '2'
					},
					{
						name: this.$t("mine.nonePass"),
						enabledMarkType: '5'
					},
				],
				keyword: '',
				options: {},
			};
		},
		onLoad(options) {
			this.options = options;
			this.onGetShoreOrderList()
		},
		// #ifdef MP-WEIXIN
		onShareAppMessage() {
			console.log("1开始分享订单")
			return {
				title: this.$t("common.shareSend"),
				path: `/subpages/order/receiving?orderId=${this.shareInfo.share.id}&tenantId=${this.shareInfo.share.tenantId}`,
			}
		},
		// #endif
		methods: {
			onAutoAllChange(n) {
				this.shareInfo.orderInfo = this.shareInfo.orderInfo.map(item => {
					item.isAudit = (n == true ? 1 : 0);
					item.checked = n;
					return item
				})
				console.log("选择需要审核的订单后、", this.shareInfo.orderInfo);
			},
			onAutoChange(item) {
				if (item.checked == true) {
					item.checked = false;
					item.isAudit = 0;
				} else {
					item.checked = true;
					item.isAudit = 1;
				}
				this.$forceUpdate()
			},
			onGetShoreOrderList() {
				var that = this;
				let param = {
					...that.options,
					enabledMarkType: that.enabledMarkType,
				}
				getShareOrderInfo(param).then(res => {
					if (res.statusCode == 200) {
						that.shareInfo = res.data.data.data
					}
					console.log("获取到的共享订单信息、", that.shareInfo);
				})
			},
			onAudit(data) {
				let param = {
					tenantId: data.tenantId,
					"orderInfos": [{
						orderId: data.id,
						isAudit: "1"
					}]
				}
				this.audit("1", param)
			},
			onAuditBatch(type) {
				var arrOrderId = this.shareInfo.orderInfo.filter(ele => ele.isAudit == 1);
				if (!arrOrderId || arrOrderId.length == 0) {
					uni.showToast({
						title: this.$t("order.noAuditOrderData"),
						icon: 'none',
						duration: 2000
					})
					return;
				}
				let orderInfos = []
				arrOrderId.forEach(item => {
					orderInfos.push({
						orderId: item.id,
						isAudit: type
					});
				});
				let param = {
					"tenantId": this.options.tenantId,
					"orderInfos": orderInfos
				}
				this.audit(type, param)
			},

			audit(type, param) {
				uni.showModal({
					content: (type == 1 ? this.$t("order.isAuditPass") : this.$t("order.isAuditNoPass")),
					success: ({
						confirm,
						cancel
					}) => {
						if (confirm) {
							console.log("开始审核订单信息、", param);
							receiveOrderAudit(param).then(res => {
								if (res.statusCode == 200) {
									uni.showToast({
										title: this.$t("common.complete"),
										icon: 'none',
										duration: 2000
									})
									this.onGetShoreOrderList()
								}
							})
						}
					}
				})
			},

			onChangeStatus(index) {
				this.statusActive = index;
				var enabledMarkType = this.statusList[index].enabledMarkType;
				if (this.enabledMarkType == enabledMarkType) {
					return
				} else {
					this.enabledMarkType = enabledMarkType;
					this.onGetShoreOrderList()
				}
			},
		},
	};
</script>
<style scoped>
	/* #ifndef APP-NVUE */
	view {
		display: flex;
		box-sizing: border-box;
		flex-direction: column;
	}

	page {
		box-sizing: border-box;
		/* padding: 40rpx 40rpx 80rpx; */
		/* height: 100%;
	
	background-size: 750rpx auto; */
	}

	/* #endif*/
</style>
<style lang="scss" scoped>
	@import '../../common/css/public.scss';

	.order-card {
		margin: 24rpx;
	}
</style>