<template>
	<view>
		<view class="content1">
			<view class="left">
				<image src="../../static/c3.png" mode="widthFix" class="img"></image>
			</view>
			<view class="right">
				<view class="row1">
					{{cardInfo.name}}|{{cardInfo.post}}
				</view>
				<view class="">
					{{cardInfo.companyName}}
				</view>
				<view class="">
					地址{{cardInfo.province}}{{cardInfo.city}}{{cardInfo.area}}{{cardInfo.detailedAddress}}
				</view>
				<view class="">
					联系电话{{cardInfo.phone}}
				</view>
				<view class="">
					备注{{cardInfo.remark?cardInfo.remark:''}}
				</view>
			</view>
		</view>
		<u--form
			labelPosition="left"
			:model="cardInfo"
			:rules="rules"
			ref="uForm">
			<u-form-item
				label="名片分类"
				prop="userInfo.name"
				borderBottom
				ref="item1">
				<u-button @click="show = true">{{cardInfo.classify?cardInfo.classify:'默认分类'}}</u-button>
			</u-form-item>
			<u-form-item
				label="备注（选填）"
				prop="userInfo.name"
				borderBottom
				ref="item1">
				<u--textarea v-model="cardInfo.remark" placeholder="输入备注，不超过150个字 " ></u--textarea>
			</u-form-item>
			<u-form-item
				label="我的名片"
				prop="userInfo.name"
				borderBottom
				ref="item1">
				<u-button @click="show1 = true">{{cardInfo.cardBusiness?cardInfo.cardBusiness:'无名片'}}</u-button>
			</u-form-item>
		</u--form>
		<u-picker keyName="cardBusiness" title="选择名片" @close="show1=false"
			@cancel="show1=false" closeOnClickOverlay @confirm="cardConfirm" :show="show1" :columns="cardList"></u-picker>
		<u-picker keyName="circleName" title="选择分类" @close="show=false"
			@cancel="show=false" closeOnClickOverlay @confirm="typeConfirm" :show="show" :columns="columns"></u-picker>
		<u-button @click='cancel' text="取消"></u-button>
		<u-button @click='$u.debounce(save, 500)' text="保存"></u-button>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
				cardInfo:{},
				show:false,
				show1:false,
				columns:[],
				cardList:[],
				rules: {
					'userInfo.name': {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
					'userInfo.sex': {
						type: 'string',
						max: 1,
						required: true,
						message: '请选择男或女',
						trigger: ['blur', 'change']
					},
				},
			}
		},
		onLoad(options) {
				this.id=options.id
				this.getList()
		},
		onShow() {
			
		},
		methods: {
			save(){
				uni.showLoading({
					title: '数据加载中',
					mask:true
				})
				this.$request.baseRequest('admin.unimall.cardHolderInfo', 'add', {
					cardHolderInfo:JSON.stringify({
						cardId:this.cardInfo.id,
						remark:this.cardInfo.remark,
						cardCommonId:this.cardInfo.cardCommonId,
						myCardId:this.cardInfo.myCardId,
						commonId:uni.getStorageSync("userInfo").id,
						classify:this.cardInfo.classify
						})
				}, failres => {
					this.$refs.uToast.show({
						type: 'error',
						message: failres.errmsg,
					})
					uni.hideLoading()
				}).then(res => {
					this.$refs.uToast.show({
						type: 'success',
						message: '保存成功！',
					})
					uni.switchTab({
						url:"/pages/cardHolder/cardHolder"
						
					})
				})
			},
			cancel(){
				uni.switchTab({
					url:"/pages/cardHolder/cardHolder"
					
				})
			},
			cardConfirm(e){
				console.log(e)
				this.cardInfo.cardBusiness=e.value[0].cardBusiness
				this.cardInfo.myCardId=e.value[0].id
				this.show1=false
			},
			typeConfirm(e){
				console.log(e)
				this.cardInfo.classify=e.value[0].circleName
				this.show=false
			},
			getList(){
				this.$request.baseRequest('admin.unimall.cardManagementInfo', 'list', {
					commonId: uni.getStorageSync("userInfo").id
				}, failres => {
					this.$refs.uToast.show({
						type: 'error',
						message: failres.errmsg,
					})
					uni.hideLoading()
				}).then(res => {
					this.cardList = [res.data.items]
				})
				this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'list',{
					page:1,
					limit:9999,
					commonId:uni.getStorageSync("userInfo").id
				}, failres => {
					console.log('res+++++', failres.errmsg)
					this.$refs.uToast.show({
						type: 'error',
						message: failres.errmsg,
					})
				}).then(res => {
					this.columns=[res.data.items]
					console.log(this.columns)
				})
				this.$request.baseRequest('admin.unimall.cardManagementInfo', 'get',{
						id:this.id
					}, failres => {
						console.log('res+++++', failres.errmsg)
						this.$refs.uToast.show({
							type: 'error',
							message: failres.errmsg,
						})
						uni.hideLoading()
					}).then(res => {
						this.cardInfo=res.data
						this.cardInfo.cardCommonId=res.data.commonId
						console.log(res)
					})
					
				}
		}
	}
</script>

<style>

</style>
