<template>
	<view>
		<scroll-view :scroll-y="true">
			<view class="cu-bar bg-white solid-bottom">
				<view class="action">
					<text class="cuIcon-title text-orange "></text> 建档列表
				</view>
				<view class="action">
					<button class="cu-btn bg-blue shadow" @click="addClick">新增</button>
				</view>
			</view>
	<scroll-view scroll-x class="bg-white nav">
			<view class="flex text-center">
				<view class="cu-item flex-sub" :class="index==TabCur?'text-orange cur':''" v-for="(item,index) in tabs"
					:key="index" @tap="tabSelect" :data-id="index">
					{{item.name}}
				</view>
			</view>
		</scroll-view>
			<view class="cu-list menu card-menu margin-top">
				<view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''" @touchstart="ListTouchStart"
					@touchmove="ListTouchMove" @touchend="ListTouchEnd" :data-target="'move-box-' + index"
					style="margin-top: 10rpx;" v-for="(item,index) in filingList" :key="index">
					<view class="content" @click="editFiling(item)">
						<view class="cu-form-group">
							<view class="title" style="min-width: calc(6em + 15px);">制衣生产车间</view>
							<text class="text-grey" style="flex: 1;">{{item.workshop.zyProductWorkshop}}</text>
						</view>
						<view class="cu-form-group">
							<view class="title" style="min-width: calc(6em + 15px);">制衣班组</view>
							<text class="text-grey" style="flex: 1;">{{item.team.zyTeam}}</text>
						</view>
						<view class="cu-form-group">
							<view class="title" style="min-width: calc(6em + 15px);">订单号</view>
							<text class="text-grey" style="flex: 1;">{{item.orderNo}}</text>
						</view>
						<view class="cu-form-group">
							<view class="title" style="min-width: calc(6em + 15px);">交期</view>
							<text class="text-grey" style="flex: 1;">{{item.deliveryDate}}</text>
						</view>
							<view class="cu-form-group">
							<view class="title" style="min-width: calc(6em + 15px);">建档时间</view>
							<text class="text-grey" style="flex: 1;">{{item.filingDate}}</text>
						</view>
					</view>
					<view class="move">
						<view class="bg-grey" @click="editFiling(item)">修改</view>
						<view class="bg-red" @click="deleteFiling(item)">删除</view>
					</view>
				</view>
			</view>
			<u-toast ref="uToast" />
		</scroll-view>
	</view>
</template>

<script>
	import {
		list,
		deleteFiling
	} from '@/api/biz/filing.js'
	export default {
		data() {
			return {
				filingList: [],
				modalName: null,
				tabs: [{
						key: 0,
						name: '未封存'
					},
					{
						key: 1,
						name: '封存'
					}
				],
				TabCur: 0,
			}
		},
		methods: {
			addClick() {
				uni.navigateTo({
					url: '/pages/filing/index'
				})
			},

			// loadData() {
			// 	list().then(res => {
			// 		if (res.success) {
			// 			this.filingList = res.data
			// 		} else {}
			// 	})
			// },
			loadData(tabIndex){
					list(tabIndex).then(res => {
						if (res.success) {
							this.filingList = res.data
						} else {}
					})
				// if (tabIndex == 0) {
				// 	getRcvReport().then(res => {
				// 		if (res.success) {
				// 			this.reportData = res.data
				// 		}
				// 	})
				// } else if (tabIndex == 1) {
				// 	getBackReport().then(res => {
				// 		this.reportData = res.data
				// 	})
				// } else {
				
				// }
			},
			editFiling(item) {
				uni.navigateTo({
					url: '/pages/filing/edit?orderInfo=' + encodeURIComponent(JSON.stringify(item))
				})
			},
			// ListTouch触摸开始
			ListTouchStart(e) {
				this.listTouchStart = e.touches[0].pageX
			},

			// ListTouch计算方向
			ListTouchMove(e) {
				this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left'
			},

			// ListTouch计算滚动
			ListTouchEnd(e) {
				if (this.listTouchDirection == 'left') {
					this.modalName = e.currentTarget.dataset.target
				} else {
					this.modalName = null
				}
				this.listTouchDirection = null
			},
			deleteFiling(item) {
				const arr = []
				arr.push(item)
				deleteFiling(arr).then(res => {
					if (res.success) {
						this.removeFilingInfo(item)
					}else{
						this.$refs.uToast.show({
							type: 'error',
							message: res.message,
							iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
						})
					}
				})
			},
			removeFilingInfo(item) {
				const index = this.filingList.findIndex(ele => {
					return ele.id == item.id
				})
				this.filingList.splice(index, 1)
			},
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.loadData(this.TabCur)
			},
		},
		onLoad() {
			this.loadData(0)
			uni.$on('loadData', (data) => {
				this.TabCur = data;
				console.log("xiugai"+data)
				this.loadData(data);
			})
		}
	}
</script>

<style>
	.cu-form-group {
		min-height: 0;
		border: none;

	}
</style>
