<template>
	<!-- 扫码出库确认页面 -->
	<view>
		<u-modal v-model="show" :show-title="false" @confirm="confirm">
			<view style="width: 100%;height: 42rpx;margin-top: 30rpx;margin-bottom: 10rpx;text-align: center;">成功信息</view>
			<u-table border-color="#f2f2f2">
				<u-tr class="u-tr">
					<u-td class="u-td">{{successCount}}{{$t('scancodeenter.strip')}}</u-td>
					<u-td class="u-td">{{$t('scancodeenter.delivery')}}</u-td>
				</u-tr>
			</u-table>
			<view style="width: 100%;height: 42rpx;margin-top: 30rpx;margin-bottom: 10rpx;text-align: center;">失败信息</view>
			<u-table border-color="#f2f2f2" font-size="20rpx">
				<u-tr class="u-tr">
					<u-th class="u-th">{{$t('scanningconfirm.number')}}</u-th>
					<u-th class="u-th">{{$t('scanningconfirm.failreason')}}</u-th>
				</u-tr>
				<u-tr class="u-tr" v-for="(item,index) in notBelongStoreBrandTyreNumbers" :key="index">
					<u-td class="u-td">{{item}}</u-td>
					<u-td class="u-td">{{$t('scanningconfirm.stateA')}}</u-td>
				</u-tr>
				<u-tr class="u-tr" v-for="(item,index) in nonRegularTyreNumbers" :key="index">
					<u-td class="u-td">{{item}}</u-td>
					<u-td class="u-td">{{$t('scanningconfirm.stateB')}}</u-td>
				</u-tr>
				<u-tr class="u-tr" v-for="(item,index) in notScanInTyres" :key="index">
					<u-td class="u-td">{{item}}</u-td>
					<u-td class="u-td">{{$t('scanningconfirm.notincluded')}}</u-td>
				</u-tr>
				<view style="width: 100%;height: 42rpx;margin-top: 30rpx;margin-bottom: 10rpx;text-align: center;">奖励合计</view>
				<u-table border-color="#f2f2f2">
					<u-tr class="u-tr">
						<u-td class="u-td">{{$t('scanningconfirm.reward')}}：{{rewardMoney}}{{$t('scanningconfirm.yuan')}}</u-td>
						<u-td class="u-td">{{$t('scanningconfirm.integral')}}：{{rewardIntegral}}{{$t('scanningconfirm.one')}}</u-td>
					</u-tr>
				</u-table>
			</u-table>
		</u-modal>
		
		<view class="header">
			<view class="behind"></view>
			<view class="content">
				<view class="content-one">
					<view>{{$t('scanningconfirm.number_s')}}</view>
					<view>{{$t('scanningconfirm.materiel')}}</view>
					<view>{{$t('scanningconfirm.estimatereward')}}</view>
				</view>
				<view v-for="(item,index) in dalist" :key="index">
					<view class="content-two">
						<view>{{item.tireNumber}}</view>
						<view>{{item.maktx}}</view>
						<view>{{item.rewardMoney}}{{$t('scanningconfirm.yuan')}}</view>
					</view>
				</view>
			</view>
		</view>
		<u-toast ref="repeat" position="bottom" />
		<view class="tail" @click="location">
			{{$t('scanningconfirm.confirm')}}
		</view>
	</view>
</template>

