From e2f129ee192ae3469848beeceac262b13ba8eacb Mon Sep 17 00:00:00 2001
From: 马宇豪 <978517621@qq.com>
Date: 星期三, 14 六月 2023 15:52:11 +0800
Subject: [PATCH] 新增页面和配置,对接口

---
 src/views/Admin/sameLevel.vue |  178 +++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 112 insertions(+), 66 deletions(-)

diff --git a/src/views/Admin/sameLevel.vue b/src/views/Admin/sameLevel.vue
index 1aa7c5f..09231d2 100644
--- a/src/views/Admin/sameLevel.vue
+++ b/src/views/Admin/sameLevel.vue
@@ -2,15 +2,15 @@
   <div class="inner">
     <a-row type="flex" justify="space-between" style="margin-bottom: 20px">
       <a-col :span="4">
-        <a-button type="primary" @click="editData('add',{})">新增用户</a-button>
+        <a-button v-if="unittype && unittype !== null" type="primary" @click="editData('add',{})">新增用户</a-button>
       </a-col>
-      <a-col :span="20">
+      <a-col :span="20" v-if="unittype == null || !unittype">
         <a-row type="flex" justify="end" :gutter="12">
           <a-col :span="4">
-            <a-cascader :options="areaData" v-model="areaVal" placeholder="行政规划" expandTrigger="hover" changeOnSelect @change="onChange" style="width: 100%"/>
+            <a-cascader :options="areaData" v-model="areaVal" placeholder="行政规划" expandTrigger="hover" :fieldNames="fieldNames" changeOnSelect @change="onChange" style="width: 100%"/>
           </a-col>
           <a-col :span="4">
-            <a-button type="primary">查询</a-button>
+            <a-button type="primary" @click="getUserList">查询</a-button>
             <a-button style="margin-left: 12px" @click="resetSearch">重置</a-button>
           </a-col>
         </a-row>
@@ -22,7 +22,7 @@
           <a-tag
               :color="unittype === 1 ? 'purple' : unittype === 2 ? 'blue' : unittype === 3 ? 'cyan' : 'green'"
           >
-            {{ unittype==1?'省级':unittype==2?'地(市、州)级':unittype==3?'区县级':'村(乡、镇)级' }}
+            {{ unittype==1?'省级':unittype==2?'地(市、州)级':unittype==3?'区县级':unittype==4?'村(乡、镇)级':'管理员' }}
           </a-tag>
         </template>
         <template #area="text,row">
@@ -33,17 +33,19 @@
         </template>
         <template #action="action,row">
           <a-button type="link" @click="editData('edit',row)">编辑</a-button>
-          <a-button type="link" class="delBtn">删除</a-button>
+          <a-button type="link" class="delBtn" @click="delData(row)">删除</a-button>
         </template>
       </a-table>
     </div>
-    <same-level-mod ref="sameLevelMod" @refrech=""></same-level-mod>
+    <same-level-mod ref="sameLevelMod" @refresh="getUserList"></same-level-mod>
   </div>
 </template>
 
 <script>
-import {getRecipient} from '@/api/user'
+import {delRecipient, delUser, getRecipient, getUser} from '@/api/user'
 import sameLevelMod from "@/views/Admin/components/sameLevelMod"
