<template>
	<view class="mainBox">
		<view v-for="(item, index) in tableList" :key="index" style="position: relative;">

			<myCard @del="del(index)" @add="add('edit',item,index)" :item="item" :btnList="btnList" :index="index+1"
				:columns="columns">
			</myCard>
		</view>

		<view class="add" @click="add('add')">
			<u-icon name="plus" color="#fff"></u-icon>
		</view>

	</view>
</template>

<script>
	import myCard from '../../components/myCard.vue'
	export default {
		props: {
			contact_link_status: {
				default: () => []
			},
			isDrawer: {
				default: false
			}
		},
		data() {
			return {
				columns: [
					[{
						label: '姓名：',
						prop: 'linkName',
						type: 'title',
						className: 'perce100',
					}],
					[{
						label: '手机：',
						prop: 'mobilePhone'
					}, {
						label: '部门：',
						prop: 'deptName',
					}],
					[{
						label: '微信号：',
						prop: 'wechat'
					}, {
						label: '邮箱：',
						prop: 'email',
					}],
					[{
						label: '职务：',
						prop: 'post',
						className: 'perce100',
					}],
					[{
						label: '操作：',
						prop: 'action',
						type: 'action',
						className: 'perce100',
					}],
				],
				btnList: [{
					name: '修改',
					apiName: 'add',
					btnType: 'primary',
					type: '2',
				}, {
					name: '删除',
					apiName: 'del',
					btnType: 'error',
					type: '2',
					pageUrl: '',

				}],
				tableList: [],

				ifChiefList: [{
						value: 0,
						label: '否'
					},
					{
						value: 1,
						label: '是'
					}
				]
			}
		},
		components: {
			myCard
		},
		created() {
			uni.$off('updatelinKList')
			uni.$on('updatelinKList', ({
				type,
				data
			}) => {
				if (type == 'add') {
					this.tableList.push(data)
				} else {
					this.$set(this.tableList, data.index, data)
				}
				if (this.isDrawer) {
					uni.$emit('setContact', {
						key: 'linKList',
						data: this.tableList
					})
				}
			})
		},
		methods: {
			getStatus(status) {
				return this.contact_link_status.find(item => item.value == status)?.text
			},
			init(list) {
				if (list) {
					this.tableList = JSON.parse(JSON.stringify(list))
				}
			},

			del(index) {
				this.tableList.splice(index, 1);
				if (this.isDrawer) {
					uni.$emit('setContact', {
						key: 'linKList',
						data: this.tableList
					})
				}
			},
			getValue() {
				return this.tableList
			},

			add(type, data, index) {
				if (type == 'edit') {
					data['index'] = index
				}
				uni.navigateTo({
					url: '/pages/saleManage/contact/components/linkListAdd?type=' + type + (type == 'edit' ?
						'&data=' + JSON.stringify(data) : '')
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.add {
		width: 96rpx;
		height: 96rpx;
		border-radius: 48rpx;
		background: #3c9cff;
		position: fixed;
		bottom: 100rpx;
		right: 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 99;
	}
</style>