马宇豪
2024-04-08 743a085df156140f4a3f4ae2d03e910790181945
src/views/Admin/sameLevel.vue
@@ -1,11 +1,16 @@
<template>
  <div class="inner">
    <a-row type="flex" justify="space-between" style="margin-bottom: 20px">
      <a-col :span="4">
        <a-button v-if="unittype && unittype !== null" type="primary" @click="editData('add',{})">新增用户</a-button>
      <a-col :span="4" v-if="unittype && unittype !== null">
        <a-button type="primary" @click="editData('add',{})">新增用户</a-button>
      </a-col>
      <a-col :span="20">
        <a-row type="flex" justify="end" :gutter="14">
        <a-row type="flex" :gutter="14">
          <a-col :span="6">
            <a-select v-model="search.searchParams.peerRecipientGroupId" placeholder="选择分组" style="width: 100%" @change="handleChange" allowClear show-search :filter-option="filterOption">
              <a-select-option v-for="item in groupData" :value="item.id" :key="item.id">{{item.name}}</a-select-option>
            </a-select>
          </a-col>
          <a-col :span="6">
            <a-input v-model="search.searchParams.company" placeholder="单位名称" style="width: 100%"/>
          </a-col>
@@ -15,12 +20,13 @@
          <a-col :span="6">
            <a-button type="primary" @click="getUserList" v-preventReClick="1500">查询</a-button>
            <a-button style="margin-left: 12px" @click="resetSearch">重置</a-button>
            <a-button type="danger" style="margin-left: 12px" @click="delBySet">批量删除</a-button>
          </a-col>
        </a-row>
      </a-col>
    </a-row>
    <div class="table-cont">
      <a-table :columns="columns" :data-source="tableData" :pagination="pagination" :rowKey="record=>record.id" bordered>
      <a-table :columns="columns" :data-source="tableData" :pagination="pagination" :rowKey="record=>record.id" bordered :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }">
        <template #unittype="unittype">
          <a-tag
              :color="unittype === 1 ? 'purple' : unittype === 2 ? 'blue' : unittype === 3 ? 'cyan' : 'green'"
@@ -45,7 +51,7 @@
</template>
<script>
import {delRecipient, delUser, getRecipient, getSameLevelGroupList, getUser} from '@/api/user'
import {delRecipient, delRecipientBatch, delUser, getRecipient, getSameLevelGroupList, getUser} from '@/api/user'
import sameLevelMod from "@/views/Admin/components/sameLevelMod"
import {getUserInfo} from "@/util/storage";
import {getDistrictInfo} from "@/api/login";
@@ -67,9 +73,11 @@
          province: '',
          city: '',
          area: '',
          town: ''
          town: '',
          peerRecipientGroupId: undefined
        }
      },
      selectedRowKeys: [],
      columns:[
        {
          title: '单位名称',
@@ -140,31 +148,15 @@
  methods:{
    async getUserList(){
      const t = this
      if(t.search.searchParams.province == '' && t.search.searchParams.city == '' && t.search.searchParams.area == '' && t.search.searchParams.company == ''){
      if(t.search.searchParams.province == '' && t.search.searchParams.city == '' && t.search.searchParams.area == '' && t.search.searchParams.company == '' && t.search.searchParams.peerRecipientGroupId == undefined){
        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
          // for(let i of t.tableData){
          //   if(i.peerRecipientGroupId == null){
          //     i['peerRecipientGroup'] = '未分类'
          //   }else{
          //     getSameLevelGroupList().then((re)=>{
          //       if(re.data.data && re.data.data.length>0){
          //         for(let j of re.data.data){
          //           if(j.id == i.peerRecipientGroupId){
          //             i['peerRecipientGroup'] = j.name
          //           }
          //         }
          //       }
          //     })
          //   }
          // }
        }else{
          t.$message.warning(res.data.msg);
        }
        console.log(t.tableData,'table')
      }else{
        const res = await getRecipient(t.search)
        if(res.data.code == 100){
@@ -191,10 +183,10 @@
      if(res.data.code == 100){
        if(res.data.data){
          let arr = res.data.data
          t.groupData = arr.concat([{id: null, name: '未分类'}])
          t.groupData = arr.concat([{id: -1, name: '未分类'}])
        }else{
          t.groupData = [{
            id: null,
            id: -1,
            name: '未分类'
          }]
        }
@@ -213,7 +205,8 @@
          province: '',
          city: '',
          area: '',
          town: ''
          town: '',
          peerRecipientGroupId: undefined
        }
      }
      t.getUserList()
@@ -225,6 +218,12 @@
      t.$refs.sameLevelMod.areaData = t.areaData
      t.$refs.sameLevelMod.form.unittype = t.unittype
      t.$refs.sameLevelMod.form.districtId = t.districtId
    },
    filterOption(input, option) {
      return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      );
    },
    async delData(row){
@@ -267,6 +266,31 @@
      return null;
    },
    async delBySet(){
      const t = this
      this.$confirm({
        title: '提示',
        content: h => <div>是否删除所选用户信息?</div>,
        cancelText: '取消',
        okText: '确认',
        centered: true,
        onOk() {
          delRecipientBatch(t.selectedRowKeys.join(',')).then(res=>{
            if(res.data.code == 100){
              t.$message.success('删除用户信息成功');
              t.getUserList()
              t.selectedRowKeys = []
            }else{
              t.$message.warning(res.data.msg);
            }
          })
        },
        onCancel() {
          console.log('Cancel');
        },
      });
    },
    onPageChange(page, pageSize) {
      const t= this
      t.pagination.current = page
@@ -280,7 +304,8 @@
        province: '',
        city: '',
        area: '',
        town: ''
        town: '',
        peerRecipientGroupId: undefined
      }
      if(value[0]){
        t.search.searchParams.province = t.findCodeById(t.areaData,value[0]).name
@@ -295,6 +320,13 @@
        t.search.searchParams.town = t.findCodeById(t.areaData,value[3]).name
      }
    },
    handleChange(value) {
      console.log(`selected ${value}`);
      this.getUserList()
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys;
    },
  }
}
</script>