<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" style="font-size: 24rpx;">{{successCount}}</u-td>
					<u-td class="u-td">成功入库轮胎</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">
				<u-tr class="u-tr">
					<u-th class="u-th">轮胎胎号</u-th>
					<u-th class="u-th">失败原因</u-th>
				</u-tr>
				<u-tr class="u-tr" v-for="(item,index) in notBelongStoreBrandTyreNumbers" :key="index">
					<u-td class="u-td" style="font-size: 24rpx;">{{item}}</u-td>
					<u-td class="u-td">非门店经营品牌</u-td>
				</u-tr>
				<u-tr class="u-tr" v-for="(item,index) in nonRegularTyreNumbers" :key="index">
					<u-td class="u-td" style="font-size: 24rpx;">{{item}}</u-td>
					<u-td class="u-td">非正规胎号</u-td>
				</u-tr>
				<u-tr class="u-tr" v-for="(item,index) in alreadyExistsTyreNumbers" :key="index">
					<u-td class="u-td" style="font-size: 24rpx;">{{item}}</u-td>
					<u-td class="u-td">库存中已存在</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">
				<u-tr class="u-tr">
					<u-td class="u-td">{{rewardMoney}}奖励</u-td>
					<u-td class="u-td">{{rewardIntegral}}积分</u-td>
				</u-tr>
			</u-table>
		</u-modal>
		<view class="header">
			<view class="behind"></view>
			<view class="content">
				<view class="content-one">
					<view>胎号</view>
					<view>物料</view>
					<view>预计奖励</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}}元</view>
					</view>
				</view>

				<view class="content-three">
					<view>
						合计：{{total}}元
					</view>
				</view>
			</view>
			<view class="content-four">
				注：请完善请完善请完善请完善请完善请完善请完善
			</view>
		</view>
		<u-toast ref="repeat" position="bottom" />
		<view class="tail" @click="Submit">
			扫码确认
		</view>
	</view>
</template>

<script>
	import {
		request
	} from '../../../common/request/request'
	require("promise.prototype.finally").shim()
	export default {
		data() {
			return {
				dalist: [],
				total: 0,
				show: false,
				successCount: '', //成功条数
				notBelongStoreBrandTyreNumbers: [], //非门店经营品牌胎号
				nonRegularTyreNumbers: [], //非正规胎号
				alreadyExistsTyreNumbers: [], //库存中已存在轮胎号
				rewardMoney: '', //奖励金额
				rewardIntegral: '' ,//奖励积分
				longitude:'',  //经度
				latitude:'',   //纬度
				address: ''	   //中文地址
				
			}
		},
		created() {
			this.getDatalist()
		},
		methods: {
			confirm() {
				this.$u.route({
					type:'redirectTo',
					url: 'pages/me/Warehousing-details/index'
				})

			},
			getDatalist() {
				uni.$on('update', data => {
					this.datalist = data.materialList
					request({
						url: '/storeScan/getTyreReword',
						method: 'Post',
						data: {
							storeId:this.$store.state.storeInfo.storeId,
							userId:this.$store.state.storeInfo.userId,
							materialList: this.datalist
						}
					}).then(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

					}).catch(err => {
						console.log(err)
					}).finally(() => {
						// Loading.close()
					})
				})
			},
			Submit() {
				uni.getLocation({
					type: 'wgs84', // 返回国测局坐标
					geocode: true,
					success: function(res) {
						console.log(res);
						this.longitude = res.longitude
						this.latitude = res.latitude
						this.address = res.address.country + res.address.province + res.address.city + res.address.district + res.address.street
					},
					fail: function(e) {
						uni.showToast({
							icon: 'none',
							title: '获取地址失败, 请检查是否开启定位权限~~'
						})
					}
				})
				this.show = true;
				request({
					url: '/storeScan/storeScanTyres',
					method: 'Post',
					data: {
						storeId:this.$store.state.storeInfo.storeId,
						userId:this.$store.state.storeInfo.userId,
						scanAddress: this.address,
						longitude: this.longitude,
						latitude: this.latitude,
						materialList: this.datalist
					}
				}).then(res => {
					console.log(res.data.msg)
					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.alreadyExistsTyreNumbers = res.data.data.alreadyExistsTyreNumbers //库存中已存在轮胎号
					this.rewardMoney = res.data.data.rewardMoney //奖励金额
					this.rewardIntegral = res.data.data.rewardIntegral //奖励积分
					console.log(res)
				}).catch(err => {
					console.log(err.data.msg)
				}).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: 50rpx;
		font-weight: bold;
		margin-top: 30rpx;
	}

	.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) {
		width: 240rpx;
		line-height: 53rpx;
		text-align: center;
		margin-right: 100rpx;
	}

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

	.tail {
		width: 678rpx;
		line-height: 83rpx;
		background: #0095FF;
		color: #fff;
		text-align: center;
		margin: 0 auto;
		margin-top: 60rpx;
		border-radius: 15rpx;
	}

	.content-three>view:nth-child(1) {
		margin-left: 500rpx;
		line-height: 80rpx;
		font-weight: bolder;
	}

	.content-four {
		color: #acacac;
		font-size: 24rpx;
		margin-top: 30rpx;
		margin-left: 20rpx;
		margin-bottom: 50rpx;
	}
</style>
