<template>
	<view class="mainBox">
		<uni-nav-bar background-color="#157A2C" color="#fff" fixed="true" statusBar="true" left-icon="back" title="联系人信息"
			@clickLeft="back">
		</uni-nav-bar>
		<u-cell-group>
			<u-cell title="姓名" arrow-direction="down">
				<u--input slot="value" placeholder="请输入" border="surround" v-model="form.contactName"></u--input>
			</u-cell>
			<u-cell title="手机" arrow-direction="down">
				<u--input slot="value" placeholder="请输入" border="surround" v-model="form.contactPhone"></u--input>
			</u-cell>
			<u-cell title="电话" arrow-direction="down">
				<u--input slot="value" placeholder="请输入" border="surround" v-model="form.telephone"></u--input>
			</u-cell>
			<u-cell title="微信号" arrow-direction="down">
				<u--input slot="value" placeholder="请输入" border="surround" v-model="form.wechat"></u--input>
			</u-cell>
			<u-cell title="邮箱" arrow-direction="down">
				<u--input slot="value" placeholder="请输入" border="surround" v-model="form.email"></u--input>
			</u-cell>
			<u-cell title="部门" arrow-direction="down">
				<u--input slot="value" placeholder="请输入" border="surround" v-model="form.deptName"></u--input>
			</u-cell>
			<u-cell title="职务" arrow-direction="down">
				<u--input slot="value" placeholder="请输入" border="surround" v-model="form.post"></u--input>
			</u-cell>
			<u-cell title="备注" arrow-direction="down">
				<u--input slot="value" placeholder="请输入" border="surround" v-model="form.remark"></u--input>
			</u-cell>
			<view class="footerButton">
				<u-button type="default" text="返回" @click="back"></u-button>
				<u-button type="primary" @click="save" text="保存"></u-button>
			</view>
		</u-cell-group>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				form: {
					contactName: '',
					contactPhone: '',
					telephone: '',
					wechat: '',
					email: '',
					deptName: '',
					post: '',
					remark: '',
				},
				type: '',
				infoIdx:'',
			}
		},

		async onLoad(data) {
			this.infoIdx = data.index;
			this.type = data.type
			if (data.data) {
				this.form = JSON.parse(data.data)
			}
		},
		methods: {
			save() {
				if (!this.form.contactName) {
					this.$refs.uToast.show({
						type: "warning",
						message: "姓名不能为空",
					})
					return
				}
				uni.$emit('updateContactList', {
				data: this.form,
				type: this.type,
				index:this.infoIdx
				})
				this.back()
			},

		}
	}
</script>

<style lang="scss" scoped>
	/deep/.u-cell__body__content {
		flex: none;
		margin-right: 16rpx;
	}

	.mainBox {
		padding-bottom: 84rpx;
	}

	.footerButton {
		width: 100%;
		height: 84rpx;
		display: flex;
		position: fixed;
		bottom: 0;

		/deep/.u-button {
			height: 100%;
		}

		>view {
			flex: 1;

		}
	}

	// /deep/.u-button {
	// 	height: 100%;
	// }

	/deep/.u-subsection__item__text {
		font-size: 28rpx !important;
	}
</style>