<template>
	<view class="container">
		<scroll-view scroll-y class="page" >
			<view class="cu-list menu-avatar">
				<view class="cu-item" :class="modalName=='move-box-'+ item.id?'move-cur':''" v-for="item in datas" :key="item.id"
				 @touchstart="ListTouchStart" @touchmove="ListTouchMove" @touchend="ListTouchEnd" :data-target="'move-box-' + item.id">
					<view class="cu-avatar radius">
						<text class="cuIcon-home"></text>
					</view>
					<view class="content" style="background-color: #FFFFFF;">
						<view class="text-grey">{{item.companyName}}</view>
						<view class="text-gray text-sm">
							<text class="margin-right-xs cuIcon-calendar"></text> {{item.identificationNo}}
						</view>
						<view class="text-gray text-sm">
							<text class="margin-right-xs cuIcon-phone"></text> {{item.companyPhone}}
						</view>
					</view>
					<view class="move">
						<view class='bg-grey' @click='editCompany(item)'>编辑</view>
						<view class='bg-red' @click='delCompany(item)'>删除</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<drag-button
			:isDock="true"
			:existTabBar="true"
			:isIcon="true"
			text="新增"
			location="20"
			@btnClick="Company"
			/>
	</view>
</template>

<script>
	import {
	    mapState 
	} from 'vuex';
	export default {
		data() {
			return {
				datas:[],
				listTouchStart: 0,
				listTouchDirection: null,
				modalName: null,
			}
		},
		computed: {
		},
		onShow() {
			var that=this
			this.$api.request('company', 'getCompany', failres => {
				that.$api.msg(failres.errmsg)
				uni.hideLoading()
			}).then(res => {
				if(res.data.code=='SUCCESS'){
					that.datas=res.data.data
					uni.hideLoading()
				}else{
					that.$api.msg(res.data.code)
					uni.hideLoading()
				}
			})
		},
		onLoad() {
			
			
		},
		onReady(){
			
		},
		methods: {
			// 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
			},
			Company(){
				uni.navigateTo({
					url: '/pageA/pages/newcompany'
				})
			},
			editCompany(item){
				console.log(item.companyName+1)
				uni.navigateTo({
					url: `/pageA/pages/newcompany?accountNo=${item.accountNo}&companyBank=${item.companyBank}&companyName=${item.companyName}&personNo=${item.personNo}&personName=${item.personName}&personNoImg=${item.personNoImg}&personNoImg1=${item.personNoImg1}&bankImg=${item.bankImg}&bankImg1=${item.bankImg1}&companyPhone=${item.companyPhone}&companyPlace=${item.companyPlace}&identificationNo=${item.identificationNo}&id=${item.id}`
				})
			},
			delCompany(item){
				var that =this
				var data={}
				data.id=item.id
				this.$api.request('company', 'deleteCompany', data, failres => {
					that.$api.msg(failres.errmsg)
				}).then(res => {
					if(res.data.code=='SUCCESS'){
						that.$api.msg('删除成功')
					}else{
						that.$api.msg(res.data.code)
					}
					setTimeout(()=>{uni.navigateBack({
						delta: 1
					})},1000);
					uni.hideLoading()
				})
			},
		},
	}
</script>

<style scoped>
	.cu-list>.cu-item.move-cur {
	    -webkit-transform: translateX(-259rpx);
	    transform: translateX(-259rpx);
	}
</style>
