<template>
	<view class="page">
		<!-- 反馈内容 -->
		<view class="feedback-data" style="padding-bottom: 15rpx;">
			<view class="titleall-box">
				<view class="titleall-left">
					<view class="titleall-left-line"></view>当前分组列表
				</view>
			</view>
			<view class="lieBiao" v-for="(it,index) in lieBiao" :key="index">
				<view class="groupName">
					{{it.fullName}}
				</view>
				<view class="groupCode">
					{{it.enCode}}
				</view>
				<view class="lef">
					<button type="primary" style="margin-right: 10rpx;" size="mini" @click="toGrouping(it.id,it.fullName)">添加企业</button>
					<button type="warn" size="mini" @click="delIt(it.id)">删除</button>
				</view>
			</view>
		</view>
		<!-- 反馈内容 -->
		<view class="feedback-data" style="padding-bottom: 15rpx;">
			<view class="titleall-box">
				<view class="titleall-left">
					<view class="titleall-left-line"></view>填写分组信息
				</view>
			</view>
			<uni-forms ref="valiForm" :rules="rules" :modelValue="valiFormData" style="width: 96%;margin: 0 auto;">
				<uni-forms-item label="组名" required name="title">
					<uni-easyinput v-model="valiFormData.title" placeholder="请输入组名" />
				</uni-forms-item>
				<uni-forms-item label="分组编码" required name="subTitle">
					<uni-easyinput v-model="valiFormData.subTitle" placeholder="请输入分组编码" />
				</uni-forms-item>
			</uni-forms>
			<view class="submit-btn" @click="submitContent('valiForm')">
				<text>确定新建分组</text>
			</view>
		</view>

		<!-- 提交 -->
		
	</view>
</template>

<script>
	import {
		data
	} from '../../../uview-ui/libs/mixin/mixin';
	import request from '@/utils/request.js'
	import utils from '../../../service/utils';
	export default {
		data() {
			return {
				userCode: {},
				// 选择图片路径
				filePath: [],
				uploadPath: [],
				type: "",
				lastModifyUserId: '',
				// 校验表单数据
				valiFormData: {
					title: '',
					bodyContent: '',
					subTitle: '',
				},
				// 通知信息标题
				noticeTitle:'',
				// 通知详情
				noticeDesc:'',
				creater: '',
				rules: {
					title: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					subTitle: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
				},
				baseUrl: "http://deyanggaoxin.fengshiyun.com",
				// 判断是否传了id
				isId: '',
				have: false,
				detailData: [],
				// 需要通知的公司的id
				companysId: [],
				tellInfo:[],
				// 当前分组列表
				lieBiao:[],
			};

		},
		// onShow() {
		// 	this.getType()
		// },
		onUnload() {
			uni.$off('idInfo')
			uni.$off('tellInfo')
		},
		onShow() {
			this.getTypeOfCompany()
		},
		onLoad(options) {
			console.log("options", options)
			uni.$on('idInfo', res => {
				console.log("选择公司页面返回的公司ID", res)
				if(res.length > 0)
				this.companysId = res
			})
			uni.$on('tellInfo', res => {
				console.log("tell信息", res)
				if(res.length > 0)
				this.tellInfo = res
			})
			if (JSON.stringify(options) == "{}") {
				this.have = true
			} else {
				this.isId = JSON.parse(options.data)
				console.log("Id", this.isId)
				this.getConDetail(this.isId)
			}
			this.getUser()
			let user = uni.getStorageSync('user')
			this.lastModifyUserId = user.userInfo.userId

		},
		methods: {
			// 获取上传状态
			select(e) {
				console.log('选择文件：', e)
				this.filePath = e.tempFilePaths
			},
			// 跳转到选择通知企业页面
			toTellInfo() {
				uni.navigateTo({
					url: '/pages/tellInfo/tellInfo'
				})
			},
			// 获取用户信息
			getUser() {
				if (uni.getStorageSync('user')) {
					this.userCode = uni.getStorageSync('user').userInfo
					// this.userInfo = this.userCode.userAccount
					// this.userInfo = '123456'
					console.log('用户已登录！', this.userCode)
				} else {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/login/index'
						})
					})
				}
			},
			// 获取企业分类
			getTypeOfCompany() {
				request({
					url: 'https://www.dygxq-es.cn/api/system/DictionaryData/365138541614728453?n=1709621749&keyword=&isTree=1',
					method: 'get',
					data: {}
				}).then(res => {
					if (res.code == 200) {
						console.log(res)
						this.lieBiao = res.data.list
						console.log('lieBiao',this.lieBiao)
					} else if (res.code == 600) {
						uni.showToast({
							title: '请登录',
							icon: 'none'
						})
					}
				})
			},
			// 提交内容
			submitContent(ref) {
				let that = this
				let query = {
					description: "",
					dictionaryTypeId: "365138541614728453",
					enCode: this.valiFormData.subTitle,
					enabledMark: 1,
					fullName: this.valiFormData.title,
					id: "",
					images: [],
					logo: [],
					parentId: "0",
					sortCode: 0,
				}
				console.log('query',query)
				request({
					url:'https://www.dygxq-es.cn/api/system/DictionaryData?n=1709622056',
					method:'post',
					data:query
				}).then(res=>{
					if(res.code == 200){
						this.getTypeOfCompany()
						uni.showToast({
							icon:"success",
							title:'新建分组成功',
							duration:1500
						})
					}
				})
			},
			// 删除该分组
			delIt(id){
				console.log("id",id)
				uni.showModal({
					title:"是否删除该分组",
					success: (res) => {
						if(res.confirm){
							request({
								url:`https://www.dygxq-es.cn/api/system/DictionaryData/${id}?n=1709622362`,
								method:'delete',
								data:{}
							}).then(res=>{
								uni.showToast({
									icon:'success',
									title:'删除成功！',
									duration:1000
								}).then(()=>{
									this.getTypeOfCompany()
								})
							})
						}
					}
				})
			},
			// 跳转到企业分组页面
			toGrouping(id,fullName){
				uni.navigateTo({
					url:'/pages/official/grouping/grouping?' + `data=${JSON.stringify(id)}` + `&fullName=${JSON.stringify(fullName)}`
				})
			}
			// /**
			//  * 反馈类型
			//  * @param {Object} 
			//  */
			// FeedbackTypeCh(val) {
			// 	console.log(val);
			// 	this.TypeIndex = val.detail.value;
			// }
			// 进行通知
		},
	}
</script>

<style scoped lang="scss">
	@import 'Feedback.scss';
	.more-content{
		display: flex;
		align-items: center;
		image{
			width: 100rpx;
			height: 100rpx;
			border-radius: 100%;
		}
		.more-content-img {
			image {
				width: 24rpx;
				height: 24rpx;
			}
		}
	}
</style>