<template>
	<view class="con">
		<block v-if="productList&&productList.length>0">
		<view class="list">
			<view class="li" v-for="(item, index) in productList" :key="index">
				<view class="pro ddflex">
					<image :src="item.pic" mode="aspectFill" class="pic"></image>
					<view class="fflex">
						<view class="title tovers">{{ item.title }}</view>
						<view class="money">¥{{ item.salePrice }}</view>
					</view>
				</view>
				<view class="del ddflex" @click="removeProduct(index)">
					<image src="../static/images/sp_del.png"></image>
					删除
				</view>
			</view>
		</view>
		<view class="tip">*最多可以添加3个商品链接</view>
		<navigator url="/office/add/add" hover-class="none" class="btn" v-if="productList.length < 3">继续添加</navigator>
		</block>
		<block v-else>
			<view class="nodata">
				<image :src="picUrlss+'empty_xd.png'"></image>
				<view>暂无商品哦~</view>
			</view>
			<navigator url="/office/add/add" hover-class="none" class="btn">添加商品</navigator>
		</block>
		<view class="complete" @click="completeProduct()">完成</view>
	</view>
</template>

<script>
const req = require('../../utils/request.js');
export default {
	data() {
		return {
			picUrlss: req.public.picUrls,
			productList: []
		};
	},
	onLoad() {
		//默认选中上面的标签
		let pages = getCurrentPages(); //获取所有页面栈实例列表
		let prevPage = pages[pages.length - 2]; //上一页页面实例
		this.productList = prevPage.$vm.productList;
	},
	methods: {
		removeProduct(indx) {
			this.productList.splice(indx, 1);
		},

		completeProduct() {
			let pages = getCurrentPages(); //获取所有页面栈实例列表
			let prevPage = pages[pages.length - 2]; //上一页页面实例
			prevPage.$vm.productList = this.productList; //修改上一页data里面的searchVal参数值为1211
			uni.navigateBack({
				//uni.navigateTo跳转的返回，默认1为返回上一级
				delta: 1
			});
		}
	}
};
</script>

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