马宇豪
2024-11-12 7a7265353879a63d47553324c19ab4bd349d03f4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<template>
  <div class="inner">
    <a-row type="flex" justify="space-between" style="margin-bottom: 20px">
      <a-col :span="4" v-if="unittype && unittype !== null" style="margin-bottom: 10px">
        <a-button type="primary" @click="editData('add',{})">新增用户</a-button>
      </a-col>
      <a-col :span="24">
        <a-row type="flex" :gutter="24">
          <a-col :span="4">
            <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="3">
            <a-input v-model="search.searchParams.company" placeholder="单位名称" style="width: 100%"/>
          </a-col>
          <a-col :span="3">
            <a-input v-model="search.searchParams.name" placeholder="姓名" style="width: 100%"/>
          </a-col>
          <a-col :span="3">
            <a-input v-model="search.searchParams.phone" placeholder="电话" style="width: 100%"/>
          </a-col>
          <a-col :span="4" v-if="unittype == null || !unittype">
            <a-cascader :options="areaData" v-model="areaVal" placeholder="所属区域" expandTrigger="hover" :fieldNames="fieldNames" changeOnSelect @change="onChange" style="width: 100%"/>
          </a-col>
          <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 :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }">
        <template #unittype="unittype">
          <a-tag
              :color="unittype === 1 ? 'purple' : unittype === 2 ? 'blue' : unittype === 3 ? 'cyan' : 'green'"
          >
            {{ unittype==1?'省级':unittype==2?'地(市、州)级':unittype==3?'区县级':unittype==4?'村(乡、镇)级':'管理员' }}
          </a-tag>
        </template>
        <template #area="text,row">
          <span v-if="row.province !== null && row.province !== ''">{{row.province}}</span>
          <span v-if="row.city !== null && row.city !== ''">-{{row.city}}</span>
          <span v-if="row.area !== null && row.area !== ''">-{{row.area}}</span>
          <span v-if="row.town !== null && row.town !== ''">-{{row.town}}</span>
        </template>
        <template #action="action,row">
          <a-button type="link" @click="editData('edit',row)">编辑</a-button>
          <a-button type="link" class="delBtn" @click="delData(row)">删除</a-button>
        </template>
      </a-table>
    </div>
    <same-level-mod ref="sameLevelMod" @refresh="getUserList"></same-level-mod>
  </div>
</template>
 
<script>
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";
export default {
  name: 'sameLevel',
  components: {
    sameLevelMod
  },
  data () {
    return {
      areaVal: [],
      unittype: null,
      districtId: null,
      search:{
        pageIndex: 1,
        pageSize: 10,
        searchParams:{
          company: '',
          province: '',
          city: '',
          area: '',
          town: '',
          name: '',
          phone: '',
          peerRecipientGroupId: undefined
        }
      },
      selectedRowKeys: [],
      columns:[
        {
          title: '单位名称',
          dataIndex: 'company',
          key: 'company'
        },
        {
          title: '接收人姓名',
          dataIndex: 'recipientName',
          key: 'recipientName'
        },
        {
          title: '所属分组',
          dataIndex: 'peerRecipientGroupName',
          key: 'peerRecipientGroupName'
        },
        {
          title: '手机号码',
          dataIndex: 'phone',
          key: 'phone'
        },
        {
          title: '级别',
          dataIndex: 'unittype',
          // key: 'unittype',
          scopedSlots: { customRender: 'unittype' }
        },
        {
          title: '行政区划',
          dataIndex: 'area',
          // key: 'area',
          scopedSlots: { customRender: 'area' }
        },
        {
          title: '操作',
          width: '12%',
          key: 'action',
          scopedSlots: { customRender: 'action' }
        },
      ],
      tableData: [],
      groupData: [],
      pagination: {
        current: 1,
        defaultCurrent: 1,
        defaultPageSize: 10,
        total: 0,
        onChange: ( page, pageSize ) => this.onPageChange(page,pageSize),
        showTotal: total => `共 ${total} 条`
      },
      areaData: [],
      fieldNames:{
        label: 'name',
        value: 'id',
        children: 'children'
      }
    }
  },
  created() {
    const t = this
    t.groupData = []
    t.unittype = getUserInfo().unittype
    t.districtId = getUserInfo().districtId
    t.getGroupList()
    t.getUserList()
    t.getDistrictInfo()
  },
  methods:{
    async getUserList(){
      const t = this
      if(t.search.searchParams.phone == '' && t.search.searchParams.recipientName == '' && 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
        console.log(data,'data')
        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{
        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);
      }
    },
 
    async getGroupList() {
      const t = this
      const res = await getSameLevelGroupList();
      if(res.data.code == 100){
        if(res.data.data){
          let arr = res.data.data
          t.groupData = arr.concat([{id: -1, name: '未分类'}])
        }else{
          t.groupData = [{
            id: -1,
            name: '未分类'
          }]
        }
      }else{
        this.$message.error(res.data.msg)
      }
    },
    resetSearch(){
      const t = this
      t.areaVal = []
      t.search = {
        pageIndex: 1,
        pageSize: 10,
        searchParams:{
          company: '',
          province: '',
          city: '',
          area: '',
          town: '',
          name: '',
          phone: '',
          peerRecipientGroupId: undefined
        }
      }
      t.getUserList()
    },
 
    editData(type,data){
      const t = this
      t.$refs.sameLevelMod.openDialog(type,data,t.groupData)
      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){
      const t = this
      this.$confirm({
        title: '提示',
        content: h => <div>是否删除该条用户信息?</div>,
        cancelText: '取消',
        okText: '确认',
        centered: true,
        onOk() {
          delRecipient(row.id).then(res=>{
            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;
    },
 
    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
      t.search.pageIndex = page
      t.getUserList()
    },
    onChange(value) {
      const t = this
      t.search.searchParams = {
        company: '',
        province: '',
        city: '',
        area: '',
        town: '',
        name: '',
        phone: '',
        peerRecipientGroupId: undefined
      }
      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
      }
    },
    handleChange(value) {
      console.log(`selected ${value}`);
      this.getUserList()
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys;
    },
  }
}
</script>
 
<style lang="less" scoped>
.delBtn{
  color: @danger
}
</style>