<template>
	<view class="content">
		<view class="card-list">
			<view class="row" v-for="(item,index) in cardList" :key="index">
				<view class="title-name">
					{{item.cardBusiness}}
				</view>
				<view class="flex card-list-item">
					<view class="left">
						<view class="top flex-row-center">
							<image :src="item.headSculpture" mode="widthFix" class="img"></image>
						</view>
						<view class="bottom flex flex-evenly">
							<uni-icons type="home" size="20" @click="toHome(item)"></uni-icons>
							<uni-icons type="home" size="20"></uni-icons>
							<uni-icons type="redo" size="20"></uni-icons>
						</view>
					</view>
					<view class="right">
						<view class="row1 flex">
							<text>{{item.name}}</text>
							<text class="line"></text>
							<text>{{item.post}}</text>
						</view>
						<view class="row2">
							{{item.companyName}}
						</view>
						<view class="row3" @click="toMap">
							<uni-icons type="redo" size="20"></uni-icons>
							<text>{{item.province}}{{item.city}}{{item.area}}{{item.detailedAddress}}</text>
						</view>
						<view class="row3">
							<uni-icons type="redo" size="20"></uni-icons>
							<text>{{item.phone}}</text>
						</view>
					</view>
				</view>
				<view class="car-bottom flex">
					<u-button text="置顶" @click="topMarking(item)" throttle-time='1000'></u-button>
					<!-- <button @click="$u.debounce(topMarking, 500)">置顶</button> -->
					<!-- <button @click="$u.debounce(topMarking(item), 500)">置顶</button> -->
					<button>删除</button>
					<button>编辑</button>
				</view>
			</view>
		</view>
		<view class="upload">
			<view class="solids" @click="addCard">
				<text class=''>添加新名片</text>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	var that;
	export default {
		data() {
			return {
				cardList: []
			};
		},
		onLoad() {
			that = this
			this.userInfo = uni.getStorageSync("userInfo")
		},
		onShow() {
			this.init()
		},
		methods: {
			init() {
				this.$request.baseRequest('admin.unimall.cardManagementInfo', 'list', {
					commonId: this.userInfo.id
				}, failres => {
					this.$refs.uToast.show({
						type: 'error',
						message: failres.errmsg,
					})
					uni.hideLoading()
				}).then(res => {
					this.cardList = res.data.items
				})
			},
			addCard() {
				uni.navigateTo({
					url: "/pages/mySet/newCard"
				})
			},
			topMarking(val) {
				that.$request.baseRequest('admin.unimall.cardManagementInfo', 'top', {
					cardManagementInfo: JSON.stringify({id:val.id})
				}, failres => {
					this.$refs.uToast.show({
						type: 'error',
						message: failres.errmsg,
					})
					uni.hideLoading()
				}).then(res => {
					this.$refs.uToast.show({
						type: 'success',
						message: '置顶成功！',
					})
						this.init()
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.card-list-item {
		border: 1px solid #ccc;
		border-radius: 30rpx;
		padding: 40rpx;
		box-sizing: border-box;

		.left {
			width: 30%;

			.top {

				margin-bottom: 20rpx;
			}

			.img {
				width: 80%;
			}

			.bottom {}
		}

		.right {
			.row1 {
				.line {
					width: 1px;
					height: 20px;
					margin: 0 20rpx;
					background: black;
				}
			}
		}
	}
</style>