From 6efbb509b876e5e4ec634efa8820bd7b288c2283 Mon Sep 17 00:00:00 2001
From: zhouwenxuan <1175765986@qq.com>
Date: 星期二, 06 二月 2024 09:16:37 +0800
Subject: [PATCH] 分组

---
 src/views/Admin/notice.vue |   74 +++++++++++++++++++++++++++++--------
 1 files changed, 58 insertions(+), 16 deletions(-)

diff --git a/src/views/Admin/notice.vue b/src/views/Admin/notice.vue
index 3b8c67e..1da15e2 100644
--- a/src/views/Admin/notice.vue
+++ b/src/views/Admin/notice.vue
@@ -78,7 +78,7 @@
 						</a-form-model-item>
 					</a-col>
 				</a-row>
-				<span><b>发布单位:</b>{{form.publishingUnit}}</span>
+<!--				<span><b>发布单位:</b>{{form.publishingUnit}}</span>-->
 				<br /><br />
 				<!-- 子单位-->
 				<a-row :gutter="24">
@@ -110,12 +110,22 @@
 							</a-checkbox>
 						</div>
 						<a-form-model-item prop="recipient">
-							<a-select mode="multiple" placeholder="选择平级接收单位" v-model="form.recipient" @change="handle"
-								:maxTagCount="3">
-								<a-select-option v-for="item in filteredOptions" :key="item.id" :value="item.id">
-									{{ item.recipientName }}({{item.company}} {{item.phone}})
-								</a-select-option>
-							</a-select>
+<!--							<a-select mode="multiple" placeholder="选择平级接收单位" v-model="form.recipient" @change="handle"-->
+<!--								:maxTagCount="3">-->
+<!--								<a-select-option v-for="item in filteredOptions" :key="item.id" :value="item.id">-->
+<!--									{{ item.recipientName }}({{item.company}} {{item.phone}})-->
+<!--								</a-select-option>-->
+<!--							</a-select>-->
+              <a-tree-select
+                  v-model="form.recipient"
+                  style="width: 100%"
+                  :tree-data="treeData"
+                  tree-checkable
+                  placeholder="选择平级接收单位"
+                  :show-checked-strategy="SHOW_PARENT"
+                  search-placeholder="Please select"
+                  @change="handle"
+              />
 						</a-form-model-item>
 					</a-col>
 				</a-row>
@@ -141,7 +151,7 @@
 				<h2>短信预览</h2>
 				<div class="mobile">
 					<div class="mesg">
-						<P>【自然灾害风险预警提示】{{form.content}}<br>发布单位:{{form.publishingUnit}}</P>
+						<P>【自然灾害风险预警提示】{{form.content}}</P>
 					</div>
 				</div>
 			</div>
@@ -166,10 +176,16 @@
 	import {
 		deleteFile
 	} from "@/api/list";
+  import { TreeSelect } from 'ant-design-vue';
+  const SHOW_PARENT = TreeSelect.SHOW_PARENT;
+  const treeData = [];
 	export default {
 		name: "notice",
 		data() {
 			return {
+        value: [],
+        SHOW_PARENT,
+        treeData,
 				userInfo: {},
 				unittype: null,
 				wrapperCol: {
@@ -322,7 +338,25 @@
 				let res = await getPeerRecipient()
 				if (res.data.code == 100) {
 					if (res.data.data) {
-						t.filteredOptions = res.data.data
+						// t.filteredOptions = res.data.data
+
+            for (const resKey in res.data.data) {
+              t.filteredOptions = t.filteredOptions.concat(...res.data.data[resKey]);
+              console.log('t.filteredOptions',t.filteredOptions)
+              const obj = {
+                  title: resKey,
+                  value: resKey,
+                  key: resKey,
+                  children: res.data.data[resKey].map(item => {
+                    return {
+                      title: item.recipientName + '(' +item.company +item.phone+ ')',
+                      value: item.id,
+                      key: item.id,
+                    }
+                  })
+              }
+              t.treeData.push(obj);
+            }
 					} else {
 						console.log('暂无数据')
 					}
@@ -384,18 +418,25 @@
 			//选择平级部门部分
 			handle(selectedItems) {
 				const t = this
-				if (t.form.recipient.length == t.filteredOptions.length) {
-					t.checkSlAll = true
-				} else {
-					t.checkSlAll = false
-				}
+				// if (t.form.recipient.length == t.filteredOptions.length) {
+				// 	t.checkSlAll = true
+				// } else {
+				// 	t.checkSlAll = false
+				// }
+        const group = t.treeData.map(item => item.value)
+        if (group.length === t.form.recipient.length && group.every((v,i) => v === t.form.recipient[i])) {
+          t.checkSlAll = true
+        } else {
+          t.checkSlAll = false
+        }
 			},
 
 			checkSlChange(e) {
 				const t = this
 				t.checkSlAll = !t.checkSlAll
 				if (t.checkSlAll == true) {
-					t.form.recipient = t.filteredOptions.map(i => i.id)
+					// t.form.recipient = t.filteredOptions.map(i => i.id)
+          t.form.recipient = t.treeData.map(item => item.value)
 				} else {
 					t.form.recipient = []
 				}
@@ -539,6 +580,7 @@
 							...data
 						} = this.form
 						msgSend(data).then(res => {
+
 							if (res.data.code == 100) {
 								this.deleteFile()
 								this.$message.success('信息已提交审核')
@@ -683,4 +725,4 @@
 		}
 
 	}
-</style>
\ No newline at end of file
+</style>

--
Gitblit v1.9.2