马宇豪
2024-07-19 5bb5c0c4cc1227b0a3f7f4ae926a3e8324022bf9
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<template>
  <div class="inner">
    <a-row>
      <a-col :span="4">
        <a-menu
            style="width: calc(100% - 20px)"
            :default-selected-keys="currentKey"
            :open-keys.sync="openKeys"
            :selectedKeys="currentKey"
            mode="inline"
            @click="handleClick"
        >
          <template v-for="(item,index) in treeData">
            <sub-menu ref="subMenuRef" :key="item.id+'-'+item.name" :menu-info="item"></sub-menu>
          </template>
        </a-menu>
      </a-col>
      <a-col :span="20">
        <div style="display: flex;justify-content: space-between">
          <div>最新更新要求下发时间:{{updateData.gmtModified?updateData.gmtModified:'暂无数据'}}</div>
          <div style="display: flex;align-items: center">
            <div>总数:<span style="color: blue;margin-right: 10px">{{updateData.totalCount?updateData.totalCount:'暂无数据'}}</span>待更新:<span style="color: orange;margin-right: 10px">{{updateData.updateNoCount?updateData.updateNoCount:'暂无数据'}}</span>已更新:<span style="color: green;margin-right: 10px">{{updateData.updateYesCount?updateData.updateYesCount: '暂无数据'}}</span>更新率:<span style="color: blue;margin-right: 10px">{{updateData.updatedRate?updateData.updatedRate + '%':'暂无数据'}}</span></div>
            <a-button type="danger" @click="deliverTask" v-if="!unittype || unittype == 1">下发更新任务</a-button>
          </div>
        </div>
        <div style="margin: 20px 0">
          <a-button  type="primary" style="margin-right: 10px" @click="editData('add',{})">新增</a-button>
          <a-button  type="primary" @click="massImport()">批量导入</a-button>
        </div>
        <div class="table-cont">
          <a-table :columns="columns" :data-source="tableData" :pagination="pagination" :rowKey="record=>record.id" bordered>
            <template #index="text,record,index">
              {{ index + 1 }}
            </template>
            <template #orgName="text,record,index">
              {{currentKey.length>0?currentKey[0].split('-')[1]: ''}}
            </template>
            <template #orgUserTypes="text,record,index">
              {{record.orgUserTypes?record.orgUserTypes.map(i=>i.typeName + '(' + i.orgUserTags.map(j=>j.tagName).join('/') +')').join(','): ''}}
            </template>
            <template #updateStatus="text,record,index">
              <span v-if="text == 0" style="color: green">已更新</span>
              <span v-else style="color: red">待更新</span>
            </template>
            <template #action="action,row">
              <a-button type="link" @click="editData('view',row)">详情</a-button>
              <a-button type="link" @click="editData('edit',row)">更新</a-button>
              <a-button type="link" v-if="row.updateStatus == 1" @click="noNeed(row)">无需更改</a-button>
              <a-button type="link" class="delBtn" @click="delData(row)">删除</a-button>
            </template>
          </a-table>
        </div>
      </a-col>
      <contactors-mod ref="contactMod" @refresh="getUserList()"></contactors-mod>
    </a-row>
    <a-modal v-model="visible" title="导入通讯录" ok-text="导入通讯录" :confirmLoading="uploadLoading" cancel-text="取消" @ok="uploadFile" centered :afterClose="clearMod">
      <a-form-model ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol" :colon="false">
        <a-form-model-item label="通讯录表格模板" extra="导入通讯录须依据此模板">
          <a-button type="primary" @click="downloadFile">下载模板</a-button>
        </a-form-model-item>
        <a-form-model-item label="通讯录表格文件">
          <a-upload :file-list="fileList" :remove="handleRemove" :before-upload="beforeUpload" accept=".xlsx,.xls">
            <a-button> <a-icon type="upload"/> 点击上传 </a-button>
          </a-upload>
        </a-form-model-item>
      </a-form-model>
    </a-modal>
  </div>
</template>
 
