<template>
	<view>
		<view class="tits">分组名称</view>
		<view class="ipt-box"><input v-model="lableTitle" maxlength="20" placeholder="请输入分组名称" placeholder-class="placeholder" class="ipt" /></view>
		
		<view class="btns dflex">
			<view class="delete" v-if="!isAdd" @click="deleteLabel()">删除分组</view>
			<view class="btn flex" @click="submitLabel()">保存</view>
		</view>
		<view class="ceng" v-if="isLabel" @click="hideLabel()"></view>
	</view>
</template>

<script>
const app = getApp();
const req = require('../../utils/request.js');
const api = require('../../utils/api.js');
export default {
	data() {
		return {
			isShow: false,
			lableTitle: '',
			isAdd: false,
			groupId: '',
			title: '',
		};
	},

	onLoad(opt) {
		this.isAdd = opt.isAdd;
		this.groupId = opt.groupId;
		this.lableTitle = opt.title;
		uni.setNavigationBarTitle({
			title: this.groupId ? '编辑分组' : '新增分组'
		});
	},

	methods: {
		jumpUrl(url) {
			uni.navigateTo({
				url: url
			});
		},
		deleteLabel() {
			console.log('deleteLabel数据>>>>>>>>>');
			this.$showModal({
			    title: '提示',
			    content: '确定要删除该分组吗'
			})
			.then(res => {
			    this.deleteLabelRequest();
			})
			.catch(err => {
			});
		},

		deleteLabelRequest() {
			req.postRequest(
				'/api/v3/visiting/card/group/delete',
				{ id: this.groupId },
				json => {
					req.msg('删除成功');
					setTimeout(() => {
						uni.navigateBack();
					}, 1500);
				},
				true
			);
		},

		submitLabel() {
			if (!this.lableTitle) {
				return req.msg('请输入分组名称');
			}
			// if (this.customersCkeckList.length == 0) {
			// 	return req.msg('请先添加客户');
			// }
			let dataP = { groupName: this.lableTitle };
			if (this.groupId) {
				dataP.id = this.groupId;
			}
			dataP.userId = req.getStorage('userInfo').id;
			console.log('数据参数>>>>>>>>>>>', dataP);
			req.postRequest('/api/v3/visiting/card/group/saveOrUpdate',dataP, json => {
				req.msg('保存成功');
				setTimeout(() => {
					uni.navigateBack();
				}, 1500);
			});
		}
	}
};
</script>
<style>
@import './addGroup.css';
</style>
