You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.3 KiB

<template>
<el-card id="address-book" class="box-card" shadow="hover">
<div slot="header" class="clearfix">
<SvgIcon style="color: var(--theme-color);width: 22px;height: 22px;" icon-class="address-book" />
<span
style=" padding-left: 15px"
>通讯录</span>
<el-autocomplete
v-model="keyword"
value-key="name"
:fetch-suggestions="querySearch"
placeholder="关键词"
clearable
size="small"
:trigger-on-focus="false"
style="float: right; width: 46%;"
@change="filterList"
/>
</div>
<div class="body" :style="{ 'height': tableHeight + 'px' }">
<el-table
v-loading="loading"
style="width: 100%;"
size="mini"
:header-cell-style="{
'font-weight': '600',
'background': '#f8f8f9',
'color': '#515a6e'
}"
element-loading-text="拼命加载中"
element-loading-spinner="el-icon-loading"
element-loading-background="rgba(255, 255, 255, 0.8)"
:height="tableHeight"
:loading="loading"
:data="lists"
>
<el-table-column type="index" width="46" align="center" />
<el-table-column label="姓名" width="80" prop="name" align="center" />
<el-table-column label="部门" min-width="140" prop="department.name" align="center" />
<el-table-column width="140" prop="mobile" label="手机号" align="center">
<template #default="{ row }">
<div v-if="row.mobile" style="cursor: pointer;" @click="copy2(row.mobile)">
<i class="el-icon-phone" />
<span style="color: var(--theme-color)">{{ row.mobile }}</span>
</div>
</template>
</el-table-column>
</el-table>
</div>
</el-card>
</template>
<script>
import { copy2 } from '@/utils'
import { userListNoAuth as index } from '@/api/common'
import SvgIcon from '@/components/SvgIcon/index.vue'
import ElementResize from 'element-resize-detector'
export default {
name: 'AddressBook',
components: {
SvgIcon
},
layout: {
x: 0,
y: 5,
w: 8,
h: 5,
i: 'AddressBook',
name: '通讯录'
},
data() {
return {
loading: false,
keyword: '',
users: [],
lists: [],
tableHeight: 200
}
},
computed: {},
mounted() {
this.init()
},
created() {
this.getUsers()
},
methods: {
async getUsers() {
try {
this.loading = true
const res = await index({
page: 1,
rows: 999
})
this.users = res.data
this.lists = res.data
this.loading = false
} catch (err) {
this.loading = false
console.error(err)
}
},
copy2,
filterList(e) {
if (!e) {
this.lists = this.users
return
}
this.lists = this.users.filter(this.createFilter(e))
},
createFilter(queryString) {
return (user) => {
return (user.name.toLowerCase().indexOf(queryString.toLowerCase()) === 0)
}
},
querySearch(queryString, cb) {
const users = this.users
const results = queryString ? users.filter(this.createFilter(queryString)) : users
// 调用 callback 返回建议列表的数据
cb(results)
},
init() {
const cardDom = document.getElementById('address-book')
const cardTitleH = 61
const elementResize = ElementResize({
strategy: 'scroll'
})
elementResize.listenTo(cardDom, (ele) => {
this.tableHeight =
cardDom.getBoundingClientRect().height -
40 -
cardTitleH
})
}
}
}
</script>
<style scoped lang="scss">
.body {
overflow: scroll;
ul {
list-style: none;
padding-left: 0;
margin: 0;
li {
line-height: 2;
padding: 8px 10px;
position: relative;
.top {
display: flex;
align-items: center;
}
.bottom {
cursor: pointer;
}
&::before {
background: repeating-linear-gradient(-45deg,#ff976a 0%,#ff976a 20%,transparent 0,transparent 25%,var(--theme-color)0,var(--theme-color)45%,transparent 0,transparent 50%);
content: "";
background-size: 80px;
height: 2px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
}
}
}
</style>