<template>
	<view class="container-view">
		<view class="return-info flex-row flex-between">
			<view class="return-top">
				<view>车牌：{{plate_number}}</view>
			</view>

			<view><img :src="model_image" /></view>
		</view>
		<view class="pictures-info">
			<view>车辆照片</view>
			<!-- <view>这里是关于激活车辆照片的文案描述，这里是关于激活车辆照片的文案描述</view> -->
			<uploader :car_info="car_imgs" @update-car-images="handleCarImagesUpdate"></uploader>
			<view @tap="submitEnabled" class="pictures-btn">激活车辆</view>
		</view>
	</view>
</template>

<script>
	import uploader from '@/component/uploader/uploader';
	const http = require('@/common/http.js');
	const config = require('@/common/config.js');
	const common = require('@/common/common.js');
	export default {
		components: {
			uploader
		},
		data() {
			return {
				carInfo: {},
				plate_number: '013657142736',
				sub_sn: '',
				model_image: '3',
				car_model: '',
				return_imgs: [],
				car_imgs: [{img_url: ''}],
				model_image_list: ''
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			console.log(options,'options');
			this.sub_sn =  options.sub_sn || ''
		},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
		},
		onUnload: function () {
		},
		methods: {
			handleCarImagesUpdate(updatedImages) {
				// 这里会接收到子组件传来的更新后的图片URL数组
				this.car_imgs = updatedImages
			},
			
			submitEnabled() {
				const me = this
				const _image_list = this.car_imgs.map(item => item.img_url)
				if (_image_list.includes('' || "")) return common.simpleToast('请上传车辆照片')
				const pData = {
					car_sn: this.plate_number,
					sub_sn: this.sub_sn,
					image_list: _image_list.join(', ')
				}
				http.postApi(config.API_FLK_CAR_ASSIGNMENT, pData, (resp) => {
					if (resp.data.code === 200) {
						common.simpleToast('车辆激活成功')
						setTimeout(function() {
							me.isCustomJump = false
							uni.switchTab({
								url: `/pages/index/index?plate_number=${me.plate_number}`,
								success: function(res) {},
								fail: function(res) {},
								complete: function(res) {}
							});
						}, 800)
					} else {
						common.simpleToast(resp.data.msg)
					}
				})
			}
		}
	};
</script>

<style>
	@import './activation.css';
</style>