<script>
	import {
		request
	} from '../../../common/request/request'
	require("promise.prototype.finally").shim()
	export default {
		data() {
			return {
				datalist: [],
				total: 0,
				show: false,
				successCount: '', //成功条数
				notBelongStoreBrandTyreNumbers: [], //非门店经营品牌胎号
				nonRegularTyreNumbers: [], //非正规胎号
				notScanInTyres: [], //未入库胎号
				longitude:'',  //经度
				latitude:''    ,//纬度
				degree:'',
				address_s:'',
				whole:'',
				dalist:[],
				rewardIntegral:'',
				rewardMoney:''
			}
		},
		created() {
			uni.setNavigationBarTitle({
			    title: this.$t('scanningconfirm.titleOut')
			});
			
			uni.$on('update', data => {
				
				//渲染页面
				// this.datalist = data.materialList
				console.log(this.datalist)
				
				request({
					url: '/storeScan/getTyreReword',
					method: 'Post',
					data: {
						storeId: this.$store.state.storeInfo.storeId,
						userId: this.$store.state.storeInfo.userId,
						materialList: data.materialList,
						scanType:'2'
					}
				}).then(res => {
					console.log(res)
					this.dalist = res.data.data
					// if (res.data.code == 0) {
					// 	console.log(res)
					// 	this.dalist = res.data.data
					// 	for (let i = 0; i < this.dalist.length; i++) {
					// 		this.total += parseInt(this.dalist[i].rewardMoney)
					// 	}
					// 	return this.total
					// } else {
					// 	uni.showToast({
					// 		icon: 'none',
					// 		title: this.$t('unified.error')
					// 	})
					// }
				
				}).catch(err => {
					uni.showToast({
						icon: 'none',
						title: this.$t('unified.networkstate')
					})
				}).finally(() => {
					// Loading.close()
				})
				
				
				
				
				
				
				
				
				
				
				this.whole = data
				// return this.datalist
			})
		},
		onBackPress(options) {
			if (options.from == 'backbutton') {
				this.$u.route({
					url: 'pages/home/scancode/scancodeout'
				})
				uni.$emit('data', {
					lisi: this.datalist
				})
			}
			return true;
		},
		methods: {
			confirm() {
				this.$u.route({
					type:'redirectTo',
					url: 'pages/me/Delivery-details/index'
				})
				this.datalist = ''
			},
			location(){
				let this_s = this
				console.log(this.whole)
				this_s.Submit()
			},
			Submit() {
				this.show = true;
				request({
					url: '/storeScan/storeScanOutTyres',
					method: 'Post',
					data: {
						storeId:this.$store.state.storeInfo.storeId,
						userId:this.$store.state.storeInfo.userId,
						scanAddress: this.whole.address, //地址
						longitude: this.whole.degree.x,
						latitude: this.whole.degree.y,
						materialList: this.dalist
					}
				}).then(res => {
					console.log(res)
					this.rewardMoney = res.data.data.rewardMoney
					this.rewardIntegral = res.data.data.rewardIntegral
					if (res.data.code == 500) {
						this.$refs.repeat.show({
							title: res.data.msg,
							type: 'default',
							position: 'bottom'
						})
					}
					this.notBelongStoreBrandTyreNumbers = res.data.data.notBelongStoreBrandTyreNumbers //非门店经营品牌胎号
					this.successCount = res.data.data.successCount //成功条数
					this.nonRegularTyreNumbers = res.data.data.nonRegularTyreNumbers //非正规胎号
					this.notScanInTyres = res.data.data.notScanInTyres //未入库轮胎号
					
					this.datalist = ''
				}).catch(err => {
					uni.showToast({
						icon: 'none',
						title: this.$t('scanningconfirm.networkstate'),
						position: "bottom"
					})
				}).finally(() => {
					// Loading.close()
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.behind {
		width: 100%;
		height: 230rpx;
		margin-bottom: -200rpx;
		background-color: #0094FE;
	}

	.header {
		width: 100%;
	}

	.content {
		width: 711rpx;
		// height: 852rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 24rpx 0rpx rgba(101, 176, 249, 0.41);
		border-radius: 20rpx;
		padding-top: 10rpx;
		padding-bottom: 10rpx;
		margin: 0 auto;
	}

	.content-one {
		display: flex;
		justify-content: space-between;
	}

	.content-one:nth-child(1) {
		margin-left: 90rpx;
		margin-right: 20rpx;
		font-weight: bold;
		margin-top: 30rpx;
		// background-color: #19BE6B;
	}

	.content-two {
		display: flex;
		justify-content: space-between;
		margin-top: 30rpx;
		line-height: 115rpx;
		width: 666rpx;
		margin: 0 auto;
		color: #9c9c9c;
		font-size: 28rpx;
		border-bottom: 1rpx solid #E8E8E8;
	}

	.content-two>view:nth-child(2) {
		padding-top: 28rpx;
		width: 350rpx;
		line-height: 53rpx;
		text-align: center;
	}

	.content-two>view:nth-child(3) {
		color: #149EE2;
		margin-right: 10rpx;
	}

	.tail {
		width: 678rpx;
		line-height: 83rpx;
		background: #0095FF;
		color: #fff;
		text-align: center;
		margin: 0 auto;
		margin-top: 60rpx;
		border-radius: 15rpx;
	}
	.content-four {
		color: #acacac;
		font-size: 24rpx;
		margin-top: 30rpx;
		margin-left: 20rpx;
		margin-bottom: 50rpx;
	}
</style>