<template>
	<view class="content">
		<!-- tabbar -->
		<!-- <view class="tabbar">
			<view>新建模板</view>
			<view>卡片排序</view>
		</view> -->
		<!-- 已添加的卡片 -->
		<view class="box">
			<view class="tips">长按拖拽可调整卡片位置</view>
			<view class="list">
				<view class="item" v-for="(item,index) in cardList.user">
					<uni-icons type="minus-filled" size="18" color="#FF6D66" @click="deleteCard(item,index)"
						v-if="item.id!=2"></uni-icons>
					<view class="info">
						<text></text>
						<view>{{item.name}}</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 可添加的卡片 -->
		<view class="box">
			<view class="tips2 tips">可添加的卡片</view>
			<view class="list">
				<view class="item" v-for="(item,index) in cardList.all">
					<uni-icons type="plus-filled" size="18" color="#05BD79" @click="addCard(item,index)"></uni-icons>
					<view class="info">
						<text></text>
						<view>{{item.name}}</view>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	export default {
		data() {
			return {}
		},
		onLoad() {},
		computed: {
			...mapState(["cardList", 'user']),
			list() {
				return this.cardList
			}
		},
		methods: {
			handleGradeList() {
				let that = this
				let list = []
				that.cardList.user.forEach(ite => {
					list.push(ite.id)
				})
				that.$model.getCardAllOrder({
					aud_id: that.user.id,
					card_order: list.join(",")
				}).then(res => {
					if (res.code != 0) {
						that.$tools.msg(res.msg)
						return
					}
					that.$store.dispatch('getUserInfo', {
						aud_id: that.user.id
					})
				}).catch(err => {})
			},

			// 删除已选择卡片
			deleteCard(item, index) {
				let that = this
				that.cardList.user.splice(index, 1)
				that.cardList.all.push(item)
				that.handleGradeList()
			},
			// 添加已有的卡片
			addCard(item, index) {
				let that = this
				that.cardList.all.splice(index, 1)
				that.cardList.user.push(item)
				that.handleGradeList()
			},
		}
	}
</script>

<style scoped lang="scss">
	.content {
		padding: 15px;
		font-size: 14px;
		background-color: #F5F6FA;
		min-height: 100vh;


		.tips {
			font-size: 12px;
			color: #999;
			width: 100%;
			margin-bottom: 15px;
		}

		.tips2 {
			color: #333;
			font-size: 16px;
			font-weight: bold;
		}

		.list {
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.item {
				width: 45%;
				background-color: #fff;
				margin-bottom: 15px;
				position: relative;
				height: 60px;
				line-height: 60px;
				border-radius: 5px;

				.uni-icons {
					font-size: 16px;
					position: absolute;
					top: -28px;
					left: -5px;
				}

				.info {
					display: flex;
					align-items: center;
					justify-content: center;

					text {
						width: 30px;
						height: 30px;
						background-color: #F2F2F2;
						margin-right: 10px;
						border-radius: 50%;
					}
				}
			}
		}
	}
</style>