<template>
	<view class="templist-box">
		<view class="list">
			<view class="item acea-row row-between-wrapper" v-for="(item,index) in tempList" :key="index" @tap="choseTemp(item)">
				<view class="temp-name">
					{{index + 1}}、{{item.name}}
				</view>
				<view class="acea-row row-middle">
					<view class="handle-btn" @tap.stop="del(item)">
						<image src="../../../static/images/del-goods.png"></image>
					</view>
					<view class="handle-btn" @tap.stop="edit(item)">
						<image src="../../../static/images/edit-icon.png"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="btn-box" @tap.stop="toTemp">新增运费模板</view>
	</view>
</template>

<script>
	import { getTempList, delTemp } from '@/api/user'
	export default{
		data(){
			return {
				tempList: []
			}
		},
		onShow(){
			this.getTempList()
		},
		mounted(){
			
		},
		onPullDownRefresh(){
			this.getTempList()
		},
		methods:{
			choseTemp(item){
				console.log(item,'item')
				let pages = getCurrentPages();
				console.log(pages,'pages')
				let page = pages[pages.length -2]
				if(page.route == 'pages/life/addGoods/index'){
					page.$vm.temp = item.name
					page.$vm.tempId = item.id
					uni.navigateBack({
						delta: 1
					})
				}
			},
			del(item){
				let id = [item.id]
				if(item.id == 1) return uni.showToast({ title: '默认模板不可删除！', icon:'none', })
				uni.showModal({
					title: '提示！',
					content: '是否确认删除运费模板？',
					success: (r) => {
						if(r.confirm){
							delTemp(id).then((res)=>{
								if(res.success){
									this.alertMessage('操作成功！')
									this.getTempList()
								} else{
									this.alertMessage(res.msg)
								}
							})
						}
					}
				})
			},
			getTempList(){
				getTempList().then((res)=>{
					// console.log(res)
					this.tempList = res.data.content
					uni.stopPullDownRefresh()
				})
			},
			toTemp(){
				uni.navigateTo({
					url:'/pages/life/temp/index'
				})
			},
			edit(item){
				uni.navigateTo({
					url:'/pages/life/temp/index?id='+ item.id
				})
			},
			alertMessage(msg){
				uni.showToast({
					title: msg,
					icon: 'none'
				})
			}
		}
	}
</script>

<style lang="less">
	.templist-box{
		width: 100%;
		min-height: 100vh;
		background: #F5F6F7;
		padding: 30rpx 20rpx 110rpx;
		position: relative;
		.list{
			width: 100%;
			padding-bottom: 60rpx;
			.item{
				width: 100%;
				background: #fff;
				padding: 24rpx;
				color: #000;
				font-size: 28rpx;
				margin-bottom: 12rpx;
				.temp-name{
					width: 80%;
					height: 50rpx;
					line-height: 50rpx;
				}
				.handle-box{
					width: 100%;
					height: 46rpx;
					border-top: 2rpx solid #F8F7F7;
					
				}
				.handle-btn{
					margin-left: 12rpx;
					width: 38rpx;
					height: 100%;
					text-align: center;
					image{
						width: 35rpx;
						height: 35rpx;
					}
				}
			}
		}
		.btn-box{
			width: 690rpx;
			height: 76rpx;
			line-height: 76rpx;
			text-align: center;
			font-size: 34rpx;
			font-weight: 500;
			border-radius: 40rpx;
			background: linear-gradient(134deg, #FFA782 0%, #FF6D31 100%);
			color: #fff;
			position: fixed;
			bottom: 30rpx;
			left: 30rpx;
		}
	}
</style>