<script>
import {getUserInfo} from "@/util/storage";
import {
  getStructure,
  getStructureDetail,
  getUpdateData,
  getContactors,
  delContactors,
  noUpdate, deliverUpdate
} from "@/api/contactBook";
import subMenu from "@/views/Admin/contactBook/subMenu";
import contactorsMod from "@/views/Admin/components/contactorsMod"
import {importUser} from "@/api/user";
import importNew from "@/assets/importNew.xlsx";
import exampleFile from "@/assets/example.xlsx";
 
export default {
  name: 'sameLevel',
  components: {
    subMenu,
    contactorsMod
  },
  data () {
    return {
      visible: false,
      uploadLoading: false,
      fileList: [],
      labelCol: { span: 8 },
      wrapperCol: { span: 14 },
      importNew,
      openKeys: [],
      areaVal: [],
      unittype: null,
      districtId: null,
      currentKey: [],
      search:{
        pageIndex: 1,
        pageSize: 10,
        searchParams: {
          name: '',
          phone: '',
          orgStructureId: null
        }
      },
      columns:[
        {
          title: '序号',
          dataIndex: 'index',
          scopedSlots: {
            customRender: 'index'
          }
        },
        {
          title: '姓名',
          dataIndex: 'name',
          key: 'name',
          align: 'center'
        },
        {
          title: '所属组织架构',
          dataIndex: 'orgName',
          scopedSlots: {
            customRender: 'orgName'
          }
        },
        {
          title: '所属单位',
          dataIndex: 'company',
          key: 'company',
        },
        {
          title: '职务',
          dataIndex: 'post',
          key: 'post',
        },
        {
          title: '电话号码',
          dataIndex: 'phone',
          key: 'phone',
        },
        {
          title: '责任类型',
          dataIndex: 'orgUserTypes',
          scopedSlots: {
            customRender: 'orgUserTypes'
          }
        },
        {
          title: '更新状态',
          dataIndex: 'updateStatus',
          scopedSlots: {
            customRender: 'updateStatus'
          }
        },
        {
          title: '操作',
          width: '12%',
          key: 'action',
          scopedSlots: { customRender: 'action' }
        },
      ],
      treeData: [],
      updateData: {},
      tableData: [],
      pagination: {
        current: 1,
        defaultCurrent: 1,
        defaultPageSize: 10,
        total: 0,
        onChange: ( page, pageSize ) => this.onPageChange(page,pageSize),
        showTotal: total => `共 ${total} 条`
      },
      fieldNames:{
        label: 'name',
        value: 'id',
        children: 'children'
      },
      currentId: null
    }
  },
  created() {
    const t = this
    t.unittype = getUserInfo().unittype
    t.districtId = getUserInfo().districtId
    t.getUserList()
    t.getUpdataData()
    t.getStructure()
  },
  mounted() {
 
  },
  watch: {
    openKeys(val) {
      console.log('openKeys', val);
    }
  },
  methods:{
    downloadFile(){
      const link = document.createElement('a')
      link.href = exampleFile
      link.target = '_blank'
      link.download = '通讯录导入模板.xlsx'
      link.click()
    },
 
    handleRemove(file) {
      const index = this.fileList.indexOf(file)
      const newFileList = this.fileList.slice()
      newFileList.splice(index, 1)
      this.fileList = newFileList;
    },
    beforeUpload(file) {
      this.fileList = [...this.fileList, file]
      this.fileList = this.fileList.slice(-1)
      return false;
    },
 
    async uploadFile(){
      if(!this.currentId || !this.search.searchParams.orgStructureId){
        this.$message.warning('请先在页面左侧单位架构处选择需要导入人员的单位')
        return
      }
      if(this.fileList.length == 0){
        this.$message.warning('请先上传通讯录表格');
        return
      }else{
        this.uploadLoading = true
        const { fileList } = this;
        const formData = new FormData();
        fileList.forEach((file) => {
          formData.append('file', file)
        })
        formData.append('districtId', this.currentId)
        formData.append('orgStructureId', this.search.searchParams.orgStructureId)
        const res = await importUser(formData)
        if(res.data.code == 100){
          this.$message.success(res.data.msg,2);
          this.fileList = []
          this.uploadLoading = false
          this.visible = false
          await this.getUserList()
        }else{
          this.$message.warning(res.data.msg);
          this.uploadLoading = false
        }
      }
    },
    clearMod(){
      this.fileList = []
    },
    async getStructure(){
      const t = this
      const res = await getStructure()
      if(res.data.code == 100){
        t.treeData = res.data.data
        const firstItem = this.firstIdWithOrgStructures(res.data.data[0])
        if(firstItem){
          t.openKeys =  [firstItem.id +'-'+  firstItem.name]
          t.currentId = firstItem.id
          t.currentKey = [firstItem.orgStructures[0].id +'-'+  firstItem.orgStructures[0].orgName]
        }else{
          t.$message.warning('暂无可操作的单位,请先进入“组织架构维护页面”新建相应的本级单位')
        }
      }else{
        t.$message.warning(res.data.msg)
      }
    },
 
 
    firstIdWithOrgStructures(node) {
      if (node.orgStructures && node.orgStructures.length > 0) {
        return node
      }
 
      if (node.children && node.children.length > 0) {
        for (let child of node.children) {
          const result = this.firstIdWithOrgStructures(child);
          if (result) {
            return result
          }
        }
      }
      return null;
    },
 
    async getUpdataData(){
      const t = this
      const res = await getUpdateData();
      if(res.data.code == 100){
        t.updateData = res.data.data
      }else{
        t.$message.warning(res.data.msg);
      }
    },
 
 
    handleClick(e) {
      this.currentId = e.keyPath[1]?e.keyPath[1].split('-')[0]:e.keyPath[0].split('-')[0]
      this.search = {
        pageIndex: 1,
        pageSize: 10,
        searchParams: {
          name: '',
          phone: '',
          orgStructureId: null
        }
      }
      this.currentKey = [e.key]
      this.search.searchParams.orgStructureId = Number(e.key.split('-')[0])
      this.getUserList()
    },
    titleClick(e) {
      console.log('titleClick', e);
    },
    async getUserList(){
      const t = this
      const res = await getContactors(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);
      }
    },
 
    massImport(){
      this.visible = true
    },
 
    resetSearch(){
      const t = this
      t.areaVal = []
      t.search = {
        pageIndex: 1,
        pageSize: 10,
      }
      t.getUserList()
    },
 
    editData(type,data){
      const t = this
      if(type == 'add' && (!t.currentId || !t.currentKey)){
        t.$message.warning('暂无可操作的单位,请先进入“组织架构维护页面”新建相应的本级单位')
        return
      }
      const areaId = t.currentId
      const orgName = t.currentKey.length>0?t.currentKey[0].split('-')[1]: ''
      const orgId = t.currentKey.length>0?t.currentKey[0].split('-')[0]: null
      t.$refs.contactMod.openDialog(type,data,areaId,orgName,orgId)
    },
 
    async delData(row){
      const t = this
      this.$confirm({
        title: '提示',
        content: h => <div>是否删除该条信息?</div>,
        cancelText: '取消',
        okText: '确认',
        centered: true,
        onOk() {
          delContactors(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');
        },
      });
    },
 
    async deliverTask(){
      const t = this
      this.$confirm({
        title: '提示',
        content: h => <div>是否确认下发更新任务?</div>,
        cancelText: '取消',
        okText: '确认',
        centered: true,
        onOk() {
          deliverUpdate().then(res=>{
            if(res.data.code == 100){
              t.$message.success('下发成功')
              t.getUpdataData()
              t.getUserList()
            }else{
              t.$message.warning(res.data.msg);
            }
          })
        },
        onCancel() {
          console.log('Cancel');
        },
      });
    },
 
    async noNeed(row){
      const t = this
      this.$confirm({
        title: '提示',
        content: h => <div>是否确认该信息无需更改?</div>,
        cancelText: '取消',
        okText: '确认',
        centered: true,
        onOk() {
          noUpdate(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');
        },
      });
    },
 
    onPageChange(page, pageSize) {
      const t= this
      t.pagination.current = page
      t.search.pageIndex = page
      t.getUserList()
    },
  }
}
</script>
 
<style lang="less" scoped>
.delBtn{
  color: @danger
}
</style>