<template>
	<view class="center">
		<view >
			<view class="" v-for="(item,index) in routeData" class="route_css">
				{{item.sendCity ? item.sendCity: item.sendProvince}} {{item.sendArea}} ----> {{item.unloadCity ? item.unloadCity: item.unloadProvince}} {{item.unloadArea}}
				<view class="flex">
					<view class="btn_css" @click="addRoute(item)">修改</view>
				    <view class="btn_css" @click="del(item.id)">删除</view>
				</view>
				
			</view>
		</view>
		<view v-if="routeData.length == 0">
			<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/car.png"></u-empty>
		</view>
	
		<u-toast ref="uToast"></u-toast>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				routeData: []
			}
		},
		onShow() {},
		onLoad() {
			this.getList()
		},
		onNavigationBarButtonTap(e) {
			this.addRoute(1)
		},
		methods: {
			del(ids) {
				this.$request.baseRequest('post', '/commonRoute/api/delete', {
						id: ids
					}).then(res => {
						if (res.code == 200) {
							this.$refs.uToast.show({
								type: 'success',
								message: "删除成功！",
							})
							this.getList()
						}
					})
					.catch(res => {
						uni.$u.toast(res.message);
					});
			},
			getList() {
				this.$request.baseRequest('get', '/commonRoute/select', {
						commonId: uni.getStorageSync("firstAuthentication").commonId,
						pageSize: 10,
						currentPage: 1
					}).then(res => {
						if (res.code == 200) {
							this.routeData = res.data.records
						}
					})
					.catch(res => {
						uni.$u.toast(res.message);
					});
			},
			addRoute(item) {
				if(item == 1 && this.routeData.length == 50){
					this.$refs.uToast.show({
						type: 'success',
						message: "最多可创建50条常用路线！",
					})
				}else{
					uni.$u.route("pages/mine/often/addRoute", {
					id: item.id
				})
				}
				
			},
		}
	}
</script>

<style lang="scss" scoped>
	.center{
		padding: 30rpx;
	}
	.route_css{
		margin-bottom: 40rpx;
		.btn_css{
			margin-right: 30rpx;
		}
	}
</style>
