<template>
	<view class="sawing-page">
		<navigation title="锯断数据"></navigation>
		<view class="list-box" v-if="dataList.length>0">
			<view class="add" @click="addInfo">
				<image class="icon" src="@/static/add.jpg"></image>
				<view class="text">新增</view>
			</view>
			<view class="list-item" v-for="(item, index) in dataList" :key="index">
				<view class="item-text">订单编号：{{ item.orderNum || '-' }}</view>
				<view class="item-text">下料长度：{{ item.allLength || '-' }}</view>
				<view class="item-text">切割长度：{{ item.cuttingLength || '-' }}</view>
				<view class="btn-box">
					<view class="btn-item" @click="editInfo(item.id)">
						<view>修改</view>
					</view>
					<view class="btn-item" @click="deleteInfo(item.id)">
						<view>删除</view>
					</view>
				</view>
			</view>
		</view>
		<empty v-else text="暂无数据" :showBtn="true" @onAdd="addInfo"></empty>
		<!-- 确认框 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="warn" cancelText="取消" confirmText="确定" title="提示" content="确认删除吗？"
				@confirm="dialogConfirm"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				id: '',
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList() {
				uni.showLoading({
					title: '正在加载...'
				})
				this.$api.mesCuttingList().then(res => {
					this.dataList = res.rows
					uni.hideLoading()
				}).catch(err => {})
			},
			addInfo() {
				uni.navigateTo({
					url: '/subPackages/sawing/add'
				});
			},
			// 修改
			editInfo(id) {
				uni.navigateTo({
					url: '/subPackages/sawing/add?id=' + id
				});
			},
			// 删除
			deleteInfo(id) {
				this.id = id
				this.$refs.alertDialog.open()
			},
			dialogConfirm() {
				let that = this
				this.$api.delMesCutting(this.id).then(res => {
					uni.showToast({
						title: '删除成功！',
						duration: 2000
					});
					setTimeout(function() {
						that.getList()
					}, 2000);
				}).catch(err => {})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.sawing-page {
		.add {
			display: flex;
			justify-content: center;
			align-items: center;
			background-color: #fff;
			padding: 20rpx;
			border-radius: 16rpx;

			.icon {
				width: 50rpx;
				height: 50rpx;
				margin-right: 16rpx;
			}
		}

		.list-box {
			padding: 0 20rpx;
			color: $uni-text-color-list;

			.list-item {
				background-color: $uni-bg-color;
				padding: 20rpx;
				border-radius: 20rpx;
				margin-top: 28rpx;

				.item-text {
					margin-top: 10rpx;
				}
			}

			.btn-box {
				display: flex;
				justify-content: flex-end;
				margin-top: 10rpx;

				.btn-item {
					width: 175rpx;
					height: 50rpx;
					line-height: 50rpx;
					text-align: center;
					border-radius: 24rpx;
					margin-left: 20rpx;
					border: 1px solid #43adfd;
					color: #43adfd;
				}
			}
		}
	}
</style>