+import {getUserInfo} from "@/util/storage";
+import {getDistrictInfo} from "@/api/login";
 export default {
   name: 'sameLevel',
   components: {
@@ -52,6 +54,8 @@
   data () {
     return {
       areaVal: [],
+      unittype: null,
+      districtId: null,
       search:{
         pageIndex: 1,
         pageSize: 10,
@@ -102,57 +106,54 @@
         defaultCurrent: 1,
         defaultPageSize: 10,
         total: 0,
-        onChange: ( page, pageSize ) => this.onPageChange(page,pageSize)
+        onChange: ( page, pageSize ) => this.onPageChange(page,pageSize),
+        showTotal: total => `共 ${total} 条`
       },
-      areaData: [
-        {
-          value: 1,
-          label: '江苏省',
-          children: [
-            {
-              value: 11,
-              label: '苏州市',
-              children: [
-                {
-                  value: 111,
-                  label: '工业园区',
-                },
-              ],
-            },
-          ],
-        },
-        {
-          value: 2,
-          label: '新疆维吾尔自治区',
-          children: [
-            {
-              value: 21,
-              label: '乌鲁木齐市',
-              children: [
-                {
-                  value: 211,
-                  label: '国泰新华',
-                },
-              ],
-            },
-          ],
-        },
-      ]
+      areaData: [],
+      fieldNames:{
+        label: 'name',
+        value: 'id',
+        children: 'children'
+      }
     }
   },
   created() {
     const t = this
-    t.getSameLevel()
+    console.log(getUserInfo(),'id')
+    t.unittype = getUserInfo().unittype
+    t.districtId = getUserInfo().districtId
+    t.getUserList()
+    t.getDistrictInfo()
   },
   methods:{
-    async getSameLevel(){
+    async getUserList(){
       const t = this
-      const res = await getRecipient(t.search)
-      if(res.data.code == 100){
-        t.tableData = res.data.data
-        t.pagination.total = res.data.total
+      if(t.search.searchParams.province == '' && t.search.searchParams.city == '' && t.search.searchParams.area == '' ){
+        const {searchParams,...data} = t.search
+        const res = await getRecipient(data)
+        if(res.data.code == 100){
+          t.tableData = res.data.data
+          t.pagination.total = res.data.total
+        }else{
+          t.$message.warning(res.data.msg);
+        }
       }else{
-        t.$message.warning(res.data.msg);
+        const res = await getRecipient(t.search)
+        if(res.data.code == 100){
+          t.tableData = res.data.data
+          t.pagination.total = res.data.total
+        }else{
+          t.$message.warning(res.data.msg);
+        }
+      }
+    },
+
+    async getDistrictInfo(){
+      let res = await getDistrictInfo()
+      if(res.data.code == 100){
+        this.areaData = res.data.data
+      } else {
+        this.$message.warning(res.data.msg);
       }
     },
 
@@ -176,31 +177,76 @@
       const t = this
       t.$refs.sameLevelMod.openDialog(type,data)
       t.$refs.sameLevelMod.areaData = t.areaData
+      t.$refs.sameLevelMod.form.unittype = t.unittype
+      t.$refs.sameLevelMod.form.districtId = t.districtId
+    },
+
+    async delData(row){
+      const t = this
+      this.$confirm({
+        title: '提示',
+        content: h => <div>是否删除该条用户信息?</div>,
+        cancelText: '取消',
+        okText: '确认',
+        centered: true,
+        async onOk() {
+          let res = await delRecipient(row.id)
+          if(res.data.code == 100){
+            t.$message.success('删除用户信息成功');
+            t.getUserList()
+          }else{
+            t.$message.warning(res.data.msg);
+          }
+        },
+        onCancel() {
+          console.log('Cancel');
+        },
+      });
+    },
+
+    // 根据id查对象
+    findCodeById(data,value) {
+      for (const node of data) {
+        if (node.id === value) {
+          return node;
+        }
+        if (node.children) {
+          const foundNode = this.findCodeById(node.children, value);
+          if (foundNode) {
+            return foundNode;
+          }
+        }
+      }
+      return null;
     },
 
     onPageChange(page, pageSize) {
       const t= this
       t.pagination.current = page
+      t.search.pageIndex = page
+      t.getUserList()
     },
     onChange(value) {
       const t = this
-      // t.search.searchParams.districtId = value[value.length - 1]
-    },
-
-    findAreaById(data,value) {
-      for (const node of data) {
-        if (node.value === value) {
-          return node.label;
-        }
-        if (node.children) {
-          const foundLabel = this.findAreaById(node.children, value);
-          if (foundLabel) {
-            return foundLabel;
-          }
-        }
+      t.search.searchParams = {
+        province: '',
+        city: '',
+        area: '',
+        town: ''
       }
-      return null;
-    }
+      if(value[0]){
+        t.search.searchParams.province = t.findCodeById(t.areaData,value[0]).name
+      }
+      if(value[1]){
+        t.search.searchParams.city = t.findCodeById(t.areaData,value[1]).name
+      }
+      if(value[2]){
+        t.search.searchParams.area = t.findCodeById(t.areaData,value[2]).name
+      }
+      if(value[3]){
+        t.search.searchParams.town = t.findCodeById(t.areaData,value[3]).name
+      }
+    },
   }
 }
 </script>

--
Gitblit v1.9.2